Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Implement SSTORE net gas metering in aleth-interpreter #5238

Merged
merged 4 commits into from
Sep 5, 2018

Conversation

gumb0
Copy link
Member

@gumb0 gumb0 commented Sep 3, 2018

Closes #5226

Includes the changes due to EVMC API change (in the separate commit)

@codecov-io
Copy link

codecov-io commented Sep 3, 2018

Codecov Report

Merging #5238 into master will increase coverage by 0.11%.
The diff coverage is 69.91%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #5238      +/-   ##
==========================================
+ Coverage    60.9%   61.01%   +0.11%     
==========================================
  Files         338      338              
  Lines       27589    27649      +60     
  Branches     3197     3203       +6     
==========================================
+ Hits        16802    16871      +69     
+ Misses       9664     9649      -15     
- Partials     1123     1129       +6

@@ -1356,22 +1356,19 @@ void VM::interpretCases()
if (m_message->flags & EVMC_STATIC)
throwDisallowedStateChange();

static_assert(
Copy link
Member Author

@gumb0 gumb0 Sep 3, 2018

Choose a reason for hiding this comment

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

For the sake of simplicity I got rid of the trick to charge sstoreSetGas before set_storage`.

To keep it I think we would need to handle pre-Constantinople as an additional special case. In Constantinople we can't know before actually calling set_storage whether the change will require DB write, or will be just a dirty write (unless we decide to provide access to "original storage values" to EVM)

Copy link
Member Author

Choose a reason for hiding this comment

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

Now I'm not sure if this is much simpler because it turns out we still need to handle Constantinople here differently (difference in the cost of X->X)
Here's the version with Constantinople as a separate case and keeping the old optimization: #5240

Copy link
Member

Choose a reason for hiding this comment

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

I think to be safe we should charge more/less the SLOAD cost, so sstoreUnchangedGas is good candidate and handles both pre and post Constantinople cases.
We want to make sure the sstoreUnchangedGas is the smallest from all SSTORE possible costs. Would be nice to use std::min here but it started be a constexpr function in C++14.

@gumb0 gumb0 removed the in progress label Sep 3, 2018
@gumb0 gumb0 requested a review from chfast September 3, 2018 15:22
Copy link
Member

@chfast chfast left a comment

Choose a reason for hiding this comment

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

Can we move the EVMC upgrade commit up front, maybe even as its own PR?

evmc_result evmcResult = {};
evmcResult.status_code = result.status;
evmcResult.gas_left = static_cast<int64_t>(gas);
evmcResult.release = nullptr;
Copy link
Member

Choose a reason for hiding this comment

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

This is not needed.

o_result->output_data = nullptr;
o_result->output_size = 0;
evmcResult.create_address = toEvmC(result.address);
evmcResult.output_data = nullptr;
Copy link
Member

Choose a reason for hiding this comment

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

This is not needed.

@@ -1356,22 +1356,19 @@ void VM::interpretCases()
if (m_message->flags & EVMC_STATIC)
throwDisallowedStateChange();

static_assert(
Copy link
Member

Choose a reason for hiding this comment

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

I think to be safe we should charge more/less the SLOAD cost, so sstoreUnchangedGas is good candidate and handles both pre and post Constantinople cases.
We want to make sure the sstoreUnchangedGas is the smallest from all SSTORE possible costs. Would be nice to use std::min here but it started be a constexpr function in C++14.

status = EVMC_STORAGE_ADDED;
else if (value == 0)
u256 const originalValue = env.originalStorageValue(index);
if (originalValue == currentValue || !schedule.eip1283Mode)
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be simplified. We should report EVMC_STORAGE_MODIFIED_DIRTY also in pre-Constantinople. It will be simply handled together with EVMC_STORAGE_MODIFIED.

@chfast chfast merged commit ebae1d7 into master Sep 5, 2018
@gumb0 gumb0 deleted the net-sstore-interpreter branch September 5, 2018 15:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants