Implement eip1380 (call-to-self) in LegacyVM#5752
Conversation
Codecov Report
@@ Coverage Diff @@
## master #5752 +/- ##
==========================================
+ Coverage 63.9% 64.01% +0.11%
==========================================
Files 359 359
Lines 30667 30770 +103
Branches 3410 3417 +7
==========================================
+ Hits 19597 19698 +101
- Misses 9841 9843 +2
Partials 1229 1229 |
724c168 to
6f1b57b
Compare
|
Need to move changes to Berlin schedule once #5754 is merged |
317a70e to
4a1ee51
Compare
|
cc @gumb0 |
|
Marking as in-progress since I'm adding call tests (non-call-to-self cases) as a part of this PR |
9c893f1 to
62c1bc2
Compare
|
Rebased + squashed some commits |
62c1bc2 to
c6974db
Compare
|
@gumb0 / @chfast These changes are ready for review again. Some things to call out:
|
Charge a reduced gas fee for calls to functions within the same contract
The tests exercise CALL/CALLCODE/DELEGATECALL/STATICCALL
Remove need for eip1380 schedule flag Simplify gas adjustment for call-self case Make minor updates to call self VM test
c6974db to
b20e385
Compare
|
Rebased + moved EIP to Berlin hardfork |
| vm->exec(gas, extVm, onOp); | ||
| // Subtract the call stipend gas since there's no code at the address being called | ||
| unsigned int gasExpected = | ||
| extVm.evmSchedule().callValueTransferGas - extVm.evmSchedule().callStipend; |
There was a problem hiding this comment.
I'm a bit lost about this. Can you explain how it can cost less than transfer gas?
There was a problem hiding this comment.
@gumb0 Yes - according to the definition of the call stipend (gcallstipend) in the YP, the call stipend is subtracted from the value transfer gas (for a non-zero value transfer). Additionally, the call stipend is added to the gas being passed to the call and its purpose is to ensure that there's just enough gas for the contract's fallback function to perform some basic steps (e.g. log something), but not enough for it to do something nefarious. Also, gas not used in a contract call is refunded to the caller. So, since there's no code at the addresses being called in my test cases, there's no fallback function to execute and therefore the stipend is refunded
| auto const destinationAddr = asAddress(m_SP[1]); | ||
| if (callParams->staticCall && isPrecompiledContract(destinationAddr)) | ||
| m_runGas = toInt63(m_schedule->precompileStaticCallGas); | ||
| m_runGas += toInt63(m_schedule->precompileStaticCallGas); |
There was a problem hiding this comment.
@halfalicious I just noticed that this became +=, why?
https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1380.md
Charge a reduced gas fee (40 vs 700) for calls (call/callcode/delegatecall/staticcall) to functions within the same contract.
Add unit tests for both call-to-self and non-call-to-self cases (for call/callcode/delegatecall/staticcall)