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

EIP-1153: Transient storage opcodes #4118

Merged
merged 67 commits into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
518a259
Exploratory changes
codyborn Jul 13, 2022
930066b
Add Shanghai fork
codyborn Jul 15, 2022
20a5c86
Multi-contract tests
codyborn Jul 15, 2022
b77a993
More tests; handle transient state across frames
codyborn Jul 16, 2022
4edfd8d
Moar tests
codyborn Jul 16, 2022
85d06e3
Backward sync exception improvements (#4092)
fab-10 Jul 13, 2022
6af79cb
Finalised blocks should not prevent reorgs in BWS (#4097)
gezero Jul 14, 2022
82d0cb6
delegate all the block checks and validation to the block import phas…
fab-10 Jul 14, 2022
4564178
Ignore 2 tests that assume that the system language is English, if th…
daniellehrner Jul 14, 2022
5b41dcf
Fix PR 4098 (#4106)
fab-10 Jul 14, 2022
0a65802
log execution errors at right level, stops transition message propaga…
jflo Jul 14, 2022
ad0890a
Add experimental config option to enable v5 discovery (#4103)
Gabriel-Trintinalia Jul 15, 2022
e520669
Move Taccat to Emeritus (#4033)
shemnon Jul 15, 2022
743fa0a
Remove hash to append from the queue only if the step succeeds (#4105)
fab-10 Jul 15, 2022
df43a9d
Create backward sync retries on demand (#4095)
fab-10 Jul 15, 2022
21a7054
Update checkpoint sync for merge (#4085)
matkt Jul 15, 2022
d61e457
Remove unintended changes
codyborn Jul 16, 2022
c126cd5
Organize bytecode enum
codyborn Jul 16, 2022
75d74aa
Remove extra space
codyborn Jul 16, 2022
b6bf7fc
Updates to address PR feedback
codyborn Jul 28, 2022
57f1fd2
TreeMap -> HashMap
codyborn Jul 28, 2022
188d201
Remove shanghai hf config
codyborn Jul 29, 2022
a1708a4
Merge with main
codyborn Jul 31, 2022
4f0a43b
Missed some changes in the merge
codyborn Jul 31, 2022
612ee73
Whitespace style fix
codyborn Jul 31, 2022
04ffcae
Remove eip from all_forks.json
codyborn Aug 1, 2022
8623f48
Clear transient storage after each transaction
codyborn Aug 2, 2022
0ad50e6
Style fixes
codyborn Aug 4, 2022
d1db3b2
Merge branch 'main' into eip1153
codyborn Aug 4, 2022
03ad001
Simple performance test
codyborn Aug 4, 2022
45f603c
javadoc ByteCodeBuilder, undo unintended change
codyborn Aug 6, 2022
42ce2ec
correct javadoc typos
codyborn Aug 6, 2022
2c24e18
style fix
codyborn Aug 6, 2022
9b3f8d8
Move transient performance test to jmh suite
codyborn Aug 8, 2022
114446d
Remove commented out line
codyborn Aug 8, 2022
7e108d5
Upgrade Web3J (#3752)
diega Aug 4, 2022
9d63c64
Fix ConcurrentModificationException on ReattemptPendingPeerRequests (…
Gabriel-Trintinalia Aug 4, 2022
c46b1bf
Log unexpected exceptions in execution engine rpc (#4222)
siladu Aug 5, 2022
b68a6a7
correct fallback ttd to correct value (#4223)
daniellehrner Aug 7, 2022
b937710
Enclave public key length constraint removed for private transactions…
freemanzMrojo Aug 8, 2022
26714f1
Merge branch 'main' into eip1153
codyborn Aug 8, 2022
34451ae
Merge branch 'main' into eip1153
codyborn Aug 9, 2022
7bf6470
Merge branch 'main' into eip1153
codyborn Aug 10, 2022
47b1f31
Merge branch 'main' into eip1153
codyborn Aug 10, 2022
4b1c2a7
Merge branch 'main' into eip1153
codyborn Aug 12, 2022
c0c3c92
Merge branch 'main' into eip1153
codyborn Aug 21, 2022
a0cc8df
Add 1153 as ExperimentalEIP cmd line
codyborn Aug 31, 2022
d184d71
Merge branch 'main' into eip1153
codyborn Aug 31, 2022
a950795
Merge upstream
codyborn Nov 30, 2022
ed3ccad
Merge upstream
codyborn Nov 30, 2022
1a0b0fd
Fix tests
codyborn Dec 3, 2022
dd3f4bd
Merge pull request #1 from codyborn/merge1153
codyborn Dec 3, 2022
ab4285d
Update tests
codyborn Nov 30, 2022
206923f
Merge branch 'eip1153' of https://github.com/codyborn/besu into eip1153
codyborn Dec 3, 2022
bed8c06
Fix merge issue
codyborn Dec 3, 2022
7e86124
Spotless fix
codyborn Dec 3, 2022
6cce1ce
Add experimental EIPs back into BesuCommand
codyborn Dec 4, 2022
aafce49
Fix merge artifacts
codyborn Dec 4, 2022
0cbedf4
Revert reference test external-resources
codyborn Dec 4, 2022
8eadf09
Merge branch 'main' into eip1153
codyborn Dec 5, 2022
82af1b8
ugly merge
shemnon Jan 26, 2023
0439c40
finish removing CLI feature flag
shemnon Jan 26, 2023
22b0cf1
Move transient storage to the MessageFrame
shemnon Jan 26, 2023
9580690
Merge remote-tracking branch 'upstream/main' into eip1153
shemnon Jan 26, 2023
6b8fa64
javadoc
shemnon Jan 26, 2023
56f04be
spotless
shemnon Jan 26, 2023
4ab15e6
Merge branch 'main' into eip1153
shemnon Feb 3, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ default boolean isConsensusMigration() {

OptionalLong getMergeNetSplitBlockNumber();

OptionalLong getEIP1153BlockNumber();

Optional<Wei> getBaseFeePerGas();

Optional<UInt256> getTerminalTotalDifficulty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ public OptionalLong getMergeNetSplitBlockNumber() {
return getOptionalLong("mergenetsplitblock");
}

@Override
public OptionalLong getEIP1153BlockNumber() {
return getOptionalLong("eip1153Block");
}

@Override
public Optional<Wei> getBaseFeePerGas() {
return Optional.ofNullable(configOverrides.get("baseFeePerGas"))
Expand Down Expand Up @@ -441,6 +446,7 @@ public Map<String, Object> asMap() {
getArrowGlacierBlockNumber().ifPresent(l -> builder.put("arrowGlacierBlock", l));
getGrayGlacierBlockNumber().ifPresent(l -> builder.put("grayGlacierBlock", l));
getMergeNetSplitBlockNumber().ifPresent(l -> builder.put("mergeNetSplitBlock", l));
getEIP1153BlockNumber().ifPresent(l -> builder.put("eip1153Block", l));
getTerminalBlockNumber().ifPresent(l -> builder.put("terminalBlockNumber", l));
getTerminalBlockHash().ifPresent(h -> builder.put("terminalBlockHash", h.toHexString()));

Expand Down Expand Up @@ -560,6 +566,7 @@ public List<Long> getForks() {
getArrowGlacierBlockNumber(),
getGrayGlacierBlockNumber(),
getMergeNetSplitBlockNumber(),
getEIP1153BlockNumber(),
getEcip1015BlockNumber(),
getDieHardBlockNumber(),
getGothamBlockNumber(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class StubGenesisConfigOptions implements GenesisConfigOptions {
private OptionalLong arrowGlacierBlockNumber = OptionalLong.empty();
private OptionalLong grayGlacierBlockNumber = OptionalLong.empty();
private OptionalLong mergeNetSplitBlockNumber = OptionalLong.empty();
private OptionalLong eip1153BlockNumber = OptionalLong.empty();
private OptionalLong terminalBlockNumber = OptionalLong.empty();
private Optional<Hash> terminalBlockHash = Optional.empty();
private Optional<UInt256> terminalTotalDifficulty = Optional.empty();
Expand Down Expand Up @@ -216,6 +217,11 @@ public OptionalLong getMergeNetSplitBlockNumber() {
return mergeNetSplitBlockNumber;
}

@Override
public OptionalLong getEIP1153BlockNumber() {
return eip1153BlockNumber;
}

@Override
public Optional<Wei> getBaseFeePerGas() {
return baseFeePerGas;
Expand Down Expand Up @@ -344,6 +350,7 @@ public Map<String, Object> asMap() {
getArrowGlacierBlockNumber().ifPresent(l -> builder.put("arrowGlacierBlock", l));
getGrayGlacierBlockNumber().ifPresent(l -> builder.put("grayGlacierBlock", l));
getMergeNetSplitBlockNumber().ifPresent(l -> builder.put("mergeNetSplitBlock", l));
getEIP1153BlockNumber().ifPresent(l -> builder.put("eip1153Block", l));
getTerminalBlockNumber().ifPresent(l -> builder.put("terminalBlockNumber", l));
getTerminalBlockHash().ifPresent(h -> builder.put("terminalBlockHash", h));
// classic fork blocks
Expand Down Expand Up @@ -482,6 +489,11 @@ public StubGenesisConfigOptions mergeNetSplitBlock(final long blockNumber) {
return this;
}

public StubGenesisConfigOptions eip1153Block(final long blockNumber) {
eip1153BlockNumber = OptionalLong.of(blockNumber);
return this;
}

public StubGenesisConfigOptions terminalTotalDifficulty(
final UInt256 updatedTerminalTotalDifficulty) {
terminalTotalDifficulty = Optional.of(updatedTerminalTotalDifficulty);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ public void shouldReturnCorrectResponse() {
Optional.empty(),
false,
Optional.empty(),
Optional.empty(),
Optional.empty());

final TransactionProcessingResult transaction1Result = mock(TransactionProcessingResult.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public void shouldReturnCorrectResponse() {
Optional.empty(),
false,
Optional.empty(),
Optional.empty(),
Optional.empty());

final TransactionProcessingResult transaction1Result = mock(TransactionProcessingResult.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public void shouldReturnCorrectResponse() {
Optional.empty(),
false,
Optional.empty(),
Optional.empty(),
Optional.empty());

final TransactionProcessingResult transaction1Result = mock(TransactionProcessingResult.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public void shouldTraceTheTransactionUsingTheTransactionTracer() {
Optional.empty(),
false,
Optional.empty(),
Optional.empty(),
Optional.empty());
final List<TraceFrame> traceFrames = Collections.singletonList(traceFrame);
final TransactionTrace transactionTrace =
Expand Down Expand Up @@ -176,6 +177,7 @@ public void shouldNotTraceTheTransactionIfNotFound() {
Optional.empty(),
false,
Optional.empty(),
Optional.empty(),
Optional.empty());
final List<TraceFrame> traceFrames = Collections.singletonList(traceFrame);
final TransactionTrace transactionTrace =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class BonsaiAccount implements MutableAccount, EvmAccount {
private Bytes code;

private final Map<UInt256, UInt256> updatedStorage = new HashMap<>();
private final Map<UInt256, UInt256> updatedTransientStorage = new HashMap<>();

BonsaiAccount(
final BonsaiWorldView context,
Expand Down Expand Up @@ -103,6 +104,7 @@ public class BonsaiAccount implements MutableAccount, EvmAccount {
this.codeHash = toCopy.codeHash;
this.code = toCopy.code;
updatedStorage.putAll(toCopy.updatedStorage);
updatedTransientStorage.putAll(toCopy.updatedTransientStorage);

this.mutable = mutable;
}
Expand All @@ -117,7 +119,7 @@ public class BonsaiAccount implements MutableAccount, EvmAccount {
this.codeHash = tracked.getCodeHash();
this.code = tracked.getCode();
updatedStorage.putAll(tracked.getUpdatedStorage());

updatedTransientStorage.putAll(tracked.getUpdatedTransientStorage());
this.mutable = true;
}

Expand Down Expand Up @@ -243,13 +245,24 @@ public void setStorageValue(final UInt256 key, final UInt256 value) {
@Override
public void clearStorage() {
updatedStorage.clear();
clearTransientStorage();
}

@Override
public void clearTransientStorage() {
updatedTransientStorage.clear();
}

@Override
public Map<UInt256, UInt256> getUpdatedStorage() {
return updatedStorage;
}

@Override
public Map<UInt256, UInt256> getUpdatedTransientStorage() {
return updatedTransientStorage;
}

@Override
public MutableAccount getMutable() throws ModificationNotAllowedException {
if (mutable) {
Expand Down Expand Up @@ -310,4 +323,21 @@ static void assertCloseEnoughForDiffing(
}
}
}

@Override
public UInt256 getTransientStorageValue(final UInt256 key) {
if (updatedTransientStorage.containsKey(key)) {
return updatedTransientStorage.get(key);
} else {
return UInt256.ZERO;
}
}

@Override
public void setTransientStorageValue(final UInt256 key, final UInt256 value) {
if (!mutable) {
throw new UnsupportedOperationException("Account is immutable");
}
updatedTransientStorage.put(key, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ public void commit() {
tracked.setStorageWasCleared(false); // storage already cleared for this transaction
}

tracked.clearTransientStorage();

// TODO maybe add address preimage?
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class TraceFrame {
private final boolean virtualOperation;
private final Optional<MemoryEntry> maybeUpdatedMemory;
private final Optional<StorageEntry> maybeUpdatedStorage;
private final Optional<StorageEntry> maybeUpdatedTransientStorage;
private OptionalLong precompiledGasCost;

public TraceFrame(
Expand All @@ -83,7 +84,8 @@ public TraceFrame(
final Optional<Bytes32[]> stackPostExecution,
final boolean virtualOperation,
final Optional<MemoryEntry> maybeUpdatedMemory,
final Optional<StorageEntry> maybeUpdatedStorage) {
final Optional<StorageEntry> maybeUpdatedStorage,
final Optional<StorageEntry> maybeUpdatedTransientStorage) {
this.pc = pc;
this.opcode = opcode;
this.gasRemaining = gasRemaining;
Expand All @@ -107,6 +109,7 @@ public TraceFrame(
this.virtualOperation = virtualOperation;
this.maybeUpdatedMemory = maybeUpdatedMemory;
this.maybeUpdatedStorage = maybeUpdatedStorage;
this.maybeUpdatedTransientStorage = maybeUpdatedTransientStorage;
precompiledGasCost = OptionalLong.empty();
}

Expand Down Expand Up @@ -229,6 +232,10 @@ public Optional<StorageEntry> getMaybeUpdatedStorage() {
return maybeUpdatedStorage;
}

public Optional<StorageEntry> getMaybeUpdatedTransientStorage() {
return maybeUpdatedTransientStorage;
}

public OptionalLong getPrecompiledGasCost() {
return precompiledGasCost;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,17 @@ public ProtocolSpecBuilder parisDefinition(final GenesisConfigOptions genesisCon
evmConfiguration);
}

public ProtocolSpecBuilder eip1153Definition(final GenesisConfigOptions genesisConfigOptions) {
codyborn marked this conversation as resolved.
Show resolved Hide resolved
return MainnetProtocolSpecs.eip1153Definition(
chainId,
contractSizeLimit,
evmStackSize,
isRevertReasonEnabled,
genesisConfigOptions,
quorumCompatibilityMode,
evmConfiguration);
}

////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
// Classic Protocol Specs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.hyperledger.besu.evm.gascalculator.BerlinGasCalculator;
import org.hyperledger.besu.evm.gascalculator.ByzantiumGasCalculator;
import org.hyperledger.besu.evm.gascalculator.ConstantinopleGasCalculator;
import org.hyperledger.besu.evm.gascalculator.EIP1153GasCalculator;
import org.hyperledger.besu.evm.gascalculator.FrontierGasCalculator;
import org.hyperledger.besu.evm.gascalculator.HomesteadGasCalculator;
import org.hyperledger.besu.evm.gascalculator.IstanbulGasCalculator;
Expand Down Expand Up @@ -632,6 +633,32 @@ static ProtocolSpecBuilder parisDefinition(
.name("ParisFork");
}

// TODO EIP-1153 change for the actual fork name when known
static ProtocolSpecBuilder eip1153Definition(
final Optional<BigInteger> chainId,
final OptionalInt configContractSizeLimit,
final OptionalInt configStackSizeLimit,
final boolean enableRevertReason,
final GenesisConfigOptions genesisConfigOptions,
final boolean quorumCompatibilityMode,
final EvmConfiguration evmConfiguration) {

return parisDefinition(
chainId,
configContractSizeLimit,
configStackSizeLimit,
enableRevertReason,
genesisConfigOptions,
quorumCompatibilityMode,
evmConfiguration)
.evmBuilder(
(gasCalculator, jdCacheConfig) ->
MainnetEVMs.eip1153(
gasCalculator, chainId.orElse(BigInteger.ZERO), evmConfiguration))
.gasCalculator(EIP1153GasCalculator::new)
.name("EIP-1153");
}

private static TransactionReceipt frontierTransactionReceiptFactory(
// ignored because it's always FRONTIER
final TransactionType __,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ private TreeMap<Long, BuilderMapEntry> buildMilestoneMap(
create(
config.getGrayGlacierBlockNumber(), specFactory.grayGlacierDefinition(config)),
create(config.getMergeNetSplitBlockNumber(), specFactory.parisDefinition(config)),
create(config.getEIP1153BlockNumber(), specFactory.eip1153Definition(config)),
// Classic Milestones
create(config.getEcip1015BlockNumber(), specFactory.tangerineWhistleDefinition()),
create(config.getDieHardBlockNumber(), specFactory.dieHardDefinition()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ public void traceExecution(final MessageFrame frame, final ExecuteOperation exec
stackPostExecution,
currentOperation.isVirtualOperation(),
frame.getMaybeUpdatedMemory(),
frame.getMaybeUpdatedStorage());
frame.getMaybeUpdatedStorage(),
frame.getMaybeUpdatedTransientStorage());
traceFrames.add(lastFrame);
frame.reset();
}
Expand Down Expand Up @@ -126,6 +127,7 @@ public void tracePrecompileCall(
Optional.empty(),
true,
Optional.empty(),
Optional.empty(),
Optional.empty());
traceFrames.add(traceFrame);
}
Expand Down Expand Up @@ -172,6 +174,7 @@ public void traceAccountCreationResult(
Optional.empty(),
true,
Optional.empty(),
Optional.empty(),
Optional.empty());
traceFrames.add(traceFrame);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,12 @@ public UInt256 getOriginalStorageValue(final UInt256 key) {
return getStorageValue(key);
}

@Override
public UInt256 getTransientStorageValue(final UInt256 key) {
// Transient state isn't persistent
return UInt256.ZERO;
}

@Override
public NavigableMap<Bytes32, AccountStorageEntry> storageEntriesFrom(
final Bytes32 startKeyHash, final int limit) {
Expand Down Expand Up @@ -435,6 +441,7 @@ public void commit() {
serializeAccount(updated.getNonce(), updated.getBalance(), storageRoot, codeHash);

wrapped.accountStateTrie.put(updated.getAddressHash(), account);
updated.clearTransientStorage();
}
}
}
Expand Down
Loading