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

core, params: implement EIP-1087, net storage gas metering #17208

Closed
wants to merge 2 commits into from

Conversation

karalabe
Copy link
Member

@karalabe karalabe commented Jul 19, 2018

Implements https://eips.ethereum.org/EIPS/eip-1087.

An important thing to note in this PR: Until now, the dirtyStorage set inside the stateObject was an optimization. It of course correctly tracked the dirtiness when something was changed, but code until now didn't much care about revertals (i.e. it still kept it dirty). This was not an issue because it was just a tiny amount of extra work during commit. With the net gas metering EIP enabled however, the SSTORE gas costs depend on accurate tracking of the dirtiness, so we need to take better care from now on (i.e. this PR starts tracking the dirtiness in the journal too).

The EIP doesn’t really specify what happens if an inner transaction makes a storage slot dirty, but then reverts. Should the slot be reverted to clean (thus incurring an additional gas hit when modifying it again), or should the slot be kept dirty? Our code currently reverts the dirtiness too but I guess we can change if needed. However this is an important subtlety to emphasize in the spec. Clarified in the EIP.

Ping @Arachnid, PTAL.

@karalabe karalabe requested a review from holiman as a code owner July 19, 2018 12:35
//
// 1. When a storage slot is written to for the first time, the slot is marked
// as dirty. If the slot was previously set to 0, 20000 gas is deducted;
// otherwise, 5000 gas is deducted. If the slot was previously set to 0,
Copy link
Contributor

Choose a reason for hiding this comment

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

Per our earlier conversation, this probably needs rewording, to make it clear that setting something to the value it already contains only charges 200 gas and doesn't set the dirty bit.

@@ -160,16 +160,20 @@ func (c *stateObject) getTrie(db Database) Trie {
}

// GetState returns a value in account storage.
Copy link
Member

Choose a reason for hiding this comment

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

Comment should say that it returns now dirty flag, too

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated.

@karalabe karalabe force-pushed the net-sstore-metering branch from 65836bd to 3acffa9 Compare August 6, 2018 10:02
return params.NetSstoreCleanInitgas, nil
case !dirty && y.Sign() != 0: // clean(non 0) => anything
return params.NetSstoreCleanUpdateGas, nil
default: // dirty(anything) => anything
Copy link
Contributor

@AlexeyAkhunov AlexeyAkhunov Aug 10, 2018

Choose a reason for hiding this comment

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

default here also includes the case !dirty && y.Sign() == 0, which per specification should charge 5k, not 200

@karalabe
Copy link
Member Author

karalabe commented Aug 10, 2018 via email

@AlexeyAkhunov
Copy link
Contributor

I think part of this PR (replacing "cachedStorage" with "originStorage") could be merged regardless of whether EIP-1087 gets implemented. I am taking this part to Turbo-Geth, because it allows it to avoid writes of the storage values that did not change

@fjl fjl added the eip label Sep 5, 2018
@holiman holiman closed this Oct 10, 2018
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.

7 participants