Skip to content

Commit

Permalink
Minor errors in counters corrected
Browse files Browse the repository at this point in the history
  • Loading branch information
hecmas committed Oct 16, 2024
1 parent 99ad53a commit 2aa5b61
Show file tree
Hide file tree
Showing 8 changed files with 329 additions and 108 deletions.
6 changes: 3 additions & 3 deletions main/modexp/array_lib/array_add_AGTB.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ VAR GLOBAL array_add_AGTB_RR
/*
* RESOURCES:
* -----------------------------
* (worst case) [steps: 9, bin: 1] + (lenB-1)*[steps: 10, bin: 2] + [steps: 3] + (lenA - lenB)*[steps: 6, bin: 1] + [steps: 6]
* total: [steps: 8 + 6*lenA + 4*lenB, bin: - 2 + lenA + lenB]
* (worst case) [steps: 11, bin: 1] + (lenB-1)*[steps: 10, bin: 2] + [steps: 3] + (lenA-lenB)*[steps: 6, bin: 1] + [steps: 6]
* total: [steps: 10 + 6*lenA + 4*lenB, bin: - 1 + lenA + lenB]
* -----------------------------
*/

array_add_AGTB:
%MAX_CNT_BINARY - CNT_BINARY + 2 - %ARRAY_MAX_LEN_DOUBLED - %ARRAY_MAX_LEN :JMPN(outOfCountersBinary)
%MAX_CNT_BINARY - CNT_BINARY + 1 - %ARRAY_MAX_LEN_DOUBLED - %ARRAY_MAX_LEN :JMPN(outOfCountersBinary)
%MAX_CNT_STEPS - STEP - 8 - 6*%ARRAY_MAX_LEN_DOUBLED - 4*%ARRAY_MAX_LEN :JMPN(outOfCountersStep)

RR :MSTORE(array_add_AGTB_RR)
Expand Down
4 changes: 2 additions & 2 deletions main/modexp/array_lib/array_add_short.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ VAR GLOBAL array_add_short_RR
/*
* RESOURCES:
* -----------------------------
* (worst case) [steps: 8, bin: 1] + (lenA-1)*[steps: 6, bin: 1] + [steps: 6]
* total: [steps: 8 + 6*lenA, bin: lenA]
* (worst case) [steps: 10, bin: 1] + (lenA-1)*[steps: 6, bin: 1] + [steps: 6]
* total: [steps: 10 + 6*lenA, bin: lenA]
* -----------------------------
*/

Expand Down
4 changes: 2 additions & 2 deletions main/modexp/array_lib/array_mul_long.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ VAR GLOBAL array_mul_long_RR
/*
* RESOURCES:
* -----------------------------
* (worst case) [steps: 12, arith: 1] + (lenB-1)*[steps: 7, arith: 1] + [steps: 3] + (lenA-1)*((lenB-1)*[steps: 19, bin: 2, arith: 1] + [steps: 14, bin: 1, arith: 1]) + [steps: 7, bin: 1]
* total: [steps: 20 - 5*lenA - 12*lenB + 19*lenA*lenB, bin: 2 - lenA - 2*lenB + 2*lenA*lenB, arith: lenA*lenB]
* (worst case) [steps: 15, arith: 1] + (lenB-1)*[steps: 7, arith: 1] + [steps: 3] + (lenA-1)*((lenB-1)*[steps: 19, bin: 2, arith: 1] + [steps: 14, bin: 1, arith: 1]) + [steps: 7, bin: 1]
* total: [steps: 23 - 5*lenA - 12*lenB + 19*lenA*lenB, bin: 2 - lenA - 2*lenB + 2*lenA*lenB, arith: lenA*lenB]
* -----------------------------
*/

Expand Down
4 changes: 2 additions & 2 deletions main/modexp/array_lib/array_mul_short.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ VAR GLOBAL array_mul_short_RR
/*
* RESOURCES:
* -----------------------------
* (worst case) [steps: 10, arith: 1] + (lenA-1)*[steps: 7, arith: 1] + [steps: 7, bin: 1]
* total: [steps: 10 + 7*lenA, bin: 1, arith: lenA]
* (worst case) [steps: 13, arith: 1] + (lenA-1)*[steps: 7, arith: 1] + [steps: 7, bin: 1]
* total: [steps: 13 + 7*lenA, bin: 1, arith: lenA]
* -----------------------------
*/

Expand Down
6 changes: 3 additions & 3 deletions main/modexp/array_lib/array_mul_two.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ VAR GLOBAL array_mul_two_RR
/*
* RESOURCES:
* -----------------------------
* (worst case) [steps: 7, bin: 1] + (lenA-1)*[steps: 9, bin: 2] + [steps: 6]
* total: [steps: 4 + 9*lenA, bin: - 1 + lenA]
* (worst case) [steps: 9, bin: 1] + (lenA-1)*[steps: 9, bin: 2] + [steps: 6]
* total: [steps: 6 + 9*lenA, bin: - 1 + 2*lenA]
* -----------------------------
*/

