From 4ce0b96f46e7d25fa1954d68b3ecdaa53da36489 Mon Sep 17 00:00:00 2001 From: Laia Soler Date: Tue, 22 Oct 2024 14:39:51 +0200 Subject: [PATCH] review audit process-tx & touched --- counters/countersConstants.zkasm | 10 +++++----- main/precompiled/selector.zkasm | 5 ++--- main/process-tx.zkasm | 4 +--- main/touched.zkasm | 15 +++++++-------- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/counters/countersConstants.zkasm b/counters/countersConstants.zkasm index 7997a17b..b3829b94 100644 --- a/counters/countersConstants.zkasm +++ b/counters/countersConstants.zkasm @@ -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 @@ -257,7 +257,7 @@ 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 @@ -265,7 +265,7 @@ 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 @@ -289,7 +289,7 @@ 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 @@ -297,7 +297,7 @@ 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 diff --git a/main/precompiled/selector.zkasm b/main/precompiled/selector.zkasm index 9f36292b..0365a0e6 100644 --- a/main/precompiled/selector.zkasm +++ b/main/precompiled/selector.zkasm @@ -77,6 +77,5 @@ selectorPrecompiled: A - 8 :JMPN(funcEcMul) A - 9 :JMPN(funcEcPairing) A - 10 :JMPN(revertPrecompiled) ;:JMPN(BLAKE2F) - -selectorPrecompiledP256Verify: - :JMP(funcP256VERIFY) \ No newline at end of file + A - 256 :JMPZ(funcP256VERIFY) + :JMP(callContract) \ No newline at end of file diff --git a/main/process-tx.zkasm b/main/process-tx.zkasm index 761a7292..08c35fac 100644 --- a/main/process-tx.zkasm +++ b/main/process-tx.zkasm @@ -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) ;;;;;;;;;;;;;;;;;; diff --git a/main/touched.zkasm b/main/touched.zkasm index 14bcbfae..14ad2d0e 100644 --- a/main/touched.zkasm +++ b/main/touched.zkasm @@ -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