1

For a smart contract idea that spins around in my head, I have the situation where I have to conserve the old values of a variable (no storage refund or cheaper SSTORE updates). As the value I write is comparatively big I wanted to estimate the gas cost that will occur and I realized that it would be cheaper to each time create a new contract with the data as code and then read it over EXTCODECOPY instead of using SSTORE and SLOAD.

A CREATE costs according to the yellow paper 32000 + 6400 per word (200 per byte), whereas an SSTORE costs 20000 per Word. in the CREATE case another 20000 are needed to store the address, so already with 4+ words stored the contract creation is cheaper.

An EXTCODECOPY costs 700 + 3 per Word (+200 to load the address with LOAD), whereas the SLOAD costs 200 per word. Here we need 5+ words for the contract creation to be cheaper.

I'm interested in the reason behind this, why is the intended way more expensive than a way where we misuse the CREATE opcode. Is one of the two ways underpriced or overpriced?

Even if in cases where the updating SSTORE (cost 5000 instead of 20000) is used it would still be beneficial in the cases where we update rarely in comparison to the expected reads.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.