array_mul_two:
%MAX_CNT_BINARY - CNT_BINARY + 1 - %ARRAY_MAX_LEN :JMPN(outOfCountersBinary)
%MAX_CNT_BINARY - CNT_BINARY + 1 - 2*%ARRAY_MAX_LEN :JMPN(outOfCountersBinary)
%MAX_CNT_STEPS - STEP - 4 - 9*%ARRAY_MAX_LEN :JMPN(outOfCountersStep)

RR :MSTORE(array_mul_two_RR)
Expand Down
21 changes: 11 additions & 10 deletions main/modexp/array_lib/array_square.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,20 @@ VAR GLOBAL array_square_RR
/*
* RESOURCES:
* -----------------------------
* (worst case) [steps: 6] + [steps: 9, arith: 1] + (len(in)-1)*[steps: 35, bin: 6, arith: 1] // Init and first row
* + (len(in)-1)*([steps: 7] + [steps: 6, arith: 1] + [steps: 29, bin: 3, arith: 1] + (len(in)-1)*[steps: 51, bin: 9, arith: 1]) // Rest of the rows
* [steps: 8, bin: 1] // Ending
* total: [steps: 32 - 25*len(in) + 51*len(in)²,
* bin: 1 - 9*len(in) + 9*len(in)²,
* arith: -1 + len(in) + len(in)²]
* (worst case) [steps: 9] + [steps: 9, arith: 1] + (len(in)-1)*[steps: 35, bin: 6, arith: 1] + [steps: 7] // Init and first row
* + (len(in)-1)*([steps: 6, arith: 1] + [steps: 7]) // Index check and ai*ai
* + len(in)*(len(in)-1)/2*([steps: 29, bin: 3, arith: 1] + [steps: 51, bin: 9, arith: 1]) // ai*aj
* [steps: 8, bin: 1] // Ending
* total: [steps: -15 + 48*len(in) + 80*len(in)*(len(in)-1)/2,
* bin: -5 + 6*len(in) + 23*len(in)*(len(in)-1)/2,
* arith: -1 + 2*len(in) + 2*len(in)*(len(in)-1)/2]
* -----------------------------
*/

array_square:
%MAX_CNT_ARITH - CNT_ARITH + 1 - %ARRAY_MAX_LEN - %ARRAY_MAX_LEN_SQ :JMPN(outOfCountersArith)
%MAX_CNT_BINARY - CNT_BINARY - 1 + 9*%ARRAY_MAX_LEN - 9*%ARRAY_MAX_LEN_SQ :JMPN(outOfCountersBinary)
%MAX_CNT_STEPS - STEP + 3 + 25*%ARRAY_MAX_LEN - 51*%ARRAY_MAX_LEN_SQ :JMPN(outOfCountersStep)
%MAX_CNT_ARITH - CNT_ARITH + 1 - 2*%ARRAY_MAX_LEN - 2*%ARRAY_MAX_LEN_DIV_TWO :JMPN(outOfCountersArith)
%MAX_CNT_BINARY - CNT_BINARY + 5 - 6*%ARRAY_MAX_LEN - 23*%ARRAY_MAX_LEN_DIV_TWO :JMPN(outOfCountersBinary)
%MAX_CNT_STEPS - STEP + 15 - 48*%ARRAY_MAX_LEN - 80*%ARRAY_MAX_LEN_DIV_TWO :JMPN(outOfCountersStep)

RR :MSTORE(array_square_RR)

Expand All @@ -73,7 +74,7 @@ array_square:

; Begin of branching
array_square_loop_index_check:
; costs [steps: 7, bin: 0, arith: 0]
; costs [steps: 7]

; out[i + len] = carry
$ => A :MLOAD(array_square_carry_chunk_1)
Expand Down
1 change: 1 addition & 0 deletions main/modexp/constants.zkasm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CONST %ARRAY_MAX_LEN_PLUS_ONE = %ARRAY_MAX_LEN + 1
CONST %ARRAY_MAX_LEN_DOUBLED = 2*%ARRAY_MAX_LEN
CONST %ARRAY_MAX_LEN_DOUBLED_MINUS_ONE = %ARRAY_MAX_LEN_DOUBLED - 1
CONST %ARRAY_MAX_LEN_SQ = (%ARRAY_MAX_LEN - 1) * (%ARRAY_MAX_LEN - 1)
CONST %ARRAY_MAX_LEN_DIV_TWO = %ARRAY_MAX_LEN * (%ARRAY_MAX_LEN - 1) / 2
CONST %ARRAY_MAX_LEN_TIMES_DOUBLED = (%ARRAY_MAX_LEN - 1) * (%ARRAY_MAX_LEN_DOUBLED - 1)

CONST %MODEXP_MAX_LEN = %ARRAY_MAX_LEN
Loading

0 comments on commit 2aa5b61

Please sign in to comment.