Skip to content

Commit

Permalink
Merge pull request #111 from 0xPolygonHermez/feature/fix-precompiled-…
Browse files Browse the repository at this point in the history
…ecrecover

fix precompiled ecrecover
  • Loading branch information
krlosMata authored Aug 5, 2022
2 parents b3034f7 + 4be6478 commit dc5623a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
22 changes: 11 additions & 11 deletions main/opcodes.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ opSTOP:
B - 1 :JMPN(handleGas)
$ => A :MLOAD(gasRefund)
$ => C :MLOAD(isCreate)
1 => D
1 => D
C - 1 :JMPN(opSTOPend)
$ => D :MLOAD(createContractAddress)

Expand Down Expand Up @@ -1023,11 +1023,11 @@ opRETURNDATASIZE:
$ => B :MLOAD(retDataCTX)
0 => A
$ :EQ, JMPC(endOpRETURNDATASIZE)
B => CTX
B => CTX
$ => A :MLOAD(retDataLength)
; Restore current context
$ => CTX :MLOAD(currentCTX)

endOpRETURNDATASIZE:
A :MSTORE(SP++)
1024 - SP :JMPN(stackOverflow)
Expand Down Expand Up @@ -1255,7 +1255,7 @@ opCHAINID:
:JMP(readCode)

opSELFBALANCE:

%MAX_CNT_POSEIDON_G - CNT_POSEIDON_G - 255 :JMPN(outOfCounters)

$ => A :MLOAD(storageAddr)
Expand Down Expand Up @@ -1290,7 +1290,7 @@ opMLOAD:
:JMP(readCode)

;MSTORE 32 bytes
opMSTORE:
opMSTORE:

%MAX_CNT_ARITH - CNT_ARITH - 32 :JMPN(outOfCounters)
%MAX_CNT_BINARY - CNT_BINARY - 32 :JMPN(outOfCounters)
Expand Down Expand Up @@ -2532,7 +2532,7 @@ opCALLCODE2:
C :MSTORE(lastMemLength)
; Mem expansion gas cost call args
:CALL(saveMem)

; Store byte offset in the memory in bytes, where to store the return data of the sub context.
$ => B :MLOAD(SP--)
B :MSTORE(lastMemOffset)
Expand Down Expand Up @@ -2780,7 +2780,7 @@ opDELEGATECALL:
SR :MSTORE(initSR)
$ => A :MLOAD(addrCall)
A :MSTORE(txDestAddr)

B :MSTORE(retCallOffset)
D :MSTORE(retCallLength)

Expand Down Expand Up @@ -2889,7 +2889,7 @@ opSTATICCALL:
A :MSTORE(lastMemOffset)

$ => B :MLOAD(SP--)
B :MSTORE(argsLengthCall)
B :MSTORE(argsLengthCall)
B :MSTORE(lastMemLength)

;Check counters
Expand Down Expand Up @@ -3017,7 +3017,7 @@ opREVERTend:
opSELFDESTRUCT:

;Check counters
%MAX_CNT_BINARY - CNT_BINARY - 10 :JMPN(outOfCounters)
%MAX_CNT_BINARY - CNT_BINARY - 10 :JMPN(outOfCounters)
%MAX_CNT_POSEIDON_G - CNT_POSEIDON_G - 2040 :JMPN(outOfCounters)

$ => A :MLOAD(isStaticCall)
Expand Down Expand Up @@ -3084,7 +3084,7 @@ opSELFDESTRUCT2:
$ :EQ,JMPC(handleGas)
$ => B :MLOAD(gasRefund)
$ => C :MLOAD(isCreate)
1 => D
1 => D
C - 1 :JMPN(opSELFDESTRUCTCend)
$ => D :MLOAD(createContractAddress)

Expand All @@ -3107,5 +3107,5 @@ opINVALID:
; Remaining gas is consumed
0 => GAS
; if main context, halt execution
$ => B :MLOAD(originCTX)
$ => B :MLOAD(originCTX)
:JMP(invalidProcess)
8 changes: 4 additions & 4 deletions main/precompiled/pre-ecrecover.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ funcECRECOVER:
; prepare return data
$ => E :MLOAD(retCallOffset)
; $ => C :MLOAD(retCallLength) ; always 32
$ => A :MLOAD(originCTX)
A - 1 :JMPN(handleGas)
$ => CTX :MLOAD(originCTX)
$ => C :MLOAD(originCTX)
C - 1 :JMPN(handleGas)
C => CTX
A :MSTORE(bytesToStore)
:CALL(MSTORE32)
:JMP(preEnd)

endECRECOVER:
$ => A :MLOAD(originCTX)
A - 1 :JMPN(handleGas)
$ => CTX :MLOAD(originCTX)
A => CTX
:JMP(preEnd)
8 changes: 4 additions & 4 deletions main/process-tx.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ readDeployBytecode:
$ => B :MLOAD(isCreate)
0 - B :JMPN(readDeployBytecodeCreate)
$ => B :MLOAD(txCalldataLen)
B - PC - 1 :JMPN(defaultOpCode)
B - PC - 1 :JMPN(defaultOpCode)
$ => HASHPOS :MLOAD(dataStarts)
HASHPOS + PC => HASHPOS
$ => E :MLOAD(batchHashDataId)
Expand All @@ -337,8 +337,8 @@ readDeployBytecode:
readDeployBytecodeCreate:
$ => CTX :MLOAD(originCTX)
$ => E :MLOAD(argsLengthCall)
E - PC - 1 :JMPN(readDeployBytecodeCreateDefault)
E - PC - 1 :JMPN(readDeployBytecodeCreateDefault)

$ => E :MLOAD(argsOffsetCall)
E + PC => E
1 => C
Expand Down Expand Up @@ -517,4 +517,4 @@ invalidTx:

defaultOpCode:
${eventLog(onOpcode(0))}
:JMP(opSTOP)
:JMP(opSTOP)
10 changes: 9 additions & 1 deletion main/utils.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ zeroDiv:
zkPC+1 => RR :JMP(loadTmp)
$ => RR :MLOAD(tmpZkPC)
:JMP(RR)

divisorSmallerDiv:
0 :MSTORE(arithRes1)
E :MSTORE(arithRes2)
Expand Down Expand Up @@ -621,11 +621,19 @@ stackOverflow:
${eventLog(onError, overflow)}
:JMP(handleError)
invalidDeploy:
<<<<<<< HEAD
${eventLog(onError, invalid)}
:JMP(handleError)
invalidStaticTx:
${eventLog(onError, invalid)}
:JMP(handleInvalidStatic)
=======
${eventLog(onError, invalid)}
:JMP(handleError)
invalidStaticTx:
${eventLog(onError, invalid)}
:JMP(handleInvalidStatic)
>>>>>>> review changes
handleError:
;revert all state changes
;initSR --> balance = balance - gas, nonce + 1
Expand Down

0 comments on commit dc5623a

Please sign in to comment.