From 787cc8903b1ac9b811fd554dfebed28d95bd0353 Mon Sep 17 00:00:00 2001 From: Dmitry Vagner Date: Mon, 13 Feb 2023 12:32:40 -0800 Subject: [PATCH] change segment --- .../curve_arithmetic/invariant_exponent.asm | 6 +- .../bn254/curve_arithmetic/tate_pairing.asm | 22 +- .../bn254/field_arithmetic/degree_12_mul.asm | 4 +- .../curve/bn254/field_arithmetic/inverse.asm | 3 +- .../asm/curve/bn254/field_arithmetic/util.asm | 198 ++++++++++-------- evm/src/cpu/kernel/tests/bn254.rs | 4 +- evm/src/memory/segments.rs | 7 +- evm/src/witness/util.rs | 4 +- 8 files changed, 138 insertions(+), 110 deletions(-) diff --git a/evm/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/invariant_exponent.asm b/evm/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/invariant_exponent.asm index b21174e1..c74db1af 100644 --- a/evm/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/invariant_exponent.asm +++ b/evm/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/invariant_exponent.asm @@ -59,9 +59,9 @@ final_exp: // stack: 300, val, retdest %stack () -> (1, 1, 1) // stack: 1, 1, 1, 300, val, retdest - %mstore_kernel_general(200) - %mstore_kernel_general(224) - %mstore_kernel_general(212) + %mstore_kernel_bn254_pairing(200) + %mstore_kernel_bn254_pairing(224) + %mstore_kernel_bn254_pairing(212) // stack: 300, val, retdest {200: y0, 212: y2, 224: y4} %stack () -> (64, 62, 65) // stack: 64, 62, 65, 300, val, retdest {200: y0, 212: y2, 224: y4} diff --git a/evm/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/tate_pairing.asm b/evm/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/tate_pairing.asm index 414e00ad..375f9bc4 100644 --- a/evm/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/tate_pairing.asm +++ b/evm/src/cpu/kernel/asm/curve/bn254/curve_arithmetic/tate_pairing.asm @@ -37,7 +37,7 @@ global bn254_miller: // stack: ptr, out, retdest %stack (ptr, out) -> (out, 1, ptr, out) // stack: out, 1, ptr, out, retdest - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: ptr, out, retdest %load_fp254_6 // stack: P, Q, out, retdest @@ -201,7 +201,7 @@ after_add: // stack: py^2 , 9, px, py, qx, qx_, qy, qy_ SUBFP254 // stack: py^2 - 9, px, py, qx, qx_, qy, qy_ - %mstore_kernel_general(100) + %mstore_kernel_bn254_pairing(100) // stack: px, py, qx, qx_, qy, qy_ DUP1 MULFP254 @@ -217,7 +217,7 @@ after_add: DUP3 MULFP254 // stack: (-3*px^2)qx, py, -3px^2, qx_, qy, qy_ - %mstore_kernel_general(102) + %mstore_kernel_bn254_pairing(102) // stack: py, -3px^2, qx_, qy, qy_ PUSH 2 MULFP254 @@ -227,15 +227,15 @@ after_add: DUP4 MULFP254 // stack: (2py)qy, -3px^2, qx_, 2py, qy_ - %mstore_kernel_general(108) + %mstore_kernel_bn254_pairing(108) // stack: -3px^2, qx_, 2py, qy_ MULFP254 // stack: (-3px^2)*qx_, 2py, qy_ - %mstore_kernel_general(103) + %mstore_kernel_bn254_pairing(103) // stack: 2py, qy_ MULFP254 // stack: (2py)*qy_ - %mstore_kernel_general(109) + %mstore_kernel_bn254_pairing(109) %endmacro /// def cord(p1x, p1y, p2x, p2y, qx, qy): @@ -257,7 +257,7 @@ after_add: // stack: p1y*p2x , p2y*p1x, p1x , p1y, p2x , p2y, qx, qx_, qy, qy_ SUBFP254 // stack: p1y*p2x - p2y*p1x, p1x , p1y, p2x , p2y, qx, qx_, qy, qy_ - %mstore_kernel_general(100) + %mstore_kernel_bn254_pairing(100) // stack: p1x , p1y, p2x , p2y, qx, qx_, qy, qy_ SWAP3 // stack: p2y , p1y, p2x , p1x, qx, qx_, qy, qy_ @@ -272,20 +272,20 @@ after_add: DUP5 MULFP254 // stack: (p1x - p2x)qy, p2y - p1y, qx, qx_, p1x - p2x, qy_ - %mstore_kernel_general(108) + %mstore_kernel_bn254_pairing(108) // stack: p2y - p1y, qx, qx_, p1x - p2x, qy_ SWAP1 // stack: qx, p2y - p1y, qx_, p1x - p2x, qy_ DUP2 MULFP254 // stack: (p2y - p1y)qx, p2y - p1y, qx_, p1x - p2x, qy_ - %mstore_kernel_general(102) + %mstore_kernel_bn254_pairing(102) // stack: p2y - p1y, qx_, p1x - p2x, qy_ MULFP254 // stack: (p2y - p1y)qx_, p1x - p2x, qy_ - %mstore_kernel_general(103) + %mstore_kernel_bn254_pairing(103) // stack: p1x - p2x, qy_ MULFP254 // stack: (p1x - p2x)*qy_ - %mstore_kernel_general(109) + %mstore_kernel_bn254_pairing(109) %endmacro diff --git a/evm/src/cpu/kernel/asm/curve/bn254/field_arithmetic/degree_12_mul.asm b/evm/src/cpu/kernel/asm/curve/bn254/field_arithmetic/degree_12_mul.asm index 3d384380..9b3e67cf 100644 --- a/evm/src/cpu/kernel/asm/curve/bn254/field_arithmetic/degree_12_mul.asm +++ b/evm/src/cpu/kernel/asm/curve/bn254/field_arithmetic/degree_12_mul.asm @@ -209,7 +209,7 @@ global mul_fp254_12_sparse: // stack: f, f', inB, f, inB, f', out, f, inB, f', inA, inB, out DUP13 // stack: inB, f, f', inB, f, inB, f', out, f, inB, f', inA, inB, out - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: g0 , f, f', inB, f, inB, f', out, f, inB, f', inA, inB, out %scale_re_fp254_6 // stack: g0 * f, f', inB, f, inB, f', out, f, inB, f', inA, inB, out @@ -238,7 +238,7 @@ global mul_fp254_12_sparse: // stack: out, G1 * sh(f) + G2 * sh2(f') + g0 * f, inB, f', out, f, inB, f', inA, inB, out %store_fp254_6 // stack: inB, f', out, f, inB, f', inA, inB, out - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: g0 , f', out, f, inB, f', inA, inB, out %scale_re_fp254_6 // stack: g0 * f', out, f, inB, f', inA, inB, out diff --git a/evm/src/cpu/kernel/asm/curve/bn254/field_arithmetic/inverse.asm b/evm/src/cpu/kernel/asm/curve/bn254/field_arithmetic/inverse.asm index 9071f396..72ca051b 100644 --- a/evm/src/cpu/kernel/asm/curve/bn254/field_arithmetic/inverse.asm +++ b/evm/src/cpu/kernel/asm/curve/bn254/field_arithmetic/inverse.asm @@ -11,7 +11,8 @@ // stack: x PROVER_INPUT(ff::bn254_base::inverse) // stack: x^-1 , x - SWAP1 DUP2 + SWAP1 + DUP2 // stack: x^-1 , x, x^-1 MULFP254 // stack: x^-1 * x, x^-1 diff --git a/evm/src/cpu/kernel/asm/curve/bn254/field_arithmetic/util.asm b/evm/src/cpu/kernel/asm/curve/bn254/field_arithmetic/util.asm index e1f043f1..af074714 100644 --- a/evm/src/cpu/kernel/asm/curve/bn254/field_arithmetic/util.asm +++ b/evm/src/cpu/kernel/asm/curve/bn254/field_arithmetic/util.asm @@ -1,10 +1,32 @@ // Load a single value from bn254 pairings memory. -%macro mload_bn254_pairings +%macro mload_kernel_bn254_pairing // stack: offset - %mload_kernel(@SEGMENT_BN254_PAIRINGS) + %mload_kernel(@SEGMENT_KERNEL_BN_PAIRING) // stack: value %endmacro +%macro mload_kernel_bn254_pairing(offset) + // stack: + PUSH $offset + // stack: offset + %mload_kernel(@SEGMENT_KERNEL_BN_PAIRING) + // stack: value +%endmacro + +// Store a single value to bn254 pairings memory. +%macro mstore_kernel_bn254_pairing + // stack: offset, value + %mstore_kernel(@SEGMENT_KERNEL_BN_PAIRING) + // stack: +%endmacro + +%macro mstore_kernel_bn254_pairing(offset) + // stack: value + PUSH $offset + // stack: offset, value + %mstore_kernel(@SEGMENT_KERNEL_BN_PAIRING) + // stack: +%endmacro // fp254_2 macros @@ -13,11 +35,11 @@ DUP1 %add_const(1) // stack: ind1, ptr - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x1, ptr SWAP1 // stack: ind0, x1 - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x0, x1 %endmacro @@ -101,31 +123,31 @@ DUP1 %add_const(4) // stack: ind4, ptr - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x4, ptr DUP2 %add_const(3) // stack: ind3, x4, ptr - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x3, x4, ptr DUP3 %add_const(2) // stack: ind2, x3, x4, ptr - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x2, x3, x4, ptr DUP4 %add_const(1) // stack: ind1, x2, x3, x4, ptr - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x1, x2, x3, x4, ptr DUP5 %add_const(5) // stack: ind5, x1, x2, x3, x4, ptr - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x5, x1, x2, x3, x4, ptr SWAP5 // stack: ind0, x1, x2, x3, x4, x5 - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x0, x1, x2, x3, x4, x5 %endmacro @@ -135,31 +157,31 @@ PUSH $ptr %add_const(5) // stack: ind5 - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x5 PUSH $ptr %add_const(4) // stack: ind4, x5 - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x4, x5 PUSH $ptr %add_const(3) // stack: ind3, x4, x5 - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x3, x4, x5 PUSH $ptr %add_const(2) // stack: ind2, x3, x4, x5 - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x2, x3, x4, x5 PUSH $ptr %add_const(1) // stack: ind1, x2, x3, x4, x5 - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x1, x2, x3, x4, x5 PUSH $ptr // stack: ind0, x1, x2, x3, x4, x5 - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x0, x1, x2, x3, x4, x5 %endmacro @@ -171,30 +193,30 @@ DUP6 %add_const(4) // stack: ind4, x4, x0, x1, x2, x3, ptr, x5 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x0, x1, x2, x3, ptr, x5 DUP5 // stack: ind0, x0, x1, x2, x3, ptr, x5 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x1, x2, x3, ptr, x5 DUP4 %add_const(1) // stack: ind1, x1, x2, x3, ptr, x5 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x2, x3, ptr, x5 DUP3 %add_const(2) // stack: ind2, x2, x3, ptr, x5 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x3, ptr, x5 DUP2 %add_const(3) // stack: ind3, x3, ptr, x5 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: ptr, x5 %add_const(5) // stack: ind5, x5 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: %endmacro @@ -209,14 +231,14 @@ DUP7 %add_const(5) // stack: ind5, 2*x5, x0, x1, x2, x3, x4, ptr - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x0, x1, x2, x3, x4, ptr PUSH 2 MULFP254 // stack: 2*x0, x1, x2, x3, x4, ptr DUP6 // stack: ind0, 2*x0, x1, x2, x3, x4, ptr - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x1, x2, x3, x4, ptr PUSH 2 MULFP254 @@ -224,7 +246,7 @@ DUP5 %add_const(1) // stack: ind1, 2*x1, x2, x3, x4, ptr - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x2, x3, x4, ptr PUSH 2 MULFP254 @@ -232,7 +254,7 @@ DUP4 %add_const(2) // stack: ind2, 2*x2, x3, x4, ptr - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x3, x4, ptr PUSH 2 MULFP254 @@ -240,7 +262,7 @@ DUP3 %add_const(3) // stack: ind3, 2*x3, x4, ptr - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x4, ptr PUSH 2 MULFP254 @@ -249,7 +271,7 @@ // stack: ptr, 2*x4 %add_const(4) // stack: ind4, 2*x4 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: %endmacro @@ -258,32 +280,32 @@ // stack: x0, x1, x2, x3, x4, x5 PUSH $ptr // stack: ind0, x0, x1, x2, x3, x4, x5 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x1, x2, x3, x4, x5 PUSH $ptr %add_const(1) // stack: ind1, x1, x2, x3, x4, x5 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x2, x3, x4, x5 PUSH $ptr %add_const(2) // stack: ind2, x2, x3, x4, x5 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x3, x4, x5 PUSH $ptr %add_const(3) // stack: ind3, x3, x4, x5 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x4, x5 PUSH $ptr %add_const(4) // stack: ind4, x4, x5 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x5 PUSH $ptr %add_const(5) // stack: ind5, x5 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: %endmacro @@ -293,33 +315,33 @@ PUSH $ptr %add_const(2) // stack: ind2, x0, x1, x2, x3, x4, x5 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x1, x2, x3, x4, x5 PUSH $ptr %add_const(3) // stack: ind3, x1, x2, x3, x4, x5 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x2, x3, x4, x5 PUSH $ptr %add_const(4) // stack: ind4, x2, x3, x4, x5 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x3, x4, x5 PUSH $ptr %add_const(5) // stack: ind5, x3, x4, x5 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x4, x5 %i9 // stack: y5, y4 PUSH $ptr %add_const(1) // stack: ind1, y5, y4 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: y4 PUSH $ptr // stack: ind0, y4 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: %endmacro @@ -795,61 +817,61 @@ DUP1 %add_const(10) // stack: ind10, ptr - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x10, ptr DUP2 %add_const(9) // stack: ind09, x10, ptr - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x09, x10, ptr DUP3 %add_const(8) // stack: ind08, x09, x10, ptr - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x08, x09, x10, ptr DUP4 %add_const(7) // stack: ind07, x08, x09, x10, ptr - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x07, x08, x09, x10, ptr DUP5 %add_const(6) // stack: ind06, x07, x08, x09, x10, ptr - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x06, x07, x08, x09, x10, ptr DUP6 %add_const(5) // stack: ind05, x06, x07, x08, x09, x10, ptr - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x05, x06, x07, x08, x09, x10, ptr DUP7 %add_const(4) // stack: ind04, x05, x06, x07, x08, x09, x10, ptr - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x04, x05, x06, x07, x08, x09, x10, ptr DUP8 %add_const(3) // stack: ind03, x04, x05, x06, x07, x08, x09, x10, ptr - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x03, x04, x05, x06, x07, x08, x09, x10, ptr DUP9 %add_const(2) // stack: ind02, x03, x04, x05, x06, x07, x08, x09, x10, ptr - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x02, x03, x04, x05, x06, x07, x08, x09, x10, ptr DUP10 %add_const(1) // stack: ind01, x02, x03, x04, x05, x06, x07, x08, x09, x10, ptr - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x01, x02, x03, x04, x05, x06, x07, x08, x09, x10, ptr DUP11 %add_const(11) // stack: ind11, x01, x02, x03, x04, x05, x06, x07, x08, x09, x10, ptr - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x11, x01, x02, x03, x04, x05, x06, x07, x08, x09, x10, ptr SWAP11 // stack: ind00, x01, x02, x03, x04, x05, x06, x07, x08, x09, x10, x11 - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x00, x01, x02, x03, x04, x05, x06, x07, x08, x09, x10, x11 %endmacro @@ -860,60 +882,60 @@ DUP12 %add_const(10) // stack: ind10, x10, x00, x01, x02, x03, x04, x05, x06, x07, x08, x09, ptr, x11 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x00, x01, x02, x03, x04, x05, x06, x07, x08, x09, ptr, x11 DUP11 // stack: ind00, x00, x01, x02, x03, x04, x05, x06, x07, x08, x09, ptr, x11 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x01, x02, x03, x04, x05, x06, x07, x08, x09, ptr, x11 DUP10 %add_const(01) // stack: ind01, x01, x02, x03, x04, x05, x06, x07, x08, x09, ptr, x11 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x02, x03, x04, x05, x06, x07, x08, x09, ptr, x11 DUP9 %add_const(02) // stack: ind02, x02, x03, x04, x05, x06, x07, x08, x09, ptr, x11 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x03, x04, x05, x06, x07, x08, x09, ptr, x11 DUP8 %add_const(03) // stack: ind03, x03, x04, x05, x06, x07, x08, x09, ptr, x11 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x04, x05, x06, x07, x08, x09, ptr, x11 DUP7 %add_const(04) // stack: ind04, x04, x05, x06, x07, x08, x09, ptr, x11 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x05, x06, x07, x08, x09, ptr, x11 DUP6 %add_const(05) // stack: ind05, x05, x06, x07, x08, x09, ptr, x11 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x06, x07, x08, x09, ptr, x11 DUP5 %add_const(06) // stack: ind06, x06, x07, x08, x09, ptr, x11 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x07, x08, x09, ptr, x11 DUP4 %add_const(07) // stack: ind07, x07, x08, x09, ptr, x11 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x08, x09, ptr, x11 DUP3 %add_const(08) // stack: ind08, x08, x09, ptr, x11 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: x09, ptr, x11 DUP2 %add_const(09) // stack: ind09, x09, ptr, x11 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: ptr, x11 %add_const(11) // stack: ind11, x11 - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: %endmacro @@ -923,120 +945,120 @@ // stack: src, dest DUP1 // stack: ind00, src, dest - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x00, src, dest DUP3 // stack: ind00', x00, src, dest - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: src, dest DUP1 %add_const(1) // stack: ind01, src, dest - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x01, src, dest DUP3 %add_const(1) // stack: ind01', x01, src, dest - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: src, dest DUP1 %add_const(2) // stack: ind02, src, dest - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x02, src, dest DUP3 %add_const(2) // stack: ind02', x02, src, dest - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: src, dest DUP1 %add_const(3) // stack: ind03, src, dest - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x03, src, dest DUP3 %add_const(3) // stack: ind03', x03, src, dest - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: src, dest DUP1 %add_const(4) // stack: ind04, src, dest - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x04, src, dest DUP3 %add_const(4) // stack: ind04', x04, src, dest - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: src, dest DUP1 %add_const(5) // stack: ind05, src, dest - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x05, src, dest DUP3 %add_const(5) // stack: ind05', x05, src, dest - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: src, dest DUP1 %add_const(6) // stack: ind06, src, dest - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x06, src, dest DUP3 %add_const(6) // stack: ind06', x06, src, dest - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: src, dest DUP1 %add_const(7) // stack: ind07, src, dest - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x07, src, dest DUP3 %add_const(7) // stack: ind07', x07, src, dest - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: src, dest DUP1 %add_const(8) // stack: ind08, src, dest - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x08, src, dest DUP3 %add_const(8) // stack: ind08', x08, src, dest - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: src, dest DUP1 %add_const(9) // stack: ind09, src, dest - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x09, src, dest DUP3 %add_const(9) // stack: ind09', x09, src, dest - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: src, dest DUP1 %add_const(10) // stack: ind10, src, dest - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x10, src, dest DUP3 %add_const(10) // stack: ind10', x10, src, dest - %mstore_kernel_general + %mstore_kernel_bn254_pairing // stack: src, dest %add_const(11) // stack: ind11, dest - %mload_kernel_general + %mload_kernel_bn254_pairing // stack: x11, dest DUP2 %add_const(11) // stack: ind11', x11, dest - %mstore_kernel_general + %mstore_kernel_bn254_pairing %endmacro %macro assert_eq_unit_fp254_12 diff --git a/evm/src/cpu/kernel/tests/bn254.rs b/evm/src/cpu/kernel/tests/bn254.rs index 3b6734c3..6e618e9b 100644 --- a/evm/src/cpu/kernel/tests/bn254.rs +++ b/evm/src/cpu/kernel/tests/bn254.rs @@ -28,7 +28,7 @@ impl InterpreterSetup { for (pointer, data) in self.memory { for (i, term) in data.iter().enumerate() { interpreter.generation_state.memory.set( - MemoryAddress::new(0, Segment::KernelGeneral, pointer + i), + MemoryAddress::new(0, Segment::BnPairing, pointer + i), *term, ) } @@ -43,7 +43,7 @@ fn extract_kernel_memory(range: Range, interpreter: Interpreter<'static>) for i in range { let term = interpreter.generation_state.memory.get(MemoryAddress::new( 0, - Segment::KernelGeneral, + Segment::BnPairing, i, )); output.push(term); diff --git a/evm/src/memory/segments.rs b/evm/src/memory/segments.rs index 4ae1afa4..c6ded3dd 100644 --- a/evm/src/memory/segments.rs +++ b/evm/src/memory/segments.rs @@ -43,10 +43,11 @@ pub(crate) enum Segment { BnWnafA = 19, BnWnafB = 20, BnTableQ = 21, + BnPairing = 22, } impl Segment { - pub(crate) const COUNT: usize = 22; + pub(crate) const COUNT: usize = 23; pub(crate) fn all() -> [Self; Self::COUNT] { [ @@ -72,6 +73,7 @@ impl Segment { Self::BnWnafA, Self::BnWnafB, Self::BnTableQ, + Self::BnPairing, ] } @@ -100,6 +102,8 @@ impl Segment { Segment::BnWnafA => "SEGMENT_KERNEL_BN_WNAF_A", Segment::BnWnafB => "SEGMENT_KERNEL_BN_WNAF_B", Segment::BnTableQ => "SEGMENT_KERNEL_BN_TABLE_Q", + Segment::BnPairing => "SEGMENT_KERNEL_BN_PAIRING", + } } @@ -128,6 +132,7 @@ impl Segment { Segment::BnWnafA => 8, Segment::BnWnafB => 8, Segment::BnTableQ => 256, + Segment::BnPairing => 256, } } } diff --git a/evm/src/witness/util.rs b/evm/src/witness/util.rs index fdf554a9..f026abbd 100644 --- a/evm/src/witness/util.rs +++ b/evm/src/witness/util.rs @@ -39,11 +39,11 @@ pub(crate) fn stack_peek(state: &GenerationState, i: usize) -> Opti ))) } -/// Peek at the kernel general item at address `i` +/// Peek at the SEGMENT_KERNEL_BN_PAIRING item at address `i` pub(crate) fn kernel_general_peek(state: &GenerationState, i: usize) -> U256 { state.memory.get(MemoryAddress::new( state.registers.context, - Segment::KernelGeneral, + Segment::BnPairing, i, )) }