Skip to content

EVM: remove contract storage slot when setting to 0 #216

@TorstenStueber

Description

@TorstenStueber

In EVM, some gas will be refunded to the transaction origin whenever a storage slot is set to zero.

In revive, there is already a complete apparatus for executing storage deposit refunds, however, it is not triggered when a storage slot is set to zero.

This logic would need to be implemented in the write_raw function of ContractInfo. Here we calculate a diff that records how many bytes have been added or removed and how many items have been added or removed. Whenever the new value of the slot is 0, we are currently just writing the value 0 into the child trie under the given key. Therefore no bytes or storage slots are removed and the storage deposit meter will not register a refund.

We can change this: if the current contract is an EVM contract, then every storage slot is always occupying a 256-bit word (32 bytes). That means that we can treat storage slots that are not in the child trie as zero and therefore whenever the new value for a storage slot is zero, we can just remove that respective entry from the child trie, create an appropriate diff and ensure that the caller gets a refund.

Important: this only works if the current contract is an EVM contract, so we need to check for that.

Metadata

Metadata

Assignees

Labels

EVMProblem occurs at the execution stage for EVM

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions