Skip to content

Commit

Permalink
Tracing - respect tx boundary for EIP-2200 cost calculations (#339)
Browse files Browse the repository at this point in the history
When we calculate the cost of a SSTORE in trace we need to consider the
original value as of when the last transaction finished, not when the
whole block started.

To create a test for this the test blockchain also needed to be upgraded
to Istanbul.  This resulted in a large number of cost only changes.

Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
  • Loading branch information
shemnon authored Jan 29, 2020
1 parent 5b1ee14 commit 0b9b68f
Show file tree
Hide file tree
Showing 50 changed files with 1,099 additions and 665 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor;

import org.hyperledger.besu.ethereum.api.jsonrpc.internal.processor.BlockReplay.TransactionAction;
import org.hyperledger.besu.ethereum.core.AbstractWorldUpdater;
import org.hyperledger.besu.ethereum.core.AbstractWorldUpdater.StackedUpdater;
import org.hyperledger.besu.ethereum.core.Block;
import org.hyperledger.besu.ethereum.core.Hash;
import org.hyperledger.besu.ethereum.core.WorldUpdater;
Expand Down Expand Up @@ -51,6 +53,8 @@ private TransactionAction<TransactionTrace> prepareReplayAction(
// if we have no prior updater, it must be the first TX, so use the block's initial state
if (chainedUpdater == null) {
chainedUpdater = mutableWorldState.updater();
} else if (chainedUpdater instanceof AbstractWorldUpdater.StackedUpdater) {
((StackedUpdater) chainedUpdater).markTransactionBoundary();
}
// create an updater for just this tx
chainedUpdater = chainedUpdater.updater();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ public Stream<Trace> generateStateDiff(final TransactionTrace transactionTrace)
updatedAccount.getUpdatedStorage().entrySet()) {
final UInt256 originalValue = rootAccount.getStorageValue(entry.getKey());
final UInt256 newValue = entry.getValue();
storageDiff.put(
entry.getKey().toHexString(),
new DiffNode(originalValue.toHexString(), newValue.toHexString()));
if (!originalValue.equals(newValue)) {
storageDiff.put(
entry.getKey().toHexString(),
new DiffNode(originalValue.toHexString(), newValue.toHexString()));
}
}

// populate the diff object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@
"gasPrice": "0xEF",
"to": "0x0010000000000000000000000000000000000000",
"data": "0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004"
},
{
"comment": "Set contract storage (key,value)'s: (1,3),(1,0)",
"secretKey": "0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3",
"gasLimit": "0xFFFFF2",
"gasPrice": "0xEF",
"to": "0x0010000000000000000000000000000000000000",
"data": "0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000300000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"constantinopleFixBlock": 0,
"istanbulBlock": 0,
"ethash": {
"fixeddifficulty": 15
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"balance": {
"*": {
"from": "0x3782dace9ddc9578",
"to": "0x3782dace9ea423b8"
"to": "0x3782dace9ea1ac9c"
}
},
"code": "=",
Expand All @@ -33,7 +33,7 @@
"balance": {
"*": {
"from": "0xeffffffffffffffffb36a87",
"to": "0xefffffffffffffffeebdc47"
"to": "0xefffffffffffffffeee5363"
}
},
"code": "=",
Expand Down Expand Up @@ -62,7 +62,7 @@
{
"action": {
"from": "0x627306090abab3a6e1400e9345bc60c78a8bef57",
"gas": "0xff2d6a",
"gas": "0xff300e",
"init": "0x6004600c60003960046000f3600035ff",
"value": "0x0"
},
Expand All @@ -88,7 +88,7 @@
"0x4"
],
"store": null,
"used": 16723303
"used": 16723979
},
"pc": 0,
"sub": null
Expand All @@ -101,7 +101,7 @@
"0xc"
],
"store": null,
"used": 16723300
"used": 16723976
},
"pc": 2,
"sub": null
Expand All @@ -114,7 +114,7 @@
"0x0"
],
"store": null,
"used": 16723297
"used": 16723973
},
"pc": 4,
"sub": null
Expand All @@ -128,7 +128,7 @@
},
"push": [],
"store": null,
"used": 16723288
"used": 16723964
},
"pc": 6,
"sub": null
Expand All @@ -141,7 +141,7 @@
"0x4"
],
"store": null,
"used": 16723285
"used": 16723961
},
"pc": 7,
"sub": null
Expand All @@ -154,7 +154,7 @@
"0x0"
],
"store": null,
"used": 16723282
"used": 16723958
},
"pc": 9,
"sub": null
Expand All @@ -165,7 +165,7 @@
"mem": null,
"push": [],
"store": null,
"used": 16723282
"used": 16723958
},
"pc": 11,
"sub": null
Expand Down
Loading

0 comments on commit 0b9b68f

Please sign in to comment.