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

Implement gas refund #493

Merged
merged 8 commits into from
Aug 19, 2022
Merged

Implement gas refund #493

merged 8 commits into from
Aug 19, 2022

Conversation

chfast
Copy link
Member

@chfast chfast commented Aug 18, 2022

Calculate, aggregate and report the gas refund. This requires changes to SSTORE, SELFDESTRUCT and calls (propagate gas refund).

@chfast chfast requested review from axic, gumb0 and yperbasis August 18, 2022 12:18
@chfast chfast force-pushed the refund branch 2 times, most recently from bb7d211 to a6121d0 Compare August 18, 2022 12:40
@codecov
Copy link

codecov bot commented Aug 18, 2022

Codecov Report

Merging #493 (490116d) into master (08c97c8) will increase coverage by 0.01%.
The diff coverage is 100.00%.

❗ Current head 490116d differs from pull request most recent head 366853b. Consider uploading reports for the commit 366853b to get more accurate results

@@            Coverage Diff             @@
##           master     #493      +/-   ##
==========================================
+ Coverage   99.39%   99.40%   +0.01%     
==========================================
  Files          53       53              
  Lines        5145     5249     +104     
==========================================
+ Hits         5114     5218     +104     
  Misses         31       31              
Flag Coverage Δ
consensus 78.95% <100.00%> (-0.29%) ⬇️
statetests 7.59% <5.14%> (-0.03%) ⬇️
unittests 99.55% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
lib/evmone/execution_state.hpp 94.64% <ø> (ø)
lib/evmone/advanced_execution.cpp 100.00% <100.00%> (ø)
lib/evmone/baseline.cpp 100.00% <100.00%> (ø)
lib/evmone/instructions.hpp 100.00% <100.00%> (ø)
lib/evmone/instructions_calls.cpp 100.00% <100.00%> (ø)
lib/evmone/instructions_storage.cpp 100.00% <100.00%> (ø)
test/unittests/evm_calls_test.cpp 100.00% <100.00%> (ø)
test/unittests/evm_state_test.cpp 100.00% <100.00%> (ø)
test/unittests/evm_storage_test.cpp 100.00% <100.00%> (ø)
test/utils/bytecode.hpp 95.95% <100.00%> (+0.02%) ⬆️

@chfast chfast force-pushed the instructions_storage branch from 7e25e13 to 5350ed2 Compare August 18, 2022 14:23
Base automatically changed from instructions_storage to master August 18, 2022 14:49
int64_t expected_gas_refund) {
auto& storage = host.accounts[msg.recipient].storage;
storage[key] = {current, original};
execute(sstore(0xef, calldataload(0)), value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe could be simpler

Suggested change
execute(sstore(0xef, calldataload(0)), value);
execute(sstore(0xef, value), {});

int64_t clear = -1;
};

auto test = [this](const evmc::bytes32& original, const evmc::bytes32& current,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this helper be reused between two tests?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is rather difficult because it accesses this.

EXPECT_GAS_USED(EVMC_SUCCESS, 7603); // Cold access to 0xbe.
EXPECT_EQ(result.gas_refund, 24000);

// Second selfdestruct of the same account.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also add a test for another selfdestruct of different account


const auto a = 0xaa_address;
const auto code =
call(a) + callcode(a) + delegatecall(a) + staticcall(a) + create() + create2();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be redundant, but I thought of having two calls of each type to check that it's also aggregated for same type calls.

Copy link
Member

@gumb0 gumb0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, some minor suggestions only in tests.

@chfast chfast merged commit bb1e353 into master Aug 19, 2022
@chfast chfast deleted the refund branch August 19, 2022 16:46
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

Successfully merging this pull request may close these issues.

2 participants