Giter VIP home page Giter VIP logo

starknet-tokens-showdown's Introduction

starknet-tokens-showdown

This repo illustrates the difference in gas costs when using a Uint256 and a felt based token on StarkNet.

It contains two ERC20 implementations:

  • the uint one is a copy of OpenZeppelin's ERC20, v0.3.1
  • the afelt one is based on the OZ token with a slight modification of completely dropping the use of Uint256 and replacing if with felts everywhere

I used the standard testing framework to gather the transaction execution resources. The cost calculation is using v.0.8.0 fees and does not take into account storage costs as those would be the same (assuming values less than 2^128).

Here is the breakdown:

approve

# pytest -s tests/uint/test_ERC20.py::test_approve

tests/uint/test_ERC20.py Uint256 test_approve
ExecutionResources(n_steps=501, builtin_instance_counter={'pedersen_builtin': 2, 'range_check_builtin': 10, 'ecdsa_builtin': 1, 'bitwise_builtin': 0, 'output_builtin': 0}, n_memory_holes=17)
Gas cost: 55.45

# pytest -s tests/afelt/test_ERC20.py::test_approve

tests/afelt/test_ERC20.py felt test_approve
ExecutionResources(n_steps=470, builtin_instance_counter={'pedersen_builtin': 2, 'range_check_builtin': 6, 'ecdsa_builtin': 1, 'bitwise_builtin': 0, 'output_builtin': 0}, n_memory_holes=16)
Gas cost: 52.3

transfer

# pytest -s tests/uint/test_ERC20.py::test_transfer

tests/uint/test_ERC20.py Uint256 test_transfer
ExecutionResources(n_steps=889, builtin_instance_counter={'pedersen_builtin': 4, 'range_check_builtin': 32, 'ecdsa_builtin': 1, 'bitwise_builtin': 0, 'output_builtin': 0}, n_memory_holes=46)
Gas cost: 84.45000000000002

# pytest -s tests/afelt/test_ERC20.py::test_transfer

tests/afelt/test_ERC20.py felt test_transfer
ExecutionResources(n_steps=673, builtin_instance_counter={'pedersen_builtin': 4, 'range_check_builtin': 17, 'ecdsa_builtin': 1, 'bitwise_builtin': 0, 'output_builtin': 0}, n_memory_holes=80)
Gas cost: 67.65

transferFrom

# pytest -s tests/uint/test_ERC20.py::test_transferFrom
tests/uint/test_ERC20.py Uint256 test_transferFrom
ExecutionResources(n_steps=1305, builtin_instance_counter={'pedersen_builtin': 8, 'range_check_builtin': 51, 'ecdsa_builtin': 1, 'bitwise_builtin': 0, 'output_builtin': 0}, n_memory_holes=67)
Gas cost: 114.45

# pytest -s tests/afelt/test_ERC20.py::test_transferFrom
tests/afelt/test_ERC20.py felt test_transferFrom
ExecutionResources(n_steps=905, builtin_instance_counter={'pedersen_builtin': 8, 'range_check_builtin': 25, 'ecdsa_builtin': 1, 'bitwise_builtin': 0, 'output_builtin': 0}, n_memory_holes=138)
Gas cost: 84.05000000000001

Results

Cost values from the results above are rounded-up:

approve transfer transferFrom
Uint256 56 85 115
felt 53 68 85
savings (%) 5.3 20 26

starknet-tokens-showdown's People

Contributors

milancermak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.