Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a set_storage_or_clear that deletes an storage item if 0u256 is passed as value #6944

Open
athei opened this issue Dec 18, 2024 · 3 comments

Comments

@athei
Copy link
Member

athei commented Dec 18, 2024

On Ethereum writing zero to a key constitutes deleting the key. We should add a new host function that behaves the same as set_storage except that the value is deleted if zero is passed. This is useful because it allows refunding the storage deposit when a key is deleted.

Note that revive could do that without any new host function by calling clear_storage in case the key is zero. However, this would increase contract code by adding this additional check.

In the same vein we could also add a get_storage_or_zero that returns 0 of the key does not exist. It would remove some code from the contract that is needed to check the return value of get_storage.

cc @xermicus

@athei athei converted this from a draft issue Dec 18, 2024
@xermicus
Copy link
Member

xermicus commented Dec 18, 2024

Good idea, I think we might just want to provide EVM tailored storage setters and getters but leave the more generic ones intact for other languages that are more flexible?

Regarding set_storage, other contract languages might not be limited to 32 byte storage values, and if the value is large the check might get costly and unwanted? Maybe for Solidity we should just add a set_storage_or_delete which accepts 32 bytes key and value and deletes the key if the value equals zero?

For the getter, how I implemented it in revive for now is contracts zero out the output buffer of get_storage and ignore the return value. Which results in the desired behavior. However it would be slightly more efficient if the pallet would do it. We could just change get_storage to resemble the EVM semantics, however other languages might have a use case for a fallible get_storage method, so adding an infallible get_storage_or_zero host function seems sensible to me.

@athei
Copy link
Member Author

athei commented Dec 18, 2024

Yes, the idea is to add two new functions tailored towards EVM and leave the other ones intact.

@xermicus
Copy link
Member

Sounds good. I can take care of this, i.e. implementing those pallet-revive plus a companion in revive. But I'll not assign it just yet as it's also a good first issue for anyone wanting to help out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Nice to have
Development

No branches or pull requests

2 participants