Skip to content

Commit

Permalink
fixes rom & update GHA
Browse files Browse the repository at this point in the history
  • Loading branch information
laisolizq committed Jan 31, 2023
1 parent 3b9f881 commit f747993
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
run: |
npm i
npm run build
npm run build:gasLimit:v1
npm run build:gasLimit:v2
npm run build:gasLimit:v3
- name: run counters tests
run: |
npm run test:counters
Expand Down
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
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"scripts": {
"build": "mkdir -p build && npx zkasm main/main.zkasm -o build/rom.json && npm run build:metadata",
"build:metadata": "echo \"COMMIT=$(git rev-parse HEAD)\nSHA256SUM=$(sha256sum ./build/rom.json)\" > build/metadata-rom.txt",
"build:gasLimit:v1": "mkdir -p build && npx zkasm main/main.zkasm -o build/rom-89128960.json -D TX_GAS_LIMIT=89128960",
"build:gasLimit:v2": "mkdir -p build && npx zkasm main/main.zkasm -o build/rom-100000000.json -D TX_GAS_LIMIT=100000000",
"build:gasLimit:v3": "mkdir -p build && npx zkasm main/main.zkasm -o build/rom-2147483647.json -D TX_GAS_LIMIT=2147483647",
"test:bitwise": "mkdir -p build && npx zkasm test/bitwise.zkasm -o build/rom-bitwise.test.json",
"test:comp": "mkdir -p build && npx zkasm test/comp.zkasm -o build/rom-comp.test.json",
"test:utils": "mkdir -p build && npx zkasm test/utils-getLenBytes.zkasm -o build/rom-utils.test.json",
Expand Down
10 changes: 4 additions & 6 deletions tools/parallel-tests-sample/sample.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
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');

let rom = require('../../build/rom.json');
let stepsN = 2 ** 23;
let counters = false;

const fileCachePil = path.join(__dirname, '../../node_modules/@0xpolygonhermez/zkevm-proverjs/cache-main-pil.json');

Expand All @@ -28,13 +27,11 @@ it(`${nameFile}`, async () => {
const pil = JSON.parse(fs.readFileSync(fileCachePil));
const cmPols = newCommitPolsArray(pil);
if (input.gasLimit) {
if(!fs.existsSync(`../../build/rom-${input.gasLimit}.json`)) {
execSync(`cd ../../ && mkdir -p build && npx zkasm main/main.zkasm -o build/rom-${input.gasLimit}.json`)
}
rom = require(`../../build/rom-${input.gasLimit}.json`)
}
if (inputPath.includes("tests-OOC") && input.stepsN) {
if (input.stepsN) {
stepsN = input.stepsN
counters = true;
}
try {
const config = {
Expand All @@ -43,6 +40,7 @@ it(`${nameFile}`, async () => {
inputName: path.basename(inputPath),
},
stepsN: stepsN,
counters,
};
await smMain.execute(cmPols.Main, input, rom, config);
} catch (err) {
Expand Down

0 comments on commit f747993

Please sign in to comment.