Is the compiled code charged storage fees also?

taramanictaramanic Member Posts: 24 ✭✭
I'm re-designing my system in a way that pushes as much storage out to the clients.
However, in the process I'm needing to create a fairly substantial increase in contract code in order to verify that users are not cheating the contract.

So, is the compiled code charged storage fees also?
The fee system is not clear to me yet. All I've heard is that storage is expensive and communicating between contracts is cheap.

Comments

  • tomgalvintomgalvin Member Posts: 10
    If my understanding of the Yellow Paper is correct, then gas for storing contract code G_createdata is a comparatively cheap 5 gas per byte, as opposed the average 100 gas per word for storage. Note that the gas for storing code is only payed once during contract creation, whereas storage might need to be paid for during every transaction. Rather than comparing the recurring data storage cost to one-time code storage cost, you should really be comparing it do the increase in gas cost of the actual code execution: it's not worth it to need to verify 10 signatures just to be able to avoid storing one word.
  • GlasswalkerGlasswalker CanadaMember Posts: 7
    Storage isn't paid for every tx, only on create/write. Fee is charged on storage cell (256bit) granularity. Last data I saw is very high for create 20k gas, less for modify 5k gas. But most execution averages 2-5 gas per evm operation.

    Don't remember how evm code itself is charged though. I suspect it stores at same cost but packs multiple evm instructions into a cell... I know I've actually hit the gas limit on one of my contracts because of code complexity.

    Also keep in mind you pay fee for initial upload but also execution of constructor, so any initial storage instantiated and/or written to is charged at that time as well.

    And Tomgalvin is correct, you pay on upload of contract once, and only once. After that tx fees are gas cost of operations and any storage either newly created or altered by the tx.

    Example: if you have a contract that consumes 100k gas for its evm code, and it has a constructor and 2 methods, if method one creates a new storage cell and writes to another (for example adding to an array and updating a counter) and the second method is declared constant and only reads values, and the constructor initializes 5 storage cells.

    Then in the example you would pay (based on the rough numbers I me time above) approx 200k gas to upload it. And any user calling method one would then pay 25k gas (maybe 26k if you have 200-300 instructions of logic being executed) per tx... And a user calling method 2 would pay nothing (client side call only). But if another contract calls method 2 and that contract isn't constant it would need to pay the gas for the instructions to execute only...

    I may have that wrong of course, this is just what I've figured out so far building and testing my dapps... (I think lol)

    Hope that helps. Perhaps someone from ethdev can comment more clearly? :smiley:
Sign In or Register to comment.