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

Tune the cost of EXTCALL with value #94

Closed
chfast opened this issue Apr 24, 2024 · 5 comments
Closed

Tune the cost of EXTCALL with value #94

chfast opened this issue Apr 24, 2024 · 5 comments
Assignees

Comments

@chfast
Copy link
Member

chfast commented Apr 24, 2024

There is the table comparing the gas and costs of all legacy and EOF calls.

Cost (burned) Callee min Callee max Min retained
CALL V=0 100 0 g - g/64 g/64
CALL V≠0 100+6700 2300 g - g/64 g/64
DELEGATECALL 100 0 g - g/64 g/64
STATICCALL 100 0 g - g/64 g/64
EXTCALL V=0 100 2300 g - max(g/64, 5000) 5000
EXTCALL V≠0 100+9000 2300 g - max(g/64, 5000) 5000
EXTDELEGATECALL 100 2300 g - max(g/64, 5000) 5000
EXTSTATICCALL 100 2300 g - max(g/64, 5000) 5000

Note that in legacy the additional value transfer cost in CALL is 6700 while in EXTCALL this is 9000.

This is because of how stipend is applied in legacy and how we do it in EXTCALL. I think it is just a coincidence and we should fix it.
I.e. in legacy CALL the stipend gas (2300) is added from nowhere so the actual value transfer is 6700 not 9000. Try sending a value to an empty contract, you will get the 2300 back.
In EOF we kinda implemented it properly so the cost is actually 9000.

@axic
Copy link
Member

axic commented Apr 24, 2024

How about also defining the retained gas not by a fixed number, but rather as i.e. "maximum cost of SSTORE * 1.5x" ?

Also left this comment on #95.

@chfast
Copy link
Member Author

chfast commented Apr 26, 2024

I reviewed the implementation of CALL and EXTCALL and there are some important details:

  1. In CALL relation between the value transfer cost (9000) and the stipend (2300) is more convoluted than presented in the table above. Some checks and calculations (including 63/64 rule) are performed in the context where 9000 cost is already burned but the 2300 stipend is not added back yet. E.g. a CALL can fail of OOG if it cannot cover the 9000 cost although the total gas balance would be positive if the callee returned any of its stipend back.
  2. In EXTCALL the stipend mechanism is replaced with "min callee gas". This is worth mentioning in https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7069.md#stipend-and-6364th-rule.

So the conclusion is: if the value transfer in EXTCALL is lowered from 9000 to 6700 its behavior will be closer to CALL but not identical. Main differences are:

  • in EXTCALL the callee will receive more gas because the 63/64 rule is calculated out of higher value.
  • there are cases where CALL fails of OOG while EXTCALL can go though.

In my opinion keeping the cost of 9000 is still slightly better than changing to 6700.

@chfast
Copy link
Member Author

chfast commented Apr 29, 2024

Updated table. What do you think?

Caller required gas Caller cost (burned gas) Caller min retained gas Callee min gas
CALL V=0 100 100 0 0
CALL V≠0 100+9000 100+6700 0 2300
DELEGATECALL 100 100 0 0
STATICCALL 100 100 0 0
EXTCALL V=0 100 100 5000 2300
EXTCALL V≠0 100+9000 100+9000 5000 2300
EXTDELEGATECALL 100 100 5000 2300
EXTSTATICCALL 100 100 5000 2300
  • caller required gas: the minimum amount of gas a caller is required to have to execute a call instruction, lower value causes caller's OOG,
  • caller cost: the amount of gas deducted from the caller to execute the instruction, this amount is not available to the callee,
  • caller min retained gas: the minimum amount of gas the caller is guaranteed to have after the call, if this cannot be guaranteed the call fails with 0 without even reaching the callee,
  • callee min gas: the minimum gas limit for the callee's execution.

@chfast
Copy link
Member Author

chfast commented Apr 29, 2024

Posted the EIP update: ethereum/EIPs#8506

@chfast
Copy link
Member Author

chfast commented May 10, 2024

The "rough consensus" is not to change the 9000 value.

@chfast chfast closed this as completed May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants