Skip to content

Commit

Permalink
Merge pull request #413 from 0xPolygonHermez/feature/audit-touched
Browse files Browse the repository at this point in the history
Feature/audit touched
  • Loading branch information
laisolizq authored Nov 7, 2024
2 parents c482434 + 4ce0b96 commit b481ddc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 19 deletions.
10 changes: 5 additions & 5 deletions counters/countersConstants.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ CONST %OPCODECOPY_CNT_PADDING_PG = 0
CONST %OPCODECOPY_CNT_POSEIDON_G = 0
; opEXTCODECOPY - COMPLEX - hardcoded values at test
CONST %OPEXTCODECOPY_STEP = 2000
CONST %OPEXTCODECOPY_CNT_BINARY = 105
CONST %OPEXTCODECOPY_CNT_BINARY = 103
CONST %OPEXTCODECOPY_CNT_ARITH = 4
CONST %OPEXTCODECOPY_CNT_KECCAK_F = 0
CONST %OPEXTCODECOPY_CNT_MEM_ALIGN = 43
Expand All @@ -257,15 +257,15 @@ CONST %OPCREATE2_CNT_PADDING_PG = 0
CONST %OPCREATE2_CNT_POSEIDON_G = 27
; opCALL - COMPLEX - hardcoded values at test
CONST %OPCALL_STEP = 600
CONST %OPCALL_CNT_BINARY = 28
CONST %OPCALL_CNT_BINARY = 26
CONST %OPCALL_CNT_ARITH = 3
CONST %OPCALL_CNT_KECCAK_F = 0
CONST %OPCALL_CNT_MEM_ALIGN = 0
CONST %OPCALL_CNT_PADDING_PG = 0
CONST %OPCALL_CNT_POSEIDON_G = 14
; opCALLCODE - COMPLEX - hardcoded values at test
CONST %OPCALLCODE_STEP = 600
CONST %OPCALLCODE_CNT_BINARY = 27
CONST %OPCALLCODE_CNT_BINARY = 25
CONST %OPCALLCODE_CNT_ARITH = 3
CONST %OPCALLCODE_CNT_KECCAK_F = 0
CONST %OPCALLCODE_CNT_MEM_ALIGN = 0
Expand All @@ -289,15 +289,15 @@ CONST %OPREVERT_CNT_PADDING_PG = 0
CONST %OPREVERT_CNT_POSEIDON_G = 0
; opDELEGATECALL - COMPLEX - hardcoded values at test
CONST %OPDELEGATECALL_STEP = 600
CONST %OPDELEGATECALL_CNT_BINARY = 24
CONST %OPDELEGATECALL_CNT_BINARY = 22
CONST %OPDELEGATECALL_CNT_ARITH = 3
CONST %OPDELEGATECALL_CNT_KECCAK_F = 0
CONST %OPDELEGATECALL_CNT_MEM_ALIGN = 0
CONST %OPDELEGATECALL_CNT_PADDING_PG = 0
CONST %OPDELEGATECALL_CNT_POSEIDON_G = 6
; opSTATICCALL - COMPLEX - hardcoded values at test
CONST %OPSTATICCALL_STEP = 600
CONST %OPSTATICCALL_CNT_BINARY = 24
CONST %OPSTATICCALL_CNT_BINARY = 22
CONST %OPSTATICCALL_CNT_ARITH = 3
CONST %OPSTATICCALL_CNT_KECCAK_F = 0
CONST %OPSTATICCALL_CNT_MEM_ALIGN = 0
Expand Down
5 changes: 2 additions & 3 deletions main/precompiled/selector.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,5 @@ selectorPrecompiled:
A - 8 :JMPN(funcEcMul)
A - 9 :JMPN(funcEcPairing)
A - 10 :JMPN(revertPrecompiled) ;:JMPN(BLAKE2F)

selectorPrecompiledP256Verify:
:JMP(funcP256VERIFY)
A - 256 :JMPZ(funcP256VERIFY)
:JMP(callContract)
4 changes: 1 addition & 3 deletions main/process-tx.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,7 @@ txType:
; Check zero address since zero address is not a precompiled contract
0 => B
$ :EQ, JMPC(callContract)
0x100 => B
$ :EQ, JMPC(selectorPrecompiledP256Verify)
10 => B
0x101 => B
$ :LT, JMPC(selectorPrecompiled, callContract)

;;;;;;;;;;;;;;;;;;
Expand Down
15 changes: 7 additions & 8 deletions main/touched.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,20 @@ revertTouched:
isColdAddress:
; checks zk-counters
%MAX_CNT_STEPS - STEP - 100 :JMPN(outOfCountersStep)
%MAX_CNT_BINARY - CNT_BINARY - 4 :JMPN(outOfCountersBinary)
%MAX_CNT_BINARY - CNT_BINARY - 2 :JMPN(outOfCountersBinary)
%MAX_CNT_POSEIDON_G - CNT_POSEIDON_G - %MAX_CNT_POSEIDON_SLOAD_SSTORE*2 :JMPN(outOfCountersPoseidon)
; store previous registers values temporary
B :MSTORE(tmpB)
C :MSTORE(tmpC)
E :MSTORE(tmpE)

; if address is a zero address check if it is warm
0 => B
$ :EQ, JMPC(checkWarmed)
; if address is a precompiled considered as warm address
10 => B
$ :LT, JMPC(finishColdPrecompiled)
0x100 => B
$ :EQ, JMPC(finishColdPrecompiled)
0x101 => B
$ :LT, JMPNC(checkWarmed)
; if address is a zero address check if it is warm (A <= 256)
A :JMPZ(checkWarmed)
A - 0x100 :JMPZ(finishColdPrecompiled)
A - 10 :JMPN(finishColdPrecompiled)

checkWarmed:
; save current state root & load touched root
Expand Down

0 comments on commit b481ddc

Please sign in to comment.