diff --git a/system-contracts/contracts/EvmEmulator.yul b/system-contracts/contracts/EvmEmulator.yul index c69e8407a..86f799a27 100644 --- a/system-contracts/contracts/EvmEmulator.yul +++ b/system-contracts/contracts/EvmEmulator.yul @@ -187,7 +187,7 @@ object "EvmEmulator" { function OVERHEAD() -> overhead { overhead := 2000 } - function UINT32_MAX() -> ret { ret := 4294967295 } // 2^32 - 1 + function MAX_UINT32() -> ret { ret := 4294967295 } // 2^32 - 1 function EMPTY_KECCAK() -> value { // keccak("") value := 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 @@ -290,7 +290,7 @@ object "EvmEmulator" { } } - function expandMemory2(retOffset, retSize, argsOffset, argsSize) -> maxExpand { + function expandMemory2(retOffset, retSize, argsOffset, argsSize) -> gasCost { let maxNewMemsize := _memsizeRequired(retOffset, retSize) let argsMemsize := _memsizeRequired(argsOffset, argsSize) @@ -299,7 +299,7 @@ object "EvmEmulator" { } if maxNewMemsize { // Memory expansion costs 0 if size is 0 - maxExpand := _expandMemoryInternal(maxNewMemsize) + gasCost := _expandMemoryInternal(maxNewMemsize) } } @@ -931,8 +931,8 @@ object "EvmEmulator" { zkEvmGasToPass := add(zkEvmGasToPass, additionalStipend) - if gt(zkEvmGasToPass, UINT32_MAX()) { // just in case - zkEvmGasToPass := UINT32_MAX() + if gt(zkEvmGasToPass, MAX_UINT32()) { // just in case + zkEvmGasToPass := MAX_UINT32() } let zkEvmGasBefore := gas() @@ -1710,14 +1710,14 @@ object "EvmEmulator" { dstOffset := add(dstOffset, MEM_OFFSET()) // EraVM will revert if offset + length overflows uint32 - if gt(sourceOffset, UINT32_MAX()) { - sourceOffset := UINT32_MAX() + if gt(sourceOffset, MAX_UINT32()) { + sourceOffset := MAX_UINT32() } // Check bytecode out-of-bounds access let truncatedLen := len - if gt(add(sourceOffset, len), UINT32_MAX()) { - truncatedLen := sub(UINT32_MAX(), sourceOffset) // truncate + if gt(add(sourceOffset, len), MAX_UINT32()) { + truncatedLen := sub(MAX_UINT32(), sourceOffset) // truncate $llvm_AlwaysInline_llvm$_memsetToZero(add(dstOffset, truncatedLen), sub(len, truncatedLen)) // pad with zeroes any out-of-bounds } @@ -3315,7 +3315,7 @@ object "EvmEmulator" { function OVERHEAD() -> overhead { overhead := 2000 } - function UINT32_MAX() -> ret { ret := 4294967295 } // 2^32 - 1 + function MAX_UINT32() -> ret { ret := 4294967295 } // 2^32 - 1 function EMPTY_KECCAK() -> value { // keccak("") value := 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 @@ -3418,7 +3418,7 @@ object "EvmEmulator" { } } - function expandMemory2(retOffset, retSize, argsOffset, argsSize) -> maxExpand { + function expandMemory2(retOffset, retSize, argsOffset, argsSize) -> gasCost { let maxNewMemsize := _memsizeRequired(retOffset, retSize) let argsMemsize := _memsizeRequired(argsOffset, argsSize) @@ -3427,7 +3427,7 @@ object "EvmEmulator" { } if maxNewMemsize { // Memory expansion costs 0 if size is 0 - maxExpand := _expandMemoryInternal(maxNewMemsize) + gasCost := _expandMemoryInternal(maxNewMemsize) } } @@ -4059,8 +4059,8 @@ object "EvmEmulator" { zkEvmGasToPass := add(zkEvmGasToPass, additionalStipend) - if gt(zkEvmGasToPass, UINT32_MAX()) { // just in case - zkEvmGasToPass := UINT32_MAX() + if gt(zkEvmGasToPass, MAX_UINT32()) { // just in case + zkEvmGasToPass := MAX_UINT32() } let zkEvmGasBefore := gas() @@ -4826,14 +4826,14 @@ object "EvmEmulator" { dstOffset := add(dstOffset, MEM_OFFSET()) // EraVM will revert if offset + length overflows uint32 - if gt(sourceOffset, UINT32_MAX()) { - sourceOffset := UINT32_MAX() + if gt(sourceOffset, MAX_UINT32()) { + sourceOffset := MAX_UINT32() } // Check bytecode out-of-bounds access let truncatedLen := len - if gt(add(sourceOffset, len), UINT32_MAX()) { - truncatedLen := sub(UINT32_MAX(), sourceOffset) // truncate + if gt(add(sourceOffset, len), MAX_UINT32()) { + truncatedLen := sub(MAX_UINT32(), sourceOffset) // truncate $llvm_AlwaysInline_llvm$_memsetToZero(add(dstOffset, truncatedLen), sub(len, truncatedLen)) // pad with zeroes any out-of-bounds } @@ -6262,7 +6262,7 @@ object "EvmEmulator" { function $llvm_AlwaysInline_llvm$_calldataload(calldataOffset) -> res { // EraVM will revert if offset + length overflows uint32 - if lt(calldataOffset, UINT32_MAX()) { + if lt(calldataOffset, MAX_UINT32()) { res := calldataload(calldataOffset) } } diff --git a/system-contracts/contracts/KnownCodesStorage.sol b/system-contracts/contracts/KnownCodesStorage.sol index 463105a64..3f0ced702 100644 --- a/system-contracts/contracts/KnownCodesStorage.sol +++ b/system-contracts/contracts/KnownCodesStorage.sol @@ -93,20 +93,20 @@ contract KnownCodesStorage is IKnownCodesStorage, SystemContractBase { uint256 evmBytecodeLen, bytes calldata paddedBytecode ) external payable onlyCallFrom(address(DEPLOYER_SYSTEM_CONTRACT)) returns (bytes32) { - bytes32 vesionedBytecodeHash = Utils.hashEVMBytecode(evmBytecodeLen, paddedBytecode); + bytes32 versionedBytecodeHash = Utils.hashEVMBytecode(evmBytecodeLen, paddedBytecode); - if (getMarker(vesionedBytecodeHash) == 0) { + if (getMarker(versionedBytecodeHash) == 0) { L1_MESSENGER_CONTRACT.sendToL1(paddedBytecode); assembly { - sstore(vesionedBytecodeHash, 1) + sstore(versionedBytecodeHash, 1) } - emit MarkedAsKnown(vesionedBytecodeHash, false); + emit MarkedAsKnown(versionedBytecodeHash, false); } assembly { - mstore(0x0, vesionedBytecodeHash) + mstore(0x0, versionedBytecodeHash) return(0x0, 0x20) } } diff --git a/system-contracts/evm-emulator/EvmEmulatorFunctions.template.yul b/system-contracts/evm-emulator/EvmEmulatorFunctions.template.yul index 7057e510b..5aa90eecc 100644 --- a/system-contracts/evm-emulator/EvmEmulatorFunctions.template.yul +++ b/system-contracts/evm-emulator/EvmEmulatorFunctions.template.yul @@ -127,7 +127,7 @@ function MSG_VALUE_SIMULATOR_STIPEND_GAS() -> gas_stipend { function OVERHEAD() -> overhead { overhead := 2000 } -function UINT32_MAX() -> ret { ret := 4294967295 } // 2^32 - 1 +function MAX_UINT32() -> ret { ret := 4294967295 } // 2^32 - 1 function EMPTY_KECCAK() -> value { // keccak("") value := 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 @@ -230,7 +230,7 @@ function _memsizeRequired(offset, size) -> memorySize { } } -function expandMemory2(retOffset, retSize, argsOffset, argsSize) -> maxExpand { +function expandMemory2(retOffset, retSize, argsOffset, argsSize) -> gasCost { let maxNewMemsize := _memsizeRequired(retOffset, retSize) let argsMemsize := _memsizeRequired(argsOffset, argsSize) @@ -239,7 +239,7 @@ function expandMemory2(retOffset, retSize, argsOffset, argsSize) -> maxExpand { } if maxNewMemsize { // Memory expansion costs 0 if size is 0 - maxExpand := _expandMemoryInternal(maxNewMemsize) + gasCost := _expandMemoryInternal(maxNewMemsize) } } @@ -871,8 +871,8 @@ function callZkVmNative(addr, evmGasToPass, value, argsOffset, argsSize, retOffs zkEvmGasToPass := add(zkEvmGasToPass, additionalStipend) - if gt(zkEvmGasToPass, UINT32_MAX()) { // just in case - zkEvmGasToPass := UINT32_MAX() + if gt(zkEvmGasToPass, MAX_UINT32()) { // just in case + zkEvmGasToPass := MAX_UINT32() } let zkEvmGasBefore := gas() diff --git a/system-contracts/evm-emulator/EvmEmulatorLoop.template.yul b/system-contracts/evm-emulator/EvmEmulatorLoop.template.yul index 58e959514..c9700c5d9 100644 --- a/system-contracts/evm-emulator/EvmEmulatorLoop.template.yul +++ b/system-contracts/evm-emulator/EvmEmulatorLoop.template.yul @@ -373,14 +373,14 @@ for { } true { } { dstOffset := add(dstOffset, MEM_OFFSET()) // EraVM will revert if offset + length overflows uint32 - if gt(sourceOffset, UINT32_MAX()) { - sourceOffset := UINT32_MAX() + if gt(sourceOffset, MAX_UINT32()) { + sourceOffset := MAX_UINT32() } // Check bytecode out-of-bounds access let truncatedLen := len - if gt(add(sourceOffset, len), UINT32_MAX()) { - truncatedLen := sub(UINT32_MAX(), sourceOffset) // truncate + if gt(add(sourceOffset, len), MAX_UINT32()) { + truncatedLen := sub(MAX_UINT32(), sourceOffset) // truncate $llvm_AlwaysInline_llvm$_memsetToZero(add(dstOffset, truncatedLen), sub(len, truncatedLen)) // pad with zeroes any out-of-bounds } diff --git a/system-contracts/evm-emulator/calldata-opcodes/RuntimeScope.template.yul b/system-contracts/evm-emulator/calldata-opcodes/RuntimeScope.template.yul index 51c88e7b5..7f02e012f 100644 --- a/system-contracts/evm-emulator/calldata-opcodes/RuntimeScope.template.yul +++ b/system-contracts/evm-emulator/calldata-opcodes/RuntimeScope.template.yul @@ -8,7 +8,7 @@ function $llvm_AlwaysInline_llvm$_calldatacopy(dstOffset, sourceOffset, truncate function $llvm_AlwaysInline_llvm$_calldataload(calldataOffset) -> res { // EraVM will revert if offset + length overflows uint32 - if lt(calldataOffset, UINT32_MAX()) { + if lt(calldataOffset, MAX_UINT32()) { res := calldataload(calldataOffset) } } \ No newline at end of file