Skip to content

Commit

Permalink
fixes rom
Browse files Browse the repository at this point in the history
  • Loading branch information
laisolizq committed Jan 31, 2023
1 parent 9e10123 commit c763e67
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
20 changes: 12 additions & 8 deletions main/opcodes/calldata-returndata-code.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,8 @@ opCODECOPY:
; store lastMemOffset for memory expansion gas cost
C :MSTORE(lastMemOffset)
; store lastMemLength for memory expansion gas cost
E :MSTORE(lastMemLength)
; compute memory expansion gas cost
:CALL(saveMem); in: [lastMemOffset, lastMemLength]
E :MSTORE(lastMemLength), CALL(saveMem); in: [lastMemOffset, lastMemLength]
; check out-of-gas
GAS - %GAS_FASTEST_STEP => GAS :JMPN(outOfGas)
;${3*((E+31)/32)}
Expand Down Expand Up @@ -403,7 +402,8 @@ VAR GLOBAL tmpContractLength
*/
opEXTCODECOPY:
; checks zk-counters
%MAX_CNT_STEPS - STEP - 300 :JMPN(outOfCountersStep)
%MAX_CNT_STEPS - STEP - 300 :JMPN(outOfCountersStep)
%MAX_CNT_BINARY - CNT_BINARY - 1 :JMPN(outOfCountersBinary)

; check stack underflow
SP - 4 => SP :JMPN(stackUnderflow)
Expand All @@ -421,7 +421,8 @@ opEXTCODECOPY:
C :MSTORE(lastMemOffset)

; store lastMemLength for memory expansion gas cost
E :MSTORE(lastMemLength)
; compute memory expansion gas cost
E :MSTORE(lastMemLength), CALL(saveMem); in: [lastMemOffset, lastMemLength]

; check out-of-gas
;${3*((E+31)/32)}
Expand All @@ -438,9 +439,6 @@ opEXTCODECOPY:
$ => A :MLOAD(arithRes1)
; check out-of-gas
GAS - A => GAS :JMPN(outOfGas)

; compute memory expansion gas cost
:CALL(saveMem); in: [lastMemOffset, lastMemLength]
; if offset is above data len, length => offset
D => A
$ => B :MLOAD(tmpContractLength)
Expand Down Expand Up @@ -558,15 +556,21 @@ opRETURNDATACOPY:
; Load ret data length from last ctx
B => CTX
E => B

; check offset is lower than max memory
%MAX_MEM_EXPANSION_BYTES => A
$ :LT,JMPC(outOfGas)

$ => A :MLOAD(retDataLength)
$ => E :MLOAD(retDataOffset)
$ => CTX :MLOAD(currentCTX)
; E ret data offset (memory pointer) of last context, B offset in return data that want to retrive
E + B => E
; if retDataSize <= retdataOffset + dataLen -> OOG
;A retDataSize
; A retDataSize
B + C => B ; total offset (retdataOffset + dataLen)
$ :LT, JMPC(outOfGas)

E => B ; memory pointer where start to copy memory
;${3*((C+31)/32)}
C+31 => A
Expand Down
2 changes: 0 additions & 2 deletions tools/parallel-tests-sample/sample.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
const { expect } = require('chai');
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');


const { newCommitPolsArray } = require('pilcom');
const smMain = require('@0xpolygonhermez/zkevm-proverjs/src/sm/sm_main/sm_main');
Expand Down

0 comments on commit c763e67

Please sign in to comment.