Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(EVM): Fix namings (N-02) #1169

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -932,8 +932,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 @@ -1711,14 +1711,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 @@ -3316,7 +3316,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 @@ -3419,7 +3419,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 @@ -3428,7 +3428,7 @@ object "EvmEmulator" {
}

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

Expand Down Expand Up @@ -4061,8 +4061,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 @@ -4828,14 +4828,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 @@ -6264,7 +6264,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
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 @@ -872,8 +872,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)
}
}
Loading