diff --git a/main/opcodes.zkasm b/main/opcodes.zkasm index bf5b184b..ce93b890 100644 --- a/main/opcodes.zkasm +++ b/main/opcodes.zkasm @@ -334,14 +334,7 @@ opSHR: SP - 1 => SP $ => D :MLOAD(SP--) $ => A :MLOAD(SP) - A => E - ${exp(2,D)} => B - ${B-1} => B - $ => C :AND - ${exp(2,D)} => B - ${A >> D} => A - 0 => D - E :ARITH + :CALL(SHRarithBit) A :MSTORE(SP++) GAS-3 => GAS :JMP(readCode) @@ -350,30 +343,8 @@ opSHL: SP - 1 => SP $ => D :MLOAD(SP--) $ => A :MLOAD(SP) - ${A << D} => E - 256 - D => D :JMPC(SHL0) - ${exp(2,D)} => B - ${B-1} => B - $ => C :GT - 256 - D => D - ${exp(2,D)} => B - 0 - C :JMPC(SHLbig) - 0 => D,C - E :ARITH - :JMP(SHLfinal) -SHL0: - 0 :MSTORE(SP++) - GAS-3 => GAS - :JMP(readCode) -SHLbig: - 256 - D => D - ${exp(2,D)} => D - ${A/D} => D - 0 => C - E :ARITH - -SHLfinal: - E :MSTORE(SP++) + :CALL(SHLarithBit) + A :MSTORE(SP++) GAS-3 => GAS :JMP(readCode) diff --git a/main/utils.zkasm b/main/utils.zkasm index 26d01dd7..7d6236b5 100644 --- a/main/utils.zkasm +++ b/main/utils.zkasm @@ -515,28 +515,52 @@ storeTmp: :JMP(RR) ;@in A - (A >> D) -;@in D - (A >> D) +;@in D - (A >> D) D bytes ;@out A - A >> D => A SHRarith: B :MSTORE(tmpVarB2) C :MSTORE(tmpVarC2) D :MSTORE(tmpVarD2) E :MSTORE(tmpVarE2) + A => E + D => A + 8 => B + 0 => C + 0 => D + ${A*B} => D :ARITH + E => A + :JMP(SHRarithinit) + +;@in A - (A >> D) +;@in D - (A >> D) D bits +;@out A - A >> D => A +SHRarithBit: + B :MSTORE(tmpVarB2) + C :MSTORE(tmpVarC2) + D :MSTORE(tmpVarD2) + E :MSTORE(tmpVarE2) + +SHRarithinit: 0 => B $ => B :EQ 0 - B :JMPC(SHRarithfinal) A => E - ${exp(2,D*8)} => B + D => A + 255 => B + $ => B :GT + 0 - B :JMPC(SHRarith0) + E => A + ${exp(2,D)} => B ${B-1} => B $ => C :AND - ${exp(2,D*8)} => B - 0 => A - $ => B :EQ - 0 - B :JMPC(SHRarithfinal) - ${exp(2,D*8)} => B + ${exp(2,D)} => B ${E/B} => A 0 => D E :ARITH + :JMP(SHRarithfinal) + +SHRarith0: + 0 => A SHRarithfinal: $ => B :MLOAD(tmpVarB2) @@ -546,27 +570,45 @@ SHRarithfinal: :JMP(RR) ;@in A - (A << D) -;@in D - (A << D) +;@in D - (A << D) D bytes ;@out A - A << D => A SHLarith: B :MSTORE(tmpVarB2) C :MSTORE(tmpVarC2) D :MSTORE(tmpVarD2) E :MSTORE(tmpVarE2) + A => E + D => A + 8 => B + 0 => C + 0 => D + ${A*B} => D :ARITH + E => A + :JMP(SHLarithinit) +;@in A - (A << D) +;@in D - (A << D) D bits +;@out A - A << D => A +SHLarithBit: + B :MSTORE(tmpVarB2) + C :MSTORE(tmpVarC2) + D :MSTORE(tmpVarD2) + E :MSTORE(tmpVarE2) + +SHLarithinit: A => E 0 => A D => B $ => B :EQ 0 - B :JMPC(SHLarithfinal) E => A - ${exp(2,D*8)} => B + ${exp(2,D)} => B ${A*B} => E - 32 - D => D :JMPC(SHLarith0) - ${exp(2,D*8)} => B + 256 - D => D :JMPC(SHLarith0) + ${exp(2,D)} => B ${B-1} => B $ => C :GT - 32 - D => D - ${exp(2,D*8)} => B + 256 - D => D + ${exp(2,D)} => B 0 - C :JMPC(SHLarithBig) 0 => D,C E :ARITH @@ -577,8 +619,8 @@ SHLarith0: :JMP(SHLarithfinal) SHLarithBig: - 32 - D => D - ${exp(2,D*8)} => D + 256 - D => D + ${exp(2,D)} => D ${A/D} => D 0 => C E :ARITH