Skip to content

Commit dc970f5

Browse files
committed
Reg fixes
1 parent aba71da commit dc970f5

4 files changed

Lines changed: 18 additions & 11 deletions

File tree

‎main/opcodes/calldata-returndata-code.zkasm‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -385,12 +385,12 @@ opEXTCODECOPY:
385385
$ => D :MLOAD(SP+1); [offset => D]
386386
$ => E :MLOAD(SP); [size => E]
387387

388-
; store lastMemOffset for memory expansion gas cost
389-
C :MSTORE(lastMemOffset)
388+
; store lastMemOffset for memory expansion gas cost, we store also at B to recover later
389+
C => B :MSTORE(lastMemOffset)
390390

391-
; store lastMemLength for memory expansion gas cost
391+
; store lastMemLength for memory expansion gas cost, we store also at RCX to recover later
392392
; compute memory expansion gas cost
393-
E :MSTORE(lastMemLength), CALL(saveMem); in: [lastMemOffset, lastMemLength]
393+
E => RCX :MSTORE(lastMemLength), CALL(saveMem); in: [lastMemOffset, lastMemLength]
394394

395395
; check out-of-gas
396396
;${3*((E+31)/32)}
@@ -401,6 +401,8 @@ opEXTCODECOPY:
401401
; 3*((E+31)/32)
402402
; check out-of-gas
403403
GAS - 3 * E => GAS :JMPN(outOfGas)
404+
RCX => E
405+
B => C
404406
; if offset is above data len, length => offset
405407
D => A
406408
$ => B :MLOAD(tmpContractLength)
@@ -504,8 +506,8 @@ opRETURNDATACOPY:
504506
$ => C :MLOAD(SP); [size => C]
505507
; store lastMemOffset for memory expansion gas cost
506508
D :MSTORE(lastMemOffset)
507-
; store lastMemLength for memory expansion gas cost
508-
C :MSTORE(lastMemLength), CALL(saveMem); in: [lastMemOffset, lastMemLength]
509+
; store lastMemLength for memory expansion gas cost, we store also at RCX to recover later
510+
C => RCX :MSTORE(lastMemLength), CALL(saveMem); in: [lastMemOffset, lastMemLength]
509511
; if retDataCTX is 0, end opcode execution
510512
$ => B :MLOAD(retDataCTX), JMPZ(opRETURNDATACOPYEmpty)
511513
; Load ret data length from last ctx
@@ -527,6 +529,7 @@ opRETURNDATACOPY:
527529
; C is secured to be less than 32 bits after calling saveMem
528530
;(C+31)/32
529531
C + 31 => A :CALL(offsetUtil); in: [A: offset] out: [E: offset/32, C: offset%32]
532+
RCX => C
530533
; 3*((C+31)/32)
531534
; check out-of-gas
532535
GAS - 3 * E => GAS :JMPN(outOfGas)

‎main/opcodes/crypto.zkasm‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ opSHA3:
1717
; check out-of-gas
1818
GAS - %KECCAK_GAS => GAS :JMPN(outOfGas)
1919
SP - 1 => SP
20-
$ => E :MLOAD(SP--); [offset => E]
21-
$ => C :MLOAD(SP) ; [size => C]
20+
$ => E, D :MLOAD(SP--); [offset => E]
21+
$ => C, B :MLOAD(SP) ; [size => C]
2222

2323
; store lastMemOffset for memory expansion gas cost
2424
E :MSTORE(lastMemOffset)
@@ -34,6 +34,9 @@ opSHA3:
3434
; E is less than 32 bits because C is less than 32 bits and E = C/32
3535
; 6*((C+31)/32)
3636
GAS - 6 * E => GAS :JMPN(outOfGas) ; dynamic_gas = 6 * minimum_word_size + memory_expansion_cost
37+
; Recover offset and size at E and C
38+
D => E
39+
B => C
3740
; check keccak counters
3841
C + 1 :MSTORE(arithA)
3942
136 :MSTORE(arithB), CALL(divARITH); in: [arithA, arithB] out: [arithRes1: arithA/arithB, arithRes2: arithA%arithB]

‎main/precompiled/identity.zkasm‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ IDENTITY:
1717
$ :LT, JMPC(moveBalances)
1818

1919
GAS - %IDENTITY_GAS => GAS :JMPN(outOfGas)
20-
$ => C :MLOAD(txCalldataLen)
20+
$ => C, D :MLOAD(txCalldataLen)
2121
;(C+31)/32 => A
2222
C + 31 => A :CALL(offsetUtil); in: [A: offset] out: [E: offset/32, C: offset%32]
23+
D => C
2324
GAS - %IDENTITY_WORD_GAS*E => GAS :JMPN(outOfGas)
2425
0 => E, D :MSTORE(retDataOffset)
2526
C :MSTORE(retDataLength)

‎main/precompiled/pre-sha2-256.zkasm‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ funcSHA256:
2525
; GAS - staticGas
2626
GAS - %SHA2_256_GAS => GAS :JMPN(outOfGas)
2727

28-
$ => C :MLOAD(txCalldataLen)
28+
$ => C, D :MLOAD(txCalldataLen)
2929

3030
;words => A === (C+31)/32 => A
3131
C + 31 => A :CALL(offsetUtil); in: [A: offset] out: [E: offset/32, C: offset%32]
32-
32+
D => C
3333
; GAS - dynamicGas
3434
GAS - %SHA2_256_WORD_GAS*E => GAS :JMPN(outOfGas)
3535

0 commit comments

Comments
 (0)