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

Wrong GasCost for CALLs with value transfer on StorageRent (RSKIP240) #279

Open
fedejinich opened this issue Sep 27, 2021 · 2 comments
Open
Assignees
Labels

Comments

@fedejinich
Copy link
Contributor

fedejinich commented Sep 27, 2021

According to the RSKIP240, CALLs with value transfer are priced with 9000 gas, but that's not the actual RSK implementation. If you execute a CALL opcode, it will require at first 700 gas (CALL), then if you're sending value, you'll need to charge an extra of 9000 gas (VT_CALL).

To be more precisely the actual gas cost for a CALL with value transfer it's given by:

CALL (with value > 0): CALL (700) + VT_CALL (9000) = 9700 gas

NOTE: I'm excluding the STIPEND_CALL (2300) gas cost

@fedejinich fedejinich added the bug label Sep 27, 2021
@fedejinich
Copy link
Contributor Author

fedejinich commented Sep 27, 2021

Another find

Value-transferring CALLs cost 9000 gas. From this 9000, an amount 2300 gas is subtracted as a call stipend and passed to the receiving contract. The stipend is intended to cover the cost for logging the value transfer. If the receiving contract performs any BAL or SLOAD operations as part of logging, and if enough rent has accumulated in those accounts or storage cells, then some CALLs may fail.

This is not what's actually happening in rskj, a CWV it's priced at 9700 gas, then the STPIEND cost it's also charged (but not taken from the 9700), making the whole CWV cost 12000.

@smishraIOV smishraIOV self-assigned this Sep 30, 2021
@smishraIOV
Copy link
Contributor

Thanks for pointing out these mistakes. The 700 gas for CALL is an obvious miss and it directly affects the fixed costs. This will be updated in the next version. The fact that the 2300 gas for call_stipend is added on top of the 9700 (and not sourced from it) does not change the backwards compatibility issue. But it is a factual error and will be corrected.

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

No branches or pull requests

2 participants