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
Scratch space #167
Comments
Wouldn't this make more sense as an EVM feature? Alternately, could the gas model be adjusted so that nearly all the cost of an SSTORE is refunded at the end of the call if it resulted in no committable changes to state? |
I would like to present another use-case, where this can be of great use. |
There has been no activity on this issue for two months. It will be closed in a week if no further activity occurs. If you would like to move this EIP forward, please respond to any outstanding feedback or add a comment indicating that you have addressed all required feedback and are ready for a review. |
This issue was closed due to inactivity. If you are still pursuing it, feel free to reopen it and respond to any feedback or request a review in a comment. |
Specification
If
block.number >= FORK_BLKNUM
, add two precompile contracts at addresses 0x0e and 0x0f. Both contracts shard 1 gas per byte of calldata plus 20 base gas cost. The contracts work as follows:0x0e
: All bytes of the calldata except for the first 32 are saved in a new key/value map usingsha3(sender) xor sha3(target)
as a key wheretarget
is the address in the first 32 bytes andsender
is the sender of the call.0x0f
: Immediately return the calldata saved in the key/value map usingsha3(sender) xor sha3(target)
as a key wheretarget
is the address in the first 32 bytes of calldata as a key andsender
is the sender of the call.The key/value map is reset at the end of processing every transaction.
Rationale
This allows for certain kinds of applications to be built more cheaply, safely and efficiently. For example, consider the use case of sending ERC20 tokens along with a call. The current workflow is:
However, this is ugly, requiring ERC20 tokens to have a complex withdrawal feature, and is gas-inefficient, requiring four SSTOREs: (i) creating the withdrawal authorization, (ii) decreasing sender's ERC20 token balance, (iii) increasing the contract's ERC20 token balance, (iv) removing the withdrawal authorization. Also, it requires a call to the token contract as the first operation of the contract's code, before other state changes; if the token is untrusted this may lead to re-entrancy vulnerabilities.
Using scratch space, we can change the mechanism to the following:
This now only requires two SSTOREs, to do the actual balance change, and so has a gas cost that is proportional to the actual cost of what took place. Re-entrancy is no longer an issue.
Another use case is mutex locks - a contract may put a mutex flag into some scratch space, using a random address as a target, thereby avoiding the 10000 gas cost of having a mutex feature. A third is as a general call-deferral technique to avoid re-entrancy issues, where instead of making a call immediately, the contract saves a record in scratch space and then allows the sender to later call the contract and "consume" the record. A final important use case is for keeping track of intermediate variables for purposes of gas payment in the context of EIP #86.
The text was updated successfully, but these errors were encountered: