From a7fd80b531aa37354e06a90fd6d779bb5e781904 Mon Sep 17 00:00:00 2001 From: Wolmin <44748271+Wolmin@users.noreply.github.com> Date: Mon, 24 Jun 2024 11:00:11 +0200 Subject: [PATCH 1/3] feat: Add network option for LUKSO Mainnet (#7223) * Add option for LUKSO network Signed-off-by: Wolmin * Add tests for LUKSO Signed-off-by: Wolmin * Apply spotless Signed-off-by: Wolmin * Add changelog entry Signed-off-by: Wolmin * Fix duplicate func Signed-off-by: Wolmin * Fix changelog Signed-off-by: Wolmin * Add bootnodes to genesis Signed-off-by: Wolmin --------- Signed-off-by: Wolmin Signed-off-by: Wolmin <44748271+Wolmin@users.noreply.github.com> --- CHANGELOG.md | 1 + .../besu/cli/config/NetworkName.java | 2 + .../hyperledger/besu/cli/BesuCommandTest.java | 17 + .../cli/NetworkDeprecationMessageTest.java | 2 +- config/src/main/resources/lukso.json | 852 ++++++++++++++++++ 5 files changed, 873 insertions(+), 1 deletion(-) create mode 100644 config/src/main/resources/lukso.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 5edb1d4253e..93294dfd781 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - A full and up to date implementation of EOF for Prague [#7169](https://github.com/hyperledger/besu/pull/7169) - Add Subnet-Based Peer Permissions. [#7168](https://github.com/hyperledger/besu/pull/7168) - Reduce lock contention on transaction pool when building a block [#7180](https://github.com/hyperledger/besu/pull/7180) +- Add LUKSO as predefined network name [#7223](https://github.com/hyperledger/besu/pull/7223) ### Bug fixes - Validation errors ignored in accounts-allowlist and empty list [#7138](https://github.com/hyperledger/besu/issues/7138) diff --git a/besu/src/main/java/org/hyperledger/besu/cli/config/NetworkName.java b/besu/src/main/java/org/hyperledger/besu/cli/config/NetworkName.java index bd41015a7a1..f864068bb4e 100644 --- a/besu/src/main/java/org/hyperledger/besu/cli/config/NetworkName.java +++ b/besu/src/main/java/org/hyperledger/besu/cli/config/NetworkName.java @@ -28,6 +28,8 @@ public enum NetworkName { SEPOLIA("/sepolia.json", BigInteger.valueOf(11155111)), /** Holešky network name. */ HOLESKY("/holesky.json", BigInteger.valueOf(17000)), + /** LUKSO mainnet network name. */ + LUKSO("/lukso.json", BigInteger.valueOf(42)), /** Dev network name. */ DEV("/dev.json", BigInteger.valueOf(2018), false), diff --git a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java index 1e8d15cdb4f..2c17cc42c9a 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/BesuCommandTest.java @@ -22,6 +22,7 @@ import static org.hyperledger.besu.cli.config.NetworkName.EXPERIMENTAL_EIPS; import static org.hyperledger.besu.cli.config.NetworkName.FUTURE_EIPS; import static org.hyperledger.besu.cli.config.NetworkName.HOLESKY; +import static org.hyperledger.besu.cli.config.NetworkName.LUKSO; import static org.hyperledger.besu.cli.config.NetworkName.MAINNET; import static org.hyperledger.besu.cli.config.NetworkName.MORDOR; import static org.hyperledger.besu.cli.config.NetworkName.SEPOLIA; @@ -1747,6 +1748,22 @@ public void holeskyValuesAreUsed() { verify(mockLogger, never()).warn(contains("Holesky is deprecated and will be shutdown")); } + @Test + public void luksoValuesAreUsed() { + parseCommand("--network", "lukso"); + + final ArgumentCaptor networkArg = + ArgumentCaptor.forClass(EthNetworkConfig.class); + + verify(mockControllerBuilderFactory).fromEthNetworkConfig(networkArg.capture(), any()); + verify(mockControllerBuilder).build(); + + assertThat(networkArg.getValue()).isEqualTo(EthNetworkConfig.getNetworkConfig(LUKSO)); + + assertThat(commandOutput.toString(UTF_8)).isEmpty(); + assertThat(commandErrorOutput.toString(UTF_8)).isEmpty(); + } + @Test public void classicValuesAreUsed() { parseCommand("--network", "classic"); diff --git a/besu/src/test/java/org/hyperledger/besu/cli/NetworkDeprecationMessageTest.java b/besu/src/test/java/org/hyperledger/besu/cli/NetworkDeprecationMessageTest.java index 9a8fb427491..e140db8c2a8 100644 --- a/besu/src/test/java/org/hyperledger/besu/cli/NetworkDeprecationMessageTest.java +++ b/besu/src/test/java/org/hyperledger/besu/cli/NetworkDeprecationMessageTest.java @@ -39,7 +39,7 @@ void shouldGenerateDeprecationMessageForDeprecatedNetworks(final NetworkName net @EnumSource( value = NetworkName.class, names = { - "MAINNET", "SEPOLIA", "DEV", "CLASSIC", "MORDOR", "HOLESKY", + "MAINNET", "SEPOLIA", "DEV", "CLASSIC", "MORDOR", "HOLESKY", "LUKSO", }) void shouldThrowErrorForNonDeprecatedNetworks(final NetworkName network) { assertThatThrownBy(() -> NetworkDeprecationMessage.generate(network)) diff --git a/config/src/main/resources/lukso.json b/config/src/main/resources/lukso.json new file mode 100644 index 00000000000..ff4296eae84 --- /dev/null +++ b/config/src/main/resources/lukso.json @@ -0,0 +1,852 @@ +{ + "config": { + "ethash": {}, + "chainId": 42, + "homesteadBlock": 0, + "eip150Block": 0, + "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "eip155Block": 0, + "eip158Block": 0, + "byzantiumBlock": 0, + "constantinopleBlock": 0, + "petersburgBlock": 0, + "istanbulBlock": 0, + "berlinBlock": 0, + "londonBlock": 0, + "mergeForkBlock": 0, + "terminalTotalDifficulty": 0, + "terminalTotalDifficultyPassed": true, + "shanghaiTime": 1687969198, + "cancunTime": 1767182400, + "discovery": { + "bootnodes": [ + "enode://c2bb19ce658cfdf1fecb45da599ee6c7bf36e5292efb3fb61303a0b2cd07f96c20ac9b376a464d687ac456675a2e4a44aec39a0509bcb4b6d8221eedec25aca2@34.147.73.193:30303", + "enode://276f14e4049840a0f5aa5e568b772ab6639251149a52ba244647277175b83f47b135f3b3d8d846cf81a8e681684e37e9fc10ec205a9841d3ae219aa08aa9717b@34.32.192.211:30303" + ] + } + }, + "number": "0x0", + "nonce": "0x1", + "difficulty": "0x1", + "gasLimit": "0x280de80", + "gasUsed": "0x0", + "timestamp": "0x646CE7B0", + "extraData": "0x416e642074686520776f726c6420626563616d65206f6e65", + "coinbase": "0x0000000000000000000000000000000000000000", + "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "alloc": { + "0x953534215D31D0f2756b8A855aaFB7E641848c2e": { + "balance": "11143518000000000000000000" + }, + "0x5a4154edddE64858664F6219e031B6a47BA30993": { + "balance": "30525730000000000000000000" + }, + "0x0000000000000000000000000000000000000000": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000001": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000002": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000003": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000004": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000005": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000006": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000007": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000008": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000009": { + "balance": "1" + }, + "0x000000000000000000000000000000000000000a": { + "balance": "1" + }, + "0x000000000000000000000000000000000000000b": { + "balance": "1" + }, + "0x000000000000000000000000000000000000000c": { + "balance": "1" + }, + "0x000000000000000000000000000000000000000d": { + "balance": "1" + }, + "0x000000000000000000000000000000000000000e": { + "balance": "1" + }, + "0x000000000000000000000000000000000000000f": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000010": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000011": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000012": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000013": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000014": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000015": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000016": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000017": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000018": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000019": { + "balance": "1" + }, + "0x000000000000000000000000000000000000001a": { + "balance": "1" + }, + "0x000000000000000000000000000000000000001b": { + "balance": "1" + }, + "0x000000000000000000000000000000000000001c": { + "balance": "1" + }, + "0x000000000000000000000000000000000000001d": { + "balance": "1" + }, + "0x000000000000000000000000000000000000001e": { + "balance": "1" + }, + "0x000000000000000000000000000000000000001f": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000020": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000021": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000022": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000023": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000024": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000025": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000026": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000027": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000028": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000029": { + "balance": "1" + }, + "0x000000000000000000000000000000000000002a": { + "balance": "1" + }, + "0x000000000000000000000000000000000000002b": { + "balance": "1" + }, + "0x000000000000000000000000000000000000002c": { + "balance": "1" + }, + "0x000000000000000000000000000000000000002d": { + "balance": "1" + }, + "0x000000000000000000000000000000000000002e": { + "balance": "1" + }, + "0x000000000000000000000000000000000000002f": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000030": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000031": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000032": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000033": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000034": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000035": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000036": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000037": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000038": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000039": { + "balance": "1" + }, + "0x000000000000000000000000000000000000003a": { + "balance": "1" + }, + "0x000000000000000000000000000000000000003b": { + "balance": "1" + }, + "0x000000000000000000000000000000000000003c": { + "balance": "1" + }, + "0x000000000000000000000000000000000000003d": { + "balance": "1" + }, + "0x000000000000000000000000000000000000003e": { + "balance": "1" + }, + "0x000000000000000000000000000000000000003f": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000040": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000041": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000042": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000043": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000044": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000045": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000046": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000047": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000048": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000049": { + "balance": "1" + }, + "0x000000000000000000000000000000000000004a": { + "balance": "1" + }, + "0x000000000000000000000000000000000000004b": { + "balance": "1" + }, + "0x000000000000000000000000000000000000004c": { + "balance": "1" + }, + "0x000000000000000000000000000000000000004d": { + "balance": "1" + }, + "0x000000000000000000000000000000000000004e": { + "balance": "1" + }, + "0x000000000000000000000000000000000000004f": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000050": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000051": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000052": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000053": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000054": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000055": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000056": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000057": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000058": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000059": { + "balance": "1" + }, + "0x000000000000000000000000000000000000005a": { + "balance": "1" + }, + "0x000000000000000000000000000000000000005b": { + "balance": "1" + }, + "0x000000000000000000000000000000000000005c": { + "balance": "1" + }, + "0x000000000000000000000000000000000000005d": { + "balance": "1" + }, + "0x000000000000000000000000000000000000005e": { + "balance": "1" + }, + "0x000000000000000000000000000000000000005f": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000060": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000061": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000062": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000063": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000064": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000065": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000066": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000067": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000068": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000069": { + "balance": "1" + }, + "0x000000000000000000000000000000000000006a": { + "balance": "1" + }, + "0x000000000000000000000000000000000000006b": { + "balance": "1" + }, + "0x000000000000000000000000000000000000006c": { + "balance": "1" + }, + "0x000000000000000000000000000000000000006d": { + "balance": "1" + }, + "0x000000000000000000000000000000000000006e": { + "balance": "1" + }, + "0x000000000000000000000000000000000000006f": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000070": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000071": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000072": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000073": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000074": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000075": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000076": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000077": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000078": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000079": { + "balance": "1" + }, + "0x000000000000000000000000000000000000007a": { + "balance": "1" + }, + "0x000000000000000000000000000000000000007b": { + "balance": "1" + }, + "0x000000000000000000000000000000000000007c": { + "balance": "1" + }, + "0x000000000000000000000000000000000000007d": { + "balance": "1" + }, + "0x000000000000000000000000000000000000007e": { + "balance": "1" + }, + "0x000000000000000000000000000000000000007f": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000080": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000081": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000082": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000083": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000084": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000085": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000086": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000087": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000088": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000089": { + "balance": "1" + }, + "0x000000000000000000000000000000000000008a": { + "balance": "1" + }, + "0x000000000000000000000000000000000000008b": { + "balance": "1" + }, + "0x000000000000000000000000000000000000008c": { + "balance": "1" + }, + "0x000000000000000000000000000000000000008d": { + "balance": "1" + }, + "0x000000000000000000000000000000000000008e": { + "balance": "1" + }, + "0x000000000000000000000000000000000000008f": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000090": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000091": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000092": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000093": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000094": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000095": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000096": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000097": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000098": { + "balance": "1" + }, + "0x0000000000000000000000000000000000000099": { + "balance": "1" + }, + "0x000000000000000000000000000000000000009a": { + "balance": "1" + }, + "0x000000000000000000000000000000000000009b": { + "balance": "1" + }, + "0x000000000000000000000000000000000000009c": { + "balance": "1" + }, + "0x000000000000000000000000000000000000009d": { + "balance": "1" + }, + "0x000000000000000000000000000000000000009e": { + "balance": "1" + }, + "0x000000000000000000000000000000000000009f": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000a0": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000a1": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000a2": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000a3": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000a4": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000a5": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000a6": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000a7": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000a8": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000a9": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000aa": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000ab": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000ac": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000ad": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000ae": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000af": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000b0": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000b1": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000b2": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000b3": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000b4": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000b5": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000b6": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000b7": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000b8": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000b9": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000ba": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000bb": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000bc": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000bd": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000be": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000bf": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000c0": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000c1": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000c2": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000c3": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000c4": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000c5": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000c6": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000c7": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000c8": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000c9": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000ca": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000cb": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000cc": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000cd": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000ce": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000cf": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000d0": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000d1": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000d2": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000d3": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000d4": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000d5": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000d6": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000d7": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000d8": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000d9": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000da": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000db": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000dc": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000dd": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000de": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000df": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000e0": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000e1": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000e2": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000e3": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000e4": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000e5": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000e6": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000e7": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000e8": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000e9": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000ea": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000eb": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000ec": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000ed": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000ee": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000ef": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000f0": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000f1": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000f2": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000f3": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000f4": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000f5": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000f6": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000f7": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000f8": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000f9": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000fa": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000fb": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000fc": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000fd": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000fe": { + "balance": "1" + }, + "0x00000000000000000000000000000000000000ff": { + "balance": "1" + }, + "0xcafe00000000000000000000000000000000cafe": { + "balance": "0", + "code": "0x60806040526004361061003f5760003560e01c806301ffc9a71461004457806322895118146100a4578063621fd130146101ba578063c5f2892f14610244575b600080fd5b34801561005057600080fd5b506100906004803603602081101561006757600080fd5b50357fffffffff000000000000000000000000000000000000000000000000000000001661026b565b604080519115158252519081900360200190f35b6101b8600480360360808110156100ba57600080fd5b8101906020810181356401000000008111156100d557600080fd5b8201836020820111156100e757600080fd5b8035906020019184600183028401116401000000008311171561010957600080fd5b91939092909160208101903564010000000081111561012757600080fd5b82018360208201111561013957600080fd5b8035906020019184600183028401116401000000008311171561015b57600080fd5b91939092909160208101903564010000000081111561017957600080fd5b82018360208201111561018b57600080fd5b803590602001918460018302840111640100000000831117156101ad57600080fd5b919350915035610304565b005b3480156101c657600080fd5b506101cf6110b5565b6040805160208082528351818301528351919283929083019185019080838360005b838110156102095781810151838201526020016101f1565b50505050905090810190601f1680156102365780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561025057600080fd5b506102596110c7565b60408051918252519081900360200190f35b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f01ffc9a70000000000000000000000000000000000000000000000000000000014806102fe57507fffffffff0000000000000000000000000000000000000000000000000000000082167f8564090700000000000000000000000000000000000000000000000000000000145b92915050565b6030861461035d576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806118056026913960400191505060405180910390fd5b602084146103b6576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252603681526020018061179c6036913960400191505060405180910390fd5b6060821461040f576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260298152602001806118786029913960400191505060405180910390fd5b670de0b6b3a7640000341015610470576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260268152602001806118526026913960400191505060405180910390fd5b633b9aca003406156104cd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260338152602001806117d26033913960400191505060405180910390fd5b633b9aca00340467ffffffffffffffff811115610535576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040180806020018281038252602781526020018061182b6027913960400191505060405180910390fd5b6060610540826114ba565b90507f649bbc62d0e31342afea4e5cd82d4049e7e1ee912fc0889aa790803be39038c589898989858a8a6105756020546114ba565b6040805160a0808252810189905290819060208201908201606083016080840160c085018e8e80828437600083820152601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01690910187810386528c815260200190508c8c808284376000838201819052601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe01690920188810386528c5181528c51602091820193918e019250908190849084905b83811015610648578181015183820152602001610630565b50505050905090810190601f1680156106755780820380516001836020036101000a031916815260200191505b5086810383528881526020018989808284376000838201819052601f9091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169092018881038452895181528951602091820193918b019250908190849084905b838110156106ef5781810151838201526020016106d7565b50505050905090810190601f16801561071c5780820380516001836020036101000a031916815260200191505b509d505050505050505050505050505060405180910390a1600060028a8a600060801b604051602001808484808284377fffffffffffffffffffffffffffffffff0000000000000000000000000000000090941691909301908152604080517ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0818403018152601090920190819052815191955093508392506020850191508083835b602083106107fc57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016107bf565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610859573d6000803e3d6000fd5b5050506040513d602081101561086e57600080fd5b5051905060006002806108846040848a8c6116fe565b6040516020018083838082843780830192505050925050506040516020818303038152906040526040518082805190602001908083835b602083106108f857805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016108bb565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610955573d6000803e3d6000fd5b5050506040513d602081101561096a57600080fd5b5051600261097b896040818d6116fe565b60405160009060200180848480828437919091019283525050604080518083038152602092830191829052805190945090925082918401908083835b602083106109f457805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe090920191602091820191016109b7565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610a51573d6000803e3d6000fd5b5050506040513d6020811015610a6657600080fd5b5051604080516020818101949094528082019290925280518083038201815260609092019081905281519192909182918401908083835b60208310610ada57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610a9d565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610b37573d6000803e3d6000fd5b5050506040513d6020811015610b4c57600080fd5b50516040805160208101858152929350600092600292839287928f928f92018383808284378083019250505093505050506040516020818303038152906040526040518082805190602001908083835b60208310610bd957805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610b9c565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610c36573d6000803e3d6000fd5b5050506040513d6020811015610c4b57600080fd5b50516040518651600291889160009188916020918201918291908601908083835b60208310610ca957805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610c6c565b6001836020036101000a0380198251168184511680821785525050505050509050018367ffffffffffffffff191667ffffffffffffffff1916815260180182815260200193505050506040516020818303038152906040526040518082805190602001908083835b60208310610d4e57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610d11565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610dab573d6000803e3d6000fd5b5050506040513d6020811015610dc057600080fd5b5051604080516020818101949094528082019290925280518083038201815260609092019081905281519192909182918401908083835b60208310610e3457805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610df7565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015610e91573d6000803e3d6000fd5b5050506040513d6020811015610ea657600080fd5b50519050858114610f02576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260548152602001806117486054913960600191505060405180910390fd5b60205463ffffffff11610f60576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004018080602001828103825260218152602001806117276021913960400191505060405180910390fd5b602080546001019081905560005b60208110156110a9578160011660011415610fa0578260008260208110610f9157fe5b0155506110ac95505050505050565b600260008260208110610faf57fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061102557805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101610fe8565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa158015611082573d6000803e3d6000fd5b5050506040513d602081101561109757600080fd5b50519250600282049150600101610f6e565b50fe5b50505050505050565b60606110c26020546114ba565b905090565b6020546000908190815b60208110156112f05781600116600114156111e6576002600082602081106110f557fe5b01548460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061116b57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161112e565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa1580156111c8573d6000803e3d6000fd5b5050506040513d60208110156111dd57600080fd5b505192506112e2565b600283602183602081106111f657fe5b015460405160200180838152602001828152602001925050506040516020818303038152906040526040518082805190602001908083835b6020831061126b57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161122e565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa1580156112c8573d6000803e3d6000fd5b5050506040513d60208110156112dd57600080fd5b505192505b6002820491506001016110d1565b506002826112ff6020546114ba565b600060401b6040516020018084815260200183805190602001908083835b6020831061135a57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0909201916020918201910161131d565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790527fffffffffffffffffffffffffffffffffffffffffffffffff000000000000000095909516920191825250604080518083037ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8018152601890920190819052815191955093508392850191508083835b6020831061143f57805182527fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe09092019160209182019101611402565b51815160209384036101000a7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01801990921691161790526040519190930194509192505080830381855afa15801561149c573d6000803e3d6000fd5b5050506040513d60208110156114b157600080fd5b50519250505090565b60408051600880825281830190925260609160208201818036833701905050905060c082901b8060071a60f81b826000815181106114f457fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060061a60f81b8260018151811061153757fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060051a60f81b8260028151811061157a57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060041a60f81b826003815181106115bd57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060031a60f81b8260048151811061160057fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060021a60f81b8260058151811061164357fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060011a60f81b8260068151811061168657fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053508060001a60f81b826007815181106116c957fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535050919050565b6000808585111561170d578182fd5b83861115611719578182fd5b505082019391909203915056fe4465706f736974436f6e74726163743a206d65726b6c6520747265652066756c6c4465706f736974436f6e74726163743a207265636f6e7374727563746564204465706f7369744461746120646f6573206e6f74206d6174636820737570706c696564206465706f7369745f646174615f726f6f744465706f736974436f6e74726163743a20696e76616c6964207769746864726177616c5f63726564656e7469616c73206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c7565206e6f74206d756c7469706c65206f6620677765694465706f736974436f6e74726163743a20696e76616c6964207075626b6579206c656e6774684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f20686967684465706f736974436f6e74726163743a206465706f7369742076616c756520746f6f206c6f774465706f736974436f6e74726163743a20696e76616c6964207369676e6174757265206c656e677468a26469706673582212201dd26f37a621703009abf16e77e69c93dc50c79db7f6cc37543e3e0e3decdc9764736f6c634300060b0033", + "storage": { + "0x00000000000000000000000000000000000000000000000000000000000022":"0xf5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a92759fb4b", + "0x00000000000000000000000000000000000000000000000000000000000023":"0xdb56114e00fdd4c1f85c892bf35ac9a89289aaecb1ebd0a96cde606a748b5d71", + "0x00000000000000000000000000000000000000000000000000000000000024":"0xc78009fdf07fc56a11f122370658a353aaa542ed63e44c4bc15ff4cd105ab33c", + "0x00000000000000000000000000000000000000000000000000000000000025":"0x536d98837f2dd165a55d5eeae91485954472d56f246df256bf3cae19352a123c", + "0x00000000000000000000000000000000000000000000000000000000000026":"0x9efde052aa15429fae05bad4d0b1d7c64da64d03d7a1854a588c2cb8430c0d30", + "0x00000000000000000000000000000000000000000000000000000000000027":"0xd88ddfeed400a8755596b21942c1497e114c302e6118290f91e6772976041fa1", + "0x00000000000000000000000000000000000000000000000000000000000028":"0x87eb0ddba57e35f6d286673802a4af5975e22506c7cf4c64bb6be5ee11527f2c", + "0x00000000000000000000000000000000000000000000000000000000000029":"0x26846476fd5fc54a5d43385167c95144f2643f533cc85bb9d16b782f8d7db193", + "0x0000000000000000000000000000000000000000000000000000000000002a":"0x506d86582d252405b840018792cad2bf1259f1ef5aa5f887e13cb2f0094f51e1", + "0x0000000000000000000000000000000000000000000000000000000000002b":"0xffff0ad7e659772f9534c195c815efc4014ef1e1daed4404c06385d11192e92b", + "0x0000000000000000000000000000000000000000000000000000000000002c":"0x6cf04127db05441cd833107a52be852868890e4317e6a02ab47683aa75964220", + "0x0000000000000000000000000000000000000000000000000000000000002d":"0xb7d05f875f140027ef5118a2247bbb84ce8f2f0f1123623085daf7960c329f5f", + "0x0000000000000000000000000000000000000000000000000000000000002e":"0xdf6af5f5bbdb6be9ef8aa618e4bf8073960867171e29676f8b284dea6a08a85e", + "0x0000000000000000000000000000000000000000000000000000000000002f":"0xb58d900f5e182e3c50ef74969ea16c7726c549757cc23523c369587da7293784", + "0x00000000000000000000000000000000000000000000000000000000000030":"0xd49a7502ffcfb0340b1d7885688500ca308161a7f96b62df9d083b71fcc8f2bb", + "0x00000000000000000000000000000000000000000000000000000000000031":"0x8fe6b1689256c0d385f42f5bbe2027a22c1996e110ba97c171d3e5948de92beb", + "0x00000000000000000000000000000000000000000000000000000000000032":"0x8d0d63c39ebade8509e0ae3c9c3876fb5fa112be18f905ecacfecb92057603ab", + "0x00000000000000000000000000000000000000000000000000000000000033":"0x95eec8b2e541cad4e91de38385f2e046619f54496c2382cb6cacd5b98c26f5a4", + "0x00000000000000000000000000000000000000000000000000000000000034":"0xf893e908917775b62bff23294dbbe3a1cd8e6cc1c35b4801887b646a6f81f17f", + "0x00000000000000000000000000000000000000000000000000000000000035":"0xcddba7b592e3133393c16194fac7431abf2f5485ed711db282183c819e08ebaa", + "0x00000000000000000000000000000000000000000000000000000000000036":"0x8a8d7fe3af8caa085a7639a832001457dfb9128a8061142ad0335629ff23ff9c", + "0x00000000000000000000000000000000000000000000000000000000000037":"0xfeb3c337d7a51a6fbf00b9e34c52e1c9195c969bd4e7a0bfd51d5c5bed9c1167", + "0x00000000000000000000000000000000000000000000000000000000000038":"0xe71f0aa83cc32edfbefa9f4d3e0174ca85182eec9f3a09f6a6c0df6377a510d7", + "0x00000000000000000000000000000000000000000000000000000000000039":"0x31206fa80a50bb6abe29085058f16212212a60eec8f049fecb92d8c8e0a84bc0", + "0x0000000000000000000000000000000000000000000000000000000000003a":"0x21352bfecbeddde993839f614c3dac0a3ee37543f9b412b16199dc158e23b544", + "0x0000000000000000000000000000000000000000000000000000000000003b":"0x619e312724bb6d7c3153ed9de791d764a366b389af13c58bf8a8d90481a46765", + "0x0000000000000000000000000000000000000000000000000000000000003c":"0x7cdd2986268250628d0c10e385c58c6191e6fbe05191bcc04f133f2cea72c1c4", + "0x0000000000000000000000000000000000000000000000000000000000003d":"0x848930bd7ba8cac54661072113fb278869e07bb8587f91392933374d017bcbe1", + "0x0000000000000000000000000000000000000000000000000000000000003e":"0x8869ff2c22b28cc10510d9853292803328be4fb0e80495e8bb8d271f5b889636", + "0x0000000000000000000000000000000000000000000000000000000000003f":"0xb5fe28e79f1b850f8658246ce9b6a1e7b49fc06db7143e8fe0b4f2b0c5523a5c", + "0x00000000000000000000000000000000000000000000000000000000000040":"0x985e929f70af28d0bdd1a90a808f977f597c7c778c489e98d3bd8910d31ac0f7" + } + } + } +} + From af80e53ad993d6257d2c56971ce4d4b83864e54d Mon Sep 17 00:00:00 2001 From: Fabio Di Fabio Date: Mon, 24 Jun 2024 12:54:34 +0200 Subject: [PATCH 2/3] Update Docker base image to Ubuntu 24.04 (#7251) Signed-off-by: Fabio Di Fabio --- CHANGELOG.md | 1 + docker/Dockerfile | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93294dfd781..2118b9abdcd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - A full and up to date implementation of EOF for Prague [#7169](https://github.com/hyperledger/besu/pull/7169) - Add Subnet-Based Peer Permissions. [#7168](https://github.com/hyperledger/besu/pull/7168) - Reduce lock contention on transaction pool when building a block [#7180](https://github.com/hyperledger/besu/pull/7180) +- Update Docker base image to Ubuntu 24.04 [#7251](https://github.com/hyperledger/besu/pull/7251) - Add LUKSO as predefined network name [#7223](https://github.com/hyperledger/besu/pull/7223) ### Bug fixes diff --git a/docker/Dockerfile b/docker/Dockerfile index ee138afca62..c16345a82bd 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,5 +1,4 @@ - -FROM ubuntu:23.10 +FROM ubuntu:24.04 ARG VERSION="dev" ENV NO_PROXY_CACHE="-o Acquire::BrokenProxy=true -o Acquire::http::No-Cache=true -o Acquire::http::Pipeline-Depth=0" @@ -12,7 +11,7 @@ RUN apt-get update $NO_PROXY_CACHE && \ apt-get clean && \ rm -rf /var/cache/apt/archives/* /var/cache/apt/archives/partial/* && \ rm -rf /var/lib/apt/lists/* && \ - # Ubuntu 23.10 comes with an "ubuntu" user with uid 1000. We need 1000 for besu. + # Starting from version 23.10, Ubuntu comes with an "ubuntu" user with uid 1000. We need 1000 for besu. userdel ubuntu 2>/dev/null || true && rm -rf /home/ubuntu && \ # Ensure we use a stable UID for besu, as file permissions are tied to UIDs. adduser --uid 1000 --disabled-password --gecos "" --home /opt/besu besu && \ From 7e840ab6400c70be88f31dd4b6fa557aa1c6eb80 Mon Sep 17 00:00:00 2001 From: Danno Ferrin Date: Mon, 24 Jun 2024 14:41:27 -0600 Subject: [PATCH 3/3] Reconfigure how Protocol Specs are created WRT EVM condiguration (#7245) Make the max code size and max initcode size a part of the EVM configuration. As part of the change we need to move the tasks CodeFactory once handled as a static class and move it into the EVM. This has a nice follow on effect that we don't need to pass in max EOF versions or max code sizes anymore. Signed-off-by: Danno Ferrin --- CHANGELOG.md | 1 + .../mainnet/ClassicProtocolSpecs.java | 141 ++------ .../mainnet/MainnetProtocolSpecFactory.java | 175 ++------- .../mainnet/MainnetProtocolSpecs.java | 334 +++++------------- .../mainnet/ProtocolScheduleBuilder.java | 68 ++-- .../ethereum/mainnet/ProtocolSpecBuilder.java | 13 +- .../besu/evmtool/BenchmarkSubCommand.java | 9 +- .../besu/evmtool/CodeValidateSubCommand.java | 76 ++-- .../besu/evmtool/EOFTestSubCommand.java | 33 +- .../besu/evmtool/EvmToolCommand.java | 11 +- .../besu/evmtool/EvmToolComponent.java | 7 +- .../evmtool/MainnetGenesisFileModule.java | 16 +- .../besu/evmtool/PrettyPrintSubCommand.java | 22 +- .../besu/evmtool/ProtocolModule.java | 18 +- .../evmtool/CodeValidationSubCommandTest.java | 38 +- .../ReferenceTestProtocolSchedules.java | 13 + .../ethereum/eof/EOFReferenceTestTools.java | 31 +- .../java/org/hyperledger/besu/evm/Code.java | 10 +- .../java/org/hyperledger/besu/evm/EVM.java | 21 +- .../hyperledger/besu/evm/EvmSpecVersion.java | 89 +++-- .../besu/evm/code/CodeFactory.java | 109 +++--- .../besu/evm/code/CodeInvalid.java | 8 +- .../org/hyperledger/besu/evm/code/CodeV0.java | 8 +- .../org/hyperledger/besu/evm/code/CodeV1.java | 19 +- .../besu/evm/code/CodeV1Validation.java | 39 +- .../hyperledger/besu/evm/code/EOFLayout.java | 6 +- .../besu/evm/code/EOFValidator.java | 49 +++ .../CachedInvalidCodeRule.java | 61 ---- .../ContractValidationRule.java | 4 +- .../EOFValidationCodeRule.java | 20 +- .../contractvalidation/MaxCodeSizeRule.java | 28 +- .../contractvalidation/PrefixCodeRule.java | 7 +- .../besu/evm/fluent/EVMExecutor.java | 22 +- .../besu/evm/frame/ExceptionalHaltReason.java | 12 +- .../besu/evm/internal/EvmConfiguration.java | 55 ++- .../operation/AbstractCreateOperation.java | 3 +- .../evm/operation/EOFCreateOperation.java | 2 +- .../operation/ReturnContractOperation.java | 10 +- .../processor/AbstractMessageProcessor.java | 7 +- .../processor/ContractCreationProcessor.java | 20 +- .../besu/evm/code/CodeFactoryTest.java | 36 +- .../hyperledger/besu/evm/code/CodeV0Test.java | 16 +- .../hyperledger/besu/evm/code/CodeV1Test.java | 16 +- .../besu/evm/fluent/EVMExecutorTest.java | 18 +- .../besu/evm/internal/CodeCacheTest.java | 6 +- .../AbstractCreateOperationTest.java | 5 +- .../evm/operations/Create2OperationTest.java | 20 +- .../evm/operations/CreateOperationTest.java | 10 +- .../operations/EofCreateOperationTest.java | 13 +- .../evm/operations/ExtCallOperationTest.java | 24 +- .../ExtDelegateCallOperationTest.java | 41 ++- .../ExtStaticCallOperationTest.java | 19 +- .../evm/operations/JumpOperationTest.java | 25 +- .../operations/SelfDestructOperationTest.java | 7 +- .../ContractCreationProcessorTest.java | 112 ++---- .../besu/evm/toy/EvmToyCommand.java | 3 +- .../tracing/ExtendedOperationTracerTest.java | 13 +- 57 files changed, 881 insertions(+), 1118 deletions(-) create mode 100644 evm/src/main/java/org/hyperledger/besu/evm/code/EOFValidator.java delete mode 100644 evm/src/main/java/org/hyperledger/besu/evm/contractvalidation/CachedInvalidCodeRule.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 2118b9abdcd..07cdf586349 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Reduce lock contention on transaction pool when building a block [#7180](https://github.com/hyperledger/besu/pull/7180) - Update Docker base image to Ubuntu 24.04 [#7251](https://github.com/hyperledger/besu/pull/7251) - Add LUKSO as predefined network name [#7223](https://github.com/hyperledger/besu/pull/7223) +- Refactored how code, initcode, and max stack size are configured in forks. [#7245](https://github.com/hyperledger/besu/pull/7245) ### Bug fixes - Validation errors ignored in accounts-allowlist and empty list [#7138](https://github.com/hyperledger/besu/issues/7138) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java index 7575c7fe314..aec844894f7 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ClassicProtocolSpecs.java @@ -26,7 +26,6 @@ import org.hyperledger.besu.evm.MainnetEVMs; import org.hyperledger.besu.evm.contractvalidation.MaxCodeSizeRule; import org.hyperledger.besu.evm.contractvalidation.PrefixCodeRule; -import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.gascalculator.BerlinGasCalculator; import org.hyperledger.besu.evm.gascalculator.DieHardGasCalculator; import org.hyperledger.besu.evm.gascalculator.IstanbulGasCalculator; @@ -44,7 +43,6 @@ import java.util.Collections; import java.util.List; import java.util.Optional; -import java.util.OptionalInt; import java.util.OptionalLong; import java.util.Set; @@ -56,38 +54,28 @@ private ClassicProtocolSpecs() { } public static ProtocolSpecBuilder classicRecoveryInitDefinition( - final OptionalInt contractSizeLimit, - final OptionalInt configStackSizeLimit, final EvmConfiguration evmConfiguration) { - return MainnetProtocolSpecs.homesteadDefinition( - contractSizeLimit, configStackSizeLimit, evmConfiguration) + return MainnetProtocolSpecs.homesteadDefinition(evmConfiguration) .blockHeaderValidatorBuilder( feeMarket -> MainnetBlockHeaderValidator.createClassicValidator()) .name("ClassicRecoveryInit"); } public static ProtocolSpecBuilder tangerineWhistleDefinition( - final Optional chainId, - final OptionalInt contractSizeLimit, - final OptionalInt configStackSizeLimit, - final EvmConfiguration evmConfiguration) { - return MainnetProtocolSpecs.homesteadDefinition( - contractSizeLimit, configStackSizeLimit, evmConfiguration) + final Optional chainId, final EvmConfiguration evmConfiguration) { + return MainnetProtocolSpecs.homesteadDefinition(evmConfiguration) .isReplayProtectionSupported(true) .gasCalculator(TangerineWhistleGasCalculator::new) .transactionValidatorFactoryBuilder( - (gasCalculator, gasLimitCalculator, feeMarket) -> - new TransactionValidatorFactory(gasCalculator, gasLimitCalculator, true, chainId)) + (evm, gasLimitCalculator, feeMarket) -> + new TransactionValidatorFactory( + evm.getGasCalculator(), gasLimitCalculator, true, chainId)) .name("ClassicTangerineWhistle"); } public static ProtocolSpecBuilder dieHardDefinition( - final Optional chainId, - final OptionalInt ignoredConfigContractSizeLimit, - final OptionalInt configStackSizeLimit, - final EvmConfiguration evmConfiguration) { - return tangerineWhistleDefinition( - chainId, OptionalInt.empty(), configStackSizeLimit, evmConfiguration) + final Optional chainId, final EvmConfiguration evmConfiguration) { + return tangerineWhistleDefinition(chainId, evmConfiguration) .gasCalculator(DieHardGasCalculator::new) .difficultyCalculator(ClassicDifficultyCalculators.DIFFICULTY_BOMB_PAUSED) .name("DieHard"); @@ -95,11 +83,9 @@ public static ProtocolSpecBuilder dieHardDefinition( public static ProtocolSpecBuilder gothamDefinition( final Optional chainId, - final OptionalInt contractSizeLimit, - final OptionalInt configStackSizeLimit, final OptionalLong ecip1017EraRounds, final EvmConfiguration evmConfiguration) { - return dieHardDefinition(chainId, contractSizeLimit, configStackSizeLimit, evmConfiguration) + return dieHardDefinition(chainId, evmConfiguration) .blockReward(MAX_BLOCK_REWARD) .difficultyCalculator(ClassicDifficultyCalculators.DIFFICULTY_BOMB_DELAYED) .blockProcessorBuilder( @@ -122,35 +108,23 @@ public static ProtocolSpecBuilder gothamDefinition( public static ProtocolSpecBuilder defuseDifficultyBombDefinition( final Optional chainId, - final OptionalInt contractSizeLimit, - final OptionalInt configStackSizeLimit, final OptionalLong ecip1017EraRounds, final EvmConfiguration evmConfiguration) { - return gothamDefinition( - chainId, contractSizeLimit, configStackSizeLimit, ecip1017EraRounds, evmConfiguration) + return gothamDefinition(chainId, ecip1017EraRounds, evmConfiguration) .difficultyCalculator(ClassicDifficultyCalculators.DIFFICULTY_BOMB_REMOVED) .transactionValidatorFactoryBuilder( - (gasCalculator, gasLimitCalculator, feeMarket) -> - new TransactionValidatorFactory(gasCalculator, gasLimitCalculator, true, chainId)) + (evm, gasLimitCalculator, feeMarket) -> + new TransactionValidatorFactory( + evm.getGasCalculator(), gasLimitCalculator, true, chainId)) .name("DefuseDifficultyBomb"); } public static ProtocolSpecBuilder atlantisDefinition( final Optional chainId, - final OptionalInt configContractSizeLimit, - final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final OptionalLong ecip1017EraRounds, final EvmConfiguration evmConfiguration) { - final int contractSizeLimit = - configContractSizeLimit.orElse(MainnetProtocolSpecs.SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT); - final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE); - return gothamDefinition( - chainId, - configContractSizeLimit, - configStackSizeLimit, - ecip1017EraRounds, - evmConfiguration) + return gothamDefinition(chainId, ecip1017EraRounds, evmConfiguration) .evmBuilder(MainnetEVMs::byzantium) .evmConfiguration(evmConfiguration) .gasCalculator(SpuriousDragonGasCalculator::new) @@ -163,13 +137,9 @@ public static ProtocolSpecBuilder atlantisDefinition( ? ClassicProtocolSpecs::byzantiumTransactionReceiptFactoryWithReasonEnabled : ClassicProtocolSpecs::byzantiumTransactionReceiptFactory) .contractCreationProcessorBuilder( - (gasCalculator, evm) -> + evm -> new ContractCreationProcessor( - gasCalculator, - evm, - true, - Collections.singletonList(MaxCodeSizeRule.of(contractSizeLimit)), - 1)) + evm, true, Collections.singletonList(MaxCodeSizeRule.from(evm)), 1)) .transactionProcessorBuilder( (gasCalculator, feeMarket, @@ -183,7 +153,7 @@ public static ProtocolSpecBuilder atlantisDefinition( messageCallProcessor, true, false, - stackSizeLimit, + evmConfiguration.evmStackSize(), feeMarket, CoinbaseFeePriceCalculator.frontier())) .name("Atlantis"); @@ -191,18 +161,10 @@ public static ProtocolSpecBuilder atlantisDefinition( public static ProtocolSpecBuilder aghartaDefinition( final Optional chainId, - final OptionalInt configContractSizeLimit, - final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final OptionalLong ecip1017EraRounds, final EvmConfiguration evmConfiguration) { - return atlantisDefinition( - chainId, - configContractSizeLimit, - configStackSizeLimit, - enableRevertReason, - ecip1017EraRounds, - evmConfiguration) + return atlantisDefinition(chainId, enableRevertReason, ecip1017EraRounds, evmConfiguration) .evmBuilder(MainnetEVMs::constantinople) .gasCalculator(PetersburgGasCalculator::new) .evmBuilder(MainnetEVMs::constantinople) @@ -212,18 +174,10 @@ public static ProtocolSpecBuilder aghartaDefinition( public static ProtocolSpecBuilder phoenixDefinition( final Optional chainId, - final OptionalInt configContractSizeLimit, - final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final OptionalLong ecip1017EraRounds, final EvmConfiguration evmConfiguration) { - return aghartaDefinition( - chainId, - configContractSizeLimit, - configStackSizeLimit, - enableRevertReason, - ecip1017EraRounds, - evmConfiguration) + return aghartaDefinition(chainId, enableRevertReason, ecip1017EraRounds, evmConfiguration) .gasCalculator(IstanbulGasCalculator::new) .evmBuilder( (gasCalculator, evmConfig) -> @@ -235,18 +189,10 @@ public static ProtocolSpecBuilder phoenixDefinition( public static ProtocolSpecBuilder thanosDefinition( final Optional chainId, - final OptionalInt configContractSizeLimit, - final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final OptionalLong ecip1017EraRounds, final EvmConfiguration evmConfiguration) { - return phoenixDefinition( - chainId, - configContractSizeLimit, - configStackSizeLimit, - enableRevertReason, - ecip1017EraRounds, - evmConfiguration) + return phoenixDefinition(chainId, enableRevertReason, ecip1017EraRounds, evmConfiguration) .blockHeaderValidatorBuilder( feeMarket -> MainnetBlockHeaderValidator.createPgaBlockHeaderValidator( @@ -280,23 +226,15 @@ private static TransactionReceipt byzantiumTransactionReceiptFactoryWithReasonEn public static ProtocolSpecBuilder magnetoDefinition( final Optional chainId, - final OptionalInt configContractSizeLimit, - final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final OptionalLong ecip1017EraRounds, final EvmConfiguration evmConfiguration) { - return thanosDefinition( - chainId, - configContractSizeLimit, - configStackSizeLimit, - enableRevertReason, - ecip1017EraRounds, - evmConfiguration) + return thanosDefinition(chainId, enableRevertReason, ecip1017EraRounds, evmConfiguration) .gasCalculator(BerlinGasCalculator::new) .transactionValidatorFactoryBuilder( - (gasCalculator, gasLimitCalculator, feeMarket) -> + (evm, gasLimitCalculator, feeMarket) -> new TransactionValidatorFactory( - gasCalculator, + evm.getGasCalculator(), gasLimitCalculator, true, chainId, @@ -310,47 +248,24 @@ public static ProtocolSpecBuilder magnetoDefinition( public static ProtocolSpecBuilder mystiqueDefinition( final Optional chainId, - final OptionalInt configContractSizeLimit, - final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final OptionalLong ecip1017EraRounds, final EvmConfiguration evmConfiguration) { - final int contractSizeLimit = - configContractSizeLimit.orElse(MainnetProtocolSpecs.SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT); - return magnetoDefinition( - chainId, - configContractSizeLimit, - configStackSizeLimit, - enableRevertReason, - ecip1017EraRounds, - evmConfiguration) + return magnetoDefinition(chainId, enableRevertReason, ecip1017EraRounds, evmConfiguration) .gasCalculator(LondonGasCalculator::new) .contractCreationProcessorBuilder( - (gasCalculator, evm) -> + evm -> new ContractCreationProcessor( - gasCalculator, - evm, - true, - List.of(MaxCodeSizeRule.of(contractSizeLimit), PrefixCodeRule.of()), - 1)) + evm, true, List.of(MaxCodeSizeRule.from(evm), PrefixCodeRule.of()), 1)) .name("Mystique"); } public static ProtocolSpecBuilder spiralDefinition( final Optional chainId, - final OptionalInt configContractSizeLimit, - final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final OptionalLong ecip1017EraRounds, final EvmConfiguration evmConfiguration) { - final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE); - return mystiqueDefinition( - chainId, - configContractSizeLimit, - configStackSizeLimit, - enableRevertReason, - ecip1017EraRounds, - evmConfiguration) + return mystiqueDefinition(chainId, enableRevertReason, ecip1017EraRounds, evmConfiguration) // EIP-3860 .gasCalculator(ShanghaiGasCalculator::new) // EIP-3855 @@ -372,7 +287,7 @@ public static ProtocolSpecBuilder spiralDefinition( messageCallProcessor, true, true, - stackSizeLimit, + evmConfiguration.evmStackSize(), feeMarket, CoinbaseFeePriceCalculator.frontier())) .name("Spiral"); diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecFactory.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecFactory.java index 095a85ef53f..a902d9faa74 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecFactory.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecFactory.java @@ -20,14 +20,11 @@ import java.math.BigInteger; import java.util.Optional; -import java.util.OptionalInt; import java.util.OptionalLong; public class MainnetProtocolSpecFactory { private final Optional chainId; - private final OptionalInt contractSizeLimit; - private final OptionalInt evmStackSize; private final boolean isRevertReasonEnabled; private final OptionalLong ecip1017EraRounds; private final EvmConfiguration evmConfiguration; @@ -35,15 +32,11 @@ public class MainnetProtocolSpecFactory { public MainnetProtocolSpecFactory( final Optional chainId, - final OptionalInt contractSizeLimit, - final OptionalInt evmStackSize, final boolean isRevertReasonEnabled, final OptionalLong ecip1017EraRounds, final EvmConfiguration evmConfiguration, final MiningParameters miningParameters) { this.chainId = chainId; - this.contractSizeLimit = contractSizeLimit; - this.evmStackSize = evmStackSize; this.isRevertReasonEnabled = isRevertReasonEnabled; this.ecip1017EraRounds = ecip1017EraRounds; this.evmConfiguration = evmConfiguration; @@ -51,153 +44,98 @@ public MainnetProtocolSpecFactory( } public ProtocolSpecBuilder frontierDefinition() { - return MainnetProtocolSpecs.frontierDefinition( - contractSizeLimit, evmStackSize, evmConfiguration); + return MainnetProtocolSpecs.frontierDefinition(evmConfiguration); } public ProtocolSpecBuilder homesteadDefinition() { - return MainnetProtocolSpecs.homesteadDefinition( - contractSizeLimit, evmStackSize, evmConfiguration); + return MainnetProtocolSpecs.homesteadDefinition(evmConfiguration); } public ProtocolSpecBuilder daoRecoveryInitDefinition() { - return MainnetProtocolSpecs.daoRecoveryInitDefinition( - contractSizeLimit, evmStackSize, evmConfiguration); + return MainnetProtocolSpecs.daoRecoveryInitDefinition(evmConfiguration); } public ProtocolSpecBuilder daoRecoveryTransitionDefinition() { - return MainnetProtocolSpecs.daoRecoveryTransitionDefinition( - contractSizeLimit, evmStackSize, evmConfiguration); + return MainnetProtocolSpecs.daoRecoveryTransitionDefinition(evmConfiguration); } public ProtocolSpecBuilder tangerineWhistleDefinition() { - return MainnetProtocolSpecs.tangerineWhistleDefinition( - contractSizeLimit, evmStackSize, evmConfiguration); + return MainnetProtocolSpecs.tangerineWhistleDefinition(evmConfiguration); } public ProtocolSpecBuilder spuriousDragonDefinition() { - return MainnetProtocolSpecs.spuriousDragonDefinition( - chainId, contractSizeLimit, evmStackSize, evmConfiguration); + return MainnetProtocolSpecs.spuriousDragonDefinition(chainId, evmConfiguration); } public ProtocolSpecBuilder byzantiumDefinition() { return MainnetProtocolSpecs.byzantiumDefinition( - chainId, contractSizeLimit, evmStackSize, isRevertReasonEnabled, evmConfiguration); + chainId, isRevertReasonEnabled, evmConfiguration); } public ProtocolSpecBuilder constantinopleDefinition() { return MainnetProtocolSpecs.constantinopleDefinition( - chainId, contractSizeLimit, evmStackSize, isRevertReasonEnabled, evmConfiguration); + chainId, isRevertReasonEnabled, evmConfiguration); } public ProtocolSpecBuilder petersburgDefinition() { return MainnetProtocolSpecs.petersburgDefinition( - chainId, contractSizeLimit, evmStackSize, isRevertReasonEnabled, evmConfiguration); + chainId, isRevertReasonEnabled, evmConfiguration); } public ProtocolSpecBuilder istanbulDefinition() { return MainnetProtocolSpecs.istanbulDefinition( - chainId, contractSizeLimit, evmStackSize, isRevertReasonEnabled, evmConfiguration); + chainId, isRevertReasonEnabled, evmConfiguration); } public ProtocolSpecBuilder muirGlacierDefinition() { return MainnetProtocolSpecs.muirGlacierDefinition( - chainId, contractSizeLimit, evmStackSize, isRevertReasonEnabled, evmConfiguration); + chainId, isRevertReasonEnabled, evmConfiguration); } public ProtocolSpecBuilder berlinDefinition() { - return MainnetProtocolSpecs.berlinDefinition( - chainId, contractSizeLimit, evmStackSize, isRevertReasonEnabled, evmConfiguration); + return MainnetProtocolSpecs.berlinDefinition(chainId, isRevertReasonEnabled, evmConfiguration); } public ProtocolSpecBuilder londonDefinition(final GenesisConfigOptions genesisConfigOptions) { return MainnetProtocolSpecs.londonDefinition( - chainId, - contractSizeLimit, - evmStackSize, - isRevertReasonEnabled, - genesisConfigOptions, - evmConfiguration, - miningParameters); + chainId, isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, miningParameters); } public ProtocolSpecBuilder arrowGlacierDefinition( final GenesisConfigOptions genesisConfigOptions) { return MainnetProtocolSpecs.arrowGlacierDefinition( - chainId, - contractSizeLimit, - evmStackSize, - isRevertReasonEnabled, - genesisConfigOptions, - evmConfiguration, - miningParameters); + chainId, isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, miningParameters); } public ProtocolSpecBuilder grayGlacierDefinition( final GenesisConfigOptions genesisConfigOptions) { return MainnetProtocolSpecs.grayGlacierDefinition( - chainId, - contractSizeLimit, - evmStackSize, - isRevertReasonEnabled, - genesisConfigOptions, - evmConfiguration, - miningParameters); + chainId, isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, miningParameters); } public ProtocolSpecBuilder parisDefinition(final GenesisConfigOptions genesisConfigOptions) { return MainnetProtocolSpecs.parisDefinition( - chainId, - contractSizeLimit, - evmStackSize, - isRevertReasonEnabled, - genesisConfigOptions, - evmConfiguration, - miningParameters); + chainId, isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, miningParameters); } public ProtocolSpecBuilder shanghaiDefinition(final GenesisConfigOptions genesisConfigOptions) { return MainnetProtocolSpecs.shanghaiDefinition( - chainId, - contractSizeLimit, - evmStackSize, - isRevertReasonEnabled, - genesisConfigOptions, - evmConfiguration, - miningParameters); + chainId, isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, miningParameters); } public ProtocolSpecBuilder cancunDefinition(final GenesisConfigOptions genesisConfigOptions) { return MainnetProtocolSpecs.cancunDefinition( - chainId, - contractSizeLimit, - evmStackSize, - isRevertReasonEnabled, - genesisConfigOptions, - evmConfiguration, - miningParameters); + chainId, isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, miningParameters); } public ProtocolSpecBuilder pragueDefinition(final GenesisConfigOptions genesisConfigOptions) { return MainnetProtocolSpecs.pragueDefinition( - chainId, - contractSizeLimit, - evmStackSize, - isRevertReasonEnabled, - genesisConfigOptions, - evmConfiguration, - miningParameters); + chainId, isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, miningParameters); } public ProtocolSpecBuilder pragueEOFDefinition(final GenesisConfigOptions genesisConfigOptions) { return MainnetProtocolSpecs.pragueEOFDefinition( - chainId, - contractSizeLimit, - evmStackSize, - isRevertReasonEnabled, - genesisConfigOptions, - evmConfiguration, - miningParameters); + chainId, isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, miningParameters); } /** @@ -213,13 +151,7 @@ public ProtocolSpecBuilder pragueEOFDefinition(final GenesisConfigOptions genesi */ public ProtocolSpecBuilder futureEipsDefinition(final GenesisConfigOptions genesisConfigOptions) { return MainnetProtocolSpecs.futureEipsDefinition( - chainId, - contractSizeLimit, - evmStackSize, - isRevertReasonEnabled, - genesisConfigOptions, - evmConfiguration, - miningParameters); + chainId, isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, miningParameters); } /** @@ -235,100 +167,57 @@ public ProtocolSpecBuilder futureEipsDefinition(final GenesisConfigOptions genes public ProtocolSpecBuilder experimentalEipsDefinition( final GenesisConfigOptions genesisConfigOptions) { return MainnetProtocolSpecs.experimentalEipsDefinition( - chainId, - contractSizeLimit, - evmStackSize, - isRevertReasonEnabled, - genesisConfigOptions, - evmConfiguration, - miningParameters); + chainId, isRevertReasonEnabled, genesisConfigOptions, evmConfiguration, miningParameters); } //////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////// // Classic Protocol Specs public ProtocolSpecBuilder dieHardDefinition() { - return ClassicProtocolSpecs.dieHardDefinition( - chainId, contractSizeLimit, evmStackSize, evmConfiguration); + return ClassicProtocolSpecs.dieHardDefinition(chainId, evmConfiguration); } public ProtocolSpecBuilder gothamDefinition() { - return ClassicProtocolSpecs.gothamDefinition( - chainId, contractSizeLimit, evmStackSize, ecip1017EraRounds, evmConfiguration); + return ClassicProtocolSpecs.gothamDefinition(chainId, ecip1017EraRounds, evmConfiguration); } public ProtocolSpecBuilder defuseDifficultyBombDefinition() { return ClassicProtocolSpecs.defuseDifficultyBombDefinition( - chainId, contractSizeLimit, evmStackSize, ecip1017EraRounds, evmConfiguration); + chainId, ecip1017EraRounds, evmConfiguration); } public ProtocolSpecBuilder atlantisDefinition() { return ClassicProtocolSpecs.atlantisDefinition( - chainId, - contractSizeLimit, - evmStackSize, - isRevertReasonEnabled, - ecip1017EraRounds, - evmConfiguration); + chainId, isRevertReasonEnabled, ecip1017EraRounds, evmConfiguration); } public ProtocolSpecBuilder aghartaDefinition() { return ClassicProtocolSpecs.aghartaDefinition( - chainId, - contractSizeLimit, - evmStackSize, - isRevertReasonEnabled, - ecip1017EraRounds, - evmConfiguration); + chainId, isRevertReasonEnabled, ecip1017EraRounds, evmConfiguration); } public ProtocolSpecBuilder phoenixDefinition() { return ClassicProtocolSpecs.phoenixDefinition( - chainId, - contractSizeLimit, - evmStackSize, - isRevertReasonEnabled, - ecip1017EraRounds, - evmConfiguration); + chainId, isRevertReasonEnabled, ecip1017EraRounds, evmConfiguration); } public ProtocolSpecBuilder thanosDefinition() { return ClassicProtocolSpecs.thanosDefinition( - chainId, - contractSizeLimit, - evmStackSize, - isRevertReasonEnabled, - ecip1017EraRounds, - evmConfiguration); + chainId, isRevertReasonEnabled, ecip1017EraRounds, evmConfiguration); } public ProtocolSpecBuilder magnetoDefinition() { return ClassicProtocolSpecs.magnetoDefinition( - chainId, - contractSizeLimit, - evmStackSize, - isRevertReasonEnabled, - ecip1017EraRounds, - evmConfiguration); + chainId, isRevertReasonEnabled, ecip1017EraRounds, evmConfiguration); } public ProtocolSpecBuilder mystiqueDefinition() { return ClassicProtocolSpecs.mystiqueDefinition( - chainId, - contractSizeLimit, - evmStackSize, - isRevertReasonEnabled, - ecip1017EraRounds, - evmConfiguration); + chainId, isRevertReasonEnabled, ecip1017EraRounds, evmConfiguration); } public ProtocolSpecBuilder spiralDefinition() { return ClassicProtocolSpecs.spiralDefinition( - chainId, - contractSizeLimit, - evmStackSize, - isRevertReasonEnabled, - ecip1017EraRounds, - evmConfiguration); + chainId, isRevertReasonEnabled, ecip1017EraRounds, evmConfiguration); } } diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java index 16fee28bb50..763c751e4f9 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/MainnetProtocolSpecs.java @@ -48,7 +48,6 @@ import org.hyperledger.besu.evm.contractvalidation.EOFValidationCodeRule; import org.hyperledger.besu.evm.contractvalidation.MaxCodeSizeRule; import org.hyperledger.besu.evm.contractvalidation.PrefixCodeRule; -import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.gascalculator.BerlinGasCalculator; import org.hyperledger.besu.evm.gascalculator.ByzantiumGasCalculator; import org.hyperledger.besu.evm.gascalculator.CancunGasCalculator; @@ -74,8 +73,8 @@ import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.Optional; -import java.util.OptionalInt; import java.util.Set; import java.util.stream.IntStream; @@ -85,11 +84,6 @@ /** Provides the various {@link ProtocolSpec}s on mainnet hard forks. */ public abstract class MainnetProtocolSpecs { - public static final int FRONTIER_CONTRACT_SIZE_LIMIT = Integer.MAX_VALUE; - - public static final int SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT = 24576; - public static final int SHANGHAI_INIT_CODE_SIZE_LIMIT = 2 * SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT; - private static final Address RIPEMD160_PRECOMPILE = Address.fromHexString("0x0000000000000000000000000000000000000003"); @@ -107,12 +101,7 @@ public abstract class MainnetProtocolSpecs { private MainnetProtocolSpecs() {} - public static ProtocolSpecBuilder frontierDefinition( - final OptionalInt configContractSizeLimit, - final OptionalInt configStackSizeLimit, - final EvmConfiguration evmConfiguration) { - final int contractSizeLimit = configContractSizeLimit.orElse(FRONTIER_CONTRACT_SIZE_LIMIT); - final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE); + public static ProtocolSpecBuilder frontierDefinition(final EvmConfiguration evmConfiguration) { return new ProtocolSpecBuilder() .gasCalculator(FrontierGasCalculator::new) .gasLimitCalculatorBuilder(feeMarket -> new FrontierTargetingGasLimitCalculator()) @@ -120,17 +109,13 @@ public static ProtocolSpecBuilder frontierDefinition( .precompileContractRegistryBuilder(MainnetPrecompiledContractRegistries::frontier) .messageCallProcessorBuilder(MessageCallProcessor::new) .contractCreationProcessorBuilder( - (gasCalculator, evm) -> + evm -> new ContractCreationProcessor( - gasCalculator, - evm, - false, - Collections.singletonList(MaxCodeSizeRule.of(contractSizeLimit)), - 0)) + evm, false, Collections.singletonList(MaxCodeSizeRule.from(evm)), 0)) .transactionValidatorFactoryBuilder( - (gasCalculator, gasLimitCalculator, feeMarket) -> + (evm, gasLimitCalculator, feeMarket) -> new TransactionValidatorFactory( - gasCalculator, gasLimitCalculator, false, Optional.empty())) + evm.getGasCalculator(), gasLimitCalculator, false, Optional.empty())) .transactionProcessorBuilder( (gasCalculator, feeMarket, @@ -144,7 +129,7 @@ public static ProtocolSpecBuilder frontierDefinition( messageCallProcessor, false, false, - stackSizeLimit, + evmConfiguration.evmStackSize(), FeeMarket.legacy(), CoinbaseFeePriceCalculator.frontier())) .privateTransactionProcessorBuilder( @@ -157,7 +142,7 @@ public static ProtocolSpecBuilder frontierDefinition( contractCreationProcessor, messageCallProcessor, false, - stackSizeLimit, + evmConfiguration.evmStackSize(), new PrivateTransactionValidator(Optional.empty()))) .difficultyCalculator(MainnetDifficultyCalculators.FRONTIER) .blockHeaderValidatorBuilder(feeMarket -> MainnetBlockHeaderValidator.create()) @@ -188,35 +173,25 @@ public static BlockValidatorBuilder blockValidatorBuilder() { return MainnetBlockValidator::new; } - public static ProtocolSpecBuilder homesteadDefinition( - final OptionalInt configContractSizeLimit, - final OptionalInt configStackSizeLimit, - final EvmConfiguration evmConfiguration) { - final int contractSizeLimit = configContractSizeLimit.orElse(FRONTIER_CONTRACT_SIZE_LIMIT); - return frontierDefinition(configContractSizeLimit, configStackSizeLimit, evmConfiguration) + public static ProtocolSpecBuilder homesteadDefinition(final EvmConfiguration evmConfiguration) { + return frontierDefinition(evmConfiguration) .gasCalculator(HomesteadGasCalculator::new) .evmBuilder(MainnetEVMs::homestead) .contractCreationProcessorBuilder( - (gasCalculator, evm) -> + evm -> new ContractCreationProcessor( - gasCalculator, - evm, - true, - Collections.singletonList(MaxCodeSizeRule.of(contractSizeLimit)), - 0)) + evm, true, Collections.singletonList(MaxCodeSizeRule.from(evm)), 0)) .transactionValidatorFactoryBuilder( - (gasCalculator, gasLimitCalculator, feeMarket) -> + (evm, gasLimitCalculator, feeMarket) -> new TransactionValidatorFactory( - gasCalculator, gasLimitCalculator, true, Optional.empty())) + evm.getGasCalculator(), gasLimitCalculator, true, Optional.empty())) .difficultyCalculator(MainnetDifficultyCalculators.HOMESTEAD) .name("Homestead"); } public static ProtocolSpecBuilder daoRecoveryInitDefinition( - final OptionalInt contractSizeLimit, - final OptionalInt configStackSizeLimit, final EvmConfiguration evmConfiguration) { - return homesteadDefinition(contractSizeLimit, configStackSizeLimit, evmConfiguration) + return homesteadDefinition(evmConfiguration) .blockHeaderValidatorBuilder(feeMarket -> MainnetBlockHeaderValidator.createDaoValidator()) .blockProcessorBuilder( (transactionProcessor, @@ -237,33 +212,22 @@ public static ProtocolSpecBuilder daoRecoveryInitDefinition( } public static ProtocolSpecBuilder daoRecoveryTransitionDefinition( - final OptionalInt contractSizeLimit, - final OptionalInt configStackSizeLimit, final EvmConfiguration evmConfiguration) { - return daoRecoveryInitDefinition(contractSizeLimit, configStackSizeLimit, evmConfiguration) + return daoRecoveryInitDefinition(evmConfiguration) .blockProcessorBuilder(MainnetBlockProcessor::new) .name("DaoRecoveryTransition"); } public static ProtocolSpecBuilder tangerineWhistleDefinition( - final OptionalInt contractSizeLimit, - final OptionalInt configStackSizeLimit, final EvmConfiguration evmConfiguration) { - return homesteadDefinition(contractSizeLimit, configStackSizeLimit, evmConfiguration) + return homesteadDefinition(evmConfiguration) .gasCalculator(TangerineWhistleGasCalculator::new) .name("TangerineWhistle"); } public static ProtocolSpecBuilder spuriousDragonDefinition( - final Optional chainId, - final OptionalInt configContractSizeLimit, - final OptionalInt configStackSizeLimit, - final EvmConfiguration evmConfiguration) { - final int contractSizeLimit = - configContractSizeLimit.orElse(SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT); - final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE); - - return tangerineWhistleDefinition(OptionalInt.empty(), configStackSizeLimit, evmConfiguration) + final Optional chainId, final EvmConfiguration evmConfiguration) { + return tangerineWhistleDefinition(evmConfiguration) .isReplayProtectionSupported(true) .gasCalculator(SpuriousDragonGasCalculator::new) .skipZeroBlockRewards(true) @@ -274,17 +238,17 @@ public static ProtocolSpecBuilder spuriousDragonDefinition( precompileContractRegistry, SPURIOUS_DRAGON_FORCE_DELETE_WHEN_EMPTY_ADDRESSES)) .contractCreationProcessorBuilder( - (gasCalculator, evm) -> + evm -> new ContractCreationProcessor( - gasCalculator, evm, true, - Collections.singletonList(MaxCodeSizeRule.of(contractSizeLimit)), + Collections.singletonList(MaxCodeSizeRule.from(evm)), 1, SPURIOUS_DRAGON_FORCE_DELETE_WHEN_EMPTY_ADDRESSES)) .transactionValidatorFactoryBuilder( - (gasCalculator, gasLimitCalculator, feeMarket) -> - new TransactionValidatorFactory(gasCalculator, gasLimitCalculator, true, chainId)) + (evm, gasLimitCalculator, feeMarket) -> + new TransactionValidatorFactory( + evm.getGasCalculator(), gasLimitCalculator, true, chainId)) .transactionProcessorBuilder( (gasCalculator, feeMarket, @@ -298,7 +262,7 @@ public static ProtocolSpecBuilder spuriousDragonDefinition( messageCallProcessor, true, false, - stackSizeLimit, + evmConfiguration.evmStackSize(), feeMarket, CoinbaseFeePriceCalculator.frontier())) .name("SpuriousDragon"); @@ -306,13 +270,9 @@ public static ProtocolSpecBuilder spuriousDragonDefinition( public static ProtocolSpecBuilder byzantiumDefinition( final Optional chainId, - final OptionalInt contractSizeLimit, - final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final EvmConfiguration evmConfiguration) { - final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE); - return spuriousDragonDefinition( - chainId, contractSizeLimit, configStackSizeLimit, evmConfiguration) + return spuriousDragonDefinition(chainId, evmConfiguration) .gasCalculator(ByzantiumGasCalculator::new) .evmBuilder(MainnetEVMs::byzantium) .precompileContractRegistryBuilder(MainnetPrecompiledContractRegistries::byzantium) @@ -333,19 +293,16 @@ public static ProtocolSpecBuilder byzantiumDefinition( contractCreationProcessor, messageCallProcessor, false, - stackSizeLimit, + evmConfiguration.evmStackSize(), privateTransactionValidator)) .name("Byzantium"); } public static ProtocolSpecBuilder constantinopleDefinition( final Optional chainId, - final OptionalInt contractSizeLimit, - final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final EvmConfiguration evmConfiguration) { - return byzantiumDefinition( - chainId, contractSizeLimit, configStackSizeLimit, enableRevertReason, evmConfiguration) + return byzantiumDefinition(chainId, enableRevertReason, evmConfiguration) .difficultyCalculator(MainnetDifficultyCalculators.CONSTANTINOPLE) .gasCalculator(ConstantinopleGasCalculator::new) .evmBuilder(MainnetEVMs::constantinople) @@ -355,30 +312,18 @@ public static ProtocolSpecBuilder constantinopleDefinition( public static ProtocolSpecBuilder petersburgDefinition( final Optional chainId, - final OptionalInt contractSizeLimit, - final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final EvmConfiguration evmConfiguration) { - return constantinopleDefinition( - chainId, contractSizeLimit, configStackSizeLimit, enableRevertReason, evmConfiguration) + return constantinopleDefinition(chainId, enableRevertReason, evmConfiguration) .gasCalculator(PetersburgGasCalculator::new) .name("Petersburg"); } public static ProtocolSpecBuilder istanbulDefinition( final Optional chainId, - final OptionalInt configContractSizeLimit, - final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final EvmConfiguration evmConfiguration) { - final int contractSizeLimit = - configContractSizeLimit.orElse(SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT); - return petersburgDefinition( - chainId, - configContractSizeLimit, - configStackSizeLimit, - enableRevertReason, - evmConfiguration) + return petersburgDefinition(chainId, enableRevertReason, evmConfiguration) .gasCalculator(IstanbulGasCalculator::new) .evmBuilder( (gasCalculator, jdCacheConfig) -> @@ -386,12 +331,11 @@ public static ProtocolSpecBuilder istanbulDefinition( gasCalculator, chainId.orElse(BigInteger.ZERO), evmConfiguration)) .precompileContractRegistryBuilder(MainnetPrecompiledContractRegistries::istanbul) .contractCreationProcessorBuilder( - (gasCalculator, evm) -> + evm -> new ContractCreationProcessor( - gasCalculator, evm, true, - Collections.singletonList(MaxCodeSizeRule.of(contractSizeLimit)), + Collections.singletonList(MaxCodeSizeRule.from(evm)), 1, SPURIOUS_DRAGON_FORCE_DELETE_WHEN_EMPTY_ADDRESSES)) .name("Istanbul"); @@ -399,29 +343,23 @@ public static ProtocolSpecBuilder istanbulDefinition( static ProtocolSpecBuilder muirGlacierDefinition( final Optional chainId, - final OptionalInt contractSizeLimit, - final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final EvmConfiguration evmConfiguration) { - return istanbulDefinition( - chainId, contractSizeLimit, configStackSizeLimit, enableRevertReason, evmConfiguration) + return istanbulDefinition(chainId, enableRevertReason, evmConfiguration) .difficultyCalculator(MainnetDifficultyCalculators.MUIR_GLACIER) .name("MuirGlacier"); } static ProtocolSpecBuilder berlinDefinition( final Optional chainId, - final OptionalInt contractSizeLimit, - final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final EvmConfiguration evmConfiguration) { - return muirGlacierDefinition( - chainId, contractSizeLimit, configStackSizeLimit, enableRevertReason, evmConfiguration) + return muirGlacierDefinition(chainId, enableRevertReason, evmConfiguration) .gasCalculator(BerlinGasCalculator::new) .transactionValidatorFactoryBuilder( - (gasCalculator, gasLimitCalculator, feeMarket) -> + (evm, gasLimitCalculator, feeMarket) -> new TransactionValidatorFactory( - gasCalculator, + evm.getGasCalculator(), gasLimitCalculator, true, chainId, @@ -435,30 +373,24 @@ static ProtocolSpecBuilder berlinDefinition( static ProtocolSpecBuilder londonDefinition( final Optional chainId, - final OptionalInt configContractSizeLimit, - final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, final MiningParameters miningParameters) { - final int contractSizeLimit = - configContractSizeLimit.orElse(SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT); - final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE); final long londonForkBlockNumber = genesisConfigOptions.getLondonBlockNumber().orElse(Long.MAX_VALUE); - final BaseFeeMarket londonFeeMarket = - genesisConfigOptions.isZeroBaseFee() - ? FeeMarket.zeroBaseFee(londonForkBlockNumber) - : genesisConfigOptions.isFixedBaseFee() - ? FeeMarket.fixedBaseFee( - londonForkBlockNumber, miningParameters.getMinTransactionGasPrice()) - : FeeMarket.london(londonForkBlockNumber, genesisConfigOptions.getBaseFeePerGas()); - return berlinDefinition( - chainId, - configContractSizeLimit, - configStackSizeLimit, - enableRevertReason, - evmConfiguration) + final BaseFeeMarket londonFeeMarket; + if (genesisConfigOptions.isZeroBaseFee()) { + londonFeeMarket = FeeMarket.zeroBaseFee(londonForkBlockNumber); + } else if (genesisConfigOptions.isFixedBaseFee()) { + londonFeeMarket = + FeeMarket.fixedBaseFee( + londonForkBlockNumber, miningParameters.getMinTransactionGasPrice()); + } else { + londonFeeMarket = + FeeMarket.london(londonForkBlockNumber, genesisConfigOptions.getBaseFeePerGas()); + } + return berlinDefinition(chainId, enableRevertReason, evmConfiguration) .feeMarket(londonFeeMarket) .gasCalculator(LondonGasCalculator::new) .gasLimitCalculatorBuilder( @@ -466,9 +398,9 @@ static ProtocolSpecBuilder londonDefinition( new LondonTargetingGasLimitCalculator( londonForkBlockNumber, (BaseFeeMarket) feeMarket)) .transactionValidatorFactoryBuilder( - (gasCalculator, gasLimitCalculator, feeMarket) -> + (evm, gasLimitCalculator, feeMarket) -> new TransactionValidatorFactory( - gasCalculator, + evm.getGasCalculator(), gasLimitCalculator, feeMarket, true, @@ -491,16 +423,15 @@ static ProtocolSpecBuilder londonDefinition( messageCallProcessor, true, false, - stackSizeLimit, + evmConfiguration.evmStackSize(), feeMarket, CoinbaseFeePriceCalculator.eip1559())) .contractCreationProcessorBuilder( - (gasCalculator, evm) -> + evm -> new ContractCreationProcessor( - gasCalculator, evm, true, - List.of(MaxCodeSizeRule.of(contractSizeLimit), PrefixCodeRule.of()), + List.of(MaxCodeSizeRule.from(evm), PrefixCodeRule.of()), 1, SPURIOUS_DRAGON_FORCE_DELETE_WHEN_EMPTY_ADDRESSES)) .evmBuilder( @@ -521,61 +452,37 @@ static ProtocolSpecBuilder londonDefinition( static ProtocolSpecBuilder arrowGlacierDefinition( final Optional chainId, - final OptionalInt configContractSizeLimit, - final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, final MiningParameters miningParameters) { return londonDefinition( - chainId, - configContractSizeLimit, - configStackSizeLimit, - enableRevertReason, - genesisConfigOptions, - evmConfiguration, - miningParameters) + chainId, enableRevertReason, genesisConfigOptions, evmConfiguration, miningParameters) .difficultyCalculator(MainnetDifficultyCalculators.ARROW_GLACIER) .name("ArrowGlacier"); } static ProtocolSpecBuilder grayGlacierDefinition( final Optional chainId, - final OptionalInt configContractSizeLimit, - final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, final MiningParameters miningParameters) { return arrowGlacierDefinition( - chainId, - configContractSizeLimit, - configStackSizeLimit, - enableRevertReason, - genesisConfigOptions, - evmConfiguration, - miningParameters) + chainId, enableRevertReason, genesisConfigOptions, evmConfiguration, miningParameters) .difficultyCalculator(MainnetDifficultyCalculators.GRAY_GLACIER) .name("GrayGlacier"); } static ProtocolSpecBuilder parisDefinition( final Optional chainId, - final OptionalInt configContractSizeLimit, - final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, final MiningParameters miningParameters) { return grayGlacierDefinition( - chainId, - configContractSizeLimit, - configStackSizeLimit, - enableRevertReason, - genesisConfigOptions, - evmConfiguration, - miningParameters) + chainId, enableRevertReason, genesisConfigOptions, evmConfiguration, miningParameters) .evmBuilder( (gasCalculator, jdCacheConfig) -> MainnetEVMs.paris(gasCalculator, chainId.orElse(BigInteger.ZERO), evmConfiguration)) @@ -589,24 +496,12 @@ static ProtocolSpecBuilder parisDefinition( static ProtocolSpecBuilder shanghaiDefinition( final Optional chainId, - final OptionalInt configContractSizeLimit, - final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, final MiningParameters miningParameters) { - - // extra variables need to support flipping the warm coinbase flag. - final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE); - return parisDefinition( - chainId, - configContractSizeLimit, - configStackSizeLimit, - enableRevertReason, - genesisConfigOptions, - evmConfiguration, - miningParameters) + chainId, enableRevertReason, genesisConfigOptions, evmConfiguration, miningParameters) // gas calculator has new code to support EIP-3860 limit and meter initcode .gasCalculator(ShanghaiGasCalculator::new) // EVM has a new operation for EIP-3855 PUSH0 instruction @@ -628,14 +523,14 @@ static ProtocolSpecBuilder shanghaiDefinition( messageCallProcessor, true, true, - stackSizeLimit, + evmConfiguration.evmStackSize(), feeMarket, CoinbaseFeePriceCalculator.eip1559())) // Contract creation rules for EIP-3860 Limit and meter intitcode .transactionValidatorFactoryBuilder( - (gasCalculator, gasLimitCalculator, feeMarket) -> + (evm, gasLimitCalculator, feeMarket) -> new TransactionValidatorFactory( - gasCalculator, + evm.getGasCalculator(), gasLimitCalculator, feeMarket, true, @@ -644,7 +539,7 @@ static ProtocolSpecBuilder shanghaiDefinition( TransactionType.FRONTIER, TransactionType.ACCESS_LIST, TransactionType.EIP1559), - SHANGHAI_INIT_CODE_SIZE_LIMIT)) + evm.getEvmVersion().getMaxInitcodeSize())) .withdrawalsProcessor(new WithdrawalsProcessor()) .withdrawalsValidator(new WithdrawalsValidator.AllowedWithdrawals()) .name("Shanghai"); @@ -652,31 +547,25 @@ static ProtocolSpecBuilder shanghaiDefinition( static ProtocolSpecBuilder cancunDefinition( final Optional chainId, - final OptionalInt configContractSizeLimit, - final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, final MiningParameters miningParameters) { - - final int stackSizeLimit = configStackSizeLimit.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE); final long londonForkBlockNumber = genesisConfigOptions.getLondonBlockNumber().orElse(0L); - final BaseFeeMarket cancunFeeMarket = - genesisConfigOptions.isZeroBaseFee() - ? FeeMarket.zeroBaseFee(londonForkBlockNumber) - : genesisConfigOptions.isFixedBaseFee() - ? FeeMarket.fixedBaseFee( - londonForkBlockNumber, miningParameters.getMinTransactionGasPrice()) - : FeeMarket.cancun(londonForkBlockNumber, genesisConfigOptions.getBaseFeePerGas()); + final BaseFeeMarket cancunFeeMarket; + if (genesisConfigOptions.isZeroBaseFee()) { + cancunFeeMarket = FeeMarket.zeroBaseFee(londonForkBlockNumber); + } else if (genesisConfigOptions.isFixedBaseFee()) { + cancunFeeMarket = + FeeMarket.fixedBaseFee( + londonForkBlockNumber, miningParameters.getMinTransactionGasPrice()); + } else { + cancunFeeMarket = + FeeMarket.cancun(londonForkBlockNumber, genesisConfigOptions.getBaseFeePerGas()); + } return shanghaiDefinition( - chainId, - configContractSizeLimit, - configStackSizeLimit, - enableRevertReason, - genesisConfigOptions, - evmConfiguration, - miningParameters) + chainId, enableRevertReason, genesisConfigOptions, evmConfiguration, miningParameters) .feeMarket(cancunFeeMarket) // gas calculator for EIP-4844 blob gas .gasCalculator(CancunGasCalculator::new) @@ -704,14 +593,14 @@ static ProtocolSpecBuilder cancunDefinition( messageCallProcessor, true, true, - stackSizeLimit, + evmConfiguration.evmStackSize(), feeMarket, CoinbaseFeePriceCalculator.eip1559())) // change to check for max blob gas per block for EIP-4844 .transactionValidatorFactoryBuilder( - (gasCalculator, gasLimitCalculator, feeMarket) -> + (evm, gasLimitCalculator, feeMarket) -> new TransactionValidatorFactory( - gasCalculator, + evm.getGasCalculator(), gasLimitCalculator, feeMarket, true, @@ -721,7 +610,7 @@ static ProtocolSpecBuilder cancunDefinition( TransactionType.ACCESS_LIST, TransactionType.EIP1559, TransactionType.BLOB), - SHANGHAI_INIT_CODE_SIZE_LIMIT)) + evm.getEvmVersion().getMaxInitcodeSize())) .precompileContractRegistryBuilder(MainnetPrecompiledContractRegistries::cancun) .blockHeaderValidatorBuilder(MainnetBlockHeaderValidator::cancunBlockHeaderValidator) .blockHashProcessor(new CancunBlockHashProcessor()) @@ -730,8 +619,6 @@ static ProtocolSpecBuilder cancunDefinition( static ProtocolSpecBuilder pragueDefinition( final Optional chainId, - final OptionalInt configContractSizeLimit, - final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, @@ -741,13 +628,7 @@ static ProtocolSpecBuilder pragueDefinition( genesisConfigOptions.getDepositContractAddress().orElse(DEFAULT_DEPOSIT_CONTRACT_ADDRESS); return cancunDefinition( - chainId, - configContractSizeLimit, - configStackSizeLimit, - enableRevertReason, - genesisConfigOptions, - evmConfiguration, - miningParameters) + chainId, enableRevertReason, genesisConfigOptions, evmConfiguration, miningParameters) // EIP-3074 AUTH and AUTCALL gas .gasCalculator(PragueGasCalculator::new) // EIP-3074 AUTH and AUTCALL @@ -759,9 +640,9 @@ static ProtocolSpecBuilder pragueDefinition( // EIP-2537 BLS12-381 precompiles .precompileContractRegistryBuilder(MainnetPrecompiledContractRegistries::prague) - // EIP-7002 Withdrawls / EIP-6610 Deposits / EIP-7685 Requests + // EIP-7002 Withdrawals / EIP-6610 Deposits / EIP-7685 Requests .requestsValidator(pragueRequestsValidator(depositContractAddress)) - // EIP-7002 Withdrawls / EIP-6610 Deposits / EIP-7685 Requests + // EIP-7002 Withdrawals / EIP-6610 Deposits / EIP-7685 Requests .requestProcessorCoordinator(pragueRequestsProcessors(depositContractAddress)) // EIP-2935 Blockhash processor @@ -771,23 +652,13 @@ static ProtocolSpecBuilder pragueDefinition( static ProtocolSpecBuilder pragueEOFDefinition( final Optional chainId, - final OptionalInt configContractSizeLimit, - final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, final MiningParameters miningParameters) { - final int contractSizeLimit = - configContractSizeLimit.orElse(SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT); return pragueDefinition( - chainId, - configContractSizeLimit, - configStackSizeLimit, - enableRevertReason, - genesisConfigOptions, - evmConfiguration, - miningParameters) + chainId, enableRevertReason, genesisConfigOptions, evmConfiguration, miningParameters) // EIP-7692 EOF v1 Gas calculator .gasCalculator(PragueEOFGasCalculator::new) // EIP-7692 EOF v1 EVM and opcodes @@ -797,12 +668,11 @@ static ProtocolSpecBuilder pragueEOFDefinition( gasCalculator, chainId.orElse(BigInteger.ZERO), evmConfiguration)) // EIP-7698 EOF v1 creation transaction .contractCreationProcessorBuilder( - (gasCalculator, evm) -> + evm -> new ContractCreationProcessor( - gasCalculator, evm, true, - List.of(MaxCodeSizeRule.of(contractSizeLimit), EOFValidationCodeRule.of(1)), + List.of(MaxCodeSizeRule.from(evm), EOFValidationCodeRule.from(evm)), 1, SPURIOUS_DRAGON_FORCE_DELETE_WHEN_EMPTY_ADDRESSES)) .name("PragueEOF"); @@ -810,22 +680,12 @@ static ProtocolSpecBuilder pragueEOFDefinition( static ProtocolSpecBuilder futureEipsDefinition( final Optional chainId, - final OptionalInt configContractSizeLimit, - final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, final MiningParameters miningParameters) { - final int contractSizeLimit = - configContractSizeLimit.orElse(SPURIOUS_DRAGON_CONTRACT_SIZE_LIMIT); return pragueEOFDefinition( - chainId, - configContractSizeLimit, - configStackSizeLimit, - enableRevertReason, - genesisConfigOptions, - evmConfiguration, - miningParameters) + chainId, enableRevertReason, genesisConfigOptions, evmConfiguration, miningParameters) // Use Future EIP configured EVM .evmBuilder( (gasCalculator, jdCacheConfig) -> @@ -833,12 +693,11 @@ static ProtocolSpecBuilder futureEipsDefinition( gasCalculator, chainId.orElse(BigInteger.ZERO), evmConfiguration)) // change contract call creator to accept EOF code .contractCreationProcessorBuilder( - (gasCalculator, evm) -> + evm -> new ContractCreationProcessor( - gasCalculator, evm, true, - List.of(MaxCodeSizeRule.of(contractSizeLimit), EOFValidationCodeRule.of(1)), + List.of(MaxCodeSizeRule.from(evm), EOFValidationCodeRule.from(evm)), 1, SPURIOUS_DRAGON_FORCE_DELETE_WHEN_EMPTY_ADDRESSES)) // use future configured precompiled contracts @@ -848,21 +707,13 @@ static ProtocolSpecBuilder futureEipsDefinition( static ProtocolSpecBuilder experimentalEipsDefinition( final Optional chainId, - final OptionalInt configContractSizeLimit, - final OptionalInt configStackSizeLimit, final boolean enableRevertReason, final GenesisConfigOptions genesisConfigOptions, final EvmConfiguration evmConfiguration, final MiningParameters miningParameters) { return futureEipsDefinition( - chainId, - configContractSizeLimit, - configStackSizeLimit, - enableRevertReason, - genesisConfigOptions, - evmConfiguration, - miningParameters) + chainId, enableRevertReason, genesisConfigOptions, evmConfiguration, miningParameters) .evmBuilder( (gasCalculator, jdCacheConfig) -> MainnetEVMs.experimentalEips( @@ -929,13 +780,7 @@ static TransactionReceipt berlinTransactionReceiptFactoryWithReasonEnabled( transactionProcessingResult.getRevertReason()); } - private static class DaoBlockProcessor implements BlockProcessor { - - private final BlockProcessor wrapped; - - public DaoBlockProcessor(final BlockProcessor wrapped) { - this.wrapped = wrapped; - } + private record DaoBlockProcessor(BlockProcessor wrapped) implements BlockProcessor { @Override public BlockProcessingResult processBlock( @@ -965,7 +810,8 @@ private void updateWorldStateForDao(final MutableWorldState worldState) { final JsonArray json = new JsonArray( Resources.toString( - this.getClass().getResource("/daoAddresses.json"), StandardCharsets.UTF_8)); + Objects.requireNonNull(this.getClass().getResource("/daoAddresses.json")), + StandardCharsets.UTF_8)); final List
addresses = IntStream.range(0, json.size()) .mapToObj(json::getString) diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java index 78198922ea4..100a4425cdd 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolScheduleBuilder.java @@ -24,6 +24,7 @@ import java.math.BigInteger; import java.util.NavigableMap; import java.util.Optional; +import java.util.OptionalInt; import java.util.OptionalLong; import java.util.TreeMap; import java.util.function.Function; @@ -45,8 +46,6 @@ public class ProtocolScheduleBuilder { private final MiningParameters miningParameters; private final BadBlockManager badBlockManager; - private DefaultProtocolSchedule protocolSchedule; - public ProtocolScheduleBuilder( final GenesisConfigOptions config, final BigInteger defaultChainId, @@ -107,7 +106,7 @@ private ProtocolScheduleBuilder( public ProtocolSchedule createProtocolSchedule() { final Optional chainId = config.getChainId().or(() -> defaultChainId); - protocolSchedule = new DefaultProtocolSchedule(chainId); + DefaultProtocolSchedule protocolSchedule = new DefaultProtocolSchedule(chainId); initSchedule(protocolSchedule, chainId); return protocolSchedule; } @@ -118,18 +117,18 @@ private void initSchedule( final MainnetProtocolSpecFactory specFactory = new MainnetProtocolSpecFactory( chainId, - config.getContractSizeLimit(), - config.getEvmStackSize(), isRevertReasonEnabled, config.getEcip1017EraRounds(), - evmConfiguration, + evmConfiguration.overrides( + config.getContractSizeLimit(), OptionalInt.empty(), config.getEvmStackSize()), miningParameters); validateForkOrdering(); final NavigableMap builders = buildMilestoneMap(specFactory); - // At this stage, all milestones are flagged with correct modifier, but ProtocolSpecs must be + // At this stage, all milestones are flagged with the correct modifier, but ProtocolSpecs must + // be // inserted _AT_ the modifier block entry. if (!builders.isEmpty()) { protocolSpecAdapters.stream() @@ -143,10 +142,7 @@ private void initSchedule( builders.put( modifierBlock, new BuilderMapEntry( - parent.milestoneType, - modifierBlock, - parent.getBuilder(), - entry.getValue())); + parent.milestoneType, modifierBlock, parent.builder(), entry.getValue())); }); } @@ -158,8 +154,8 @@ private void initSchedule( addProtocolSpec( protocolSchedule, e.milestoneType, - e.getBlockIdentifier(), - e.getBuilder(), + e.blockIdentifier(), + e.builder(), e.modifier)); // NOTE: It is assumed that Daofork blocks will not be used for private networks @@ -173,8 +169,8 @@ private void initSchedule( final ProtocolSpec originalProtocolSpec = getProtocolSpec( protocolSchedule, - previousSpecBuilder.getBuilder(), - previousSpecBuilder.getModifier()); + previousSpecBuilder.builder(), + previousSpecBuilder.modifier()); addProtocolSpec( protocolSchedule, BuilderMapEntry.MilestoneType.BLOCK_NUMBER, @@ -201,14 +197,13 @@ private void initSchedule( final ProtocolSpec originalProtocolSpec = getProtocolSpec( protocolSchedule, - previousSpecBuilder.getBuilder(), - previousSpecBuilder.getModifier()); + previousSpecBuilder.builder(), + previousSpecBuilder.modifier()); addProtocolSpec( protocolSchedule, BuilderMapEntry.MilestoneType.BLOCK_NUMBER, classicBlockNumber, - ClassicProtocolSpecs.classicRecoveryInitDefinition( - config.getContractSizeLimit(), config.getEvmStackSize(), evmConfiguration), + ClassicProtocolSpecs.classicRecoveryInitDefinition(evmConfiguration), Function.identity()); protocolSchedule.putBlockNumberMilestone( classicBlockNumber + 1, originalProtocolSpec); @@ -298,7 +293,7 @@ private NavigableMap buildMilestoneMap( .flatMap(Optional::stream) .collect( Collectors.toMap( - BuilderMapEntry::getBlockIdentifier, + BuilderMapEntry::blockIdentifier, b -> b, (existing, replacement) -> replacement, TreeMap::new)); @@ -413,34 +408,11 @@ private void addProtocolSpec( } } - private static class BuilderMapEntry { - private final MilestoneType milestoneType; - private final long blockIdentifier; - private final ProtocolSpecBuilder builder; - private final Function modifier; - - public BuilderMapEntry( - final MilestoneType milestoneType, - final long blockIdentifier, - final ProtocolSpecBuilder builder, - final Function modifier) { - this.milestoneType = milestoneType; - this.blockIdentifier = blockIdentifier; - this.builder = builder; - this.modifier = modifier; - } - - public long getBlockIdentifier() { - return blockIdentifier; - } - - public ProtocolSpecBuilder getBuilder() { - return builder; - } - - public Function getModifier() { - return modifier; - } + private record BuilderMapEntry( + ProtocolScheduleBuilder.BuilderMapEntry.MilestoneType milestoneType, + long blockIdentifier, + ProtocolSpecBuilder builder, + Function modifier) { private enum MilestoneType { BLOCK_NUMBER, diff --git a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java index f79c6a874bb..cd886b6c847 100644 --- a/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java +++ b/ethereum/core/src/main/java/org/hyperledger/besu/ethereum/mainnet/ProtocolSpecBuilder.java @@ -60,7 +60,7 @@ public class ProtocolSpecBuilder { private Function blockHeaderValidatorBuilder; private Function ommerHeaderValidatorBuilder; private Function blockBodyValidatorBuilder; - private BiFunction contractCreationProcessorBuilder; + private Function contractCreationProcessorBuilder; private Function precompileContractRegistryBuilder; private BiFunction @@ -155,8 +155,7 @@ public ProtocolSpecBuilder blockBodyValidatorBuilder( } public ProtocolSpecBuilder contractCreationProcessorBuilder( - final BiFunction - contractCreationProcessorBuilder) { + final Function contractCreationProcessorBuilder) { this.contractCreationProcessorBuilder = contractCreationProcessorBuilder; return this; } @@ -165,7 +164,7 @@ public ProtocolSpecBuilder precompileContractRegistryBuilder( final Function precompileContractRegistryBuilder) { this.precompileContractRegistryBuilder = - (precompiledContractConfiguration) -> { + precompiledContractConfiguration -> { final PrecompileContractRegistry registry = precompileContractRegistryBuilder.apply(precompiledContractConfiguration); if (precompiledContractConfiguration.getPrivacyParameters().isEnabled()) { @@ -327,9 +326,9 @@ public ProtocolSpec build(final ProtocolSchedule protocolSchedule) { final PrecompiledContractConfiguration precompiledContractConfiguration = new PrecompiledContractConfiguration(gasCalculator, privacyParameters); final TransactionValidatorFactory transactionValidatorFactory = - transactionValidatorFactoryBuilder.apply(gasCalculator, gasLimitCalculator, feeMarket); + transactionValidatorFactoryBuilder.apply(evm, gasLimitCalculator, feeMarket); final AbstractMessageProcessor contractCreationProcessor = - contractCreationProcessorBuilder.apply(gasCalculator, evm); + contractCreationProcessorBuilder.apply(evm); final PrecompileContractRegistry precompileContractRegistry = precompileContractRegistryBuilder.apply(precompiledContractConfiguration); final AbstractMessageProcessor messageCallProcessor = @@ -507,6 +506,6 @@ public interface BlockImporterBuilder { public interface TransactionValidatorFactoryBuilder { TransactionValidatorFactory apply( - GasCalculator gasCalculator, GasLimitCalculator gasLimitCalculator, FeeMarket feeMarket); + EVM evm, GasLimitCalculator gasLimitCalculator, FeeMarket feeMarket); } } diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/BenchmarkSubCommand.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/BenchmarkSubCommand.java index d190e55b0df..05d90a7b358 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/BenchmarkSubCommand.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/BenchmarkSubCommand.java @@ -18,7 +18,6 @@ import static picocli.CommandLine.ScopeType.INHERIT; import org.hyperledger.besu.BesuInfo; -import org.hyperledger.besu.evm.EvmSpecVersion; import org.hyperledger.besu.evmtool.benchmarks.AltBN128Benchmark; import org.hyperledger.besu.evmtool.benchmarks.BenchmarkExecutor; import org.hyperledger.besu.evmtool.benchmarks.ECRecoverBenchmark; @@ -64,12 +63,6 @@ enum Benchmark { negatable = true) Boolean nativeCode; - @Option( - names = {"--fork"}, - paramLabel = "", - description = "Fork to evaluate, when it impacts gas costing.") - String fork = EvmSpecVersion.defaultVersion().getName(); - @Parameters(description = "One or more of ${COMPLETION-CANDIDATES}.") EnumSet benchmarks = EnumSet.noneOf(Benchmark.class); @@ -91,7 +84,7 @@ public void run() { var benchmarksToRun = benchmarks.isEmpty() ? EnumSet.allOf(Benchmark.class) : benchmarks; for (var benchmark : benchmarksToRun) { System.out.println("Benchmarks for " + benchmark); - benchmark.benchmarkExecutor.runBenchmark(output, nativeCode, fork); + benchmark.benchmarkExecutor.runBenchmark(output, nativeCode, parentCommand.getFork()); } } } diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/CodeValidateSubCommand.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/CodeValidateSubCommand.java index beb51cd4a6c..10e167f4069 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/CodeValidateSubCommand.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/CodeValidateSubCommand.java @@ -17,9 +17,12 @@ import static java.nio.charset.StandardCharsets.UTF_8; import static org.hyperledger.besu.evmtool.CodeValidateSubCommand.COMMAND_NAME; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; +import org.hyperledger.besu.ethereum.referencetests.ReferenceTestProtocolSchedules; import org.hyperledger.besu.evm.Code; -import org.hyperledger.besu.evm.code.CodeFactory; -import org.hyperledger.besu.evm.code.CodeV1Validation; +import org.hyperledger.besu.evm.EVM; +import org.hyperledger.besu.evm.EvmSpecVersion; +import org.hyperledger.besu.evm.code.CodeInvalid; import org.hyperledger.besu.evm.code.EOFLayout; import org.hyperledger.besu.util.LogConfigurator; @@ -27,9 +30,7 @@ import java.io.File; import java.io.FileReader; import java.io.IOException; -import java.io.InputStream; import java.io.InputStreamReader; -import java.io.PrintStream; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -37,7 +38,9 @@ import org.apache.tuweni.bytes.Bytes; import picocli.CommandLine; +import picocli.CommandLine.ParentCommand; +@SuppressWarnings({"ConstantValue", "DataFlowIssue"}) @CommandLine.Command( name = COMMAND_NAME, description = "Validates EVM code for fuzzing", @@ -45,8 +48,10 @@ versionProvider = VersionProvider.class) public class CodeValidateSubCommand implements Runnable { public static final String COMMAND_NAME = "code-validate"; - private final InputStream input; - private final PrintStream output; + + @ParentCommand EvmToolCommand parentCommand; + + private final EVM evm; @CommandLine.Option( names = {"--file"}, @@ -60,41 +65,46 @@ public class CodeValidateSubCommand implements Runnable { @SuppressWarnings("unused") public CodeValidateSubCommand() { // PicoCLI requires this - this(System.in, System.out); + this(null); } - CodeValidateSubCommand(final InputStream input, final PrintStream output) { - this.input = input; - this.output = output; + CodeValidateSubCommand(final EvmToolCommand parentCommand) { + this.parentCommand = parentCommand; + String fork = EvmSpecVersion.PRAGUE.getName(); + if (parentCommand != null && parentCommand.hasFork()) { + fork = parentCommand.getFork(); + } + ProtocolSpec protocolSpec = ReferenceTestProtocolSchedules.create().geSpecByName(fork); + evm = protocolSpec.getEvm(); } @Override public void run() { LogConfigurator.setLevel("", "OFF"); if (cliCode.isEmpty() && codeFile == null) { - try (BufferedReader in = new BufferedReader(new InputStreamReader(input, UTF_8))) { + try (BufferedReader in = new BufferedReader(new InputStreamReader(parentCommand.in, UTF_8))) { checkCodeFromBufferedReader(in); } catch (IOException e) { throw new RuntimeException(e); } - } else { - if (codeFile != null) { - try (BufferedReader in = new BufferedReader(new FileReader(codeFile, UTF_8))) { - checkCodeFromBufferedReader(in); - } catch (IOException e) { - throw new RuntimeException(e); - } + } else if (codeFile != null) { + try (BufferedReader in = new BufferedReader(new FileReader(codeFile, UTF_8))) { + checkCodeFromBufferedReader(in); + } catch (IOException e) { + throw new RuntimeException(e); } + } else { for (String code : cliCode) { - output.print(considerCode(code)); + parentCommand.out.print(considerCode(code)); } } + parentCommand.out.flush(); } private void checkCodeFromBufferedReader(final BufferedReader in) { try { for (String code = in.readLine(); code != null; code = in.readLine()) { - output.print(considerCode(code)); + parentCommand.out.print(considerCode(code)); } } catch (IOException e) { throw new RuntimeException(e); @@ -114,24 +124,22 @@ public String considerCode(final String hexCode) { return ""; } - EOFLayout layout = EOFLayout.parseEOF(codeBytes); + EOFLayout layout = evm.parseEOF(codeBytes); if (!layout.isValid()) { return "err: layout - " + layout.invalidReason() + "\n"; } - String error = CodeV1Validation.validate(layout); - if (error != null) { - return "err: " + error + "\n"; + Code code = evm.getCodeUncached(codeBytes); + if (code instanceof CodeInvalid codeInvalid) { + return "err: " + codeInvalid.getInvalidReason(); + } else { + return "OK " + + IntStream.range(0, code.getCodeSectionCount()) + .mapToObj(code::getCodeSection) + .map(cs -> code.getBytes().slice(cs.getEntryPoint(), cs.getLength())) + .map(Bytes::toUnprefixedHexString) + .collect(Collectors.joining(",")) + + "\n"; } - - Code code = CodeFactory.createCode(codeBytes, 1); - - return "OK " - + IntStream.range(0, code.getCodeSectionCount()) - .mapToObj(code::getCodeSection) - .map(cs -> layout.container().slice(cs.getEntryPoint(), cs.getLength())) - .map(Bytes::toUnprefixedHexString) - .collect(Collectors.joining(",")) - + "\n"; } } diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EOFTestSubCommand.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EOFTestSubCommand.java index cb2fbbfeb64..ab53b41e1d4 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EOFTestSubCommand.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/EOFTestSubCommand.java @@ -20,13 +20,13 @@ import static org.hyperledger.besu.evmtool.EOFTestSubCommand.COMMAND_NAME; import org.hyperledger.besu.crypto.SignatureAlgorithmFactory; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.ethereum.referencetests.EOFTestCaseSpec; import org.hyperledger.besu.ethereum.referencetests.EOFTestCaseSpec.TestResult; +import org.hyperledger.besu.ethereum.referencetests.ReferenceTestProtocolSchedules; +import org.hyperledger.besu.evm.EVM; import org.hyperledger.besu.evm.EvmSpecVersion; -import org.hyperledger.besu.evm.code.CodeFactory; import org.hyperledger.besu.evm.code.CodeInvalid; -import org.hyperledger.besu.evm.code.CodeV1; -import org.hyperledger.besu.evm.code.CodeV1Validation; import org.hyperledger.besu.evm.code.EOFLayout; import org.hyperledger.besu.util.LogConfigurator; @@ -57,16 +57,14 @@ public class EOFTestSubCommand implements Runnable { // picocli does it magically @CommandLine.Parameters private final List eofTestFiles = new ArrayList<>(); - @CommandLine.Option( - names = {"--fork-name"}, - description = "Limit execution to one fork.") - private String forkName = null; - @CommandLine.Option( names = {"--test-name"}, description = "Limit execution to one test.") private String testVectorName = null; + EVM evm; + String fork = null; + public EOFTestSubCommand() { this(null); } @@ -82,6 +80,14 @@ public void run() { SignatureAlgorithmFactory.setDefaultInstance(); final ObjectMapper eofTestMapper = JsonUtils.createObjectMapper(); + if (parentCommand.hasFork()) { + fork = parentCommand.getFork(); + } + ProtocolSpec protocolSpec = + ReferenceTestProtocolSchedules.create() + .geSpecByName(fork == null ? EvmSpecVersion.PRAGUE.getName() : fork); + evm = protocolSpec.getEvm(); + final JavaType javaType = eofTestMapper .getTypeFactory() @@ -146,7 +152,8 @@ private void executeEOFTest(final String fileName, final Map getProtocolSpec(); + ProtocolSpec getProtocolSpec(); + + EVM getEVM(); WorldUpdater getWorldUpdater(); diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/MainnetGenesisFileModule.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/MainnetGenesisFileModule.java index 761c81811ae..dc6b6dce00e 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/MainnetGenesisFileModule.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/MainnetGenesisFileModule.java @@ -27,9 +27,11 @@ import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder; import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecAdapters; +import org.hyperledger.besu.evm.EvmSpecVersion; import org.hyperledger.besu.evm.internal.EvmConfiguration; import java.math.BigInteger; +import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.function.Function; @@ -68,13 +70,15 @@ ProtocolSchedule provideProtocolSchedule( } } - if (fork.isPresent()) { - var schedules = createSchedules(); - var schedule = schedules.get(fork.map(String::toLowerCase).get()); - if (schedule != null) { - return schedule.get(); - } + var schedules = createSchedules(); + var schedule = + schedules.get( + fork.orElse(EvmSpecVersion.defaultVersion().getName()) + .toLowerCase(Locale.getDefault())); + if (schedule != null) { + return schedule.get(); } + return MainnetProtocolSchedule.fromConfig( configOptions, evmConfiguration, MiningParameters.newDefault(), new BadBlockManager()); } diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/PrettyPrintSubCommand.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/PrettyPrintSubCommand.java index 4e03f1aa69e..10d31960a82 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/PrettyPrintSubCommand.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/PrettyPrintSubCommand.java @@ -16,7 +16,11 @@ import static org.hyperledger.besu.evmtool.PrettyPrintSubCommand.COMMAND_NAME; -import org.hyperledger.besu.evm.code.CodeV1Validation; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; +import org.hyperledger.besu.ethereum.referencetests.ReferenceTestProtocolSchedules; +import org.hyperledger.besu.evm.EVM; +import org.hyperledger.besu.evm.EvmSpecVersion; +import org.hyperledger.besu.evm.code.CodeInvalid; import org.hyperledger.besu.evm.code.EOFLayout; import org.hyperledger.besu.util.LogConfigurator; @@ -63,14 +67,20 @@ public void run() { "Pretty printing of legacy EVM is not supported. Patches welcome!"); } else { - EOFLayout layout = EOFLayout.parseEOF(container); + String fork = EvmSpecVersion.PRAGUE.getName(); + if (parentCommand.hasFork()) { + fork = parentCommand.getFork(); + } + ProtocolSpec protocolSpec = ReferenceTestProtocolSchedules.create().geSpecByName(fork); + EVM evm = protocolSpec.getEvm(); + EOFLayout layout = evm.parseEOF(container); if (layout.isValid()) { - String validation = CodeV1Validation.validate(layout); - if (validation == null || force) { + var validatedCode = evm.getCodeUncached(container); + if (validatedCode.isValid() || force) { layout.prettyPrint(parentCommand.out); } - if (validation != null) { - parentCommand.out.println("EOF code is invalid - " + validation); + if (validatedCode instanceof CodeInvalid codeInvalid) { + parentCommand.out.println("EOF code is invalid - " + codeInvalid.getInvalidReason()); } } else { parentCommand.out.println("EOF layout is invalid - " + layout.invalidReason()); diff --git a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/ProtocolModule.java b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/ProtocolModule.java index 13ec7d877bd..1b8f557b3b8 100644 --- a/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/ProtocolModule.java +++ b/ethereum/evmtool/src/main/java/org/hyperledger/besu/evmtool/ProtocolModule.java @@ -14,11 +14,11 @@ */ package org.hyperledger.besu.evmtool; -import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.core.BlockHeaderBuilder; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; +import org.hyperledger.besu.evm.EVM; -import java.util.function.Function; import javax.inject.Singleton; import dagger.Module; @@ -30,7 +30,17 @@ public class ProtocolModule { @Provides @Singleton - Function getProtocolSpec(final ProtocolSchedule protocolSchedule) { - return protocolSchedule::getByBlockHeader; + ProtocolSpec getProtocolSpec(final ProtocolSchedule protocolSchedule) { + return protocolSchedule.getByBlockHeader( + BlockHeaderBuilder.createDefault() + .timestamp(Long.MAX_VALUE) + .number(Long.MAX_VALUE) + .buildBlockHeader()); + } + + @Provides + @Singleton + EVM getEVM(final ProtocolSpec protocolSpec) { + return protocolSpec.getEvm(); } } diff --git a/ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/CodeValidationSubCommandTest.java b/ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/CodeValidationSubCommandTest.java index 87af915f665..dd7133f862e 100644 --- a/ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/CodeValidationSubCommandTest.java +++ b/ethereum/evmtool/src/test/java/org/hyperledger/besu/evmtool/CodeValidationSubCommandTest.java @@ -19,7 +19,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.io.PrintStream; +import java.io.PrintWriter; import org.junit.jupiter.api.Test; import picocli.CommandLine; @@ -44,8 +44,8 @@ class CodeValidationSubCommandTest { void testSingleValidViaInput() { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ByteArrayInputStream bais = new ByteArrayInputStream(CODE_STOP_ONLY.getBytes(UTF_8)); - final CodeValidateSubCommand codeValidateSubCommand = - new CodeValidateSubCommand(bais, new PrintStream(baos)); + EvmToolCommand parentCommand = new EvmToolCommand(bais, new PrintWriter(baos, true, UTF_8)); + final CodeValidateSubCommand codeValidateSubCommand = new CodeValidateSubCommand(parentCommand); codeValidateSubCommand.run(); assertThat(baos.toString(UTF_8)).contains("OK 00\n"); } @@ -54,8 +54,8 @@ void testSingleValidViaInput() { void testSingleInvalidViaInput() { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ByteArrayInputStream bais = new ByteArrayInputStream(CODE_BAD_MAGIC.getBytes(UTF_8)); - final CodeValidateSubCommand codeValidateSubCommand = - new CodeValidateSubCommand(bais, new PrintStream(baos)); + EvmToolCommand parentCommand = new EvmToolCommand(bais, new PrintWriter(baos, true, UTF_8)); + final CodeValidateSubCommand codeValidateSubCommand = new CodeValidateSubCommand(parentCommand); codeValidateSubCommand.run(); assertThat(baos.toString(UTF_8)).contains("err: layout - EOF header byte 1 incorrect\n"); } @@ -64,8 +64,8 @@ void testSingleInvalidViaInput() { void testMultipleViaInput() { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ByteArrayInputStream bais = new ByteArrayInputStream(CODE_MULTIPLE.getBytes(UTF_8)); - final CodeValidateSubCommand codeValidateSubCommand = - new CodeValidateSubCommand(bais, new PrintStream(baos)); + EvmToolCommand parentCommand = new EvmToolCommand(bais, new PrintWriter(baos, true, UTF_8)); + final CodeValidateSubCommand codeValidateSubCommand = new CodeValidateSubCommand(parentCommand); codeValidateSubCommand.run(); assertThat(baos.toString(UTF_8)) .contains( @@ -80,8 +80,8 @@ void testMultipleViaInput() { void testSingleValidViaCli() { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); - final CodeValidateSubCommand codeValidateSubCommand = - new CodeValidateSubCommand(bais, new PrintStream(baos)); + EvmToolCommand parentCommand = new EvmToolCommand(bais, new PrintWriter(baos, true, UTF_8)); + final CodeValidateSubCommand codeValidateSubCommand = new CodeValidateSubCommand(parentCommand); final CommandLine cmd = new CommandLine(codeValidateSubCommand); cmd.parseArgs(CODE_STOP_ONLY); codeValidateSubCommand.run(); @@ -92,8 +92,8 @@ void testSingleValidViaCli() { void testSingleInvalidViaCli() { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); - final CodeValidateSubCommand codeValidateSubCommand = - new CodeValidateSubCommand(bais, new PrintStream(baos)); + EvmToolCommand parentCommand = new EvmToolCommand(bais, new PrintWriter(baos, true, UTF_8)); + final CodeValidateSubCommand codeValidateSubCommand = new CodeValidateSubCommand(parentCommand); final CommandLine cmd = new CommandLine(codeValidateSubCommand); cmd.parseArgs(CODE_BAD_MAGIC); codeValidateSubCommand.run(); @@ -104,8 +104,8 @@ void testSingleInvalidViaCli() { void testMultipleViaCli() { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); - final CodeValidateSubCommand codeValidateSubCommand = - new CodeValidateSubCommand(bais, new PrintStream(baos)); + EvmToolCommand parentCommand = new EvmToolCommand(bais, new PrintWriter(baos, true, UTF_8)); + final CodeValidateSubCommand codeValidateSubCommand = new CodeValidateSubCommand(parentCommand); final CommandLine cmd = new CommandLine(codeValidateSubCommand); cmd.parseArgs(CODE_STOP_ONLY, CODE_BAD_MAGIC, CODE_RETURN_ONLY); codeValidateSubCommand.run(); @@ -122,8 +122,8 @@ void testMultipleViaCli() { void testCliEclipsesInput() { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ByteArrayInputStream bais = new ByteArrayInputStream(CODE_STOP_ONLY.getBytes(UTF_8)); - final CodeValidateSubCommand codeValidateSubCommand = - new CodeValidateSubCommand(bais, new PrintStream(baos)); + EvmToolCommand parentCommand = new EvmToolCommand(bais, new PrintWriter(baos, true, UTF_8)); + final CodeValidateSubCommand codeValidateSubCommand = new CodeValidateSubCommand(parentCommand); final CommandLine cmd = new CommandLine(codeValidateSubCommand); cmd.parseArgs(CODE_RETURN_ONLY); codeValidateSubCommand.run(); @@ -134,8 +134,8 @@ void testCliEclipsesInput() { void testInteriorCommentsSkipped() { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); - final CodeValidateSubCommand codeValidateSubCommand = - new CodeValidateSubCommand(bais, new PrintStream(baos)); + EvmToolCommand parentCommand = new EvmToolCommand(bais, new PrintWriter(baos, true, UTF_8)); + final CodeValidateSubCommand codeValidateSubCommand = new CodeValidateSubCommand(parentCommand); final CommandLine cmd = new CommandLine(codeValidateSubCommand); cmd.parseArgs(CODE_INTERIOR_COMMENTS); codeValidateSubCommand.run(); @@ -147,8 +147,8 @@ void testBlankLinesAndCommentsSkipped() { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final ByteArrayInputStream bais = new ByteArrayInputStream(("# comment\n\n#blank line\n\n" + CODE_MULTIPLE).getBytes(UTF_8)); - final CodeValidateSubCommand codeValidateSubCommand = - new CodeValidateSubCommand(bais, new PrintStream(baos)); + EvmToolCommand parentCommand = new EvmToolCommand(bais, new PrintWriter(baos, true, UTF_8)); + final CodeValidateSubCommand codeValidateSubCommand = new CodeValidateSubCommand(parentCommand); codeValidateSubCommand.run(); assertThat(baos.toString(UTF_8)) .isEqualTo( diff --git a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestProtocolSchedules.java b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestProtocolSchedules.java index 2ebf5f79969..0976b924213 100644 --- a/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestProtocolSchedules.java +++ b/ethereum/referencetests/src/main/java/org/hyperledger/besu/ethereum/referencetests/ReferenceTestProtocolSchedules.java @@ -17,10 +17,13 @@ import org.hyperledger.besu.config.GenesisConfigOptions; import org.hyperledger.besu.config.StubGenesisConfigOptions; import org.hyperledger.besu.ethereum.chain.BadBlockManager; +import org.hyperledger.besu.ethereum.core.BlockHeader; +import org.hyperledger.besu.ethereum.core.BlockHeaderTestFixture; import org.hyperledger.besu.ethereum.core.MiningParameters; import org.hyperledger.besu.ethereum.core.PrivacyParameters; import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; import org.hyperledger.besu.ethereum.mainnet.ProtocolScheduleBuilder; +import org.hyperledger.besu.ethereum.mainnet.ProtocolSpec; import org.hyperledger.besu.ethereum.mainnet.ProtocolSpecAdapters; import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.evm.precompile.KZGPointEvalPrecompiledContract; @@ -102,6 +105,16 @@ public ProtocolSchedule getByName(final String name) { return schedules.get(name); } + public ProtocolSpec geSpecByName(final String name) { + ProtocolSchedule schedule = getByName(name); + if (schedule == null) { + return null; + } + BlockHeader header = + new BlockHeaderTestFixture().timestamp(Long.MAX_VALUE).number(Long.MAX_VALUE).buildHeader(); + return schedule.getByBlockHeader(header); + } + private static ProtocolSchedule createSchedule(final GenesisConfigOptions options) { return new ProtocolScheduleBuilder( options, diff --git a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/eof/EOFReferenceTestTools.java b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/eof/EOFReferenceTestTools.java index 22bf3839010..58f8c025297 100644 --- a/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/eof/EOFReferenceTestTools.java +++ b/ethereum/referencetests/src/reference-test/java/org/hyperledger/besu/ethereum/eof/EOFReferenceTestTools.java @@ -23,12 +23,10 @@ import java.util.Map; import org.apache.tuweni.bytes.Bytes; import org.hyperledger.besu.ethereum.referencetests.EOFTestCaseSpec; +import org.hyperledger.besu.ethereum.referencetests.ReferenceTestProtocolSchedules; import org.hyperledger.besu.evm.Code; -import org.hyperledger.besu.evm.EvmSpecVersion; -import org.hyperledger.besu.evm.code.CodeFactory; +import org.hyperledger.besu.evm.EVM; import org.hyperledger.besu.evm.code.CodeInvalid; -import org.hyperledger.besu.evm.code.CodeV1; -import org.hyperledger.besu.evm.code.CodeV1Validation; import org.hyperledger.besu.evm.code.EOFLayout; import org.hyperledger.besu.testutil.JsonTestParameters; @@ -74,7 +72,7 @@ public class EOFReferenceTestTools { params.ignore("EOF1_undefined_opcodes_186"); // embedded containers rules changed - params.ignore("EOF1_embedded_container"); + params.ignore("efValidation/EOF1_embedded_container-Prague\\[EOF1_embedded_container_\\d+\\]"); // truncated data is only allowed in embedded containers params.ignore("ori/validInvalid-Prague\\[validInvalid_48\\]"); @@ -101,19 +99,20 @@ public static Collection generateTestParametersForConfig(final String[ return params.generate(filePath); } + @SuppressWarnings("java:S5960") // This is not production code, this is testing code. public static void executeTest( final String fork, final Bytes code, final EOFTestCaseSpec.TestResult expected) { - EvmSpecVersion evmVersion = EvmSpecVersion.fromName(fork); - assertThat(evmVersion).isNotNull(); + EVM evm = ReferenceTestProtocolSchedules.create().geSpecByName(fork).getEvm(); + assertThat(evm).isNotNull(); // hardwire in the magic byte transaction checks - if (evmVersion.getMaxEofVersion() < 1) { + if (evm.getMaxEOFVersion() < 1) { assertThat(expected.exception()).isEqualTo("EOF_InvalidCode"); } else { EOFLayout layout = EOFLayout.parseEOF(code); if (layout.isValid()) { - Code parsedCode = CodeFactory.createCode(code, evmVersion.getMaxEofVersion()); + Code parsedCode = evm.getCodeUncached(code); assertThat(parsedCode.isValid()) .withFailMessage( () -> @@ -125,22 +124,8 @@ public static void executeTest( ? null : ((CodeInvalid) parsedCode).getInvalidReason())) .isEqualTo(expected.result()); - if (parsedCode instanceof CodeV1 codeV1) { - var deepValidate = CodeV1Validation.validate(codeV1.getEofLayout()); - assertThat(deepValidate) - .withFailMessage( - () -> - codeV1.prettyPrint() - + "\nExpected exception :" - + expected.exception() - + " actual exception :" - + (parsedCode.isValid() ? null : deepValidate)) - .isNull(); - } if (expected.result()) { - System.out.println(code); - System.out.println(layout.writeContainer(null)); assertThat(code) .withFailMessage("Container round trip failed") .isEqualTo(layout.writeContainer(null)); diff --git a/evm/src/main/java/org/hyperledger/besu/evm/Code.java b/evm/src/main/java/org/hyperledger/besu/evm/Code.java index bcec2872498..ac269d281da 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/Code.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/Code.java @@ -39,6 +39,13 @@ public interface Code { */ int getDataSize(); + /** + * Declared size of the data in bytes. For containers with aux data this may be larger. + * + * @return the declared data size + */ + int getDeclaredDataSize(); + /** * Get the bytes for the entire container, for example what EXTCODECOPY would want. For V0 it is * the same as getCodeBytes, for V1 it is the entire container, not just the data section. @@ -107,9 +114,10 @@ public interface Code { * @param index the index in the container to return * @param auxData any Auxiliary data to append to the subcontainer code. If fetching an initcode * container, pass null. + * @param evm the EVM in which we are instantiating the code * @return Either the subcontainer, or empty. */ - Optional getSubContainer(final int index, final Bytes auxData); + Optional getSubContainer(final int index, final Bytes auxData, EVM evm); /** * Loads data from the appropriate data section diff --git a/evm/src/main/java/org/hyperledger/besu/evm/EVM.java b/evm/src/main/java/org/hyperledger/besu/evm/EVM.java index 03348d9ab78..f2eb7cf29df 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/EVM.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/EVM.java @@ -20,6 +20,7 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.evm.code.CodeFactory; +import org.hyperledger.besu.evm.code.EOFLayout; import org.hyperledger.besu.evm.frame.ExceptionalHaltReason; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.frame.MessageFrame.State; @@ -87,6 +88,7 @@ public class EVM { private final OperationRegistry operations; private final GasCalculator gasCalculator; private final Operation endOfScriptStop; + private final CodeFactory codeFactory; private final CodeCache codeCache; private final EvmConfiguration evmConfiguration; private final EvmSpecVersion evmSpecVersion; @@ -114,6 +116,11 @@ public EVM( this.codeCache = new CodeCache(evmConfiguration); this.evmSpecVersion = evmSpecVersion; + codeFactory = + new CodeFactory( + evmSpecVersion.maxEofVersion, + evmConfiguration.maxInitcodeSizeOverride().orElse(evmSpecVersion.maxInitcodeSize)); + enableShanghai = EvmSpecVersion.SHANGHAI.ordinal() <= evmSpecVersion.ordinal(); } @@ -365,7 +372,7 @@ public Code getCode(final Hash codeHash, final Bytes codeBytes) { * @return the code */ public Code getCodeUncached(final Bytes codeBytes) { - return CodeFactory.createCode(codeBytes, evmSpecVersion.getMaxEofVersion()); + return codeFactory.createCode(codeBytes); } /** @@ -375,6 +382,16 @@ public Code getCodeUncached(final Bytes codeBytes) { * @return the code */ public Code getCodeForCreation(final Bytes codeBytes) { - return CodeFactory.createCode(codeBytes, evmSpecVersion.getMaxEofVersion(), false, true); + return codeFactory.createCode(codeBytes, true); + } + + /** + * Parse the EOF Layout of a byte-stream. No Code or stack validation is performed. + * + * @param bytes the bytes to parse + * @return an EOF layout represented by they byte-stream. + */ + public EOFLayout parseEOF(final Bytes bytes) { + return EOFLayout.parseEOF(bytes, true); } } diff --git a/evm/src/main/java/org/hyperledger/besu/evm/EvmSpecVersion.java b/evm/src/main/java/org/hyperledger/besu/evm/EvmSpecVersion.java index e543f672df0..9bf370d0318 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/EvmSpecVersion.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/EvmSpecVersion.java @@ -23,49 +23,58 @@ /** The enum Evm spec version. */ public enum EvmSpecVersion { /** Frontier evm spec version. */ - FRONTIER(0, true, "Frontier", "Finalized"), + FRONTIER(Integer.MAX_VALUE, Integer.MAX_VALUE, 0, true, "Frontier", "Finalized"), /** Homestead evm spec version. */ - HOMESTEAD(0, true, "Homestead", "Finalized"), + HOMESTEAD(Integer.MAX_VALUE, Integer.MAX_VALUE, 0, true, "Homestead", "Finalized"), /** Tangerine Whistle evm spec version. */ - TANGERINE_WHISTLE(0, true, "Tangerine Whistle", "Finalized"), + TANGERINE_WHISTLE( + Integer.MAX_VALUE, Integer.MAX_VALUE, 0, true, "Tangerine Whistle", "Finalized"), /** Spurious Dragon evm spec version. */ - SPURIOUS_DRAGON(0, true, "Spuruous Dragon", "Finalized"), + SPURIOUS_DRAGON(0x6000, Integer.MAX_VALUE, 0, true, "Spuruous Dragon", "Finalized"), /** Byzantium evm spec version. */ - BYZANTIUM(0, true, "Byzantium", "Finalized"), + BYZANTIUM(0x6000, Integer.MAX_VALUE, 0, true, "Byzantium", "Finalized"), /** Constantinople evm spec version. */ - CONSTANTINOPLE(0, true, "Constantinople", "Did not reach Mainnet"), + CONSTANTINOPLE(0x6000, Integer.MAX_VALUE, 0, true, "Constantinople", "Did not reach Mainnet"), /** Petersburg / ConstantinopleFix evm spec version. */ - PETERSBURG(0, true, "ConstantinopleFix", "Finalized (also called Petersburg)"), + PETERSBURG( + 0x6000, + Integer.MAX_VALUE, + 0, + true, + "ConstantinopleFix", + "Finalized (also called Petersburg)"), /** Istanbul evm spec version. */ - ISTANBUL(0, true, "Istanbul", "Finalized"), + ISTANBUL(0x6000, Integer.MAX_VALUE, 0, true, "Istanbul", "Finalized"), /** Berlin evm spec version */ - BERLIN(0, true, "Berlin", "Finalized"), + BERLIN(0x6000, Integer.MAX_VALUE, 0, true, "Berlin", "Finalized"), /** London evm spec version. */ - LONDON(0, true, "London", "Finalized"), + LONDON(0x6000, Integer.MAX_VALUE, 0, true, "London", "Finalized"), /** Paris evm spec version. */ - PARIS(0, true, "Merge", "Finalized (also called Paris)"), + PARIS(0x6000, Integer.MAX_VALUE, 0, true, "Merge", "Finalized (also called Paris)"), /** Shanghai evm spec version. */ - SHANGHAI(0, true, "Shanghai", "Finalized"), + SHANGHAI(0x6000, 0xc000, 0, true, "Shanghai", "Finalized"), /** Cancun evm spec version. */ - CANCUN(0, true, "Cancun", "Finalized"), + CANCUN(0x6000, 0xc000, 0, true, "Cancun", "Finalized"), /** Prague evm spec version. */ - PRAGUE(0, false, "Prague", "In Development"), + PRAGUE(0x6000, 0xc000, 0, false, "Prague", "In Development"), /** PragueEOF evm spec version. */ - PRAGUE_EOF(1, false, "PragueEOF", "Prague + EOF. In Development"), + PRAGUE_EOF(0x6000, 0xc000, 1, false, "PragueEOF", "Prague + EOF. In Development"), /** Osaka evm spec version. */ - OSAKA(1, false, "Osaka", "Placeholder"), + OSAKA(0x6000, 0xc000, 1, false, "Osaka", "Placeholder"), /** Amstedam evm spec version. */ - AMSTERDAM(1, false, "Amsterdam", "Placeholder"), + AMSTERDAM(0x6000, 0xc000, 1, false, "Amsterdam", "Placeholder"), /** Bogota evm spec version. */ - BOGOTA(1, false, "Bogota", "Placeholder"), + BOGOTA(0x6000, 0xc000, 1, false, "Bogota", "Placeholder"), /** Polis evm spec version. */ - POLIS(1, false, "Polis", "Placeholder"), + POLIS(0x6000, 0xc000, 1, false, "Polis", "Placeholder"), /** Bogota evm spec version. */ - BANGKOK(1, false, "Bangkok", "Placeholder"), + BANGKOK(0x6000, 0xc000, 1, false, "Bangkok", "Placeholder"), /** Development fork for unscheduled EIPs */ - FUTURE_EIPS(1, false, "Future_EIPs", "Development, for accepted and unscheduled EIPs"), + FUTURE_EIPS( + 0x6000, 0xc000, 1, false, "Future_EIPs", "Development, for accepted and unscheduled EIPs"), /** Development fork for EIPs not accepted to Mainnet */ - EXPERIMENTAL_EIPS(1, false, "Experimental_EIPs", "Development, for experimental EIPs"); + EXPERIMENTAL_EIPS( + 0x6000, 0xc000, 1, false, "Experimental_EIPs", "Development, for experimental EIPs"); private static final Logger LOGGER = LoggerFactory.getLogger(EvmSpecVersion.class); @@ -75,6 +84,12 @@ public enum EvmSpecVersion { /** The Max eof version. */ final int maxEofVersion; + /** Maximum size of deployed code */ + final int maxCodeSize; + + /** Maximum size of initcode */ + final int maxInitcodeSize; + /** Public name matching execution-spec-tests name */ final String name; @@ -85,11 +100,15 @@ public enum EvmSpecVersion { boolean versionWarned = false; EvmSpecVersion( + final int maxCodeSize, + final int maxInitcodeSize, final int maxEofVersion, final boolean specFinalized, final String name, final String description) { this.maxEofVersion = maxEofVersion; + this.maxCodeSize = maxCodeSize; + this.maxInitcodeSize = maxInitcodeSize; this.specFinalized = specFinalized; this.name = name; this.description = description; @@ -102,7 +121,13 @@ public enum EvmSpecVersion { * @return the current mainnet for as of the release of this version of Besu */ public static EvmSpecVersion defaultVersion() { - return SHANGHAI; + EvmSpecVersion answer = null; + for (EvmSpecVersion version : EvmSpecVersion.values()) { + if (version.specFinalized) { + answer = version; + } + } + return answer; } /** @@ -114,6 +139,24 @@ public int getMaxEofVersion() { return maxEofVersion; } + /** + * Gets max deployed code size this EVM supports. + * + * @return the max eof version + */ + public int getMaxCodeSize() { + return maxCodeSize; + } + + /** + * Gets max initcode size this EVM supports. + * + * @return the max eof version + */ + public int getMaxInitcodeSize() { + return maxInitcodeSize; + } + /** * Name of the fork, in execution-spec-tests form * diff --git a/evm/src/main/java/org/hyperledger/besu/evm/code/CodeFactory.java b/evm/src/main/java/org/hyperledger/besu/evm/code/CodeFactory.java index f9a85a20b70..a0bba703718 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/code/CodeFactory.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/code/CodeFactory.java @@ -14,112 +14,99 @@ */ package org.hyperledger.besu.evm.code; -import static org.hyperledger.besu.evm.code.EOFLayout.EOFContainerMode.INITCODE; - import org.hyperledger.besu.evm.Code; import javax.annotation.Nonnull; -import com.google.errorprone.annotations.InlineMe; import org.apache.tuweni.bytes.Bytes; /** The Code factory. */ -public final class CodeFactory { +public class CodeFactory { /** The constant EOF_LEAD_BYTE. */ public static final byte EOF_LEAD_BYTE = -17; // 0xEF in signed byte form - private CodeFactory() { - // factory class, no instantiations. - } + /** Maximum EOF version that can be produced. Legacy is considered EOF version zero. */ + protected final int maxEofVersion; + + /** Maximum size of the code stream that can be produced, including all header bytes. */ + protected final int maxContainerSize; + + /** The EOF validator against which EOF layouts will be validated. */ + EOFValidator eofValidator; /** - * Create Code. + * Create a code factory. * - * @param bytes the bytes - * @param maxEofVersion the max eof version - * @return the code + * @param maxEofVersion Maximum EOF version that can be set + * @param maxContainerSize Maximum size of a container that will be parsed. */ - public static Code createCode(final Bytes bytes, final int maxEofVersion) { - return createCode(bytes, maxEofVersion, false, false); + public CodeFactory(final int maxEofVersion, final int maxContainerSize) { + this.maxEofVersion = maxEofVersion; + this.maxContainerSize = maxContainerSize; + + eofValidator = new CodeV1Validation(maxContainerSize); } /** * Create Code. * * @param bytes the bytes - * @param maxEofVersion the max eof version - * @param legacyCreation Allow some corner cases. `EF` and not `EF00` code - * @deprecated use the no boolean or two boolean variant * @return the code */ - @Deprecated(since = "24.4.1") - @InlineMe( - replacement = "CodeFactory.createCode(bytes, maxEofVersion, legacyCreation, false)", - imports = "org.hyperledger.besu.evm.code.CodeFactory") - public static Code createCode( - final Bytes bytes, final int maxEofVersion, final boolean legacyCreation) { - return createCode(bytes, maxEofVersion, legacyCreation, false); + public Code createCode(final Bytes bytes) { + return createCode(bytes, false); } /** * Create Code. * * @param bytes the bytes - * @param maxEofVersion the max eof version - * @param legacyCreation Allow some corner cases. `EF` and not `EF00` code * @param createTransaction This is in a create transaction, allow dangling data * @return the code */ - public static Code createCode( - final Bytes bytes, - final int maxEofVersion, - final boolean legacyCreation, - final boolean createTransaction) { - if (maxEofVersion == 0) { - return new CodeV0(bytes); - } else if (maxEofVersion == 1) { - int codeSize = bytes.size(); - if (codeSize > 0 && bytes.get(0) == EOF_LEAD_BYTE) { - if (codeSize == 1 && !legacyCreation) { - return new CodeV0(bytes); - } - if (codeSize < 3) { - return new CodeInvalid(bytes, "EOF Container too short"); - } - if (bytes.get(1) != 0) { - if (legacyCreation) { - // because some 0xef code made it to mainnet, this is only an error at contract create - return new CodeInvalid(bytes, "Incorrect second byte"); - } else { - return new CodeV0(bytes); - } - } - int version = bytes.get(2); - if (version != 1) { - return new CodeInvalid(bytes, "Unsupported EOF Version: " + version); - } + public Code createCode(final Bytes bytes, final boolean createTransaction) { + return switch (maxEofVersion) { + case 0 -> new CodeV0(bytes); + case 1 -> createV1Code(bytes, createTransaction); + default -> new CodeInvalid(bytes, "Unsupported max code version " + maxEofVersion); + }; + } - final EOFLayout layout = EOFLayout.parseEOF(bytes, !createTransaction); + private @Nonnull Code createV1Code(final Bytes bytes, final boolean createTransaction) { + int codeSize = bytes.size(); + if (codeSize > 0 && bytes.get(0) == EOF_LEAD_BYTE) { + if (codeSize < 3) { + return new CodeInvalid(bytes, "EOF Container too short"); + } + if (bytes.get(1) != 0) { if (createTransaction) { - layout.containerMode().set(INITCODE); + // because some 0xef code made it to mainnet, this is only an error at contract creation + // time + return new CodeInvalid(bytes, "Incorrect second byte"); + } else { + return new CodeV0(bytes); } - return createCode(layout, createTransaction); - } else { - return new CodeV0(bytes); } + int version = bytes.get(2); + if (version != 1) { + return new CodeInvalid(bytes, "Unsupported EOF Version: " + version); + } + + final EOFLayout layout = EOFLayout.parseEOF(bytes, !createTransaction); + return createCode(layout); } else { - return new CodeInvalid(bytes, "Unsupported max code version " + maxEofVersion); + return new CodeV0(bytes); } } @Nonnull - static Code createCode(final EOFLayout layout, final boolean createTransaction) { + Code createCode(final EOFLayout layout) { if (!layout.isValid()) { return new CodeInvalid(layout.container(), "Invalid EOF Layout: " + layout.invalidReason()); } - final String validationError = CodeV1Validation.validate(layout); + final String validationError = eofValidator.validate(layout); if (validationError != null) { return new CodeInvalid(layout.container(), "EOF Code Invalid : " + validationError); } diff --git a/evm/src/main/java/org/hyperledger/besu/evm/code/CodeInvalid.java b/evm/src/main/java/org/hyperledger/besu/evm/code/CodeInvalid.java index be71c296aef..c7efd230f38 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/code/CodeInvalid.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/code/CodeInvalid.java @@ -16,6 +16,7 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.evm.Code; +import org.hyperledger.besu.evm.EVM; import org.hyperledger.besu.evm.internal.Words; import java.util.Optional; @@ -66,6 +67,11 @@ public int getDataSize() { return 0; } + @Override + public int getDeclaredDataSize() { + return 0; + } + @Override public Bytes getBytes() { return codeBytes; @@ -107,7 +113,7 @@ public int getSubcontainerCount() { } @Override - public Optional getSubContainer(final int index, final Bytes auxData) { + public Optional getSubContainer(final int index, final Bytes auxData, final EVM evm) { return Optional.empty(); } diff --git a/evm/src/main/java/org/hyperledger/besu/evm/code/CodeV0.java b/evm/src/main/java/org/hyperledger/besu/evm/code/CodeV0.java index 31a49ba15aa..45b9cb82eea 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/code/CodeV0.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/code/CodeV0.java @@ -16,6 +16,7 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.evm.Code; +import org.hyperledger.besu.evm.EVM; import org.hyperledger.besu.evm.internal.Words; import org.hyperledger.besu.evm.operation.JumpDestOperation; @@ -90,6 +91,11 @@ public int getDataSize() { return 0; } + @Override + public int getDeclaredDataSize() { + return 0; + } + @Override public Bytes getBytes() { return bytes; @@ -149,7 +155,7 @@ public int getSubcontainerCount() { } @Override - public Optional getSubContainer(final int index, final Bytes auxData) { + public Optional getSubContainer(final int index, final Bytes auxData, final EVM evm) { return Optional.empty(); } diff --git a/evm/src/main/java/org/hyperledger/besu/evm/code/CodeV1.java b/evm/src/main/java/org/hyperledger/besu/evm/code/CodeV1.java index 2bea400ed7f..50ffdd41061 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/code/CodeV1.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/code/CodeV1.java @@ -18,6 +18,7 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.evm.Code; +import org.hyperledger.besu.evm.EVM; import org.hyperledger.besu.evm.internal.Words; import java.io.PrintWriter; @@ -94,22 +95,23 @@ public int getSubcontainerCount() { } @Override - public Optional getSubContainer(final int index, final Bytes auxData) { + public Optional getSubContainer(final int index, final Bytes auxData, final EVM evm) { EOFLayout subcontainerLayout = eofLayout.getSubcontainer(index); + Bytes codeToLoad; if (auxData != null && !auxData.isEmpty()) { - Bytes subcontainerWithAuxData = subcontainerLayout.writeContainer(auxData); - if (subcontainerWithAuxData == null) { + codeToLoad = subcontainerLayout.writeContainer(auxData); + if (codeToLoad == null) { return Optional.empty(); } - subcontainerLayout = EOFLayout.parseEOF(subcontainerWithAuxData); } else { - // if no auxdata is added we must validate data is not truncated separately + // if no auxdata is added, we must validate data is not truncated separately if (subcontainerLayout.dataLength() != subcontainerLayout.data().size()) { return Optional.empty(); } + codeToLoad = subcontainerLayout.container(); } - Code subContainerCode = CodeFactory.createCode(subcontainerLayout, auxData == null); + Code subContainerCode = evm.getCodeForCreation(codeToLoad); return subContainerCode.isValid() && subContainerCode.getEofVersion() > 0 ? Optional.of(subContainerCode) @@ -150,6 +152,11 @@ public int getDataSize() { return eofLayout.data().size(); } + @Override + public int getDeclaredDataSize() { + return eofLayout.dataLength(); + } + @Override public int readBigEndianI16(final int index) { return Words.readBigEndianI16(index, eofLayout.container().toArrayUnsafe()); diff --git a/evm/src/main/java/org/hyperledger/besu/evm/code/CodeV1Validation.java b/evm/src/main/java/org/hyperledger/besu/evm/code/CodeV1Validation.java index c940a7d930b..3c85bd1eb22 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/code/CodeV1Validation.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/code/CodeV1Validation.java @@ -52,12 +52,20 @@ import org.apache.tuweni.bytes.Bytes; /** Code V1 Validation */ -public final class CodeV1Validation { +public class CodeV1Validation implements EOFValidator { static final int MAX_STACK_HEIGHT = 1024; - private CodeV1Validation() { - // to prevent instantiation + /** Maximum size of the code stream that can be produced, including all header bytes. */ + protected final int maxContainerSize; + + /** + * Create a new container, with a configurable maximim container size. + * + * @param maxContainerSize the maximum size of any container. + */ + public CodeV1Validation(final int maxContainerSize) { + this.maxContainerSize = maxContainerSize; } /** @@ -69,7 +77,12 @@ private CodeV1Validation() { */ @SuppressWarnings( "ReferenceEquality") // comparison `container != layout` is deliberate and correct - public static String validate(final EOFLayout layout) { + @Override + public String validate(final EOFLayout layout) { + if (layout.container().size() > maxContainerSize) { + return "EOF container is larger than maximum size of " + maxContainerSize; + } + Queue workList = new ArrayDeque<>(layout.getSubcontainerCount()); workList.add(layout); @@ -87,12 +100,12 @@ public static String validate(final EOFLayout layout) { : " in container #" + layout.indexOfSubcontainer(container)); } - final String codeValidationError = CodeV1Validation.validateCode(container); + final String codeValidationError = validateCode(container); if (codeValidationError != null) { return codeValidationError; } - final String stackValidationError = CodeV1Validation.validateStack(container); + final String stackValidationError = validateStack(container); if (stackValidationError != null) { return stackValidationError; } @@ -107,13 +120,14 @@ public static String validate(final EOFLayout layout) { * @param eofLayout The EOF Layout * @return validation code, null otherwise. */ - public static String validateCode(final EOFLayout eofLayout) { + @Override + public String validateCode(final EOFLayout eofLayout) { if (!eofLayout.isValid()) { return "Invalid EOF container - " + eofLayout.invalidReason(); } for (CodeSection cs : eofLayout.codeSections()) { var validation = - CodeV1Validation.validateCode( + validateCode( eofLayout.container().slice(cs.getEntryPoint(), cs.getLength()), cs, eofLayout); if (validation != null) { return validation; @@ -128,7 +142,7 @@ public static String validateCode(final EOFLayout eofLayout) { * @param code the code section code * @return null if valid, otherwise a string containing an error reason. */ - static String validateCode( + String validateCode( final Bytes code, final CodeSection thisCodeSection, final EOFLayout eofLayout) { final int size = code.size(); final BitSet rjumpdests = new BitSet(size); @@ -359,12 +373,13 @@ static String validateCode( } @Nullable - static String validateStack(final EOFLayout eofLayout) { + @Override + public String validateStack(final EOFLayout eofLayout) { WorkList workList = new WorkList(eofLayout.getCodeSectionCount()); workList.put(0); int sectionToValidatie = workList.take(); while (sectionToValidatie >= 0) { - var validation = CodeV1Validation.validateStack(sectionToValidatie, eofLayout, workList); + var validation = validateStack(sectionToValidatie, eofLayout, workList); if (validation != null) { return validation; } @@ -388,7 +403,7 @@ static String validateStack(final EOFLayout eofLayout) { * @return null if valid, otherwise an error string providing the validation error. */ @Nullable - static String validateStack( + String validateStack( final int codeSectionToValidate, final EOFLayout eofLayout, final WorkList workList) { if (!eofLayout.isValid()) { return "EOF Layout invalid - " + eofLayout.invalidReason(); diff --git a/evm/src/main/java/org/hyperledger/besu/evm/code/EOFLayout.java b/evm/src/main/java/org/hyperledger/besu/evm/code/EOFLayout.java index 1cce49b4531..8b41a979231 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/code/EOFLayout.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/code/EOFLayout.java @@ -323,7 +323,7 @@ public static EOFLayout parseEOF(final Bytes container, final boolean strictSize } Bytes subcontainer = container.slice(pos, subcontianerSize); pos += subcontianerSize; - EOFLayout subLayout = EOFLayout.parseEOF(subcontainer); + EOFLayout subLayout = EOFLayout.parseEOF(subcontainer, false); if (!subLayout.isValid()) { String invalidSubReason = subLayout.invalidReason; return invalidLayout( @@ -349,6 +349,10 @@ public static EOFLayout parseEOF(final Bytes container, final boolean strictSize } else { completeContainer = container; } + if (strictSize && dataSize != data.size()) { + return invalidLayout( + container, version, "Truncated data section when a complete section was required"); + } return new EOFLayout(completeContainer, version, codeSections, subContainers, dataSize, data); } diff --git a/evm/src/main/java/org/hyperledger/besu/evm/code/EOFValidator.java b/evm/src/main/java/org/hyperledger/besu/evm/code/EOFValidator.java new file mode 100644 index 00000000000..3cbdb404f0c --- /dev/null +++ b/evm/src/main/java/org/hyperledger/besu/evm/code/EOFValidator.java @@ -0,0 +1,49 @@ +/* + * Copyright contributors to Hyperledger Besu. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + */ +package org.hyperledger.besu.evm.code; + +import javax.annotation.Nullable; + +/** Code Validation */ +public interface EOFValidator { + + /** + * Validates the code and stack for the EOF Layout, with optional deep consideration of the + * containers. + * + * @param layout The parsed EOFLayout of the code + * @return either null, indicating no error, or a String describing the validation error. + */ + @Nullable + String validate(final EOFLayout layout); + + /** + * Performs code validation of the EOF layout. + * + * @param eofLayout The EOF Layout + * @return validation code, null otherwise. + */ + @Nullable + String validateCode(final EOFLayout eofLayout); + + /** + * Performs stack validation of the EOF layout. Presumes that code validation has been perfromed + * + * @param eofLayout The EOF Layout + * @return validation code, null otherwise. + */ + @Nullable + String validateStack(final EOFLayout eofLayout); +} diff --git a/evm/src/main/java/org/hyperledger/besu/evm/contractvalidation/CachedInvalidCodeRule.java b/evm/src/main/java/org/hyperledger/besu/evm/contractvalidation/CachedInvalidCodeRule.java deleted file mode 100644 index e0a7e49f416..00000000000 --- a/evm/src/main/java/org/hyperledger/besu/evm/contractvalidation/CachedInvalidCodeRule.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright contributors to Hyperledger Besu. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ -package org.hyperledger.besu.evm.contractvalidation; - -import org.hyperledger.besu.evm.Code; -import org.hyperledger.besu.evm.EvmSpecVersion; -import org.hyperledger.besu.evm.code.CodeFactory; -import org.hyperledger.besu.evm.frame.ExceptionalHaltReason; -import org.hyperledger.besu.evm.frame.MessageFrame; - -import java.util.Optional; - -import org.apache.tuweni.bytes.Bytes; - -/** The Cached invalid code rule. */ -public class CachedInvalidCodeRule implements ContractValidationRule { - - private final int maxEofVersion; - - /** - * Instantiates a new Cached invalid code rule. - * - * @param maxEofVersion the max eof version - */ - public CachedInvalidCodeRule(final int maxEofVersion) { - this.maxEofVersion = maxEofVersion; - } - - @Override - public Optional validate( - final Bytes contractCode, final MessageFrame frame) { - final Code code = CodeFactory.createCode(contractCode, maxEofVersion); - if (!code.isValid()) { - return Optional.of(ExceptionalHaltReason.INVALID_CODE); - } else { - return Optional.empty(); - } - } - - /** - * Instantiate contract validation rule. - * - * @param specVersion The evm spec version - * @return the contract validation rule - */ - public static ContractValidationRule of(final EvmSpecVersion specVersion) { - return new CachedInvalidCodeRule(specVersion.getMaxEofVersion()); - } -} diff --git a/evm/src/main/java/org/hyperledger/besu/evm/contractvalidation/ContractValidationRule.java b/evm/src/main/java/org/hyperledger/besu/evm/contractvalidation/ContractValidationRule.java index a32718e7494..c5c61dd7438 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/contractvalidation/ContractValidationRule.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/contractvalidation/ContractValidationRule.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.evm.contractvalidation; +import org.hyperledger.besu.evm.EVM; import org.hyperledger.besu.evm.frame.ExceptionalHaltReason; import org.hyperledger.besu.evm.frame.MessageFrame; @@ -30,7 +31,8 @@ public interface ContractValidationRule { * * @param contractCode the contract code to validate * @param frame the message frame to use for context + * @param evm the EVM against which the validation rule should be considered * @return the optional halt reason */ - Optional validate(Bytes contractCode, MessageFrame frame); + Optional validate(Bytes contractCode, MessageFrame frame, EVM evm); } diff --git a/evm/src/main/java/org/hyperledger/besu/evm/contractvalidation/EOFValidationCodeRule.java b/evm/src/main/java/org/hyperledger/besu/evm/contractvalidation/EOFValidationCodeRule.java index a052bcfa83d..e61a006f0e7 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/contractvalidation/EOFValidationCodeRule.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/contractvalidation/EOFValidationCodeRule.java @@ -14,8 +14,9 @@ */ package org.hyperledger.besu.evm.contractvalidation; +import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.evm.Code; -import org.hyperledger.besu.evm.code.CodeFactory; +import org.hyperledger.besu.evm.EVM; import org.hyperledger.besu.evm.code.CodeInvalid; import org.hyperledger.besu.evm.frame.ExceptionalHaltReason; import org.hyperledger.besu.evm.frame.MessageFrame; @@ -45,13 +46,14 @@ private EOFValidationCodeRule(final int maxEofVersion) { * * @param contractCode the contract code to validate * @param frame the message frame to use for context + * @param evm The EVM against which the validation should be considered against * @return Either an empty optional on success, or an optional containing one of the invalid * reasons. */ @Override public Optional validate( - final Bytes contractCode, final MessageFrame frame) { - Code code = CodeFactory.createCode(contractCode, maxEofVersion); + final Bytes contractCode, final MessageFrame frame, final EVM evm) { + Code code = evm.getCode(Hash.hash(contractCode), contractCode); if (!code.isValid()) { LOG.trace("EOF Validation Error: {}", ((CodeInvalid) code).getInvalidReason()); return Optional.of(ExceptionalHaltReason.INVALID_CODE); @@ -73,8 +75,20 @@ public Optional validate( * * @param maxEofVersion Maximum EOF version to validate * @return The EOF validation contract validation rule. + * @deprecated use {@link #from(EVM)} */ + @Deprecated(forRemoval = true, since = "24.6.1") public static ContractValidationRule of(final int maxEofVersion) { return new EOFValidationCodeRule(maxEofVersion); } + + /** + * Create EOF validation. + * + * @param evm The EVM for which we are enforcing the rule + * @return The EOF validation contract validation rule. + */ + public static ContractValidationRule from(final EVM evm) { + return new EOFValidationCodeRule(evm.getMaxEOFVersion()); + } } diff --git a/evm/src/main/java/org/hyperledger/besu/evm/contractvalidation/MaxCodeSizeRule.java b/evm/src/main/java/org/hyperledger/besu/evm/contractvalidation/MaxCodeSizeRule.java index 9a82e89a6fa..794650a1390 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/contractvalidation/MaxCodeSizeRule.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/contractvalidation/MaxCodeSizeRule.java @@ -14,6 +14,8 @@ */ package org.hyperledger.besu.evm.contractvalidation; +import org.hyperledger.besu.evm.EVM; +import org.hyperledger.besu.evm.EvmSpecVersion; import org.hyperledger.besu.evm.frame.ExceptionalHaltReason; import org.hyperledger.besu.evm.frame.MessageFrame; @@ -41,7 +43,7 @@ public class MaxCodeSizeRule implements ContractValidationRule { @Override public Optional validate( - final Bytes contractCode, final MessageFrame frame) { + final Bytes contractCode, final MessageFrame frame, final EVM evm) { final int contractCodeSize = contractCode.size(); if (contractCodeSize <= maxCodeSize) { return Optional.empty(); @@ -55,12 +57,34 @@ public Optional validate( } /** - * Instantiate ContractValidationRule. + * Fluent MaxCodeSizeRule constructor of an explicit size. * * @param maxCodeSize the max code size * @return the contract validation rule + * @deprecated use {@link #from(EVM)} */ + @Deprecated(forRemoval = true, since = "24.6.1") public static ContractValidationRule of(final int maxCodeSize) { return new MaxCodeSizeRule(maxCodeSize); } + + /** + * Fluent MaxCodeSizeRule from the EVM it is working with. + * + * @param evm The evm to get the size rules from. + * @return the contract validation rule + */ + public static ContractValidationRule from(final EVM evm) { + return from(evm.getEvmVersion()); + } + + /** + * Fluent MaxCodeSizeRule from the EVM it is working with. + * + * @param evmspec The evm spec version to get the size rules from. + * @return the contract validation rule + */ + public static ContractValidationRule from(final EvmSpecVersion evmspec) { + return new MaxCodeSizeRule(evmspec.getMaxCodeSize()); + } } diff --git a/evm/src/main/java/org/hyperledger/besu/evm/contractvalidation/PrefixCodeRule.java b/evm/src/main/java/org/hyperledger/besu/evm/contractvalidation/PrefixCodeRule.java index b596786bacf..b19c4729313 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/contractvalidation/PrefixCodeRule.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/contractvalidation/PrefixCodeRule.java @@ -14,6 +14,7 @@ */ package org.hyperledger.besu.evm.contractvalidation; +import org.hyperledger.besu.evm.EVM; import org.hyperledger.besu.evm.frame.ExceptionalHaltReason; import org.hyperledger.besu.evm.frame.MessageFrame; @@ -31,12 +32,14 @@ public class PrefixCodeRule implements ContractValidationRule { private static final byte FORMAT_RESERVED = (byte) 0xEF; /** Default constructor. */ - public PrefixCodeRule() {} + public PrefixCodeRule() { + // This constructor exists because of JavaDoc linting rules. + } @Override // As per https://eips.ethereum.org/EIPS/eip-3541 public Optional validate( - final Bytes contractCode, final MessageFrame frame) { + final Bytes contractCode, final MessageFrame frame, final EVM evm) { if (!contractCode.isEmpty() && contractCode.get(0) == FORMAT_RESERVED) { LOG.trace("Contract creation error: code cannot start with {}", FORMAT_RESERVED); return Optional.of(ExceptionalHaltReason.INVALID_CODE); diff --git a/evm/src/main/java/org/hyperledger/besu/evm/fluent/EVMExecutor.java b/evm/src/main/java/org/hyperledger/besu/evm/fluent/EVMExecutor.java index 64e9653ab7a..a65bd034d52 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/fluent/EVMExecutor.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/fluent/EVMExecutor.java @@ -77,7 +77,7 @@ public class EVMExecutor { private OperationTracer tracer = OperationTracer.NO_TRACING; private boolean requireDeposit = true; private List contractValidationRules = - List.of(MaxCodeSizeRule.of(0x6000), PrefixCodeRule.of()); + List.of(MaxCodeSizeRule.from(EvmSpecVersion.SPURIOUS_DRAGON), PrefixCodeRule.of()); private long initialNonce = 1; private Collection
forceCommitAddresses = List.of(Address.fromHexString("0x03")); private Set
accessListWarmAddresses = new BytesTrieSet<>(Address.SIZE); @@ -240,7 +240,8 @@ public static EVMExecutor spuriousDragon(final EvmConfiguration evmConfiguration final EVMExecutor executor = new EVMExecutor(MainnetEVMs.spuriousDragon(evmConfiguration)); executor.precompileContractRegistry = MainnetPrecompiledContracts.frontier(executor.evm.getGasCalculator()); - executor.contractValidationRules = List.of(MaxCodeSizeRule.of(0x6000)); + executor.contractValidationRules = + List.of(MaxCodeSizeRule.from(EvmSpecVersion.SPURIOUS_DRAGON)); return executor; } @@ -254,7 +255,7 @@ public static EVMExecutor byzantium(final EvmConfiguration evmConfiguration) { final EVMExecutor executor = new EVMExecutor(MainnetEVMs.byzantium(evmConfiguration)); executor.precompileContractRegistry = MainnetPrecompiledContracts.byzantium(executor.evm.getGasCalculator()); - executor.contractValidationRules = List.of(MaxCodeSizeRule.of(0x6000)); + executor.contractValidationRules = List.of(MaxCodeSizeRule.from(EvmSpecVersion.BYZANTIUM)); return executor; } @@ -268,7 +269,7 @@ public static EVMExecutor constantinople(final EvmConfiguration evmConfiguration final EVMExecutor executor = new EVMExecutor(MainnetEVMs.constantinople(evmConfiguration)); executor.precompileContractRegistry = MainnetPrecompiledContracts.byzantium(executor.evm.getGasCalculator()); - executor.contractValidationRules = List.of(MaxCodeSizeRule.of(0x6000)); + executor.contractValidationRules = List.of(MaxCodeSizeRule.from(EvmSpecVersion.CONSTANTINOPLE)); return executor; } @@ -282,7 +283,7 @@ public static EVMExecutor petersburg(final EvmConfiguration evmConfiguration) { final EVMExecutor executor = new EVMExecutor(MainnetEVMs.petersburg(evmConfiguration)); executor.precompileContractRegistry = MainnetPrecompiledContracts.byzantium(executor.evm.getGasCalculator()); - executor.contractValidationRules = List.of(MaxCodeSizeRule.of(0x6000)); + executor.contractValidationRules = List.of(MaxCodeSizeRule.from(EvmSpecVersion.PETERSBURG)); return executor; } @@ -317,7 +318,7 @@ public static EVMExecutor istanbul( final EVMExecutor executor = new EVMExecutor(MainnetEVMs.istanbul(chainId, evmConfiguration)); executor.precompileContractRegistry = MainnetPrecompiledContracts.istanbul(executor.evm.getGasCalculator()); - executor.contractValidationRules = List.of(MaxCodeSizeRule.of(0x6000)); + executor.contractValidationRules = List.of(MaxCodeSizeRule.from(EvmSpecVersion.ISTANBUL)); return executor; } @@ -352,7 +353,7 @@ public static EVMExecutor berlin( final EVMExecutor executor = new EVMExecutor(MainnetEVMs.berlin(chainId, evmConfiguration)); executor.precompileContractRegistry = MainnetPrecompiledContracts.istanbul(executor.evm.getGasCalculator()); - executor.contractValidationRules = List.of(MaxCodeSizeRule.of(0x6000)); + executor.contractValidationRules = List.of(MaxCodeSizeRule.from(EvmSpecVersion.BERLIN)); return executor; } @@ -658,12 +659,7 @@ private ContractCreationProcessor thisContractCreationProcessor() { contractCreationProcessor, () -> new ContractCreationProcessor( - evm.getGasCalculator(), - evm, - requireDeposit, - contractValidationRules, - initialNonce, - forceCommitAddresses)); + evm, requireDeposit, contractValidationRules, initialNonce, forceCommitAddresses)); } /** diff --git a/evm/src/main/java/org/hyperledger/besu/evm/frame/ExceptionalHaltReason.java b/evm/src/main/java/org/hyperledger/besu/evm/frame/ExceptionalHaltReason.java index af121ae92fb..729d10ffa50 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/frame/ExceptionalHaltReason.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/frame/ExceptionalHaltReason.java @@ -63,6 +63,12 @@ public interface ExceptionalHaltReason { /** The constant NONEXISTENT_CONTAINER */ ExceptionalHaltReason NONEXISTENT_CONTAINER = DefaultExceptionalHaltReason.NONEXISTENT_CONTAINER; + /** The constant INVALID_CONTAINER */ + ExceptionalHaltReason INVALID_CONTAINER = DefaultExceptionalHaltReason.INVALID_CONTAINER; + + /** The constant DATA_TOO_SMALL */ + ExceptionalHaltReason DATA_TOO_SMALL = DefaultExceptionalHaltReason.DATA_TOO_SMALL; + /** The constant ADDRESS_OUT_OF_RANGE */ ExceptionalHaltReason ADDRESS_OUT_OF_RANGE = DefaultExceptionalHaltReason.ADDRESS_OUT_OF_RANGE; @@ -112,7 +118,11 @@ enum DefaultExceptionalHaltReason implements ExceptionalHaltReason { EOF_CREATE_VERSION_INCOMPATIBLE( "EOF Code is attempting to create EOF code of an earlier version"), /** Container referenced by EOFCREATE operation does not exist */ - NONEXISTENT_CONTAINER("Referenced subcontainer index does not exist (too large?)"), + NONEXISTENT_CONTAINER("Referenced subcontainer index does not exist"), + /** Container referenced by EOFCREATE operation is invalid */ + INVALID_CONTAINER("Referenced subcontainer index is invalid"), + /** Container referenced by EOFCREATE operation does not exist */ + DATA_TOO_SMALL("Insufficient AuxData provided to a truncated container"), /** A given address cannot be used by EOF */ ADDRESS_OUT_OF_RANGE("Address has more than 20 bytes and is out of range"); diff --git a/evm/src/main/java/org/hyperledger/besu/evm/internal/EvmConfiguration.java b/evm/src/main/java/org/hyperledger/besu/evm/internal/EvmConfiguration.java index 1264076537b..ef7265dad9f 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/internal/EvmConfiguration.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/internal/EvmConfiguration.java @@ -14,13 +14,27 @@ */ package org.hyperledger.besu.evm.internal; +import org.hyperledger.besu.evm.frame.MessageFrame; + +import java.util.Optional; +import java.util.OptionalInt; + /** * The type Evm configuration. * * @param jumpDestCacheWeightKB the jump destination cache weight in kb * @param worldUpdaterMode the world updater mode + * @param evmStackSize the maximum evm stack size + * @param maxCodeSizeOverride An optional override of the maximum code size set by the EVM fork + * @param maxInitcodeSizeOverride An optional override of the maximum initcode size set by the EVM + * fork */ -public record EvmConfiguration(long jumpDestCacheWeightKB, WorldUpdaterMode worldUpdaterMode) { +public record EvmConfiguration( + long jumpDestCacheWeightKB, + WorldUpdaterMode worldUpdaterMode, + Integer evmStackSize, + Optional maxCodeSizeOverride, + Optional maxInitcodeSizeOverride) { /** How should the world state update be handled within transactions? */ public enum WorldUpdaterMode { @@ -36,6 +50,22 @@ public enum WorldUpdaterMode { public static final EvmConfiguration DEFAULT = new EvmConfiguration(32_000L, WorldUpdaterMode.STACKED); + /** + * Create an EVM Configuration without any overrides + * + * @param jumpDestCacheWeightKilobytes the jump dest cache weight (in kibibytes) + * @param worldstateUpdateMode the workd update mode + */ + public EvmConfiguration( + final Long jumpDestCacheWeightKilobytes, final WorldUpdaterMode worldstateUpdateMode) { + this( + jumpDestCacheWeightKilobytes, + worldstateUpdateMode, + MessageFrame.DEFAULT_MAX_STACK_SIZE, + Optional.empty(), + Optional.empty()); + } + /** * Gets jump dest cache weight bytes. * @@ -44,4 +74,27 @@ public enum WorldUpdaterMode { public long getJumpDestCacheWeightBytes() { return jumpDestCacheWeightKB * 1024L; } + + /** + * Update the configuration with new overrides, or clearing the overrides with {@link + * Optional#empty} + * + * @param newMaxCodeSize a new max code size override + * @param newMaxInitcodeSize a new max initcode size override + * @param newEvmStackSize a new EVM stack size override + * @return the updated EVM configuration + */ + public EvmConfiguration overrides( + final OptionalInt newMaxCodeSize, + final OptionalInt newMaxInitcodeSize, + final OptionalInt newEvmStackSize) { + return new EvmConfiguration( + jumpDestCacheWeightKB, + worldUpdaterMode, + newEvmStackSize.orElse(MessageFrame.DEFAULT_MAX_STACK_SIZE), + newMaxCodeSize.isPresent() ? Optional.of(newMaxCodeSize.getAsInt()) : Optional.empty(), + newMaxInitcodeSize.isPresent() + ? Optional.of(newMaxInitcodeSize.getAsInt()) + : Optional.empty()); + } } diff --git a/evm/src/main/java/org/hyperledger/besu/evm/operation/AbstractCreateOperation.java b/evm/src/main/java/org/hyperledger/besu/evm/operation/AbstractCreateOperation.java index 180eac27993..f026fd7110b 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/operation/AbstractCreateOperation.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/operation/AbstractCreateOperation.java @@ -22,7 +22,6 @@ import org.hyperledger.besu.evm.Code; import org.hyperledger.besu.evm.EVM; import org.hyperledger.besu.evm.account.MutableAccount; -import org.hyperledger.besu.evm.code.CodeFactory; import org.hyperledger.besu.evm.code.CodeInvalid; import org.hyperledger.besu.evm.frame.ExceptionalHaltReason; import org.hyperledger.besu.evm.frame.MessageFrame; @@ -218,7 +217,7 @@ private void complete(final MessageFrame frame, final MessageFrame childFrame, f Code outputCode = (childFrame.getCreatedCode() != null) ? childFrame.getCreatedCode() - : CodeFactory.createCode(childFrame.getOutputData(), evm.getMaxEOFVersion()); + : evm.getCodeForCreation(childFrame.getOutputData()); frame.popStackItems(getStackItemsConsumed()); if (outputCode.isValid()) { diff --git a/evm/src/main/java/org/hyperledger/besu/evm/operation/EOFCreateOperation.java b/evm/src/main/java/org/hyperledger/besu/evm/operation/EOFCreateOperation.java index cb6b2d4e3c4..0fb1e34a745 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/operation/EOFCreateOperation.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/operation/EOFCreateOperation.java @@ -74,7 +74,7 @@ protected Code getInitCode(final MessageFrame frame, final EVM evm) { int startIndex = frame.getPC() + 1; final int initContainerIndex = code.readU8(startIndex); - return code.getSubContainer(initContainerIndex, null).orElse(null); + return code.getSubContainer(initContainerIndex, null, evm).orElse(null); } @Override diff --git a/evm/src/main/java/org/hyperledger/besu/evm/operation/ReturnContractOperation.java b/evm/src/main/java/org/hyperledger/besu/evm/operation/ReturnContractOperation.java index c8031f4c4d8..97895800765 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/operation/ReturnContractOperation.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/operation/ReturnContractOperation.java @@ -64,9 +64,15 @@ public OperationResult execute(final MessageFrame frame, final EVM evm) { } Bytes auxData = frame.readMemory(from, length); - Optional newCode = code.getSubContainer(index, auxData); + if (code.getDataSize() + auxData.size() > evm.getEvmVersion().getMaxCodeSize()) { + return new OperationResult(cost, ExceptionalHaltReason.CODE_TOO_LARGE); + } + if (code.getDataSize() + auxData.size() < code.getDeclaredDataSize()) { + return new OperationResult(cost, ExceptionalHaltReason.DATA_TOO_SMALL); + } + Optional newCode = code.getSubContainer(index, auxData, evm); if (newCode.isEmpty()) { - return new OperationResult(cost, ExceptionalHaltReason.NONEXISTENT_CONTAINER); + return new OperationResult(cost, ExceptionalHaltReason.INVALID_CONTAINER); } frame.setCreatedCode(newCode.get()); diff --git a/evm/src/main/java/org/hyperledger/besu/evm/processor/AbstractMessageProcessor.java b/evm/src/main/java/org/hyperledger/besu/evm/processor/AbstractMessageProcessor.java index 5e668326345..0d394b2f887 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/processor/AbstractMessageProcessor.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/processor/AbstractMessageProcessor.java @@ -71,7 +71,7 @@ public abstract class AbstractMessageProcessor { // List of addresses to force delete when they are touched but empty // when the state changes in the message are were not meant to be committed. private final Collection forceDeleteAccountsWhenEmpty; - private final EVM evm; + final EVM evm; /** * Instantiates a new Abstract message processor. @@ -188,15 +188,12 @@ public void process(final MessageFrame frame, final OperationTracer operationTra if (operationTracer != null) { if (frame.getState() == MessageFrame.State.NOT_STARTED) { operationTracer.traceContextEnter(frame); + start(frame, operationTracer); } else { operationTracer.traceContextReEnter(frame); } } - if (frame.getState() == MessageFrame.State.NOT_STARTED) { - start(frame, operationTracer); - } - if (frame.getState() == MessageFrame.State.CODE_EXECUTING) { codeExecute(frame, operationTracer); diff --git a/evm/src/main/java/org/hyperledger/besu/evm/processor/ContractCreationProcessor.java b/evm/src/main/java/org/hyperledger/besu/evm/processor/ContractCreationProcessor.java index 0e47db90acb..a68c304c522 100644 --- a/evm/src/main/java/org/hyperledger/besu/evm/processor/ContractCreationProcessor.java +++ b/evm/src/main/java/org/hyperledger/besu/evm/processor/ContractCreationProcessor.java @@ -22,7 +22,6 @@ import org.hyperledger.besu.evm.contractvalidation.ContractValidationRule; import org.hyperledger.besu.evm.frame.ExceptionalHaltReason; import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.gascalculator.GasCalculator; import org.hyperledger.besu.evm.tracing.OperationTracer; import java.util.Collection; @@ -41,8 +40,6 @@ public class ContractCreationProcessor extends AbstractMessageProcessor { private final boolean requireCodeDepositToSucceed; - private final GasCalculator gasCalculator; - private final long initialContractNonce; private final List contractValidationRules; @@ -50,7 +47,6 @@ public class ContractCreationProcessor extends AbstractMessageProcessor { /** * Instantiates a new Contract creation processor. * - * @param gasCalculator the gas calculator * @param evm the evm * @param requireCodeDepositToSucceed the require code deposit to succeed * @param contractValidationRules the contract validation rules @@ -58,14 +54,12 @@ public class ContractCreationProcessor extends AbstractMessageProcessor { * @param forceCommitAddresses the force commit addresses */ public ContractCreationProcessor( - final GasCalculator gasCalculator, final EVM evm, final boolean requireCodeDepositToSucceed, final List contractValidationRules, final long initialContractNonce, final Collection
forceCommitAddresses) { super(evm, forceCommitAddresses); - this.gasCalculator = gasCalculator; this.requireCodeDepositToSucceed = requireCodeDepositToSucceed; this.contractValidationRules = contractValidationRules; this.initialContractNonce = initialContractNonce; @@ -74,25 +68,17 @@ public ContractCreationProcessor( /** * Instantiates a new Contract creation processor. * - * @param gasCalculator the gas calculator * @param evm the evm * @param requireCodeDepositToSucceed the require code deposit to succeed * @param contractValidationRules the contract validation rules * @param initialContractNonce the initial contract nonce */ public ContractCreationProcessor( - final GasCalculator gasCalculator, final EVM evm, final boolean requireCodeDepositToSucceed, final List contractValidationRules, final long initialContractNonce) { - this( - gasCalculator, - evm, - requireCodeDepositToSucceed, - contractValidationRules, - initialContractNonce, - Set.of()); + this(evm, requireCodeDepositToSucceed, contractValidationRules, initialContractNonce, Set.of()); } private static boolean accountExists(final Account account) { @@ -140,7 +126,7 @@ public void codeSuccess(final MessageFrame frame, final OperationTracer operatio final Bytes contractCode = frame.getCreatedCode() == null ? frame.getOutputData() : frame.getCreatedCode().getBytes(); - final long depositFee = gasCalculator.codeDepositGasCost(contractCode.size()); + final long depositFee = evm.getGasCalculator().codeDepositGasCost(contractCode.size()); if (frame.getRemainingGas() < depositFee) { LOG.trace( @@ -161,7 +147,7 @@ public void codeSuccess(final MessageFrame frame, final OperationTracer operatio } else { final var invalidReason = contractValidationRules.stream() - .map(rule -> rule.validate(contractCode, frame)) + .map(rule -> rule.validate(contractCode, frame, evm)) .filter(Optional::isPresent) .findFirst(); if (invalidReason.isEmpty()) { diff --git a/evm/src/test/java/org/hyperledger/besu/evm/code/CodeFactoryTest.java b/evm/src/test/java/org/hyperledger/besu/evm/code/CodeFactoryTest.java index 75ec9eb01bf..e1f1e767d21 100644 --- a/evm/src/test/java/org/hyperledger/besu/evm/code/CodeFactoryTest.java +++ b/evm/src/test/java/org/hyperledger/besu/evm/code/CodeFactoryTest.java @@ -18,6 +18,9 @@ import static org.hyperledger.besu.evm.EOFTestConstants.bytesFromPrettyPrint; import org.hyperledger.besu.evm.Code; +import org.hyperledger.besu.evm.EVM; +import org.hyperledger.besu.evm.MainnetEVMs; +import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.junit.jupiter.api.Test; @@ -25,12 +28,12 @@ class CodeFactoryTest { @Test void invalidCodeIncompleteMagic() { - invalidCode("0xEF", true); + invalidCodeForCreation("0xEF"); } @Test void invalidCodeInvalidMagic() { - invalidCode("0xEFFF0101000302000400600000AABBCCDD", true); + invalidCodeForCreation("0xEFFF0101000302000400600000AABBCCDD"); } @Test @@ -180,7 +183,9 @@ void invalidCodeUnknownSectionId3() { @Test void invalidDataTruncated() { - invalidCode("EF0001 010004 0200010001 040003 00 00800000 FE BEEF", "Incomplete data section"); + invalidCode( + "EF0001 010004 0200010001 040003 00 00800000 FE BEEF", + "Truncated data section when a complete section was required"); } @Test @@ -588,35 +593,28 @@ void invalidReturncontractReturncontract() { "RETURNCONTRACT is only a valid opcode in containers used for initcode"); } - // // valid subcontainer references - // // invalid subcontainer references - // - // { - // "EF0001 010004 0200010001 040003 00 00800000 FE BEEF", - // "Incomplete data section", - // "Incomplete data section", - // 1 - // }, - // - private static void validCode(final String str) { - Code code = CodeFactory.createCode(bytesFromPrettyPrint(str), 1); + EVM evm = MainnetEVMs.pragueEOF(EvmConfiguration.DEFAULT); + Code code = evm.getCodeUncached(bytesFromPrettyPrint(str)); assertThat(code.isValid()).isTrue(); } private static void invalidCode(final String str, final String error) { - Code code = CodeFactory.createCode(bytesFromPrettyPrint(str), 1); + EVM evm = MainnetEVMs.pragueEOF(EvmConfiguration.DEFAULT); + Code code = evm.getCodeUncached(bytesFromPrettyPrint(str)); assertThat(code.isValid()).isFalse(); assertThat(((CodeInvalid) code).getInvalidReason()).contains(error); } private static void invalidCode(final String str) { - Code code = CodeFactory.createCode(bytesFromPrettyPrint(str), 1); + EVM evm = MainnetEVMs.pragueEOF(EvmConfiguration.DEFAULT); + Code code = evm.getCodeUncached(bytesFromPrettyPrint(str)); assertThat(code.isValid()).isFalse(); } - private static void invalidCode(final String str, final boolean legacy) { - Code code = CodeFactory.createCode(bytesFromPrettyPrint(str), 1, legacy, false); + private static void invalidCodeForCreation(final String str) { + EVM evm = MainnetEVMs.pragueEOF(EvmConfiguration.DEFAULT); + Code code = evm.getCodeForCreation(bytesFromPrettyPrint(str)); assertThat(code.isValid()).isFalse(); } } diff --git a/evm/src/test/java/org/hyperledger/besu/evm/code/CodeV0Test.java b/evm/src/test/java/org/hyperledger/besu/evm/code/CodeV0Test.java index 1bc984222b4..3b16b1c9238 100644 --- a/evm/src/test/java/org/hyperledger/besu/evm/code/CodeV0Test.java +++ b/evm/src/test/java/org/hyperledger/besu/evm/code/CodeV0Test.java @@ -24,15 +24,12 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.EVM; -import org.hyperledger.besu.evm.EvmSpecVersion; +import org.hyperledger.besu.evm.MainnetEVMs; import org.hyperledger.besu.evm.frame.BlockValues; import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.gascalculator.IstanbulGasCalculator; import org.hyperledger.besu.evm.internal.EvmConfiguration; -import org.hyperledger.besu.evm.operation.JumpDestOperation; import org.hyperledger.besu.evm.operation.JumpOperation; import org.hyperledger.besu.evm.operation.Operation.OperationResult; -import org.hyperledger.besu.evm.operation.OperationRegistry; import org.hyperledger.besu.evm.worldstate.WorldUpdater; import javax.annotation.Nonnull; @@ -45,24 +42,19 @@ class CodeV0Test { - private static final IstanbulGasCalculator gasCalculator = new IstanbulGasCalculator(); - private static final int CURRENT_PC = 1; private EVM evm; @BeforeEach void startUp() { - final OperationRegistry registry = new OperationRegistry(); - registry.put(new JumpOperation(gasCalculator)); - registry.put(new JumpDestOperation(gasCalculator)); - evm = new EVM(registry, gasCalculator, EvmConfiguration.DEFAULT, EvmSpecVersion.PARIS); + evm = MainnetEVMs.pragueEOF(EvmConfiguration.DEFAULT); } @Test void shouldReuseJumpDestMap() { - final JumpOperation operation = new JumpOperation(gasCalculator); + final JumpOperation operation = new JumpOperation(evm.getGasCalculator()); final Bytes jumpBytes = Bytes.fromHexString("0x6003565b00"); - final CodeV0 getsCached = (CodeV0) spy(CodeFactory.createCode(jumpBytes, 0)); + final CodeV0 getsCached = (CodeV0) spy(evm.getCodeUncached(jumpBytes)); MessageFrame frame = createJumpFrame(getsCached); OperationResult result = operation.execute(frame, evm); diff --git a/evm/src/test/java/org/hyperledger/besu/evm/code/CodeV1Test.java b/evm/src/test/java/org/hyperledger/besu/evm/code/CodeV1Test.java index 8eda50316fd..f32a3f48668 100644 --- a/evm/src/test/java/org/hyperledger/besu/evm/code/CodeV1Test.java +++ b/evm/src/test/java/org/hyperledger/besu/evm/code/CodeV1Test.java @@ -15,8 +15,6 @@ package org.hyperledger.besu.evm.code; import static org.assertj.core.api.Assertions.assertThat; -import static org.hyperledger.besu.evm.code.CodeV1Validation.validateCode; -import static org.hyperledger.besu.evm.code.CodeV1Validation.validateStack; import java.util.Arrays; import java.util.List; @@ -72,7 +70,8 @@ private static void assertValidation( final Bytes codeBytes, final CodeSection thisCodeSection, final EOFLayout eofLayout) { - final String validationError = validateCode(codeBytes, thisCodeSection, eofLayout); + CodeV1Validation validator = new CodeV1Validation(0xc000); + final String validationError = validator.validateCode(codeBytes, thisCodeSection, eofLayout); if (error == null) { assertThat(validationError).isNull(); } else { @@ -85,8 +84,8 @@ void validCode() { String codeHex = "0xEF0001 01000C 020003 000b 0002 0008 040000 00 00800000 02010001 01000002 60016002e30001e30002f3 01e4 60005360106000e4"; final EOFLayout layout = EOFLayout.parseEOF(Bytes.fromHexString(codeHex.replace(" ", ""))); - - String validationError = validateCode(layout); + CodeV1Validation validator = new CodeV1Validation(0xc000); + String validationError = validator.validateCode(layout); assertThat(validationError).isNull(); } @@ -96,8 +95,8 @@ void invalidCode() { String codeHex = "0xEF0001 01000C 020003 000b 0002 0008 040000 00 00000000 02010001 01000002 60016002e30001e30002f3 01e4 60005360106000e4"; final EOFLayout layout = EOFLayout.parseEOF(Bytes.fromHexString(codeHex.replace(" ", ""))); - - String validationError = validateCode(layout); + CodeV1Validation validator = new CodeV1Validation(0xc000); + String validationError = validator.validateCode(layout); assertThat(validationError) .isEqualTo( @@ -475,8 +474,9 @@ void validateStackAnalysis( + codeData; EOFLayout eofLayout = EOFLayout.parseEOF(Bytes.fromHexString(sb)); + CodeV1Validation validator = new CodeV1Validation(0xc000); - assertThat(validateStack(sectionToTest, eofLayout, new WorkList(sectionCount))) + assertThat(validator.validateStack(sectionToTest, eofLayout, new WorkList(sectionCount))) .isEqualTo(expectedError); } diff --git a/evm/src/test/java/org/hyperledger/besu/evm/fluent/EVMExecutorTest.java b/evm/src/test/java/org/hyperledger/besu/evm/fluent/EVMExecutorTest.java index 871d99f768d..a080f649c90 100644 --- a/evm/src/test/java/org/hyperledger/besu/evm/fluent/EVMExecutorTest.java +++ b/evm/src/test/java/org/hyperledger/besu/evm/fluent/EVMExecutorTest.java @@ -22,7 +22,6 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.EVM; import org.hyperledger.besu.evm.EvmSpecVersion; -import org.hyperledger.besu.evm.code.CodeFactory; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.gascalculator.FrontierGasCalculator; import org.hyperledger.besu.evm.internal.EvmConfiguration; @@ -135,19 +134,6 @@ void defaultChainIdAPIs() { assertThat(futureEipsVM.getChainId()).contains(defaultChainId); } - @Test - void executeCode() { - var result = - EVMExecutor.evm(EvmSpecVersion.SHANGHAI) - .worldUpdater(createSimpleWorld().updater()) - .execute( - CodeFactory.createCode(Bytes.fromHexString("0x6001600255"), 1), - Bytes.EMPTY, - Wei.ZERO, - Address.ZERO); - assertThat(result).isNotNull(); - } - @Test void executeBytes() { var result = @@ -180,7 +166,7 @@ void giantExecuteStack() { .blobGasPrice(Wei.ONE) .callData(Bytes.fromHexString("0x12345678")) .ethValue(Wei.fromEth(1)) - .code(CodeFactory.createCode(Bytes.fromHexString("0x6001600255"), 0)) + .code(Bytes.fromHexString("0x6001600255")) .blockValues(new SimpleBlockValues()) .difficulty(Bytes.ofUnsignedLong(1L)) .mixHash(Bytes32.ZERO) @@ -199,7 +185,7 @@ void giantExecuteStack() { .accessListWarmStorage( Address.ZERO, Bytes32.ZERO, Bytes32.leftPad(Bytes.ofUnsignedLong(2L))) .messageCallProcessor(new MessageCallProcessor(null, null)) - .contractCallProcessor(new ContractCreationProcessor(null, null, true, null, 1L)) + .contractCallProcessor(new ContractCreationProcessor(null, true, null, 1L)) .execute(); assertThat(result).isNotNull(); } diff --git a/evm/src/test/java/org/hyperledger/besu/evm/internal/CodeCacheTest.java b/evm/src/test/java/org/hyperledger/besu/evm/internal/CodeCacheTest.java index 94f616898a5..7b8a74b0cd9 100644 --- a/evm/src/test/java/org/hyperledger/besu/evm/internal/CodeCacheTest.java +++ b/evm/src/test/java/org/hyperledger/besu/evm/internal/CodeCacheTest.java @@ -17,7 +17,8 @@ import static org.assertj.core.api.Assertions.assertThat; import org.hyperledger.besu.evm.Code; -import org.hyperledger.besu.evm.code.CodeFactory; +import org.hyperledger.besu.evm.EVM; +import org.hyperledger.besu.evm.MainnetEVMs; import org.hyperledger.besu.evm.operation.JumpDestOperation; import org.apache.tuweni.bytes.Bytes; @@ -29,10 +30,11 @@ class CodeCacheTest { @Test void testScale() { + EVM evm = MainnetEVMs.pragueEOF(EvmConfiguration.DEFAULT); final Bytes contractBytes = Bytes.fromHexString("0xDEAD" + op + "BEEF" + op + "B0B0" + op + "C0DE" + op + "FACE"); final CodeScale scale = new CodeScale(); - final Code contractCode = CodeFactory.createCode(contractBytes, 0); + final Code contractCode = evm.getCodeUncached(contractBytes); final int weight = scale.weigh(contractCode.getCodeHash(), contractCode); assertThat(weight) .isEqualTo(contractCode.getCodeHash().size() + (contractBytes.size() * 9 + 7) / 8); diff --git a/evm/src/test/java/org/hyperledger/besu/evm/operation/AbstractCreateOperationTest.java b/evm/src/test/java/org/hyperledger/besu/evm/operation/AbstractCreateOperationTest.java index 79f07e11af5..3c99bd71ffc 100644 --- a/evm/src/test/java/org/hyperledger/besu/evm/operation/AbstractCreateOperationTest.java +++ b/evm/src/test/java/org/hyperledger/besu/evm/operation/AbstractCreateOperationTest.java @@ -30,7 +30,6 @@ import org.hyperledger.besu.evm.MainnetEVMs; import org.hyperledger.besu.evm.account.Account; import org.hyperledger.besu.evm.account.MutableAccount; -import org.hyperledger.besu.evm.code.CodeFactory; import org.hyperledger.besu.evm.code.CodeInvalid; import org.hyperledger.besu.evm.frame.BlockValues; import org.hyperledger.besu.evm.frame.ExceptionalHaltReason; @@ -166,7 +165,7 @@ private void executeOperation(final Bytes contract, final EVM evm) { .sender(Address.fromHexString(SENDER)) .value(Wei.ZERO) .apparentValue(Wei.ZERO) - .code(CodeFactory.createCode(SIMPLE_CREATE, 0)) + .code(evm.getCodeUncached(SIMPLE_CREATE)) .completer(__ -> {}) .address(Address.fromHexString(SENDER)) .blockHashLookup(n -> Hash.hash(Words.longBytes(n))) @@ -197,7 +196,7 @@ private void executeOperation(final Bytes contract, final EVM evm) { operation.execute(messageFrame, evm); final MessageFrame createFrame = messageFrameStack.peek(); final ContractCreationProcessor ccp = - new ContractCreationProcessor(evm.getGasCalculator(), evm, false, List.of(), 0, List.of()); + new ContractCreationProcessor(evm, false, List.of(), 0, List.of()); ccp.process(createFrame, OperationTracer.NO_TRACING); } diff --git a/evm/src/test/java/org/hyperledger/besu/evm/operations/Create2OperationTest.java b/evm/src/test/java/org/hyperledger/besu/evm/operations/Create2OperationTest.java index eb04ccb7419..73a4abd34ab 100644 --- a/evm/src/test/java/org/hyperledger/besu/evm/operations/Create2OperationTest.java +++ b/evm/src/test/java/org/hyperledger/besu/evm/operations/Create2OperationTest.java @@ -29,7 +29,6 @@ import org.hyperledger.besu.evm.EVM; import org.hyperledger.besu.evm.MainnetEVMs; import org.hyperledger.besu.evm.account.MutableAccount; -import org.hyperledger.besu.evm.code.CodeFactory; import org.hyperledger.besu.evm.frame.BlockValues; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.gascalculator.ConstantinopleGasCalculator; @@ -58,7 +57,7 @@ public class Create2OperationTest { private MessageFrame messageFrame; private final WorldUpdater worldUpdater = mock(WorldUpdater.class); private final MutableAccount account = mock(MutableAccount.class); - private final EVM evm = mock(EVM.class); + private final EVM evm = MainnetEVMs.pragueEOF(EvmConfiguration.DEFAULT); private final MutableAccount newAccount = mock(MutableAccount.class); private final Create2Operation operation = @@ -154,7 +153,7 @@ public void setUp(final String sender, final String salt, final String code) { .sender(Address.fromHexString(sender)) .value(Wei.ZERO) .apparentValue(Wei.ZERO) - .code(CodeFactory.createCode(codeBytes, 0)) + .code(evm.getCodeUncached(codeBytes)) .completer(__ -> {}) .address(Address.fromHexString(sender)) .blockHashLookup(n -> Hash.hash(Words.longBytes(n))) @@ -175,8 +174,6 @@ public void setUp(final String sender, final String salt, final String code) { when(account.getBalance()).thenReturn(Wei.ZERO); when(worldUpdater.getAccount(any())).thenReturn(account); when(worldUpdater.updater()).thenReturn(worldUpdater); - when(evm.getCode(any(), any())) - .thenAnswer(invocation -> CodeFactory.createCode(invocation.getArgument(1), 0)); } @ParameterizedTest @@ -190,7 +187,7 @@ void shouldCalculateAddress( setUp(sender, salt, code); final Address targetContractAddress = operation.targetContractAddress( - messageFrame, CodeFactory.createCode(Bytes.fromHexString(code), 0)); + messageFrame, evm.getCodeUncached(Bytes.fromHexString(code))); assertThat(targetContractAddress).isEqualTo(Address.fromHexString(expectedAddress)); } @@ -224,11 +221,11 @@ void shanghaiMaxInitCodeSizeCreate() { when(newAccount.isStorageEmpty()).thenReturn(true); when(worldUpdater.updater()).thenReturn(worldUpdater); - final EVM evm = MainnetEVMs.shanghai(DEV_NET_CHAIN_ID, EvmConfiguration.DEFAULT); - var result = maxInitCodeOperation.execute(messageFrame, evm); + final EVM myEVM = MainnetEVMs.shanghai(DEV_NET_CHAIN_ID, EvmConfiguration.DEFAULT); + var result = maxInitCodeOperation.execute(messageFrame, myEVM); final MessageFrame createFrame = messageFrame.getMessageFrameStack().peek(); final ContractCreationProcessor ccp = - new ContractCreationProcessor(evm.getGasCalculator(), evm, false, List.of(), 0, List.of()); + new ContractCreationProcessor(myEVM, false, List.of(), 0, List.of()); ccp.process(createFrame, OperationTracer.NO_TRACING); final Log log = createFrame.getLogs().get(0); @@ -268,7 +265,7 @@ private MessageFrame testMemoryFrame(final UInt256 memoryOffset, final UInt256 m .sender(Address.fromHexString(SENDER)) .value(Wei.ZERO) .apparentValue(Wei.ZERO) - .code(CodeFactory.createCode(SIMPLE_CREATE, 0)) + .code(evm.getCodeUncached(SIMPLE_CREATE)) .completer(__ -> {}) .address(Address.fromHexString(SENDER)) .blockHashLookup(n -> Hash.hash(Words.longBytes(n))) @@ -298,7 +295,7 @@ void eofV1CannotCall() { final UInt256 memoryOffset = UInt256.fromHexString("0xFF"); final UInt256 memoryLength = UInt256.valueOf(SIMPLE_CREATE.size()); - Code eofCode = CodeFactory.createCode(SIMPLE_EOF, 1); + Code eofCode = evm.getCodeUncached(SIMPLE_EOF); assertThat(eofCode.isValid()).isTrue(); final MessageFrame messageFrame = @@ -315,7 +312,6 @@ void eofV1CannotCall() { when(account.getBalance()).thenReturn(Wei.ZERO); when(worldUpdater.getAccount(any())).thenReturn(account); - final EVM evm = MainnetEVMs.cancun(DEV_NET_CHAIN_ID, EvmConfiguration.DEFAULT); var result = operation.execute(messageFrame, evm); assertThat(result.getHaltReason()).isEqualTo(INVALID_OPERATION); assertThat(messageFrame.getStackItem(0).trimLeadingZeros()).isEqualTo(Bytes.EMPTY); diff --git a/evm/src/test/java/org/hyperledger/besu/evm/operations/CreateOperationTest.java b/evm/src/test/java/org/hyperledger/besu/evm/operations/CreateOperationTest.java index d95875e492b..4fa5a0fdd74 100644 --- a/evm/src/test/java/org/hyperledger/besu/evm/operations/CreateOperationTest.java +++ b/evm/src/test/java/org/hyperledger/besu/evm/operations/CreateOperationTest.java @@ -28,7 +28,6 @@ import org.hyperledger.besu.evm.EVM; import org.hyperledger.besu.evm.MainnetEVMs; import org.hyperledger.besu.evm.account.MutableAccount; -import org.hyperledger.besu.evm.code.CodeFactory; import org.hyperledger.besu.evm.frame.BlockValues; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.gascalculator.ConstantinopleGasCalculator; @@ -59,6 +58,7 @@ class CreateOperationTest { private final CreateOperation maxInitCodeOperation = new CreateOperation( new ConstantinopleGasCalculator(), MainnetEVMs.SHANGHAI_INIT_CODE_SIZE_LIMIT); + private final EVM evm = MainnetEVMs.pragueEOF(EvmConfiguration.DEFAULT); private static final String TOPIC = "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; // 32 FFs @@ -102,7 +102,7 @@ void createFromMemoryMutationSafe() { operation.execute(messageFrame, evm); final MessageFrame createFrame = messageFrame.getMessageFrameStack().peek(); final ContractCreationProcessor ccp = - new ContractCreationProcessor(evm.getGasCalculator(), evm, false, List.of(), 0, List.of()); + new ContractCreationProcessor(evm, false, List.of(), 0, List.of()); ccp.process(createFrame, OperationTracer.NO_TRACING); final Log log = createFrame.getLogs().get(0); @@ -194,7 +194,7 @@ void shanghaiMaxInitCodeSizeCreate() { var result = maxInitCodeOperation.execute(messageFrame, evm); final MessageFrame createFrame = messageFrame.getMessageFrameStack().peek(); final ContractCreationProcessor ccp = - new ContractCreationProcessor(evm.getGasCalculator(), evm, false, List.of(), 0, List.of()); + new ContractCreationProcessor(evm, false, List.of(), 0, List.of()); ccp.process(createFrame, OperationTracer.NO_TRACING); final Log log = createFrame.getLogs().get(0); @@ -229,7 +229,7 @@ void eofV1CannotCall() { final UInt256 memoryLength = UInt256.valueOf(SIMPLE_CREATE.size()); final MessageFrame messageFrame = new TestMessageFrameBuilder() - .code(CodeFactory.createCode(SIMPLE_EOF, 1)) + .code(evm.getCodeUncached(SIMPLE_EOF)) .pushStackItem(memoryLength) .pushStackItem(memoryOffset) .pushStackItem(Bytes.EMPTY) @@ -261,7 +261,7 @@ private MessageFrame testMemoryFrame( .sender(Address.fromHexString(SENDER)) .value(Wei.ZERO) .apparentValue(Wei.ZERO) - .code(CodeFactory.createCode(SIMPLE_CREATE, 0)) + .code(evm.getCodeUncached(SIMPLE_CREATE)) .completer(__ -> {}) .address(Address.fromHexString(SENDER)) .blockHashLookup(n -> Hash.hash(Words.longBytes(n))) diff --git a/evm/src/test/java/org/hyperledger/besu/evm/operations/EofCreateOperationTest.java b/evm/src/test/java/org/hyperledger/besu/evm/operations/EofCreateOperationTest.java index 2e41b49665b..c0a7f2bcc45 100644 --- a/evm/src/test/java/org/hyperledger/besu/evm/operations/EofCreateOperationTest.java +++ b/evm/src/test/java/org/hyperledger/besu/evm/operations/EofCreateOperationTest.java @@ -29,7 +29,6 @@ import org.hyperledger.besu.evm.EVM; import org.hyperledger.besu.evm.MainnetEVMs; import org.hyperledger.besu.evm.account.MutableAccount; -import org.hyperledger.besu.evm.code.CodeFactory; import org.hyperledger.besu.evm.code.CodeInvalid; import org.hyperledger.besu.evm.frame.BlockValues; import org.hyperledger.besu.evm.frame.MessageFrame; @@ -63,7 +62,8 @@ class EofCreateOperationTest { @Test void innerContractIsCorrect() { - Code code = CodeFactory.createCode(INNER_CONTRACT, 1); + final EVM evm = MainnetEVMs.pragueEOF(EvmConfiguration.DEFAULT); + Code code = evm.getCodeUncached(INNER_CONTRACT); assertThat(code.isValid()).isTrue(); final MessageFrame messageFrame = testMemoryFrame(code, CALL_DATA); @@ -78,11 +78,10 @@ void innerContractIsCorrect() { when(newAccount.isStorageEmpty()).thenReturn(true); when(worldUpdater.updater()).thenReturn(worldUpdater); - final EVM evm = MainnetEVMs.pragueEOF(EvmConfiguration.DEFAULT); final MessageFrame createFrame = messageFrame.getMessageFrameStack().peek(); assertThat(createFrame).isNotNull(); final ContractCreationProcessor ccp = - new ContractCreationProcessor(evm.getGasCalculator(), evm, false, List.of(), 0, List.of()); + new ContractCreationProcessor(evm, false, List.of(), 0, List.of()); ccp.process(createFrame, OperationTracer.NO_TRACING); final Log log = createFrame.getLogs().get(0); @@ -93,8 +92,9 @@ void innerContractIsCorrect() { @Test void eofCreatePassesInCallData() { Bytes outerContract = EOF_CREATE_CONTRACT; + final EVM evm = MainnetEVMs.pragueEOF(EvmConfiguration.DEFAULT); - Code code = CodeFactory.createCode(outerContract, 1); + Code code = evm.getCodeUncached(outerContract); if (!code.isValid()) { System.out.println(outerContract); fail(((CodeInvalid) code).getInvalidReason()); @@ -112,13 +112,12 @@ void eofCreatePassesInCallData() { when(newAccount.isStorageEmpty()).thenReturn(true); when(worldUpdater.updater()).thenReturn(worldUpdater); - final EVM evm = MainnetEVMs.pragueEOF(EvmConfiguration.DEFAULT); var precompiles = MainnetPrecompiledContracts.prague(evm.getGasCalculator()); final MessageFrame createFrame = messageFrame.getMessageFrameStack().peek(); assertThat(createFrame).isNotNull(); final MessageCallProcessor mcp = new MessageCallProcessor(evm, precompiles); final ContractCreationProcessor ccp = - new ContractCreationProcessor(evm.getGasCalculator(), evm, false, List.of(), 0, List.of()); + new ContractCreationProcessor(evm, false, List.of(), 0, List.of()); while (!createFrame.getMessageFrameStack().isEmpty()) { var frame = createFrame.getMessageFrameStack().peek(); assert frame != null; diff --git a/evm/src/test/java/org/hyperledger/besu/evm/operations/ExtCallOperationTest.java b/evm/src/test/java/org/hyperledger/besu/evm/operations/ExtCallOperationTest.java index 3a2ddde7e47..984ce28027f 100644 --- a/evm/src/test/java/org/hyperledger/besu/evm/operations/ExtCallOperationTest.java +++ b/evm/src/test/java/org/hyperledger/besu/evm/operations/ExtCallOperationTest.java @@ -23,11 +23,12 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.Code; import org.hyperledger.besu.evm.EVM; +import org.hyperledger.besu.evm.MainnetEVMs; import org.hyperledger.besu.evm.account.MutableAccount; -import org.hyperledger.besu.evm.code.CodeFactory; import org.hyperledger.besu.evm.frame.ExceptionalHaltReason; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.gascalculator.PragueEOFGasCalculator; +import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.evm.operation.AbstractExtCallOperation; import org.hyperledger.besu.evm.operation.ExtCallOperation; import org.hyperledger.besu.evm.testutils.TestMessageFrameBuilder; @@ -45,11 +46,11 @@ public class ExtCallOperationTest { private final WorldUpdater worldUpdater = mock(WorldUpdater.class); private final MutableAccount account = mock(MutableAccount.class); - private final EVM evm = mock(EVM.class); + private static final EVM EOF_EVM = MainnetEVMs.pragueEOF(EvmConfiguration.DEFAULT); public static final Code SIMPLE_EOF = - CodeFactory.createCode(Bytes.fromHexString("0xEF00010100040200010001040000000080000000"), 1); + EOF_EVM.getCodeUncached(Bytes.fromHexString("0xEF00010100040200010001040000000080000000")); public static final Code INVALID_EOF = - CodeFactory.createCode(Bytes.fromHexString("0xEF00010100040200010001040000000080000023"), 1); + EOF_EVM.getCodeUncached(Bytes.fromHexString("0xEF00010100040200010001040000000080000023")); private static final Address CONTRACT_ADDRESS = Address.fromHexString("0xc0de"); static Iterable data() { @@ -130,12 +131,13 @@ void gasTest( messageFrame.warmUpAddress(CONTRACT_ADDRESS); } when(account.getBalance()).thenReturn(Wei.ZERO); + when(account.getCodeHash()).thenReturn((validCode ? SIMPLE_EOF : INVALID_EOF).getCodeHash()); + when(account.getCode()).thenReturn((validCode ? SIMPLE_EOF : INVALID_EOF).getBytes()); when(worldUpdater.get(any())).thenReturn(account); when(worldUpdater.getAccount(any())).thenReturn(account); when(worldUpdater.updater()).thenReturn(worldUpdater); - when(evm.getCode(any(), any())).thenReturn(validCode ? SIMPLE_EOF : INVALID_EOF); - var result = operation.execute(messageFrame, evm); + var result = operation.execute(messageFrame, EOF_EVM); assertThat(result.getGasCost()).isEqualTo(chargedGas); assertThat(result.getHaltReason()).isEqualTo(haltReason); @@ -218,12 +220,13 @@ void callWithValueTest( .build(); messageFrame.warmUpAddress(CONTRACT_ADDRESS); when(account.getBalance()).thenReturn(valueWeiHave); + when(account.getCodeHash()).thenReturn(SIMPLE_EOF.getCodeHash()); + when(account.getCode()).thenReturn(SIMPLE_EOF.getBytes()); when(worldUpdater.get(any())).thenReturn(account); when(worldUpdater.getAccount(any())).thenReturn(account); when(worldUpdater.updater()).thenReturn(worldUpdater); - when(evm.getCode(any(), any())).thenReturn(SIMPLE_EOF); - var result = operation.execute(messageFrame, evm); + var result = operation.execute(messageFrame, EOF_EVM); assertThat(result.getGasCost()).isEqualTo(chargedGas); assertThat(result.getHaltReason()).isEqualTo(haltReason); @@ -251,15 +254,16 @@ void overflowTest() { .build(); messageFrame.warmUpAddress(CONTRACT_ADDRESS); when(account.getBalance()).thenReturn(Wei.ZERO); + when(account.getCodeHash()).thenReturn(SIMPLE_EOF.getCodeHash()); + when(account.getCode()).thenReturn(SIMPLE_EOF.getBytes()); when(worldUpdater.get(any())).thenReturn(account); when(worldUpdater.getAccount(any())).thenReturn(account); when(worldUpdater.updater()).thenReturn(worldUpdater); - when(evm.getCode(any(), any())).thenReturn(SIMPLE_EOF); while (messageFrame.getDepth() < 1024) { messageFrame.getMessageFrameStack().add(messageFrame); } - var result = operation.execute(messageFrame, evm); + var result = operation.execute(messageFrame, EOF_EVM); assertThat(result.getGasCost()).isEqualTo(100); assertThat(result.getHaltReason()).isNull(); diff --git a/evm/src/test/java/org/hyperledger/besu/evm/operations/ExtDelegateCallOperationTest.java b/evm/src/test/java/org/hyperledger/besu/evm/operations/ExtDelegateCallOperationTest.java index 7a46654039d..d83e9f3ddc5 100644 --- a/evm/src/test/java/org/hyperledger/besu/evm/operations/ExtDelegateCallOperationTest.java +++ b/evm/src/test/java/org/hyperledger/besu/evm/operations/ExtDelegateCallOperationTest.java @@ -23,11 +23,12 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.Code; import org.hyperledger.besu.evm.EVM; +import org.hyperledger.besu.evm.MainnetEVMs; import org.hyperledger.besu.evm.account.MutableAccount; -import org.hyperledger.besu.evm.code.CodeFactory; import org.hyperledger.besu.evm.frame.ExceptionalHaltReason; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.gascalculator.PragueEOFGasCalculator; +import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.evm.operation.AbstractExtCallOperation; import org.hyperledger.besu.evm.operation.ExtDelegateCallOperation; import org.hyperledger.besu.evm.testutils.TestMessageFrameBuilder; @@ -46,13 +47,13 @@ public class ExtDelegateCallOperationTest { private final WorldUpdater worldUpdater = mock(WorldUpdater.class); private final MutableAccount account = mock(MutableAccount.class); // private final MutableAccount targetAccount = mock(MutableAccount.class); - private final EVM evm = mock(EVM.class); + private static final EVM EOF_EVM = MainnetEVMs.pragueEOF(EvmConfiguration.DEFAULT); public static final Code SIMPLE_EOF = - CodeFactory.createCode(Bytes.fromHexString("0xEF00010100040200010001040000000080000000"), 1); - public static final Code SIMPLE_LEGACY = CodeFactory.createCode(Bytes.fromHexString("0x00"), 1); - public static final Code EMPTY_CODE = CodeFactory.createCode(Bytes.fromHexString(""), 1); + EOF_EVM.getCodeUncached(Bytes.fromHexString("0xEF00010100040200010001040000000080000000")); + public static final Code SIMPLE_LEGACY = EOF_EVM.getCodeUncached(Bytes.fromHexString("0x00")); + public static final Code EMPTY_CODE = EOF_EVM.getCodeUncached(Bytes.fromHexString("")); public static final Code INVALID_EOF = - CodeFactory.createCode(Bytes.fromHexString("0xEF00010100040200010001040000000080000023"), 1); + EOF_EVM.getCodeUncached(Bytes.fromHexString("0xEF00010100040200010001040000000080000023")); private static final Address CONTRACT_ADDRESS = Address.fromHexString("0xc0de"); static Iterable data() { @@ -134,12 +135,13 @@ void gasTest( messageFrame.warmUpAddress(CONTRACT_ADDRESS); } when(account.getBalance()).thenReturn(Wei.ZERO); + when(account.getCodeHash()).thenReturn((validCode ? SIMPLE_EOF : INVALID_EOF).getCodeHash()); + when(account.getCode()).thenReturn((validCode ? SIMPLE_EOF : INVALID_EOF).getBytes()); when(worldUpdater.get(any())).thenReturn(account); when(worldUpdater.getAccount(any())).thenReturn(account); when(worldUpdater.updater()).thenReturn(worldUpdater); - when(evm.getCode(any(), any())).thenReturn(validCode ? SIMPLE_EOF : INVALID_EOF); - var result = operation.execute(messageFrame, evm); + var result = operation.execute(messageFrame, EOF_EVM); assertThat(result.getGasCost()).isEqualTo(chargedGas); assertThat(result.getHaltReason()).isEqualTo(haltReason); @@ -195,20 +197,22 @@ void callTypes( when(worldUpdater.get(TestMessageFrameBuilder.DEFAUT_ADDRESS)).thenReturn(account); when(worldUpdater.getAccount(TestMessageFrameBuilder.DEFAUT_ADDRESS)).thenReturn(account); + Code code = + switch (name) { + case "EOF" -> SIMPLE_EOF; + case "Legacy" -> SIMPLE_LEGACY; + default -> EMPTY_CODE; + }; + when(account.getBalance()).thenReturn(Wei.ZERO); + when(account.getCodeHash()).thenReturn(code.getCodeHash()); + when(account.getCode()).thenReturn(code.getBytes()); when(worldUpdater.get(CONTRACT_ADDRESS)).thenReturn("Empty".equals(name) ? null : account); when(worldUpdater.getAccount(CONTRACT_ADDRESS)) .thenReturn("Empty".equals(name) ? null : account); - when(evm.getCode(any(), any())) - .thenReturn( - switch (name) { - case "EOF" -> SIMPLE_EOF; - case "Legacy" -> SIMPLE_LEGACY; - default -> EMPTY_CODE; - }); when(worldUpdater.updater()).thenReturn(worldUpdater); - var result = operation.execute(messageFrame, evm); + var result = operation.execute(messageFrame, EOF_EVM); assertThat(result.getGasCost()).isEqualTo(chargedGas); assertThat(result.getHaltReason()).isEqualTo(haltReason); @@ -235,15 +239,16 @@ void overflowTest() { .build(); messageFrame.warmUpAddress(CONTRACT_ADDRESS); when(account.getBalance()).thenReturn(Wei.ZERO); + when(account.getCodeHash()).thenReturn(SIMPLE_EOF.getCodeHash()); + when(account.getCode()).thenReturn(SIMPLE_EOF.getBytes()); when(worldUpdater.get(any())).thenReturn(account); when(worldUpdater.getAccount(any())).thenReturn(account); when(worldUpdater.updater()).thenReturn(worldUpdater); - when(evm.getCode(any(), any())).thenReturn(SIMPLE_EOF); while (messageFrame.getDepth() < 1024) { messageFrame.getMessageFrameStack().add(messageFrame); } - var result = operation.execute(messageFrame, evm); + var result = operation.execute(messageFrame, EOF_EVM); assertThat(result.getGasCost()).isEqualTo(100); assertThat(result.getHaltReason()).isNull(); diff --git a/evm/src/test/java/org/hyperledger/besu/evm/operations/ExtStaticCallOperationTest.java b/evm/src/test/java/org/hyperledger/besu/evm/operations/ExtStaticCallOperationTest.java index 25be1d1dfee..76f267ec538 100644 --- a/evm/src/test/java/org/hyperledger/besu/evm/operations/ExtStaticCallOperationTest.java +++ b/evm/src/test/java/org/hyperledger/besu/evm/operations/ExtStaticCallOperationTest.java @@ -23,11 +23,12 @@ import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.Code; import org.hyperledger.besu.evm.EVM; +import org.hyperledger.besu.evm.MainnetEVMs; import org.hyperledger.besu.evm.account.MutableAccount; -import org.hyperledger.besu.evm.code.CodeFactory; import org.hyperledger.besu.evm.frame.ExceptionalHaltReason; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.gascalculator.PragueEOFGasCalculator; +import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.evm.operation.AbstractExtCallOperation; import org.hyperledger.besu.evm.operation.ExtStaticCallOperation; import org.hyperledger.besu.evm.testutils.TestMessageFrameBuilder; @@ -45,11 +46,11 @@ public class ExtStaticCallOperationTest { private final WorldUpdater worldUpdater = mock(WorldUpdater.class); private final MutableAccount account = mock(MutableAccount.class); - private final EVM evm = mock(EVM.class); + private static final EVM EOF_EVM = MainnetEVMs.pragueEOF(EvmConfiguration.DEFAULT); public static final Code SIMPLE_EOF = - CodeFactory.createCode(Bytes.fromHexString("0xEF00010100040200010001040000000080000000"), 1); + EOF_EVM.getCodeUncached(Bytes.fromHexString("0xEF00010100040200010001040000000080000000")); public static final Code INVALID_EOF = - CodeFactory.createCode(Bytes.fromHexString("0xEF00010100040200010001040000000080000023"), 1); + EOF_EVM.getCodeUncached(Bytes.fromHexString("0xEF00010100040200010001040000000080000023")); private static final Address CONTRACT_ADDRESS = Address.fromHexString("0xc0de"); static Iterable data() { @@ -130,12 +131,13 @@ void gasTest( messageFrame.warmUpAddress(CONTRACT_ADDRESS); } when(account.getBalance()).thenReturn(Wei.ZERO); + when(account.getCodeHash()).thenReturn((validCode ? SIMPLE_EOF : INVALID_EOF).getCodeHash()); + when(account.getCode()).thenReturn((validCode ? SIMPLE_EOF : INVALID_EOF).getBytes()); when(worldUpdater.get(any())).thenReturn(account); when(worldUpdater.getAccount(any())).thenReturn(account); when(worldUpdater.updater()).thenReturn(worldUpdater); - when(evm.getCode(any(), any())).thenReturn(validCode ? SIMPLE_EOF : INVALID_EOF); - var result = operation.execute(messageFrame, evm); + var result = operation.execute(messageFrame, EOF_EVM); assertThat(result.getGasCost()).isEqualTo(chargedGas); assertThat(result.getHaltReason()).isEqualTo(haltReason); @@ -162,15 +164,16 @@ void overflowTest() { .build(); messageFrame.warmUpAddress(CONTRACT_ADDRESS); when(account.getBalance()).thenReturn(Wei.ZERO); + when(account.getCodeHash()).thenReturn(SIMPLE_EOF.getCodeHash()); + when(account.getCode()).thenReturn(SIMPLE_EOF.getBytes()); when(worldUpdater.get(any())).thenReturn(account); when(worldUpdater.getAccount(any())).thenReturn(account); when(worldUpdater.updater()).thenReturn(worldUpdater); - when(evm.getCode(any(), any())).thenReturn(SIMPLE_EOF); while (messageFrame.getDepth() < 1024) { messageFrame.getMessageFrameStack().add(messageFrame); } - var result = operation.execute(messageFrame, evm); + var result = operation.execute(messageFrame, EOF_EVM); assertThat(result.getGasCost()).isEqualTo(100); assertThat(result.getHaltReason()).isNull(); diff --git a/evm/src/test/java/org/hyperledger/besu/evm/operations/JumpOperationTest.java b/evm/src/test/java/org/hyperledger/besu/evm/operations/JumpOperationTest.java index e04b0d16f61..3c466422ed3 100644 --- a/evm/src/test/java/org/hyperledger/besu/evm/operations/JumpOperationTest.java +++ b/evm/src/test/java/org/hyperledger/besu/evm/operations/JumpOperationTest.java @@ -18,17 +18,14 @@ import org.hyperledger.besu.datatypes.Address; import org.hyperledger.besu.evm.EVM; -import org.hyperledger.besu.evm.EvmSpecVersion; -import org.hyperledger.besu.evm.code.CodeFactory; +import org.hyperledger.besu.evm.MainnetEVMs; import org.hyperledger.besu.evm.frame.BlockValues; import org.hyperledger.besu.evm.frame.ExceptionalHaltReason; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.gascalculator.IstanbulGasCalculator; import org.hyperledger.besu.evm.internal.EvmConfiguration; -import org.hyperledger.besu.evm.operation.JumpDestOperation; import org.hyperledger.besu.evm.operation.JumpOperation; import org.hyperledger.besu.evm.operation.Operation.OperationResult; -import org.hyperledger.besu.evm.operation.OperationRegistry; import org.hyperledger.besu.evm.testutils.FakeBlockValues; import org.hyperledger.besu.evm.testutils.TestMessageFrameBuilder; @@ -46,7 +43,8 @@ class JumpOperationTest { private static final int CURRENT_PC = 1; - private Address address; + private final Address address = + Address.fromHexString("0xc0dec0dec0dec0dec0dec0dec0dec0dec0dec0de"); private EVM evm; private TestMessageFrameBuilder createMessageFrameBuilder(final long initialGas) { @@ -59,12 +57,7 @@ private TestMessageFrameBuilder createMessageFrameBuilder(final long initialGas) @BeforeEach void init() { - address = Address.fromHexString("0x18675309"); - - final OperationRegistry registry = new OperationRegistry(); - registry.put(new JumpOperation(gasCalculator)); - registry.put(new JumpDestOperation(gasCalculator)); - evm = new EVM(registry, gasCalculator, EvmConfiguration.DEFAULT, EvmSpecVersion.PARIS); + evm = MainnetEVMs.pragueEOF(EvmConfiguration.DEFAULT); } @Test @@ -74,7 +67,7 @@ void shouldJumpWhenLocationIsJumpDest() { final MessageFrame frame = createMessageFrameBuilder(10_000L) .pushStackItem(UInt256.fromHexString("0x03")) - .code(CodeFactory.createCode(jumpBytes, 0)) + .code(evm.getCodeUncached(jumpBytes)) .build(); frame.setPC(CURRENT_PC); @@ -89,7 +82,7 @@ void shouldJumpWhenLocationIsJumpDestAndAtEndOfCode() { final MessageFrame frame = createMessageFrameBuilder(10_000L) .pushStackItem(UInt256.fromHexString("0x03")) - .code(CodeFactory.createCode(jumpBytes, 0)) + .code(evm.getCodeUncached(jumpBytes)) .build(); frame.setPC(CURRENT_PC); @@ -104,7 +97,7 @@ void shouldHaltWithInvalidJumDestinationWhenLocationIsOutsideOfCodeRange() { final MessageFrame frameDestinationGreaterThanCodeSize = createMessageFrameBuilder(100L) .pushStackItem(UInt256.fromHexString("0xFFFFFFFF")) - .code(CodeFactory.createCode(jumpBytes, 0)) + .code(evm.getCodeUncached(jumpBytes)) .build(); frameDestinationGreaterThanCodeSize.setPC(CURRENT_PC); @@ -114,7 +107,7 @@ void shouldHaltWithInvalidJumDestinationWhenLocationIsOutsideOfCodeRange() { final MessageFrame frameDestinationEqualsToCodeSize = createMessageFrameBuilder(100L) .pushStackItem(UInt256.fromHexString("0x04")) - .code(CodeFactory.createCode(badJump, 0)) + .code(evm.getCodeUncached(badJump)) .build(); frameDestinationEqualsToCodeSize.setPC(CURRENT_PC); @@ -132,7 +125,7 @@ void longContractsValidate() { final MessageFrame longContract = createMessageFrameBuilder(100L) .pushStackItem(UInt256.fromHexString("0x12c")) - .code(CodeFactory.createCode(longCode, 0)) + .code(evm.getCodeUncached(longCode)) .build(); longContract.setPC(255); diff --git a/evm/src/test/java/org/hyperledger/besu/evm/operations/SelfDestructOperationTest.java b/evm/src/test/java/org/hyperledger/besu/evm/operations/SelfDestructOperationTest.java index a87c254b0ed..3b372f03a03 100644 --- a/evm/src/test/java/org/hyperledger/besu/evm/operations/SelfDestructOperationTest.java +++ b/evm/src/test/java/org/hyperledger/besu/evm/operations/SelfDestructOperationTest.java @@ -24,11 +24,12 @@ import org.hyperledger.besu.datatypes.Hash; import org.hyperledger.besu.datatypes.Wei; import org.hyperledger.besu.evm.EVM; +import org.hyperledger.besu.evm.MainnetEVMs; import org.hyperledger.besu.evm.account.MutableAccount; -import org.hyperledger.besu.evm.code.CodeFactory; import org.hyperledger.besu.evm.frame.BlockValues; import org.hyperledger.besu.evm.frame.MessageFrame; import org.hyperledger.besu.evm.gascalculator.ConstantinopleGasCalculator; +import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.evm.internal.Words; import org.hyperledger.besu.evm.operation.Operation; import org.hyperledger.besu.evm.operation.SelfDestructOperation; @@ -55,7 +56,7 @@ public class SelfDestructOperationTest { @Mock private WorldUpdater worldUpdater; @Mock private MutableAccount accountOriginator; @Mock private MutableAccount accountBeneficiary; - @Mock private EVM evm; + private final EVM evm = MainnetEVMs.pragueEOF(EvmConfiguration.DEFAULT); private final SelfDestructOperation frontierOperation = new SelfDestructOperation(new ConstantinopleGasCalculator()); @@ -79,7 +80,7 @@ void checkContractDeletionCommon( .sender(beneficiaryAddress) .value(Wei.ZERO) .apparentValue(Wei.ZERO) - .code(CodeFactory.createCode(SELFDESTRUCT_CODE, 0)) + .code(evm.getCodeUncached(SELFDESTRUCT_CODE)) .completer(__ -> {}) .address(originatorAddress) .blockHashLookup(n -> Hash.hash(Words.longBytes(n))) diff --git a/evm/src/test/java/org/hyperledger/besu/evm/processor/ContractCreationProcessorTest.java b/evm/src/test/java/org/hyperledger/besu/evm/processor/ContractCreationProcessorTest.java index 32f5ecc3238..40ef063db15 100644 --- a/evm/src/test/java/org/hyperledger/besu/evm/processor/ContractCreationProcessorTest.java +++ b/evm/src/test/java/org/hyperledger/besu/evm/processor/ContractCreationProcessorTest.java @@ -19,27 +19,25 @@ import static org.hyperledger.besu.evm.EOFTestConstants.INNER_CONTRACT; import static org.hyperledger.besu.evm.frame.MessageFrame.State.COMPLETED_SUCCESS; import static org.hyperledger.besu.evm.frame.MessageFrame.State.EXCEPTIONAL_HALT; -import static org.mockito.Mockito.when; import org.hyperledger.besu.evm.EVM; -import org.hyperledger.besu.evm.code.CodeFactory; +import org.hyperledger.besu.evm.EvmSpecVersion; +import org.hyperledger.besu.evm.MainnetEVMs; import org.hyperledger.besu.evm.contractvalidation.EOFValidationCodeRule; import org.hyperledger.besu.evm.contractvalidation.MaxCodeSizeRule; import org.hyperledger.besu.evm.contractvalidation.PrefixCodeRule; import org.hyperledger.besu.evm.frame.ExceptionalHaltReason; import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.gascalculator.GasCalculator; +import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.evm.testutils.TestMessageFrameBuilder; import org.hyperledger.besu.evm.tracing.OperationTracer; import java.util.Collections; import org.apache.tuweni.bytes.Bytes; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @Nested @@ -47,8 +45,7 @@ class ContractCreationProcessorTest extends AbstractMessageProcessorTest { - @Mock GasCalculator gasCalculator; - @Mock EVM evm; + EVM evm = MainnetEVMs.pragueEOF(EvmConfiguration.DEFAULT); private ContractCreationProcessor processor; @@ -56,18 +53,12 @@ class ContractCreationProcessorTest void shouldThrowAnExceptionWhenCodeContractFormatInvalidPreEOF() { processor = new ContractCreationProcessor( - gasCalculator, - evm, - true, - Collections.singletonList(PrefixCodeRule.of()), - 1, - Collections.emptyList()); + evm, true, Collections.singletonList(PrefixCodeRule.of()), 1, Collections.emptyList()); final Bytes contractCode = Bytes.fromHexString("EF01010101010101"); final MessageFrame messageFrame = new TestMessageFrameBuilder().build(); messageFrame.setOutputData(contractCode); - messageFrame.setGasRemaining(100L); + messageFrame.setGasRemaining(10600L); - when(gasCalculator.codeDepositGasCost(contractCode.size())).thenReturn(10L); processor.codeSuccess(messageFrame, OperationTracer.NO_TRACING); assertThat(messageFrame.getState()).isEqualTo(EXCEPTIONAL_HALT); assertThat(messageFrame.getExceptionalHaltReason()) @@ -78,18 +69,12 @@ void shouldThrowAnExceptionWhenCodeContractFormatInvalidPreEOF() { void shouldNotThrowAnExceptionWhenCodeContractIsValid() { processor = new ContractCreationProcessor( - gasCalculator, - evm, - true, - Collections.singletonList(PrefixCodeRule.of()), - 1, - Collections.emptyList()); + evm, true, Collections.singletonList(PrefixCodeRule.of()), 1, Collections.emptyList()); final Bytes contractCode = Bytes.fromHexString("0101010101010101"); final MessageFrame messageFrame = new TestMessageFrameBuilder().build(); messageFrame.setOutputData(contractCode); - messageFrame.setGasRemaining(100L); + messageFrame.setGasRemaining(10600L); - when(gasCalculator.codeDepositGasCost(contractCode.size())).thenReturn(10L); processor.codeSuccess(messageFrame, OperationTracer.NO_TRACING); assertThat(messageFrame.getState()).isEqualTo(COMPLETED_SUCCESS); } @@ -98,13 +83,12 @@ void shouldNotThrowAnExceptionWhenCodeContractIsValid() { void shouldNotThrowAnExceptionWhenPrefixCodeRuleNotAdded() { processor = new ContractCreationProcessor( - gasCalculator, evm, true, Collections.emptyList(), 1, Collections.emptyList()); + evm, true, Collections.emptyList(), 1, Collections.emptyList()); final Bytes contractCode = Bytes.fromHexString("0F01010101010101"); final MessageFrame messageFrame = new TestMessageFrameBuilder().build(); messageFrame.setOutputData(contractCode); - messageFrame.setGasRemaining(100L); + messageFrame.setGasRemaining(10600L); - when(gasCalculator.codeDepositGasCost(contractCode.size())).thenReturn(10L); processor.codeSuccess(messageFrame, OperationTracer.NO_TRACING); assertThat(messageFrame.getState()).isEqualTo(COMPLETED_SUCCESS); } @@ -113,18 +97,16 @@ void shouldNotThrowAnExceptionWhenPrefixCodeRuleNotAdded() { void shouldThrowAnExceptionWhenCodeContractFormatInvalidPostEOF() { processor = new ContractCreationProcessor( - gasCalculator, evm, true, - Collections.singletonList(EOFValidationCodeRule.of(1)), + Collections.singletonList(EOFValidationCodeRule.from(evm)), 1, Collections.emptyList()); final Bytes contractCode = Bytes.fromHexString("EF00010101010101"); final MessageFrame messageFrame = new TestMessageFrameBuilder().build(); messageFrame.setOutputData(contractCode); - messageFrame.setGasRemaining(100L); + messageFrame.setGasRemaining(10600L); - when(gasCalculator.codeDepositGasCost(contractCode.size())).thenReturn(10L); processor.codeSuccess(messageFrame, OperationTracer.NO_TRACING); assertThat(messageFrame.getState()).isEqualTo(EXCEPTIONAL_HALT); assertThat(messageFrame.getExceptionalHaltReason()) @@ -135,18 +117,16 @@ void shouldThrowAnExceptionWhenCodeContractFormatInvalidPostEOF() { void eofValidationShouldAllowLegacyDeployFromLegacyInit() { processor = new ContractCreationProcessor( - gasCalculator, evm, true, - Collections.singletonList(EOFValidationCodeRule.of(1)), + Collections.singletonList(EOFValidationCodeRule.from(evm)), 1, Collections.emptyList()); final Bytes contractCode = Bytes.fromHexString("0101010101010101"); final MessageFrame messageFrame = new TestMessageFrameBuilder().build(); messageFrame.setOutputData(contractCode); - messageFrame.setGasRemaining(100L); + messageFrame.setGasRemaining(10600L); - when(gasCalculator.codeDepositGasCost(contractCode.size())).thenReturn(10L); processor.codeSuccess(messageFrame, OperationTracer.NO_TRACING); assertThat(messageFrame.getState()).isEqualTo(COMPLETED_SUCCESS); } @@ -155,19 +135,16 @@ void eofValidationShouldAllowLegacyDeployFromLegacyInit() { void eofValidationShouldAllowEOFCode() { processor = new ContractCreationProcessor( - gasCalculator, evm, true, - Collections.singletonList(EOFValidationCodeRule.of(1)), + Collections.singletonList(EOFValidationCodeRule.from(evm)), 1, Collections.emptyList()); - final Bytes contractCode = INNER_CONTRACT; final MessageFrame messageFrame = - new TestMessageFrameBuilder().code(CodeFactory.createCode(EOF_CREATE_CONTRACT, 1)).build(); - messageFrame.setOutputData(contractCode); - messageFrame.setGasRemaining(100L); + new TestMessageFrameBuilder().code(evm.getCodeUncached(EOF_CREATE_CONTRACT)).build(); + messageFrame.setOutputData(INNER_CONTRACT); + messageFrame.setGasRemaining(10600L); - when(gasCalculator.codeDepositGasCost(contractCode.size())).thenReturn(10L); processor.codeSuccess(messageFrame, OperationTracer.NO_TRACING); assertThat(messageFrame.getState()).isEqualTo(COMPLETED_SUCCESS); } @@ -176,18 +153,11 @@ void eofValidationShouldAllowEOFCode() { void prefixValidationShouldPreventEOFCode() { processor = new ContractCreationProcessor( - gasCalculator, - evm, - true, - Collections.singletonList(PrefixCodeRule.of()), - 1, - Collections.emptyList()); - final Bytes contractCode = INNER_CONTRACT; + evm, true, Collections.singletonList(PrefixCodeRule.of()), 1, Collections.emptyList()); final MessageFrame messageFrame = new TestMessageFrameBuilder().build(); - messageFrame.setOutputData(contractCode); - messageFrame.setGasRemaining(100L); + messageFrame.setOutputData(INNER_CONTRACT); + messageFrame.setGasRemaining(10600L); - when(gasCalculator.codeDepositGasCost(contractCode.size())).thenReturn(10L); processor.codeSuccess(messageFrame, OperationTracer.NO_TRACING); assertThat(messageFrame.getState()).isEqualTo(EXCEPTIONAL_HALT); } @@ -196,41 +166,36 @@ void prefixValidationShouldPreventEOFCode() { void eofValidationShouldPreventLegacyDeployFromEOFInit() { processor = new ContractCreationProcessor( - gasCalculator, evm, true, - Collections.singletonList(EOFValidationCodeRule.of(1)), + Collections.singletonList(EOFValidationCodeRule.from(evm)), 1, Collections.emptyList()); final Bytes contractCode = Bytes.fromHexString("6030602001"); final Bytes initCode = EOF_CREATE_CONTRACT; final MessageFrame messageFrame = - new TestMessageFrameBuilder().code(CodeFactory.createCode(initCode, 1)).build(); + new TestMessageFrameBuilder().code(evm.getCodeForCreation(initCode)).build(); messageFrame.setOutputData(contractCode); - messageFrame.setGasRemaining(100L); + messageFrame.setGasRemaining(10600L); - when(gasCalculator.codeDepositGasCost(contractCode.size())).thenReturn(10L); processor.codeSuccess(messageFrame, OperationTracer.NO_TRACING); assertThat(messageFrame.getState()).isEqualTo(EXCEPTIONAL_HALT); } @Test - @Disabled("This is what's changing") void eofValidationPreventsEOFDeployFromLegacyInit() { processor = new ContractCreationProcessor( - gasCalculator, evm, true, - Collections.singletonList(EOFValidationCodeRule.of(1)), + Collections.singletonList(EOFValidationCodeRule.from(evm)), 1, Collections.emptyList()); final Bytes contractCode = EOF_CREATE_CONTRACT; final MessageFrame messageFrame = new TestMessageFrameBuilder().build(); messageFrame.setOutputData(contractCode); - messageFrame.setGasRemaining(100L); + messageFrame.setGasRemaining(10600L); - when(gasCalculator.codeDepositGasCost(contractCode.size())).thenReturn(10L); processor.codeSuccess(messageFrame, OperationTracer.NO_TRACING); assertThat(messageFrame.getState()).isEqualTo(EXCEPTIONAL_HALT); } @@ -239,18 +204,17 @@ void eofValidationPreventsEOFDeployFromLegacyInit() { void shouldThrowAnExceptionWhenCodeContractTooLarge() { processor = new ContractCreationProcessor( - gasCalculator, evm, true, - Collections.singletonList(MaxCodeSizeRule.of(24 * 1024)), + Collections.singletonList(MaxCodeSizeRule.from(EvmSpecVersion.SPURIOUS_DRAGON)), 1, Collections.emptyList()); - final Bytes contractCode = Bytes.fromHexString("00".repeat(24 * 1024 + 1)); + final Bytes contractCode = + Bytes.fromHexString("00".repeat(EvmSpecVersion.SPURIOUS_DRAGON.getMaxCodeSize() + 1)); final MessageFrame messageFrame = new TestMessageFrameBuilder().build(); messageFrame.setOutputData(contractCode); - messageFrame.setGasRemaining(100L); + messageFrame.setGasRemaining(10_000_000L); - when(gasCalculator.codeDepositGasCost(contractCode.size())).thenReturn(10L); processor.codeSuccess(messageFrame, OperationTracer.NO_TRACING); assertThat(messageFrame.getState()).isEqualTo(EXCEPTIONAL_HALT); assertThat(messageFrame.getExceptionalHaltReason()) @@ -261,18 +225,17 @@ void shouldThrowAnExceptionWhenCodeContractTooLarge() { void shouldNotThrowAnExceptionWhenCodeContractTooLarge() { processor = new ContractCreationProcessor( - gasCalculator, evm, true, - Collections.singletonList(MaxCodeSizeRule.of(24 * 1024)), + Collections.singletonList(MaxCodeSizeRule.from(EvmSpecVersion.SPURIOUS_DRAGON)), 1, Collections.emptyList()); - final Bytes contractCode = Bytes.fromHexString("00".repeat(24 * 1024)); + final Bytes contractCode = + Bytes.fromHexString("00".repeat(EvmSpecVersion.SPURIOUS_DRAGON.getMaxCodeSize())); final MessageFrame messageFrame = new TestMessageFrameBuilder().build(); messageFrame.setOutputData(contractCode); - messageFrame.setGasRemaining(100L); + messageFrame.setGasRemaining(5_000_000L); - when(gasCalculator.codeDepositGasCost(contractCode.size())).thenReturn(10L); processor.codeSuccess(messageFrame, OperationTracer.NO_TRACING); assertThat(messageFrame.getState()).isEqualTo(COMPLETED_SUCCESS); } @@ -281,13 +244,12 @@ void shouldNotThrowAnExceptionWhenCodeContractTooLarge() { void shouldNotThrowAnExceptionWhenCodeSizeRuleNotAdded() { processor = new ContractCreationProcessor( - gasCalculator, evm, true, Collections.emptyList(), 1, Collections.emptyList()); + evm, true, Collections.emptyList(), 1, Collections.emptyList()); final Bytes contractCode = Bytes.fromHexString("00".repeat(24 * 1024 + 1)); final MessageFrame messageFrame = new TestMessageFrameBuilder().build(); messageFrame.setOutputData(contractCode); - messageFrame.setGasRemaining(100L); + messageFrame.setGasRemaining(5_000_000L); - when(gasCalculator.codeDepositGasCost(contractCode.size())).thenReturn(10L); processor.codeSuccess(messageFrame, OperationTracer.NO_TRACING); assertThat(messageFrame.getState()).isEqualTo(COMPLETED_SUCCESS); } @@ -295,6 +257,6 @@ void shouldNotThrowAnExceptionWhenCodeSizeRuleNotAdded() { @Override protected ContractCreationProcessor getAbstractMessageProcessor() { return new ContractCreationProcessor( - gasCalculator, evm, true, Collections.emptyList(), 1, Collections.emptyList()); + evm, true, Collections.emptyList(), 1, Collections.emptyList()); } } diff --git a/evm/src/test/java/org/hyperledger/besu/evm/toy/EvmToyCommand.java b/evm/src/test/java/org/hyperledger/besu/evm/toy/EvmToyCommand.java index 4fc4d6bf6c7..fcf26c3c569 100644 --- a/evm/src/test/java/org/hyperledger/besu/evm/toy/EvmToyCommand.java +++ b/evm/src/test/java/org/hyperledger/besu/evm/toy/EvmToyCommand.java @@ -194,8 +194,7 @@ public void run() { .build(); final MessageCallProcessor mcp = new MessageCallProcessor(evm, precompileContractRegistry); - final ContractCreationProcessor ccp = - new ContractCreationProcessor(evm.getGasCalculator(), evm, false, List.of(), 0); + final ContractCreationProcessor ccp = new ContractCreationProcessor(evm, false, List.of(), 0); stopwatch.start(); Deque messageFrameStack = initialMessageFrame.getMessageFrameStack(); while (!messageFrameStack.isEmpty()) { diff --git a/evm/src/test/java/org/hyperledger/besu/evm/tracing/ExtendedOperationTracerTest.java b/evm/src/test/java/org/hyperledger/besu/evm/tracing/ExtendedOperationTracerTest.java index c0db4bfbf62..bd043f933b5 100644 --- a/evm/src/test/java/org/hyperledger/besu/evm/tracing/ExtendedOperationTracerTest.java +++ b/evm/src/test/java/org/hyperledger/besu/evm/tracing/ExtendedOperationTracerTest.java @@ -16,14 +16,14 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.when; import org.hyperledger.besu.evm.EVM; +import org.hyperledger.besu.evm.MainnetEVMs; import org.hyperledger.besu.evm.account.MutableAccount; import org.hyperledger.besu.evm.frame.ExceptionalHaltReason; import org.hyperledger.besu.evm.frame.MessageFrame; -import org.hyperledger.besu.evm.gascalculator.GasCalculator; +import org.hyperledger.besu.evm.internal.EvmConfiguration; import org.hyperledger.besu.evm.processor.ContractCreationProcessor; import org.hyperledger.besu.evm.worldstate.WorldUpdater; @@ -40,8 +40,6 @@ @ExtendWith(MockitoExtension.class) class ExtendedOperationTracerTest { - @Mock GasCalculator gasCalculator; - @Mock EVM evm; @Mock MessageFrame frame; @Mock WorldUpdater worldUpdater; @Mock MutableAccount mutableAccount; @@ -49,7 +47,6 @@ class ExtendedOperationTracerTest { @BeforeEach void setUp() { when(frame.getOutputData()).thenReturn(Bytes.EMPTY); - when(gasCalculator.codeDepositGasCost(anyInt())).thenReturn(0L); when(frame.getRemainingGas()).thenReturn(1L); when(frame.getWorldUpdater()).thenReturn(worldUpdater); @@ -58,8 +55,9 @@ void setUp() { @Test void shouldCallTraceAccountCreationResultIfIsExtendedTracing() { + EVM evm = MainnetEVMs.pragueEOF(EvmConfiguration.DEFAULT); final ContractCreationProcessor contractCreationProcessor = - new ContractCreationProcessor(gasCalculator, evm, false, Collections.emptyList(), 0); + new ContractCreationProcessor(evm, false, Collections.emptyList(), 0); final ExtendedOperationTracer tracer = new ExtendedOperationTracer(); contractCreationProcessor.codeSuccess(frame, tracer); @@ -71,8 +69,9 @@ void shouldCallTraceAccountCreationResultIfIsExtendedTracing() { @Test void shouldNotCallTraceAccountCreationResultIfIsNotExtendedTracing() { + EVM evm = MainnetEVMs.pragueEOF(EvmConfiguration.DEFAULT); final ContractCreationProcessor contractCreationProcessor = - new ContractCreationProcessor(gasCalculator, evm, false, Collections.emptyList(), 0); + new ContractCreationProcessor(evm, false, Collections.emptyList(), 0); final DefaultOperationTracer tracer = new DefaultOperationTracer(); contractCreationProcessor.codeSuccess(frame, tracer);