From 60db1fb9b860fe5f10fb91a943788f20637cee87 Mon Sep 17 00:00:00 2001 From: Vladislav Volosnikov Date: Sun, 27 Oct 2024 13:35:38 +0100 Subject: [PATCH] Use different memory layouts for constructor and deployed contract --- system-contracts/SystemContractsHashes.json | 8 ++++---- system-contracts/contracts/EvmEmulator.yul | 12 ++++++++++-- .../evm-emulator/EvmEmulator.template.yul | 8 ++++++++ .../evm-emulator/EvmEmulatorFunctions.template.yul | 2 +- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/system-contracts/SystemContractsHashes.json b/system-contracts/SystemContractsHashes.json index 4adbab2d1..a0aefd206 100644 --- a/system-contracts/SystemContractsHashes.json +++ b/system-contracts/SystemContractsHashes.json @@ -108,8 +108,8 @@ "contractName": "SystemContext", "bytecodePath": "artifacts-zk/contracts-preprocessed/SystemContext.sol/SystemContext.json", "sourceCodePath": "contracts-preprocessed/SystemContext.sol", - "bytecodeHash": "0x010001c5a6801732584ea1804b91e5621ac25460be6b91196fc4d68fd3a65105", - "sourceCodeHash": "0xc5ce25a94e3b510183635dd2fe0152dbcaa705bc8802fb3a4390253b5af3aa0a" + "bytecodeHash": "0x010001c516b1721bd4745d8d3a36607d4f6b65c0d51dcb1b5801aaf0234293cc", + "sourceCodeHash": "0xe2f6eb015d260aafe9405b28ef3ec27921add4de7f329b7ef61e0aa6c9365e29" }, { "contractName": "EventWriter", @@ -122,8 +122,8 @@ "contractName": "EvmEmulator", "bytecodePath": "contracts-preprocessed/artifacts/EvmEmulator.yul/EvmEmulator.yul.zbin", "sourceCodePath": "contracts-preprocessed/EvmEmulator.yul", - "bytecodeHash": "0x01000d1da56c97d7554e0e9c8397a970b5a44c569aab6fb6661f820c5ae3e58e", - "sourceCodeHash": "0xb6b321ccc368ca848ca6675eaf968dedd4b4da388d74829cd3fb9927f4550071" + "bytecodeHash": "0x01000d6d51fe13baa8278266bb8775c03df377c8b0aa6ebca6c8d98a096b7bb2", + "sourceCodeHash": "0x676b1652efec61f16eb271efda30e3a695681ce7b2f1a509b33c4afb15c55723" }, { "contractName": "EvmGasManager", diff --git a/system-contracts/contracts/EvmEmulator.yul b/system-contracts/contracts/EvmEmulator.yul index 19a8d41a6..2f8254d61 100644 --- a/system-contracts/contracts/EvmEmulator.yul +++ b/system-contracts/contracts/EvmEmulator.yul @@ -1,5 +1,9 @@ object "EvmEmulator" { code { + function MAX_POSSIBLE_ACTIVE_BYTECODE() -> max { + max := MAX_POSSIBLE_INIT_BYTECODE() + } + /// @dev This function is used to get the initCode. /// @dev It assumes that the initCode has been passed via the calldata and so we use the pointer /// to obtain the bytecode. @@ -143,7 +147,7 @@ object "EvmEmulator" { } function MEM_OFFSET() -> offset { - offset := add(BYTECODE_OFFSET(), MAX_POSSIBLE_INIT_BYTECODE()) + offset := add(BYTECODE_OFFSET(), MAX_POSSIBLE_ACTIVE_BYTECODE()) } function MEM_OFFSET_INNER() -> offset { @@ -3155,6 +3159,10 @@ object "EvmEmulator" { } object "EvmEmulator_deployed" { code { + function MAX_POSSIBLE_ACTIVE_BYTECODE() -> max { + max := MAX_POSSIBLE_DEPLOYED_BYTECODE() + } + //////////////////////////////////////////////////////////////// // CONSTANTS //////////////////////////////////////////////////////////////// @@ -3240,7 +3248,7 @@ object "EvmEmulator" { } function MEM_OFFSET() -> offset { - offset := add(BYTECODE_OFFSET(), MAX_POSSIBLE_INIT_BYTECODE()) + offset := add(BYTECODE_OFFSET(), MAX_POSSIBLE_ACTIVE_BYTECODE()) } function MEM_OFFSET_INNER() -> offset { diff --git a/system-contracts/evm-emulator/EvmEmulator.template.yul b/system-contracts/evm-emulator/EvmEmulator.template.yul index 1730a0b8e..02571acf5 100644 --- a/system-contracts/evm-emulator/EvmEmulator.template.yul +++ b/system-contracts/evm-emulator/EvmEmulator.template.yul @@ -1,5 +1,9 @@ object "EvmEmulator" { code { + function MAX_POSSIBLE_ACTIVE_BYTECODE() -> max { + max := MAX_POSSIBLE_INIT_BYTECODE() + } + /// @dev This function is used to get the initCode. /// @dev It assumes that the initCode has been passed via the calldata and so we use the pointer /// to obtain the bytecode. @@ -104,6 +108,10 @@ object "EvmEmulator" { } object "EvmEmulator_deployed" { code { + function MAX_POSSIBLE_ACTIVE_BYTECODE() -> max { + max := MAX_POSSIBLE_DEPLOYED_BYTECODE() + } + function $llvm_NoInline_llvm$_simulate( diff --git a/system-contracts/evm-emulator/EvmEmulatorFunctions.template.yul b/system-contracts/evm-emulator/EvmEmulatorFunctions.template.yul index 755f82f5e..79314427b 100644 --- a/system-contracts/evm-emulator/EvmEmulatorFunctions.template.yul +++ b/system-contracts/evm-emulator/EvmEmulatorFunctions.template.yul @@ -83,7 +83,7 @@ function MAX_POSSIBLE_INIT_BYTECODE() -> max { } function MEM_OFFSET() -> offset { - offset := add(BYTECODE_OFFSET(), MAX_POSSIBLE_INIT_BYTECODE()) + offset := add(BYTECODE_OFFSET(), MAX_POSSIBLE_ACTIVE_BYTECODE()) } function MEM_OFFSET_INNER() -> offset {