From 6e69f7d49115f6a41570a9f49d308279507e6f55 Mon Sep 17 00:00:00 2001 From: Antoine Cyr Date: Wed, 20 Nov 2024 22:06:58 -0500 Subject: [PATCH] zkevm shifts operation bbf --- .../blueprint/zkevm_bbf/opcodes/addmod.hpp | 246 +++++++----------- .../blueprint/zkevm_bbf/opcodes/mulmod.hpp | 54 ++-- .../nil/blueprint/zkevm_bbf/opcodes/sar.hpp | 17 +- .../nil/blueprint/zkevm_bbf/opcodes/shl.hpp | 26 +- .../nil/blueprint/zkevm_bbf/opcodes/shr.hpp | 13 +- crypto3/libs/blueprint/test/CMakeLists.txt | 1 - .../test/zkevm_bbf/opcodes/byte_ops.cpp | 154 ++++++----- .../test/zkevm_bbf/opcodes/mod_ops.cpp | 8 +- 8 files changed, 201 insertions(+), 318 deletions(-) diff --git a/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/addmod.hpp b/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/addmod.hpp index 1b1723b517..54cd58d9f3 100644 --- a/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/addmod.hpp +++ b/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/addmod.hpp @@ -147,9 +147,6 @@ namespace nil { TYPE first_carryless; TYPE second_row_carries; TYPE third_row_carries; - TYPE two_192_cell; - TYPE two_128_cell; - TYPE two_64_cell; std::vector N_64_chunks(4); std::vector r_64_chunks(4); std::vector s_64_chunks(4); @@ -204,10 +201,7 @@ namespace nil { // caluclate first row carries first_carryless = first_carryless_construct(s_64_chunks, N_64_chunks, r_64_chunks, q_64_chunks); - auto first_row_carries = first_carryless_construct(s_64_chunks, N_64_chunks, - r_64_chunks, q_64_chunks) - .data >> - 128; + auto first_row_carries = first_carryless.data >> 128; value_type c_1 = static_cast(first_row_carries & (two_64 - 1).data); c_2 = static_cast(first_row_carries >> 64); @@ -224,7 +218,6 @@ namespace nil { value_type N_sum = std::accumulate(N_chunks.begin(), N_chunks.end(), value_type(0)); N_sum_inverse = N_sum == 0 ? 0 : N_sum.inversed(); - N_nonzero = N_sum_inverse * N_sum; // value_type c_1_64 = chunk_sum_64(c_1_chunks, 0); @@ -233,30 +226,25 @@ namespace nil { carry[0][0] = 0; carry[1][0] = 0; - two_192_cell = two_192; - two_128_cell = two_128; - two_64_cell = two_64; + N_nonzero = N_sum_inverse * N_sum; } - // TODO: replace with memory access, which would also do range checks! - // also we can pack slightly more effectively - for (std::size_t i = 0; i < carry_amount - 1; i++) { - allocate(a_chunks[3 * i], 0, i); - allocate(b_chunks[3 * i], 1, i); - allocate(s_chunks[3 * i], 2, i); + allocate(N_nonzero, 32, 3); - allocate(a_chunks[3 * i + 1], 3, i); - allocate(b_chunks[3 * i + 1], 4, i); - allocate(s_chunks[3 * i + 1], 5, i); - - allocate(a_chunks[3 * i + 2], 6, i); - allocate(b_chunks[3 * i + 2], 7, i); - allocate(s_chunks[3 * i + 2], 8, i); + for (std::size_t i = 0; i < chunk_amount; i++) { + allocate(a_chunks[i], i, 0); + allocate(b_chunks[i], i + chunk_amount, 0); + allocate(s_chunks[i], i, 1); + allocate(N_chunks[i], chunk_amount + i, 1); + allocate(q_chunks[i], i, 2); + allocate(v_chunks[i], chunk_amount + i, 2); + allocate(q_out_chunks[i], i, 3); + constrain((N_nonzero * (q_chunks[i] - q_out_chunks[i]) + + (1 - N_nonzero) * q_out_chunks[i])); + res[i] = q_out_chunks[i]; } - allocate(a_chunks[chunk_amount - 1], 26, 3); - allocate(b_chunks[chunk_amount - 1], 27, 3); - allocate(s_chunks[chunk_amount - 1], 28, 3); + allocate(carry[0][0], 32, 0); for (std::size_t i = 0; i < carry_amount - 1; i++) { if constexpr (stage == GenerationStage::ASSIGNMENT) { carry[0][i + 1] = @@ -264,8 +252,7 @@ namespace nil { (a_chunks[3 * i + 1] + b_chunks[3 * i + 1]) * two_16 + (a_chunks[3 * i + 2] + b_chunks[3 * i + 2]) * two_32) >= two_48; } - allocate(carry[0][i], 9, i); - allocate(carry[0][i + 1], 10, i); + allocate(carry[0][i + 1], 33 + i, 0); constrain(carry_on_addition_constraint( a_chunks[3 * i], a_chunks[3 * i + 1], a_chunks[3 * i + 2], b_chunks[3 * i], b_chunks[3 * i + 1], b_chunks[3 * i + 2], @@ -279,32 +266,16 @@ namespace nil { (carry[0][carry_amount - 1] + a_chunks[3 * (carry_amount - 1)] + b_chunks[3 * (carry_amount - 1)]) >= two_16; } - allocate(carry[0][carry_amount - 1], 29, 3); - allocate(carry[0][carry_amount], 30, 3); + allocate(carry[0][carry_amount], 38, 0); constrain(last_carry_on_addition_constraint( a_chunks[3 * (carry_amount - 1)], b_chunks[3 * (carry_amount - 1)], s_chunks[3 * (carry_amount - 1)], carry[0][carry_amount - 1], carry[0][carry_amount])); - constrain(carry[0][carry_amount] * (1 - carry[0][carry_amount])); - - for (std::size_t i = 0; i < carry_amount - 1; i++) { - allocate(N_chunks[3 * i], 11, i); - allocate(q_chunks[3 * i], 12, i); - allocate(v_chunks[3 * i], 13, i); - - allocate(N_chunks[3 * i + 1], 14, i); - allocate(q_chunks[3 * i + 1], 15, i); - allocate(v_chunks[3 * i + 1], 16, i); - allocate(N_chunks[3 * i + 2], 17, i); - allocate(q_chunks[3 * i + 2], 18, i); - allocate(v_chunks[3 * i + 2], 19, i); - } - allocate(N_chunks[chunk_amount - 1], 26, 4); - allocate(q_chunks[chunk_amount - 1], 27, 4); - allocate(v_chunks[chunk_amount - 1], 28, 4); + constrain(carry[0][carry_amount] * (1 - carry[0][carry_amount])); + allocate(carry[1][0], 32, 2); for (std::size_t i = 0; i < carry_amount - 1; i++) { if constexpr (stage == GenerationStage::ASSIGNMENT) { carry[1][i + 1] = @@ -312,8 +283,7 @@ namespace nil { (N_chunks[3 * i + 1] + v_chunks[3 * i + 1]) * two_16 + (N_chunks[3 * i + 2] + v_chunks[3 * i + 2]) * two_32) >= two_48; } - allocate(carry[1][i], 20, i); - allocate(carry[1][i + 1], 21, i); + allocate(carry[1][i + 1], 33 + i, 2); constrain(carry_on_addition_constraint( N_chunks[3 * i], N_chunks[3 * i + 1], N_chunks[3 * i + 2], v_chunks[3 * i], v_chunks[3 * i + 1], v_chunks[3 * i + 2], @@ -327,54 +297,36 @@ namespace nil { (carry[1][carry_amount - 1] + N_chunks[3 * (carry_amount - 1)] + v_chunks[3 * (carry_amount - 1)]) >= two_16; } - allocate(carry[1][carry_amount - 1], 29, 4); - allocate(carry[1][carry_amount], 30, 4); + allocate(carry[1][carry_amount], 38, 2); constrain(last_carry_on_addition_constraint( N_chunks[3 * (carry_amount - 1)], v_chunks[3 * (carry_amount - 1)], q_chunks[3 * (carry_amount - 1)], carry[1][carry_amount - 1], carry[1][carry_amount])); - // // carry[1][carry_amount] is 0 or 1, but should be 1 if N_nonzero = 1 - + // carry[1][carry_amount] is 0 or 1, but should be 1 if N_nonzero = 1 constrain((N_nonzero + (1 - N_nonzero) * carry[1][carry_amount]) * (1 - carry[1][carry_amount])); - for (std::size_t i = 0; i < carry_amount - 1; i++) { - allocate(q_out_chunks[3 * i], 22, i); - allocate(q_out_chunks[3 * i + 1], 23, i); - allocate(q_out_chunks[3 * i + 2], 24, i); - } - allocate(q_out_chunks[chunk_amount - 1], 31, 4); - - for (std::size_t i = 0; i < chunk_amount; i++) { - if (i % 3 == 0) { - allocate(N_nonzero, 25, i / 3); - } - constrain((N_nonzero * (q_chunks[i] - q_out_chunks[i]) + - (1 - N_nonzero) * q_out_chunks[i])); - res[i] = q_out_chunks[i]; - } - - allocate(first_carryless, 32, 0); - allocate(c_1_64, 33, 0); - allocate(c_2, 34, 0); - constrain((first_carryless - c_1_64 * two_128 - c_2 * two_192)); - - allocate(second_row_carries, 32, 1); - allocate(c_3, 33, 1); - constrain((second_row_carries + c_1_64 + c_2 * two_64 - c_3 * two_128)); - - allocate(N_64_chunks[0], 31, 2); - allocate(third_row_carries, 32, 2); - allocate(r_overflow, 33, 2); - allocate(s_overflow, 34, 2); - allocate(N_sum, 35, 2); - allocate(N_sum_inverse, 36, 2); - constrain((third_row_carries + r_overflow * N_64_chunks[0] + c_3 - - s_overflow * N_sum * N_sum_inverse)); - - allocate(N_64_chunks[3], 30, 1); - allocate(r_64_chunks[3], 31, 1); + allocate(first_carryless, 32, 1); + allocate(c_1_64, 33, 1); + allocate(c_2, 34, 1); + constrain(first_carryless - c_1_64 * two_128 - c_2 * two_192); + + allocate(second_row_carries, 35, 1); + allocate(c_3, 36, 1); + constrain(second_row_carries + c_1_64 + c_2 * two_64 - c_3 * two_128); + + allocate(N_64_chunks[0], 16, 3); + allocate(third_row_carries, 33, 3); + allocate(r_overflow, 34, 3); + allocate(s_overflow, 35, 3); + allocate(N_sum, 36, 3); + allocate(N_sum_inverse, 37, 3); + constrain(third_row_carries + r_overflow * N_64_chunks[0] + c_3 - + s_overflow * N_sum * N_sum_inverse); + + allocate(N_64_chunks[3], 17, 3); + allocate(r_64_chunks[3], 18, 3); constrain(N_64_chunks[3] * r_64_chunks[3]); constrain(c_2 * (c_2 - 1)); @@ -384,92 +336,82 @@ namespace nil { auto A_128 = chunks16_to_chunks128_reversed(a_chunks); auto B_128 = chunks16_to_chunks128_reversed(b_chunks); auto N_128 = chunks16_to_chunks128_reversed(N_chunks); - auto Res_128 = chunks16_to_chunks128_reversed(res); + auto Res_128 = chunks16_to_chunks128_reversed(q_out_chunks); TYPE A0, A1, B0, B1, N0, N1, Res0, Res1; - if constexpr (stage == GenerationStage::ASSIGNMENT) { - A0 = A_128.first; - A1 = A_128.second; - B0 = B_128.first; - B1 = B_128.second; - N0 = N_128.first; - N1 = N_128.second; - Res0 = Res_128.first; - Res1 = Res_128.second; - } - allocate(A0, 34, 3); - allocate(A1, 34, 1); - allocate(B0, 35, 3); - allocate(B1, 35, 1); - allocate(N0, 36, 3); - allocate(N1, 36, 1); - allocate(Res0, 37, 3); - allocate(Res1, 37, 1); - - constrain(A0 - A_128.first); - constrain(A1 - A_128.second); - constrain(B0 - B_128.first); - constrain(B1 - B_128.second); - constrain(N0 - N_128.first); - constrain(N1 - N_128.second); - constrain(Res0 - Res_128.first); - constrain(Res1 - Res_128.second); + A0 = A_128.first; + A1 = A_128.second; + B0 = B_128.first; + B1 = B_128.second; + N0 = N_128.first; + N1 = N_128.second; + Res0 = Res_128.first; + Res1 = Res_128.second; + allocate(A0, 39, 0); + allocate(A1, 39, 1); + allocate(B0, 40, 0); + allocate(B1, 40, 1); + allocate(N0, 41, 0); + allocate(N1, 41, 1); + allocate(Res0, 38, 3); + allocate(Res1, 39, 3); + if constexpr (stage == GenerationStage::CONSTRAINTS) { - constrain(current_state.pc_next() - current_state.pc(4) - + constrain(current_state.pc_next() - current_state.pc(3) - 1); // PC transition - constrain(current_state.gas(4) - current_state.gas_next() - + constrain(current_state.gas(3) - current_state.gas_next() - 8); // GAS transition - constrain(current_state.stack_size(4) - current_state.stack_size_next() - + constrain(current_state.stack_size(3) - current_state.stack_size_next() - 2); // stack_size transition - constrain(current_state.memory_size(4) - + constrain(current_state.memory_size(3) - current_state.memory_size_next()); // memory_size transition - constrain(current_state.rw_counter_next() - current_state.rw_counter(4) - + constrain(current_state.rw_counter_next() - current_state.rw_counter(3) - 4); // rw_counter transition std::vector tmp; tmp = {TYPE(rw_op_to_num(rw_operation_type::stack)), - current_state.call_id(2), - current_state.stack_size(2) - 1, + current_state.call_id(1), + current_state.stack_size(1) - 1, TYPE(0), // storage_key_hi TYPE(0), // storage_key_lo TYPE(0), // field - current_state.rw_counter(2), + current_state.rw_counter(1), TYPE(0), // is_write A0, A1}; lookup(tmp, "zkevm_rw"); tmp = {TYPE(rw_op_to_num(rw_operation_type::stack)), - current_state.call_id(2), - current_state.stack_size(2) - 2, + current_state.call_id(0), + current_state.stack_size(0) - 2, TYPE(0), // storage_key_hi TYPE(0), // storage_key_lo TYPE(0), // field - current_state.rw_counter(2) + 1, + current_state.rw_counter(0) + 1, TYPE(0), // is_write B0, B1}; lookup(tmp, "zkevm_rw"); - // tmp = {TYPE(rw_op_to_num(rw_operation_type::stack)), - // current_state.call_id(2), - // current_state.stack_size(2) - 3, - // TYPE(0), // storage_key_hi - // TYPE(0), // storage_key_lo - // TYPE(0), // field - // current_state.rw_counter(2) + 2, - // TYPE(0), // is_write - // N0, - // N1}; - // lookup(tmp, "zkevm_rw"); - // tmp = {TYPE(rw_op_to_num(rw_operation_type::stack)), - // current_state.call_id(2), - // current_state.stack_size(2) - 3, - // TYPE(0), // storage_key_hi - // TYPE(0), // storage_key_lo - // TYPE(0), // field - // current_state.rw_counter(2) + 3, - // TYPE(1), // is_write - // Res0, - // Res1}; - // lookup(tmp, "zkevm_rw"); + tmp = {TYPE(rw_op_to_num(rw_operation_type::stack)), + current_state.call_id(0), + current_state.stack_size(0) - 3, + TYPE(0), // storage_key_hi + TYPE(0), // storage_key_lo + TYPE(0), // field + current_state.rw_counter(0) + 2, + TYPE(0), // is_write + N0, + N1}; + lookup(tmp, "zkevm_rw"); + tmp = {TYPE(rw_op_to_num(rw_operation_type::stack)), + current_state.call_id(0), + current_state.stack_size(0) - 3, + TYPE(0), // storage_key_hi + TYPE(0), // storage_key_lo + TYPE(0), // field + current_state.rw_counter(0) + 3, + TYPE(1), // is_write + Res0, + Res1}; + lookup(tmp, "zkevm_rw"); } } }; @@ -493,7 +435,7 @@ namespace nil { zkevm_addmod_bbf bbf_obj( context, current_state); } - virtual std::size_t rows_amount() override { return 5; } + virtual std::size_t rows_amount() override { return 4; } }; } // namespace bbf } // namespace blueprint diff --git a/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/mulmod.hpp b/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/mulmod.hpp index 285e5be3ab..a5d21847ca 100644 --- a/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/mulmod.hpp +++ b/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/mulmod.hpp @@ -138,7 +138,8 @@ namespace nil { public: zkevm_mulmod_bbf(context_type &context_object, const opcode_input_type ¤t_state) - : generic_component(context_object,false), res(chunk_amount) { + : generic_component(context_object, false), + res(chunk_amount) { using integral_type = boost::multiprecision::number< boost::multiprecision::backends::cpp_int_modular_backend<257>>; using extended_integral_type = boost::multiprecision::number< @@ -187,7 +188,6 @@ namespace nil { TYPE Nrpp_add; TYPE c_zero; - TYPE c_one; std::vector a_64_chunks(8); std::vector b_64_chunks(4); @@ -321,10 +321,7 @@ namespace nil { // caluclate first row carries first_carryless = first_carryless_construct(Nr_64_chunks, N_64_chunks, r_64_chunks); - auto first_row_carries = - first_carryless_construct(Nr_64_chunks, N_64_chunks, r_64_chunks) - .data >> - 128; + auto first_row_carries = first_carryless.data >> 128; value_type c_1 = static_cast(first_row_carries & (two_64 - 1).data); c_2 = static_cast(first_row_carries >> 64); @@ -332,22 +329,14 @@ namespace nil { // no need for c_2 chunks as there is only a single chunk second_carryless = second_carryless_construct( Nr_64_chunks, N_64_chunks, r_64_chunks); - auto second_row_carries = - (second_carryless_construct(Nr_64_chunks, N_64_chunks, r_64_chunks) + - c_1 + c_2 * two_64) - .data >> - 128; + auto second_row_carries = second_carryless.data >> 128; value_type c_3 = static_cast(second_row_carries & (two_64 - 1).data); c_4 = static_cast(second_row_carries >> 64); c_3_chunks = chunk_64_to_16(c_3); third_carryless = third_carryless_construct(Nr_64_chunks, N_64_chunks, r_64_chunks); - auto third_row_carries = - (third_carryless_construct(Nr_64_chunks, N_64_chunks, r_64_chunks) + - c_3 + c_4 * two_64) - .data >> - 128; + auto third_row_carries = third_carryless.data >> 128; value_type c_5 = static_cast(third_row_carries & (two_64 - 1).data); c_6 = static_cast(third_carryless.data >> 64); @@ -370,10 +359,10 @@ namespace nil { c_1_64 = chunk_sum_64(c_1_chunks, 0); c_3_64 = chunk_sum_64(c_3_chunks, 0); c_5_64 = chunk_sum_64(c_5_chunks, 0); - } - c_one = c_zero + 1; - N_nonzero = N_sum * N_sum_inverse; + N_nonzero = N_sum * N_sum_inverse; N_nonzero_2 = N_nonzero; + } + allocate(N_nonzero, 32, 5); for (std::size_t i = 0; i < chunk_amount; i++) { @@ -554,16 +543,14 @@ namespace nil { auto Res_128 = chunks16_to_chunks128_reversed(res); TYPE A0, A1, B0, B1, N0, N1, Res0, Res1; - if constexpr (stage == GenerationStage::ASSIGNMENT) { - A0 = A_128.first; - A1 = A_128.second; - B0 = B_128.first; - B1 = B_128.second; - N0 = N_128.first; - N1 = N_128.second; - Res0 = Res_128.first; - Res1 = Res_128.second; - } + A0 = A_128.first; + A1 = A_128.second; + B0 = B_128.first; + B1 = B_128.second; + N0 = N_128.first; + N1 = N_128.second; + Res0 = Res_128.first; + Res1 = Res_128.second; allocate(A0, 33, 4); allocate(A1, 33, 5); allocate(B0, 34, 5); @@ -572,15 +559,6 @@ namespace nil { allocate(N1, 42, 1); allocate(Res0, 34, 2); allocate(Res1, 34, 3); - - constrain(A0 - A_128.first); - constrain(A1 - A_128.second); - constrain(B0 - B_128.first); - constrain(B1 - B_128.second); - constrain(N0 - N_128.first); - constrain(N1 - N_128.second); - constrain(Res0 - Res_128.first); - constrain(Res1 - Res_128.second); if constexpr (stage == GenerationStage::CONSTRAINTS) { constrain(current_state.pc_next() - current_state.pc(6) - 1); // PC transition diff --git a/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/sar.hpp b/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/sar.hpp index 6530c6db61..2e0c2a07e3 100644 --- a/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/sar.hpp +++ b/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/sar.hpp @@ -251,7 +251,6 @@ namespace nil { sum_part_b * I2); // z is zero if input_b >= 256, otherwise it is 1 two_powers = (static_cast(1) << int(integral_type(input_b) % 16)); - tp = z * two_powers; b_sum_inverse = b_sum.is_zero() ? 0 : b_sum.inversed(); b_zero = 1 - b_sum_inverse * b_sum; @@ -353,14 +352,13 @@ namespace nil { constrain(b_zero * r_chunks[i]); } + tp = z * two_powers; allocate(tp, 35, 3); allocate(z, 36, 3); allocate(I1, 37, 3); allocate(I2, 38, 3); allocate(two_powers, 39, 3); - constrain(tp - z * two_powers); - allocate(b0p, 32, 3); allocate(b0pp, 33, 3); allocate(b0ppp, 34, 3); @@ -484,28 +482,19 @@ namespace nil { TYPE A0, A1, B0, B1, Res0, Res1; - if constexpr (stage == GenerationStage::ASSIGNMENT) { A0 = A_128.first; A1 = A_128.second; B0 = B_128.first; B1 = B_128.second; Res0 = Res_128.first; Res1 = Res_128.second; - } allocate(A0, 39, 0); - allocate(A1, 39, 2); - allocate(B0, 40, 0); + allocate(A1, 40, 0); + allocate(B0, 39, 2); allocate(B1, 40, 2); allocate(Res0, 41, 0); allocate(Res1, 41, 2); - constrain(A0 - A_128.first); - constrain(A1 - A_128.second); - constrain(B0 - B_128.first); - constrain(B1 - B_128.second); - constrain(Res0 - Res_128.first); - constrain(Res1 - Res_128.second); - if constexpr (stage == GenerationStage::CONSTRAINTS) { constrain(current_state.pc_next() - current_state.pc(4) - 1); // PC transition diff --git a/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/shl.hpp b/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/shl.hpp index 6e1f2e28c6..156cf34d34 100644 --- a/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/shl.hpp +++ b/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/shl.hpp @@ -165,7 +165,6 @@ namespace nil { (1 - sum_b * I2); // z is zero if input_b >= 256, otherwise it is 1 two_powers = (static_cast(1) << int(integral_type(input_b) % 16)); - tp = z * two_powers; // note that we don't assign 64-chunks for a/b, as we can build them from // 16-chunks with constraints under the same logic we only assign the 16 - @@ -224,14 +223,14 @@ namespace nil { res[i] = r_chunks[i]; } + tp = z * two_powers; + allocate(tp, 32, 0); allocate(z, 33, 0); allocate(I1, 34, 0); allocate(I2, 35, 0); allocate(two_powers, 36, 0); - constrain(tp - z * two_powers); - allocate(b0p, 32, 1); allocate(b0pp, 33, 1); allocate(b0ppp, 34, 1); @@ -262,14 +261,12 @@ namespace nil { auto Res_128 = chunks16_to_chunks128_reversed(res); TYPE A0, A1, B0, B1, Res0, Res1; - if constexpr (stage == GenerationStage::ASSIGNMENT) { - A0 = A_128.first; - A1 = A_128.second; - B0 = B_128.first; - B1 = B_128.second; - Res0 = Res_128.first; - Res1 = Res_128.second; - } + A0 = A_128.first; + A1 = A_128.second; + B0 = B_128.first; + B1 = B_128.second; + Res0 = Res_128.first; + Res1 = Res_128.second; allocate(A0, 37, 0); allocate(A1, 37, 1); allocate(B0, 38, 0); @@ -277,13 +274,6 @@ namespace nil { allocate(Res0, 39, 0); allocate(Res1, 39, 1); - constrain(A0 - A_128.first); - constrain(A1 - A_128.second); - constrain(B0 - B_128.first); - constrain(B1 - B_128.second); - constrain(Res0 - Res_128.first); - constrain(Res1 - Res_128.second); - if constexpr (stage == GenerationStage::CONSTRAINTS) { constrain(current_state.pc_next() - current_state.pc(2) - 1); // PC transition diff --git a/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/shr.hpp b/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/shr.hpp index 50e6e04e25..d3c64df247 100644 --- a/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/shr.hpp +++ b/crypto3/libs/blueprint/include/nil/blueprint/zkevm_bbf/opcodes/shr.hpp @@ -220,7 +220,6 @@ namespace nil { sum_part_b * I2); // z is zero if input_b >= 256, otherwise it is 1 two_powers = (static_cast(1) << int(integral_type(input_b) % 16)); - tp = z * two_powers; b_sum_inverse = b_sum.is_zero() ? 0 : b_sum.inversed(); b_zero = 1 - b_sum_inverse * b_sum; @@ -288,14 +287,13 @@ namespace nil { constrain(b_zero * r_chunks[i]); } + tp = z * two_powers; allocate(tp, 32, 1); allocate(z, 33, 1); allocate(I1, 34, 1); allocate(I2, 35, 1); allocate(two_powers, 36, 1); - constrain(tp - z * two_powers); - allocate(b0p, 32, 0); allocate(b0pp, 33, 0); allocate(b0ppp, 34, 0); @@ -349,14 +347,12 @@ namespace nil { auto Res_128 = chunks16_to_chunks128_reversed(res); TYPE A0, A1, B0, B1, Res0, Res1; - if constexpr (stage == GenerationStage::ASSIGNMENT) { A0 = A_128.first; A1 = A_128.second; B0 = B_128.first; B1 = B_128.second; Res0 = Res_128.first; Res1 = Res_128.second; - } allocate(A0, 38, 0); allocate(A1, 38, 1); allocate(B0, 39, 0); @@ -364,13 +360,6 @@ namespace nil { allocate(Res0, 40, 0); allocate(Res1, 40, 1); - constrain(A0 - A_128.first); - constrain(A1 - A_128.second); - constrain(B0 - B_128.first); - constrain(B1 - B_128.second); - constrain(Res0 - Res_128.first); - constrain(Res1 - Res_128.second); - if constexpr (stage == GenerationStage::CONSTRAINTS) { constrain(current_state.pc_next() - current_state.pc(3) - 1); // PC transition diff --git a/crypto3/libs/blueprint/test/CMakeLists.txt b/crypto3/libs/blueprint/test/CMakeLists.txt index 280c9eee0b..8d1bcdbb8e 100644 --- a/crypto3/libs/blueprint/test/CMakeLists.txt +++ b/crypto3/libs/blueprint/test/CMakeLists.txt @@ -236,7 +236,6 @@ set(ZKEVM_BBF_TESTS_FILES "zkevm_bbf/opcodes/byte_ops" "zkevm_bbf/opcodes/cmp" "zkevm_bbf/opcodes/add_sub" - "zkevm_bbf/opcodes/byte_ops" ) diff --git a/crypto3/libs/blueprint/test/zkevm_bbf/opcodes/byte_ops.cpp b/crypto3/libs/blueprint/test/zkevm_bbf/opcodes/byte_ops.cpp index ee40c4f7be..3b11b0fc6d 100644 --- a/crypto3/libs/blueprint/test/zkevm_bbf/opcodes/byte_ops.cpp +++ b/crypto3/libs/blueprint/test/zkevm_bbf/opcodes/byte_ops.cpp @@ -1,5 +1,5 @@ //---------------------------------------------------------------------------// -// Copyright (c) 2024 Elena Tatuzova +// Copyright (c) 2024 Alexey Yashunsky // // MIT License // @@ -22,58 +22,52 @@ // SOFTWARE. //---------------------------------------------------------------------------// -#define BOOST_TEST_MODULE blueprint_plonk_opcodes_test +#define BOOST_TEST_MODULE zkevm_bbf_byte_ops_test #include #include - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include -#include #include +#include #include #include - #include -#include #include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include +#include #include "../test_l1_wrapper.hpp" -using namespace nil::crypto3; -using namespace nil::blueprint::bbf; +using namespace nil::blueprint; +using namespace nil::crypto3::algebra; -// Remember that in production sizes should be preset. -// Here they are different for different tests just for fast and easy testing -BOOST_AUTO_TEST_SUITE(zkevm_opcode_test_suite) +BOOST_AUTO_TEST_SUITE(zkevm_byte_ops_test_suite) -BOOST_AUTO_TEST_CASE(byte_ops_cppui) { +BOOST_AUTO_TEST_CASE(zkevm_byte_ops_test) { using field_type = typename algebra::curves::pallas::base_field_type; zkevm_opcode_tester opcode_tester; l1_size_restrictions max_sizes; // incorrect test logic, but we have no memory operations so - opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0xFb70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0xFb70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); // opcode_tester.push_opcode(zkevm_opcode::BYTE); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0xFb70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0xFb70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); // opcode_tester.push_opcode(zkevm_opcode::SIGNEXTEND); opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0xFb70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); @@ -83,12 +77,12 @@ BOOST_AUTO_TEST_CASE(byte_ops_cppui) { opcode_tester.push_opcode(zkevm_opcode::SHR); opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0xFb70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); - // opcode_tester.push_opcode(zkevm_opcode::SAR); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x8b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,0); + opcode_tester.push_opcode(zkevm_opcode::SAR); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x8b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,0); // opcode_tester.push_opcode(zkevm_opcode::BYTE); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x8b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,0); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x8b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,0); // opcode_tester.push_opcode(zkevm_opcode::SIGNEXTEND); opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x8b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); opcode_tester.push_opcode(zkevm_opcode::PUSH32, 0); @@ -98,12 +92,12 @@ BOOST_AUTO_TEST_CASE(byte_ops_cppui) { opcode_tester.push_opcode(zkevm_opcode::SHR); opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x8b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); opcode_tester.push_opcode(zkevm_opcode::PUSH32,0); - // opcode_tester.push_opcode(zkevm_opcode::SAR); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x8b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,10); + opcode_tester.push_opcode(zkevm_opcode::SAR); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x8b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,10); // opcode_tester.push_opcode(zkevm_opcode::BYTE); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x8b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,10); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x8b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,10); // opcode_tester.push_opcode(zkevm_opcode::SIGNEXTEND); opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x8b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); opcode_tester.push_opcode(zkevm_opcode::PUSH32, 10); @@ -113,12 +107,12 @@ BOOST_AUTO_TEST_CASE(byte_ops_cppui) { opcode_tester.push_opcode(zkevm_opcode::SHR); opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x8b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); opcode_tester.push_opcode(zkevm_opcode::PUSH32,10); - // opcode_tester.push_opcode(zkevm_opcode::SAR); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x8b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,257); + opcode_tester.push_opcode(zkevm_opcode::SAR); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x8b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,257); // opcode_tester.push_opcode(zkevm_opcode::BYTE); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x8b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,257); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x8b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,257); // opcode_tester.push_opcode(zkevm_opcode::SIGNEXTEND); opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x8b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); opcode_tester.push_opcode(zkevm_opcode::PUSH32, 257); @@ -128,12 +122,12 @@ BOOST_AUTO_TEST_CASE(byte_ops_cppui) { opcode_tester.push_opcode(zkevm_opcode::SHR); opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x8b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); opcode_tester.push_opcode(zkevm_opcode::PUSH32,257); - // opcode_tester.push_opcode(zkevm_opcode::SAR); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x8b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,65538); + opcode_tester.push_opcode(zkevm_opcode::SAR); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x8b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,65538); // opcode_tester.push_opcode(zkevm_opcode::BYTE); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x8b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,65538); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x8b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,65538); // opcode_tester.push_opcode(zkevm_opcode::SIGNEXTEND); opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x8b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); opcode_tester.push_opcode(zkevm_opcode::PUSH32, 65538); @@ -143,12 +137,12 @@ BOOST_AUTO_TEST_CASE(byte_ops_cppui) { opcode_tester.push_opcode(zkevm_opcode::SHR); opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x8b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); opcode_tester.push_opcode(zkevm_opcode::PUSH32,65538); - // opcode_tester.push_opcode(zkevm_opcode::SAR); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,10); + opcode_tester.push_opcode(zkevm_opcode::SAR); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,10); // opcode_tester.push_opcode(zkevm_opcode::BYTE); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,10); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,10); // opcode_tester.push_opcode(zkevm_opcode::SIGNEXTEND); opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); opcode_tester.push_opcode(zkevm_opcode::PUSH32, 10); @@ -158,12 +152,12 @@ BOOST_AUTO_TEST_CASE(byte_ops_cppui) { opcode_tester.push_opcode(zkevm_opcode::SHR); opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); opcode_tester.push_opcode(zkevm_opcode::PUSH32,10); - // opcode_tester.push_opcode(zkevm_opcode::SAR); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,30); + opcode_tester.push_opcode(zkevm_opcode::SAR); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,30); // opcode_tester.push_opcode(zkevm_opcode::BYTE); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,30); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,30); // opcode_tester.push_opcode(zkevm_opcode::SIGNEXTEND); opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); opcode_tester.push_opcode(zkevm_opcode::PUSH32, 30); @@ -173,12 +167,12 @@ BOOST_AUTO_TEST_CASE(byte_ops_cppui) { opcode_tester.push_opcode(zkevm_opcode::SHR); opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); opcode_tester.push_opcode(zkevm_opcode::PUSH32,30); - // opcode_tester.push_opcode(zkevm_opcode::SAR); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,50); + opcode_tester.push_opcode(zkevm_opcode::SAR); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,50); // opcode_tester.push_opcode(zkevm_opcode::BYTE); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,50); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,50); // opcode_tester.push_opcode(zkevm_opcode::SIGNEXTEND); opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); opcode_tester.push_opcode(zkevm_opcode::PUSH32, 50); @@ -188,12 +182,12 @@ BOOST_AUTO_TEST_CASE(byte_ops_cppui) { opcode_tester.push_opcode(zkevm_opcode::SHR); opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1b70726fb8d3a24da9ff9647225a18412b8f010425938504d73ebc8801e2e016_cppui_modular257)); opcode_tester.push_opcode(zkevm_opcode::PUSH32,50); - // opcode_tester.push_opcode(zkevm_opcode::SAR); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1234567890_cppui_modular257)); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,1); + opcode_tester.push_opcode(zkevm_opcode::SAR); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1234567890_cppui_modular257)); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,1); // opcode_tester.push_opcode(zkevm_opcode::BYTE); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1234567890_cppui_modular257)); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,1); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1234567890_cppui_modular257)); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,1); // opcode_tester.push_opcode(zkevm_opcode::SIGNEXTEND); opcode_tester.push_opcode(zkevm_opcode::PUSH32, zwordc(0x1234567890_cppui_modular257)); opcode_tester.push_opcode(zkevm_opcode::PUSH32, 1); @@ -203,12 +197,12 @@ BOOST_AUTO_TEST_CASE(byte_ops_cppui) { opcode_tester.push_opcode(zkevm_opcode::SHR); opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1234567890_cppui_modular257)); opcode_tester.push_opcode(zkevm_opcode::PUSH32,1); - // opcode_tester.push_opcode(zkevm_opcode::SAR); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1234567890_cppui_modular257)); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,31); + opcode_tester.push_opcode(zkevm_opcode::SAR); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1234567890_cppui_modular257)); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,31); // opcode_tester.push_opcode(zkevm_opcode::BYTE); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1234567890_cppui_modular257)); - opcode_tester.push_opcode(zkevm_opcode::PUSH32,31); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1234567890_cppui_modular257)); + // opcode_tester.push_opcode(zkevm_opcode::PUSH32,31); // opcode_tester.push_opcode(zkevm_opcode::SIGNEXTEND); opcode_tester.push_opcode(zkevm_opcode::PUSH32, zwordc(0x1234567890_cppui_modular257)); opcode_tester.push_opcode(zkevm_opcode::PUSH32, 31); @@ -218,16 +212,17 @@ BOOST_AUTO_TEST_CASE(byte_ops_cppui) { opcode_tester.push_opcode(zkevm_opcode::SHR); opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1234567890_cppui_modular257)); opcode_tester.push_opcode(zkevm_opcode::PUSH32,31); - // opcode_tester.push_opcode(zkevm_opcode::SAR); + opcode_tester.push_opcode(zkevm_opcode::SAR); opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x33_cppui_modular257)); opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1_cppui_modular257)); - // opcode_tester.push_opcode(zkevm_opcode::SAR); + opcode_tester.push_opcode(zkevm_opcode::SAR); opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x33_cppui_modular257)); opcode_tester.push_opcode(zkevm_opcode::PUSH32,zwordc(0x1_cppui_modular257)); opcode_tester.push_opcode(zkevm_opcode::SHR); opcode_tester.push_opcode(zkevm_opcode::PUSH32, zwordc(0x33_cppui_modular257)); opcode_tester.push_opcode(zkevm_opcode::PUSH32, zwordc(0x1_cppui_modular257)); opcode_tester.push_opcode(zkevm_opcode::SHL); + opcode_tester.push_opcode(zkevm_opcode::STOP); max_sizes.max_keccak_blocks = 400; @@ -238,4 +233,5 @@ BOOST_AUTO_TEST_CASE(byte_ops_cppui) { max_sizes.max_zkevm_rows = 400; complex_opcode_test(opcode_tester, max_sizes); } + BOOST_AUTO_TEST_SUITE_END() diff --git a/crypto3/libs/blueprint/test/zkevm_bbf/opcodes/mod_ops.cpp b/crypto3/libs/blueprint/test/zkevm_bbf/opcodes/mod_ops.cpp index 92ca36326c..a73d3e1ff0 100644 --- a/crypto3/libs/blueprint/test/zkevm_bbf/opcodes/mod_ops.cpp +++ b/crypto3/libs/blueprint/test/zkevm_bbf/opcodes/mod_ops.cpp @@ -118,12 +118,12 @@ BOOST_AUTO_TEST_CASE(mod_ops) { opcode_tester.push_opcode(zkevm_opcode::MULMOD); opcode_tester.push_opcode(zkevm_opcode::STOP); - max_sizes.max_keccak_blocks = 10; - max_sizes.max_bytecode = 3000; + max_sizes.max_keccak_blocks = 400; + max_sizes.max_bytecode = 5000; max_sizes.max_mpt = 0; - max_sizes.max_rw = 500; + max_sizes.max_rw = 3000; max_sizes.max_copy = 500; - max_sizes.max_zkevm_rows = 300; + max_sizes.max_zkevm_rows = 400; complex_opcode_test(opcode_tester, max_sizes); } BOOST_AUTO_TEST_SUITE_END()