diff --git a/barretenberg/cpp/src/barretenberg/avm_fuzzer/fuzz_lib/instruction.hpp b/barretenberg/cpp/src/barretenberg/avm_fuzzer/fuzz_lib/instruction.hpp index fce2e07f1a28..35e70ed2ab05 100644 --- a/barretenberg/cpp/src/barretenberg/avm_fuzzer/fuzz_lib/instruction.hpp +++ b/barretenberg/cpp/src/barretenberg/avm_fuzzer/fuzz_lib/instruction.hpp @@ -573,12 +573,10 @@ struct SUCCESSCOPY_Instruction { struct ECADD_Instruction { ParamRef p1_x; ParamRef p1_y; - ParamRef p1_infinite; ParamRef p2_x; ParamRef p2_y; - ParamRef p2_infinite; AddressRef result; - SERIALIZATION_FIELDS(p1_x, p1_y, p1_infinite, p2_x, p2_y, p2_infinite, result); + SERIALIZATION_FIELDS(p1_x, p1_y, p2_x, p2_y, result); }; /// @brief POSEIDON2PERM: Perform Poseidon2 permutation on 4 FF values @@ -881,8 +879,8 @@ inline std::ostream& operator<<(std::ostream& os, const FuzzInstruction& instruc << arg.dst_address; }, [&](ECADD_Instruction arg) { - os << "ECADD_Instruction " << arg.p1_x << " " << arg.p1_y << " " << arg.p1_infinite << " " << arg.p2_x - << " " << arg.p2_y << " " << arg.p2_infinite << " " << arg.result; + os << "ECADD_Instruction " << arg.p1_x << " " << arg.p1_y << " " << arg.p2_x << " " << arg.p2_y << " " + << arg.result; }, [&](POSEIDON2PERM_Instruction arg) { os << "POSEIDON2PERM_Instruction " << arg.src_address << " " << arg.dst_address; diff --git a/barretenberg/cpp/src/barretenberg/avm_fuzzer/fuzz_lib/program_block.cpp b/barretenberg/cpp/src/barretenberg/avm_fuzzer/fuzz_lib/program_block.cpp index b719d65bca5d..7c98c29b05f3 100644 --- a/barretenberg/cpp/src/barretenberg/avm_fuzzer/fuzz_lib/program_block.cpp +++ b/barretenberg/cpp/src/barretenberg/avm_fuzzer/fuzz_lib/program_block.cpp @@ -1287,40 +1287,32 @@ void ProgramBlock::process_ecadd_instruction(ECADD_Instruction instruction) #endif auto p1_x = memory_manager.get_resolved_address_and_operand_16(instruction.p1_x); auto p1_y = memory_manager.get_resolved_address_and_operand_16(instruction.p1_y); - auto p1_inf = memory_manager.get_resolved_address_and_operand_16(instruction.p1_infinite); auto p2_x = memory_manager.get_resolved_address_and_operand_16(instruction.p2_x); auto p2_y = memory_manager.get_resolved_address_and_operand_16(instruction.p2_y); - auto p2_inf = memory_manager.get_resolved_address_and_operand_16(instruction.p2_infinite); auto result = memory_manager.get_resolved_address_and_operand_16(instruction.result); - if (!p1_x.has_value() || !p1_y.has_value() || !p1_inf.has_value() || !p2_x.has_value() || !p2_y.has_value() || - !p2_inf.has_value() || !result.has_value()) { + if (!p1_x.has_value() || !p1_y.has_value() || !p2_x.has_value() || !p2_y.has_value() || !result.has_value()) { return; } preprocess_memory_addresses(p1_x.value().first); preprocess_memory_addresses(p1_y.value().first); - preprocess_memory_addresses(p1_inf.value().first); preprocess_memory_addresses(p2_x.value().first); preprocess_memory_addresses(p2_y.value().first); - preprocess_memory_addresses(p2_inf.value().first); preprocess_memory_addresses(result.value().first); auto ecadd_instruction = bb::avm2::testing::InstructionBuilder(bb::avm2::WireOpCode::ECADD) .operand(p1_x.value().second) .operand(p1_y.value().second) - .operand(p1_inf.value().second) .operand(p2_x.value().second) .operand(p2_y.value().second) - .operand(p2_inf.value().second) .operand(result.value().second) .build(); instructions.push_back(ecadd_instruction); - // ECADD writes 3 consecutive memory locations: result_x (FF), result_y (FF), result_is_inf (U1) + // ECADD writes 2 consecutive memory locations: result_x (FF), result_y (FF) memory_manager.set_memory_address(bb::avm2::MemoryTag::FF, result.value().first.absolute_address); memory_manager.set_memory_address(bb::avm2::MemoryTag::FF, result.value().first.absolute_address + 1); - memory_manager.set_memory_address(bb::avm2::MemoryTag::U1, result.value().first.absolute_address + 2); } void ProgramBlock::process_poseidon2perm_instruction(POSEIDON2PERM_Instruction instruction) diff --git a/barretenberg/cpp/src/barretenberg/avm_fuzzer/harness/ecc.fuzzer.cpp b/barretenberg/cpp/src/barretenberg/avm_fuzzer/harness/ecc.fuzzer.cpp index 7298fc3f3e85..5237bc909014 100644 --- a/barretenberg/cpp/src/barretenberg/avm_fuzzer/harness/ecc.fuzzer.cpp +++ b/barretenberg/cpp/src/barretenberg/avm_fuzzer/harness/ecc.fuzzer.cpp @@ -94,8 +94,8 @@ struct EccFuzzerInput { AffinePoint q = AffinePoint::one(); Fq scalar = Fq::zero(); // Addresses are organised as: - // p_x, p_y, p_inf, q_x, q_y, q_inf, output_addr - std::array addresses{}; + // p_x, p_y, q_x, q_y, output_addr + std::array addresses{}; EccFuzzerInput() = default; // Serialize to buffer @@ -109,7 +109,7 @@ struct EccFuzzerInput { Fq::serialize_to_buffer(scalar, buffer + offset); offset += sizeof(Fq); // Serialize memory addresses - std::memcpy(buffer + offset, &addresses[0], sizeof(MemoryAddress) * 7); + std::memcpy(buffer + offset, &addresses[0], sizeof(MemoryAddress) * 5); } static EccFuzzerInput from_buffer(const uint8_t* buffer) @@ -137,7 +137,7 @@ struct EccFuzzerInput { input.scalar = Fq::serialize_from_buffer(buffer + offset); offset += sizeof(Fq); // Deserialize memory addresses - std::memcpy(&input.addresses[0], buffer + offset, sizeof(MemoryAddress) * 7); + std::memcpy(&input.addresses[0], buffer + offset, sizeof(MemoryAddress) * 5); return input; } @@ -210,7 +210,7 @@ extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* data, size_t size, size_t max case 7: { // Mutate memory addresses // Select a random address to mutate - std::uniform_int_distribution addr_dist(0, 6); + std::uniform_int_distribution addr_dist(0, 4); size_t addr_index = addr_dist(rng); input.addresses[addr_index] = mutate_memory_address(input.addresses[addr_index], rng); break; @@ -268,15 +268,13 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) mem->set(/*p_x_addr*/ input.addresses[0], MemoryValue::from_tag(MemoryTag::FF, point_p.x())); mem->set(/*p_y_addr*/ input.addresses[1], MemoryValue::from_tag(MemoryTag::FF, point_p.y())); - mem->set(/*p_inf*/ input.addresses[2], MemoryValue::from_tag(MemoryTag::U1, point_p.is_infinity() ? FF(1) : FF(0))); - mem->set(/*q_x_addr*/ input.addresses[3], MemoryValue::from_tag(MemoryTag::FF, point_q.x())); - mem->set(/*q_y_addr*/ input.addresses[4], MemoryValue::from_tag(MemoryTag::FF, point_q.y())); - mem->set(/*q_inf*/ input.addresses[5], MemoryValue::from_tag(MemoryTag::U1, point_q.is_infinity() ? FF(1) : FF(0))); + mem->set(/*q_x_addr*/ input.addresses[2], MemoryValue::from_tag(MemoryTag::FF, point_q.x())); + mem->set(/*q_y_addr*/ input.addresses[3], MemoryValue::from_tag(MemoryTag::FF, point_q.y())); EmbeddedCurvePoint scalar_mul_result; try { - ecc.add(*mem, point_p, point_q, /* output_addr */ input.addresses[6]); + ecc.add(*mem, point_p, point_q, /* output_addr */ input.addresses[4]); scalar_mul_result = ecc.scalar_mul(input.p, FF(uint256_t(input.scalar))); } catch (std::exception& e) { // info("Caught exception during ECC add: {}", e.what()); @@ -286,8 +284,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) EmbeddedCurvePoint expected_result = point_p + point_q; // Verify output in memory - MemoryValue res_x = mem->get(input.addresses[6]); - MemoryValue res_y = mem->get(input.addresses[6] + 1); + MemoryValue res_x = mem->get(input.addresses[4]); + MemoryValue res_y = mem->get(input.addresses[4] + 1); EmbeddedCurvePoint result_point = EmbeddedCurvePoint(res_x.as_ff(), res_y.as_ff()); @@ -307,15 +305,13 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) auto trace = TestTraceContainer({ { { Column::execution_context_id, 0 }, // Point P - { Column::execution_register_0_, point_p.x() }, // = px - { Column::execution_register_1_, point_p.y() }, // = py - { Column::execution_register_2_, point_p.is_infinity() ? FF(1) : FF(0) }, // = p_inf + { Column::execution_register_0_, point_p.x() }, // = px + { Column::execution_register_1_, point_p.y() }, // = py // Point Q - { Column::execution_register_3_, point_q.x() }, // = qx - { Column::execution_register_4_, point_q.y() }, // = qy - { Column::execution_register_5_, point_q.is_infinity() ? FF(1) : FF(0) }, // = q_inf + { Column::execution_register_2_, point_q.x() }, // = qx + { Column::execution_register_3_, point_q.y() }, // = qy // Dst address - { Column::execution_rop_6_, input.addresses[6] }, // = dst_addr + { Column::execution_rop_4_, input.addresses[4] }, // = dst_addr { Column::execution_sel_exec_dispatch_ecc_add, 1 }, // = sel { Column::execution_sel_opcode_error, error ? 1 : 0 }, // = sel_err } }); diff --git a/barretenberg/cpp/src/barretenberg/avm_fuzzer/mutations/instructions/instruction.cpp b/barretenberg/cpp/src/barretenberg/avm_fuzzer/mutations/instructions/instruction.cpp index 02b2278f658d..6801ee5ff5d3 100644 --- a/barretenberg/cpp/src/barretenberg/avm_fuzzer/mutations/instructions/instruction.cpp +++ b/barretenberg/cpp/src/barretenberg/avm_fuzzer/mutations/instructions/instruction.cpp @@ -428,17 +428,15 @@ std::vector InstructionMutator::generate_ecadd_instruction(std: // Random mode: use existing memory values (may fail if not valid points on curve) return { ECADD_Instruction{ .p1_x = generate_variable_ref(rng), .p1_y = generate_variable_ref(rng), - .p1_infinite = generate_variable_ref(rng), .p2_x = generate_variable_ref(rng), .p2_y = generate_variable_ref(rng), - .p2_infinite = generate_variable_ref(rng), .result = generate_address_ref(rng, MAX_16BIT_OPERAND) } }; } // Backfill mode: generate valid points on the Grumpkin curve and SET them - // 6 SET instructions (2 points * 3 fields each) + 1 ECADD = 7 instructions + // 4 SET instructions (2 points * 4 fields each) + 1 ECADD = 5 instructions std::vector instructions; - instructions.reserve(7); + instructions.reserve(5); // Generate a valid point via scalar multiplication of the generator (always on curve) auto generate_point = [&rng]() { @@ -447,17 +445,12 @@ std::vector InstructionMutator::generate_ecadd_instruction(std: }; // Generate SET instructions to backfill a point at the given addresses - auto backfill_point = [&instructions](const bb::avm2::EmbeddedCurvePoint& point, - AddressRef x_addr, - AddressRef y_addr, - AddressRef inf_addr) { + auto backfill_point = [&instructions]( + const bb::avm2::EmbeddedCurvePoint& point, AddressRef x_addr, AddressRef y_addr) { instructions.push_back( SET_FF_Instruction{ .value_tag = bb::avm2::MemoryTag::FF, .result_address = x_addr, .value = point.x() }); instructions.push_back( SET_FF_Instruction{ .value_tag = bb::avm2::MemoryTag::FF, .result_address = y_addr, .value = point.y() }); - instructions.push_back(SET_8_Instruction{ .value_tag = bb::avm2::MemoryTag::U1, - .result_address = inf_addr, - .value = static_cast(point.is_infinity() ? 1 : 0) }); }; auto p1 = generate_point(); @@ -466,20 +459,16 @@ std::vector InstructionMutator::generate_ecadd_instruction(std: // Generate addresses (SET_FF uses 16-bit, SET_8 uses 8-bit operands) AddressRef p1_x_addr = generate_address_ref(rng, MAX_16BIT_OPERAND); AddressRef p1_y_addr = generate_address_ref(rng, MAX_16BIT_OPERAND); - AddressRef p1_inf_addr = generate_address_ref(rng, MAX_8BIT_OPERAND); AddressRef p2_x_addr = generate_address_ref(rng, MAX_16BIT_OPERAND); AddressRef p2_y_addr = generate_address_ref(rng, MAX_16BIT_OPERAND); - AddressRef p2_inf_addr = generate_address_ref(rng, MAX_8BIT_OPERAND); - backfill_point(p1, p1_x_addr, p1_y_addr, p1_inf_addr); - backfill_point(p2, p2_x_addr, p2_y_addr, p2_inf_addr); + backfill_point(p1, p1_x_addr, p1_y_addr); + backfill_point(p2, p2_x_addr, p2_y_addr); instructions.push_back(ECADD_Instruction{ .p1_x = p1_x_addr, .p1_y = p1_y_addr, - .p1_infinite = p1_inf_addr, .p2_x = p2_x_addr, .p2_y = p2_y_addr, - .p2_infinite = p2_inf_addr, .result = generate_address_ref(rng, MAX_16BIT_OPERAND) }); return instructions; @@ -1476,8 +1465,8 @@ void InstructionMutator::mutate_successcopy_instruction(SUCCESSCOPY_Instruction& void InstructionMutator::mutate_ecadd_instruction(ECADD_Instruction& instruction, std::mt19937_64& rng) { - // ECADD has 7 operands, select one to mutate - int choice = std::uniform_int_distribution(0, 6)(rng); + // ECADD has 5 operands, select one to mutate + int choice = std::uniform_int_distribution(0, 4)(rng); switch (choice) { case 0: mutate_param_ref(instruction.p1_x, rng, MemoryTag::FF, MAX_16BIT_OPERAND); @@ -1486,18 +1475,12 @@ void InstructionMutator::mutate_ecadd_instruction(ECADD_Instruction& instruction mutate_param_ref(instruction.p1_y, rng, MemoryTag::FF, MAX_16BIT_OPERAND); break; case 2: - mutate_param_ref(instruction.p1_infinite, rng, MemoryTag::U1, MAX_16BIT_OPERAND); - break; - case 3: mutate_param_ref(instruction.p2_x, rng, MemoryTag::FF, MAX_16BIT_OPERAND); break; - case 4: + case 3: mutate_param_ref(instruction.p2_y, rng, MemoryTag::FF, MAX_16BIT_OPERAND); break; - case 5: - mutate_param_ref(instruction.p2_infinite, rng, MemoryTag::U1, MAX_16BIT_OPERAND); - break; - case 6: + case 4: mutate_address_ref(instruction.result, rng, MAX_16BIT_OPERAND); break; } diff --git a/barretenberg/cpp/src/barretenberg/vm2/common/instruction_spec.cpp b/barretenberg/cpp/src/barretenberg/vm2/common/instruction_spec.cpp index 112997b74b0d..3e6c7b6bb243 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/common/instruction_spec.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/common/instruction_spec.cpp @@ -99,7 +99,7 @@ const std::unordered_map>& { WireOpCode::POSEIDON2PERM, { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, { WireOpCode::SHA256COMPRESSION, { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, { WireOpCode::KECCAKF1600, { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, - { WireOpCode::ECADD, { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, + { WireOpCode::ECADD, { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, // Conversions { WireOpCode::TORADIXBE, { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }, }; @@ -420,7 +420,7 @@ const std::unordered_map& get_wire_instruction_ .op_dc_selectors = get_wire_opcode_dc_selectors().at(WireOpCode::KECCAKF1600) } }, { WireOpCode::ECADD, { .exec_opcode = ExecutionOpCode::ECADD, - .size_in_bytes = 17, + .size_in_bytes = 13, .op_dc_selectors = get_wire_opcode_dc_selectors().at(WireOpCode::ECADD) } }, // Conversions { WireOpCode::TORADIXBE, @@ -737,14 +737,12 @@ const std::unordered_map& get_exec_instruc { .num_addresses = 2, .gas_cost = { .opcode_gas = AVM_KECCAKF1600_BASE_L2_GAS, .base_da = 0, .dyn_l2 = 0, .dyn_da = 0 } } }, { ExecutionOpCode::ECADD, - { .num_addresses = 7, + { .num_addresses = 5, .gas_cost = { .opcode_gas = AVM_ECADD_BASE_L2_GAS, .base_da = 0, .dyn_l2 = 0, .dyn_da = 0 }, .register_info = RegisterInfo().add_inputs({ /*p_x=*/ValueTag::FF, /*p_y=*/ValueTag::FF, - /*p_inf*/ ValueTag::U1, /*q_x*/ ValueTag::FF, - /*q_y*/ ValueTag::FF, - /*q_inf*/ ValueTag::U1 }) } }, + /*q_y*/ ValueTag::FF }) } }, { ExecutionOpCode::TORADIXBE, { .num_addresses = 5, .gas_cost = { .opcode_gas = AVM_TORADIXBE_BASE_L2_GAS, diff --git a/barretenberg/cpp/src/barretenberg/vm2/constraining/avm_fixed_vk.hpp b/barretenberg/cpp/src/barretenberg/vm2/constraining/avm_fixed_vk.hpp index 52906d44e2c2..ce806adf3b29 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/constraining/avm_fixed_vk.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/constraining/avm_fixed_vk.hpp @@ -17,7 +17,7 @@ class AvmHardCodedVKAndHash { using FF = bb::curve::BN254::ScalarField; // Precomputed VK hash (hash of all commitments below). - static FF vk_hash() { return FF(uint256_t("0x183783fd7c3f269b595307224be99cf3773b781f8d1d59a305ce711101d43a60")); } + static FF vk_hash() { return FF(uint256_t("0x0f0714f53e7fcf7ffb15cfb22b7a1614c65f01742706b0ca20eb80454eaf1e48")); } static constexpr std::array get_all() { @@ -83,18 +83,15 @@ class AvmHardCodedVKAndHash { uint256_t( "0x06ea9cd6f2a50e2156f80beebc721d11d24821fd4b723932da48d8750300fbaa")), // precomputed_expected_tag_reg_1_ Commitment( - uint256_t("0x1cb1c6d46ddf9f7bd7a87a5e7dca5ef92c8a44669ab0cbc557a0fcb8331d0d8d"), + uint256_t("0x034e06277dc6d6e4f2ddea6d71635693db1a2869d33b918f0f70efa0530ecaa6"), uint256_t( - "0x281a3e4b96e4f595db502ba69acda314bc335957ae605af17423b0ff3d0528c3")), // precomputed_expected_tag_reg_2_ + "0x2d3e564f6e8885163d356daec0387132097e73dbf8e04475675b715151ce3cb9")), // precomputed_expected_tag_reg_2_ Commitment( uint256_t("0x1a3c36c4933c956751e6ca5631077a9418cd0ba4ec29e965508eaf8bc1a7ffd4"), uint256_t( "0x1203bdd1aab5bfc5f3ed6abbefc30ab303770b847d022c1c9c0f8de202a76560")), // precomputed_expected_tag_reg_3_ Commitment::infinity(), // precomputed_expected_tag_reg_4_ - Commitment( - uint256_t("0x11b316123744c8602e394b9a558ed664a70d8a7e8f5a3138c9971302c193dd84"), - uint256_t( - "0x08a817c8ab332c7f8b478ec9bddb41a8ca1593c3b8fb85d6236d3eecc2df3b37")), // precomputed_expected_tag_reg_5_ + Commitment::infinity(), // precomputed_expected_tag_reg_5_ Commitment( uint256_t("0x0000000000000000000000000000000000000000000000000000000000000001"), uint256_t( @@ -103,9 +100,9 @@ class AvmHardCodedVKAndHash { uint256_t("0x14567e2c3e84fc1e3e69d81f6ce5808ca9a0451964a7bbabbd9e369db7556253"), uint256_t("0x0378926f150c30c760965df469ae6ed609c59feecf899f2b95aff519bbf3fb3c")), // precomputed_idx Commitment( - uint256_t("0x1e497723c3f95466c480f1ac1addb1e0dc68bb123cae27ee70d00e6d6fcc6896"), + uint256_t("0x2bef1e5de8c449d3cfa4cf9ab94e8b846755023b02e94dbbba1ffb3c73da0d1d"), uint256_t( - "0x24c9a31064fb5f18c18ac3ea4be1a10809765a43b06bcea177fbb171dd547ced")), // precomputed_instr_size + "0x06905ac3e0ae01f14b1bc598f9ba30af7eced70893019ca78b0e55668c38f3e0")), // precomputed_instr_size Commitment( uint256_t("0x11b710f896157a9557278a1f776cd6c7e1e7e256a572bd080797daaf1d6307d1"), uint256_t( @@ -268,14 +265,8 @@ class AvmHardCodedVKAndHash { uint256_t("0x1530ccb47d1198320c163380a82ca8cbaf87b2d40ede856d21c60535e2251262"), uint256_t( "0x29dd7ccea05e6d47a7373ea950a7988caed0d20880612e046af575217a21652a")), // precomputed_sel_mem_op_reg_3_ - Commitment( - uint256_t("0x11b316123744c8602e394b9a558ed664a70d8a7e8f5a3138c9971302c193dd84"), - uint256_t( - "0x08a817c8ab332c7f8b478ec9bddb41a8ca1593c3b8fb85d6236d3eecc2df3b37")), // precomputed_sel_mem_op_reg_4_ - Commitment( - uint256_t("0x11b316123744c8602e394b9a558ed664a70d8a7e8f5a3138c9971302c193dd84"), - uint256_t( - "0x08a817c8ab332c7f8b478ec9bddb41a8ca1593c3b8fb85d6236d3eecc2df3b37")), // precomputed_sel_mem_op_reg_5_ + Commitment::infinity(), // precomputed_sel_mem_op_reg_4_ + Commitment::infinity(), // precomputed_sel_mem_op_reg_5_ Commitment( uint256_t("0x089cdab4e8e8381977b093cb267a1b7c8c60f4466c39a99af1247e37fe56ebfe"), uint256_t( @@ -296,10 +287,7 @@ class AvmHardCodedVKAndHash { uint256_t("0x0bf1970c2e92fee577ba15d063fa78fdd17752cafd19261ff0f176a1d3348769"), uint256_t( "0x21f1906edf2fe01e804774aa539abe8411cfda1731be99853f90253ed2652868")), // precomputed_sel_op_dc_0 - Commitment( - uint256_t("0x2ad6f77a7f7c14780d95de8bd1f5b2146fe71fb1b7e6d55016734664f10d653b"), - uint256_t( - "0x131ac1fc680fbc2584b74e5aece1f0d50afe030adf4289613e54935339829496")), // precomputed_sel_op_dc_1 + Commitment::infinity(), // precomputed_sel_op_dc_1 Commitment( uint256_t("0x225d208d9012b15a17b7dac26e737c0d2f9c8bf80de627bd13e1a9c042ede642"), uint256_t( @@ -380,14 +368,8 @@ class AvmHardCodedVKAndHash { uint256_t("0x1530ccb47d1198320c163380a82ca8cbaf87b2d40ede856d21c60535e2251262"), uint256_t( "0x29dd7ccea05e6d47a7373ea950a7988caed0d20880612e046af575217a21652a")), // precomputed_sel_op_is_address_4_ - Commitment( - uint256_t("0x11b316123744c8602e394b9a558ed664a70d8a7e8f5a3138c9971302c193dd84"), - uint256_t( - "0x08a817c8ab332c7f8b478ec9bddb41a8ca1593c3b8fb85d6236d3eecc2df3b37")), // precomputed_sel_op_is_address_5_ - Commitment( - uint256_t("0x11b316123744c8602e394b9a558ed664a70d8a7e8f5a3138c9971302c193dd84"), - uint256_t( - "0x08a817c8ab332c7f8b478ec9bddb41a8ca1593c3b8fb85d6236d3eecc2df3b37")), // precomputed_sel_op_is_address_6_ + Commitment::infinity(), // precomputed_sel_op_is_address_5_ + Commitment::infinity(), // precomputed_sel_op_is_address_6_ Commitment( uint256_t("0x1525ae740393f8dec3a1ea8f39f456861afece20561b5870db4291410d2f3429"), uint256_t( @@ -436,14 +418,8 @@ class AvmHardCodedVKAndHash { uint256_t("0x1530ccb47d1198320c163380a82ca8cbaf87b2d40ede856d21c60535e2251262"), uint256_t( "0x29dd7ccea05e6d47a7373ea950a7988caed0d20880612e046af575217a21652a")), // precomputed_sel_tag_check_reg_3_ - Commitment( - uint256_t("0x11b316123744c8602e394b9a558ed664a70d8a7e8f5a3138c9971302c193dd84"), - uint256_t( - "0x08a817c8ab332c7f8b478ec9bddb41a8ca1593c3b8fb85d6236d3eecc2df3b37")), // precomputed_sel_tag_check_reg_4_ - Commitment( - uint256_t("0x11b316123744c8602e394b9a558ed664a70d8a7e8f5a3138c9971302c193dd84"), - uint256_t( - "0x08a817c8ab332c7f8b478ec9bddb41a8ca1593c3b8fb85d6236d3eecc2df3b37")), // precomputed_sel_tag_check_reg_5_ + Commitment::infinity(), // precomputed_sel_tag_check_reg_4_ + Commitment::infinity(), // precomputed_sel_tag_check_reg_5_ Commitment( uint256_t("0x2b770f46bb0db9c1447e6010b3ca12f1dc2b2a237ff6d2390d9ddf5a056d09ad"), uint256_t( diff --git a/barretenberg/cpp/src/barretenberg/vm2/constraining/relations/instr_fetching.test.cpp b/barretenberg/cpp/src/barretenberg/vm2/constraining/relations/instr_fetching.test.cpp index 3ab83cac013e..16b5e1b14b22 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/constraining/relations/instr_fetching.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/constraining/relations/instr_fetching.test.cpp @@ -96,9 +96,7 @@ TEST(InstrFetchingConstrainingTest, EcaddWithTraceGen) Operand::from(0x127a), Operand::from(0x127b), Operand::from(0x127c), - Operand::from(0x127d), - Operand::from(0x127e), - Operand::from(0x127f) }, + Operand::from(0x127d), }, }; std::vector bytecode = ecadd_instruction.serialize(); diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.cpp index 6c4088fb3f29..d7198445dee9 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.cpp @@ -1466,24 +1466,18 @@ void Execution::poseidon2_permutation(ContextInterface& context, MemoryAddress s * @brief ECADD execution opcode handler: Perform an elliptic curve addition and * write the result to the destination memory address. * - * TODO(#AVM-266): Remove infinity flags from point representation. - * * @param context The context. * @param p_x_addr The resolved address of the x coordinate of the first point. * @param p_y_addr The resolved address of the y coordinate of the first point. - * @param p_inf_addr The resolved address of the infinity flag of the first point. * @param q_x_addr The resolved address of the x coordinate of the second point. * @param q_y_addr The resolved address of the y coordinate of the second point. - * @param q_inf_addr The resolved address of the infinity flag of the second point. * @param dst_addr The resolved address of the destination memory address. * * @throws RegisterValidationException if the tags of the input values do not match the expected tags: * - tag of the memory value at p_x_addr is not FF. * - tag of the memory value at p_y_addr is not FF. - * - tag of the memory value at p_inf_addr is not U1. * - tag of the memory value at q_x_addr is not FF. * - tag of the memory value at q_y_addr is not FF. - * - tag of the memory value at q_inf_addr is not U1. * @throws OutOfGasException if the gas limit is exceeded. * @throws OpcodeExecutionException if the elliptic curve addition operation fails: * - memory write out of bounds. @@ -1492,10 +1486,8 @@ void Execution::poseidon2_permutation(ContextInterface& context, MemoryAddress s void Execution::ecc_add(ContextInterface& context, MemoryAddress p_x_addr, MemoryAddress p_y_addr, - MemoryAddress p_inf_addr, MemoryAddress q_x_addr, MemoryAddress q_y_addr, - MemoryAddress q_inf_addr, MemoryAddress dst_addr) { BB_BENCH_NAME("Execution::ecc_add"); @@ -1505,26 +1497,17 @@ void Execution::ecc_add(ContextInterface& context, // Read the points from memory. const auto& p_x = memory.get(p_x_addr); const auto& p_y = memory.get(p_y_addr); - // TODO(#AVM-266): Remove infinity flags from point representation, the below is currently ignored in-circuit. - const auto& p_inf = memory.get(p_inf_addr); const auto& q_x = memory.get(q_x_addr); const auto& q_y = memory.get(q_y_addr); - // TODO(#AVM-266): Remove infinity flags from point representation, the below is currently ignored in-circuit. - const auto& q_inf = memory.get(q_inf_addr); - set_and_validate_inputs(opcode, { p_x, p_y, p_inf, q_x, q_y, q_inf }); + set_and_validate_inputs(opcode, { p_x, p_y, q_x, q_y }); get_gas_tracker().consume_gas(); // Once inputs are tag checked the conversion to EmbeddedCurvePoint is safe, on curve checks are done in the add - // method. TODO(#AVM-266): We derive is_infinity from coordinates using the Noir convention of (x=0, y=0) <==> - // is_infinity. The flag will be removed in future. - const FF p_x_ff = p_x.as_ff(); - const FF p_y_ff = p_y.as_ff(); - EmbeddedCurvePoint p = EmbeddedCurvePoint(p_x_ff, p_y_ff); - const FF q_x_ff = q_x.as_ff(); - const FF q_y_ff = q_y.as_ff(); - EmbeddedCurvePoint q = EmbeddedCurvePoint(q_x_ff, q_y_ff); + // method. + EmbeddedCurvePoint p = EmbeddedCurvePoint(p_x.as_ff(), p_y.as_ff()); + EmbeddedCurvePoint q = EmbeddedCurvePoint(q_x.as_ff(), q_y.as_ff()); try { embedded_curve.add(memory, p, q, dst_addr); diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.hpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.hpp index 2c40a5d412f3..af2ade7692ad 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.hpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.hpp @@ -173,10 +173,8 @@ class Execution : public ExecutionInterface { void ecc_add(ContextInterface& context, MemoryAddress p_x_addr, MemoryAddress p_y_addr, - MemoryAddress p_inf_addr, MemoryAddress q_x_addr, MemoryAddress q_y_addr, - MemoryAddress q_inf_addr, MemoryAddress dst_addr); void to_radix_be(ContextInterface& context, MemoryAddress value_addr, diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.test.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.test.cpp index 06752ba433b4..234e8b4e409b 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.test.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.test.cpp @@ -1034,10 +1034,8 @@ TEST_F(ExecutionSimulationTest, EccAdd) { MemoryAddress p_x_addr = 10; MemoryAddress p_y_addr = 15; - MemoryAddress p_is_inf_addr = 25; MemoryAddress q_x_addr = 20; MemoryAddress q_y_addr = 30; - MemoryAddress q_is_inf_addr = 35; MemoryAddress dst_addr = 40; MemoryValue p_x = MemoryValue::from(FF("0x04c95d1b26d63d46918a156cae92db1bcbc4072a27ec81dc82ea959abdbcf16a")); @@ -1049,14 +1047,11 @@ TEST_F(ExecutionSimulationTest, EccAdd) EmbeddedCurvePoint q(q_x.as_ff(), q_y.as_ff()); // Mock the context and memory interactions - MemoryValue zero = MemoryValue::from(0); EXPECT_CALL(context, get_memory()).WillRepeatedly(ReturnRef(memory)); EXPECT_CALL(Const(memory), get(p_x_addr)).WillOnce(ReturnRef(p_x)); EXPECT_CALL(memory, get(p_y_addr)).WillOnce(ReturnRef(p_y)); - EXPECT_CALL(memory, get(p_is_inf_addr)).WillOnce(ReturnRef(zero)); // p is not infinity EXPECT_CALL(memory, get(q_x_addr)).WillOnce(ReturnRef(q_x)); EXPECT_CALL(memory, get(q_y_addr)).WillOnce(ReturnRef(q_y)); - EXPECT_CALL(memory, get(q_is_inf_addr)).WillOnce(ReturnRef(zero)); // q is not infinity EXPECT_CALL(gas_tracker, consume_gas); @@ -1064,7 +1059,7 @@ TEST_F(ExecutionSimulationTest, EccAdd) EXPECT_CALL(ecc, add(_, _, _, dst_addr)); // Execute the ECC add operation - execution.ecc_add(context, p_x_addr, p_y_addr, p_is_inf_addr, q_x_addr, q_y_addr, q_is_inf_addr, dst_addr); + execution.ecc_add(context, p_x_addr, p_y_addr, q_x_addr, q_y_addr, dst_addr); } TEST_F(ExecutionSimulationTest, ToRadixBE) diff --git a/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/serialization.cpp b/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/serialization.cpp index 54446cb8fe27..b879a8ff1ea3 100644 --- a/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/serialization.cpp +++ b/barretenberg/cpp/src/barretenberg/vm2/simulation/lib/serialization.cpp @@ -188,10 +188,8 @@ const std::unordered_map>& get_wire_opcode_ { OperandType::INDIRECT16, OperandType::UINT16, // lhs.x OperandType::UINT16, // lhs.y - OperandType::UINT16, // lhs.is_infinite OperandType::UINT16, // rhs.x OperandType::UINT16, // rhs.y - OperandType::UINT16, // rhs.is_infinite OperandType::UINT16 } }, // dst_offset // Gadget - Conversion { WireOpCode::TORADIXBE,