Skip to content

Commit

Permalink
fix(EVM): Fix namings (N-02) (#1169)
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolosnikov authored Dec 30, 2024
1 parent 34918c3 commit 7328b8c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 34 deletions.
38 changes: 19 additions & 19 deletions system-contracts/contracts/EvmEmulator.yul
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -299,7 +299,7 @@ object "EvmEmulator" {
}

if maxNewMemsize { // Memory expansion costs 0 if size is 0
maxExpand := _expandMemoryInternal(maxNewMemsize)
gasCost := _expandMemoryInternal(maxNewMemsize)
}
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -3427,7 +3427,7 @@ object "EvmEmulator" {
}

if maxNewMemsize { // Memory expansion costs 0 if size is 0
maxExpand := _expandMemoryInternal(maxNewMemsize)
gasCost := _expandMemoryInternal(maxNewMemsize)
}
}

Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
}
}
Expand Down
10 changes: 5 additions & 5 deletions system-contracts/contracts/KnownCodesStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
10 changes: 5 additions & 5 deletions system-contracts/evm-emulator/EvmEmulatorFunctions.template.yul
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions system-contracts/evm-emulator/EvmEmulatorLoop.template.yul
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 7328b8c

Please sign in to comment.