Skip to content

Commit 8b38420

Browse files
committed
feat: remove inf flags from ecadd opcode - ec flow only
1 parent 20859b8 commit 8b38420

7 files changed

Lines changed: 23 additions & 77 deletions

File tree

barretenberg/cpp/src/barretenberg/vm2/common/instruction_spec.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ const std::unordered_map<WireOpCode, std::array<uint8_t, NUM_OP_DC_SELECTORS>>&
9999
{ WireOpCode::POSEIDON2PERM, { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
100100
{ WireOpCode::SHA256COMPRESSION, { 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
101101
{ WireOpCode::KECCAKF1600, { 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
102-
{ WireOpCode::ECADD, { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
102+
{ WireOpCode::ECADD, { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
103103
// Conversions
104104
{ WireOpCode::TORADIXBE, { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } },
105105
};
@@ -420,7 +420,7 @@ const std::unordered_map<WireOpCode, WireInstructionSpec>& get_wire_instruction_
420420
.op_dc_selectors = get_wire_opcode_dc_selectors().at(WireOpCode::KECCAKF1600) } },
421421
{ WireOpCode::ECADD,
422422
{ .exec_opcode = ExecutionOpCode::ECADD,
423-
.size_in_bytes = 17,
423+
.size_in_bytes = 13,
424424
.op_dc_selectors = get_wire_opcode_dc_selectors().at(WireOpCode::ECADD) } },
425425
// Conversions
426426
{ WireOpCode::TORADIXBE,
@@ -737,14 +737,12 @@ const std::unordered_map<ExecutionOpCode, ExecInstructionSpec>& get_exec_instruc
737737
{ .num_addresses = 2,
738738
.gas_cost = { .opcode_gas = AVM_KECCAKF1600_BASE_L2_GAS, .base_da = 0, .dyn_l2 = 0, .dyn_da = 0 } } },
739739
{ ExecutionOpCode::ECADD,
740-
{ .num_addresses = 7,
740+
{ .num_addresses = 5,
741741
.gas_cost = { .opcode_gas = AVM_ECADD_BASE_L2_GAS, .base_da = 0, .dyn_l2 = 0, .dyn_da = 0 },
742742
.register_info = RegisterInfo().add_inputs({ /*p_x=*/ValueTag::FF,
743743
/*p_y=*/ValueTag::FF,
744-
/*p_inf*/ ValueTag::U1,
745744
/*q_x*/ ValueTag::FF,
746-
/*q_y*/ ValueTag::FF,
747-
/*q_inf*/ ValueTag::U1 }) } },
745+
/*q_y*/ ValueTag::FF }) } },
748746
{ ExecutionOpCode::TORADIXBE,
749747
{ .num_addresses = 5,
750748
.gas_cost = { .opcode_gas = AVM_TORADIXBE_BASE_L2_GAS,

barretenberg/cpp/src/barretenberg/vm2/constraining/avm_fixed_vk.hpp

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class AvmHardCodedVKAndHash {
1717
using FF = bb::curve::BN254::ScalarField;
1818

1919
// Precomputed VK hash (hash of all commitments below).
20-
static FF vk_hash() { return FF(uint256_t("0x183783fd7c3f269b595307224be99cf3773b781f8d1d59a305ce711101d43a60")); }
20+
static FF vk_hash() { return FF(uint256_t("0x0f0714f53e7fcf7ffb15cfb22b7a1614c65f01742706b0ca20eb80454eaf1e48")); }
2121

2222
static constexpr std::array<Commitment, NUM_PRECOMPUTED_ENTITIES> get_all()
2323
{
@@ -83,18 +83,15 @@ class AvmHardCodedVKAndHash {
8383
uint256_t(
8484
"0x06ea9cd6f2a50e2156f80beebc721d11d24821fd4b723932da48d8750300fbaa")), // precomputed_expected_tag_reg_1_
8585
Commitment(
86-
uint256_t("0x1cb1c6d46ddf9f7bd7a87a5e7dca5ef92c8a44669ab0cbc557a0fcb8331d0d8d"),
86+
uint256_t("0x034e06277dc6d6e4f2ddea6d71635693db1a2869d33b918f0f70efa0530ecaa6"),
8787
uint256_t(
88-
"0x281a3e4b96e4f595db502ba69acda314bc335957ae605af17423b0ff3d0528c3")), // precomputed_expected_tag_reg_2_
88+
"0x2d3e564f6e8885163d356daec0387132097e73dbf8e04475675b715151ce3cb9")), // precomputed_expected_tag_reg_2_
8989
Commitment(
9090
uint256_t("0x1a3c36c4933c956751e6ca5631077a9418cd0ba4ec29e965508eaf8bc1a7ffd4"),
9191
uint256_t(
9292
"0x1203bdd1aab5bfc5f3ed6abbefc30ab303770b847d022c1c9c0f8de202a76560")), // precomputed_expected_tag_reg_3_
9393
Commitment::infinity(), // precomputed_expected_tag_reg_4_
94-
Commitment(
95-
uint256_t("0x11b316123744c8602e394b9a558ed664a70d8a7e8f5a3138c9971302c193dd84"),
96-
uint256_t(
97-
"0x08a817c8ab332c7f8b478ec9bddb41a8ca1593c3b8fb85d6236d3eecc2df3b37")), // precomputed_expected_tag_reg_5_
94+
Commitment::infinity(), // precomputed_expected_tag_reg_5_
9895
Commitment(
9996
uint256_t("0x0000000000000000000000000000000000000000000000000000000000000001"),
10097
uint256_t(
@@ -103,9 +100,9 @@ class AvmHardCodedVKAndHash {
103100
uint256_t("0x14567e2c3e84fc1e3e69d81f6ce5808ca9a0451964a7bbabbd9e369db7556253"),
104101
uint256_t("0x0378926f150c30c760965df469ae6ed609c59feecf899f2b95aff519bbf3fb3c")), // precomputed_idx
105102
Commitment(
106-
uint256_t("0x1e497723c3f95466c480f1ac1addb1e0dc68bb123cae27ee70d00e6d6fcc6896"),
103+
uint256_t("0x2bef1e5de8c449d3cfa4cf9ab94e8b846755023b02e94dbbba1ffb3c73da0d1d"),
107104
uint256_t(
108-
"0x24c9a31064fb5f18c18ac3ea4be1a10809765a43b06bcea177fbb171dd547ced")), // precomputed_instr_size
105+
"0x06905ac3e0ae01f14b1bc598f9ba30af7eced70893019ca78b0e55668c38f3e0")), // precomputed_instr_size
109106
Commitment(
110107
uint256_t("0x11b710f896157a9557278a1f776cd6c7e1e7e256a572bd080797daaf1d6307d1"),
111108
uint256_t(
@@ -268,14 +265,8 @@ class AvmHardCodedVKAndHash {
268265
uint256_t("0x1530ccb47d1198320c163380a82ca8cbaf87b2d40ede856d21c60535e2251262"),
269266
uint256_t(
270267
"0x29dd7ccea05e6d47a7373ea950a7988caed0d20880612e046af575217a21652a")), // precomputed_sel_mem_op_reg_3_
271-
Commitment(
272-
uint256_t("0x11b316123744c8602e394b9a558ed664a70d8a7e8f5a3138c9971302c193dd84"),
273-
uint256_t(
274-
"0x08a817c8ab332c7f8b478ec9bddb41a8ca1593c3b8fb85d6236d3eecc2df3b37")), // precomputed_sel_mem_op_reg_4_
275-
Commitment(
276-
uint256_t("0x11b316123744c8602e394b9a558ed664a70d8a7e8f5a3138c9971302c193dd84"),
277-
uint256_t(
278-
"0x08a817c8ab332c7f8b478ec9bddb41a8ca1593c3b8fb85d6236d3eecc2df3b37")), // precomputed_sel_mem_op_reg_5_
268+
Commitment::infinity(), // precomputed_sel_mem_op_reg_4_
269+
Commitment::infinity(), // precomputed_sel_mem_op_reg_5_
279270
Commitment(
280271
uint256_t("0x089cdab4e8e8381977b093cb267a1b7c8c60f4466c39a99af1247e37fe56ebfe"),
281272
uint256_t(
@@ -296,10 +287,7 @@ class AvmHardCodedVKAndHash {
296287
uint256_t("0x0bf1970c2e92fee577ba15d063fa78fdd17752cafd19261ff0f176a1d3348769"),
297288
uint256_t(
298289
"0x21f1906edf2fe01e804774aa539abe8411cfda1731be99853f90253ed2652868")), // precomputed_sel_op_dc_0
299-
Commitment(
300-
uint256_t("0x2ad6f77a7f7c14780d95de8bd1f5b2146fe71fb1b7e6d55016734664f10d653b"),
301-
uint256_t(
302-
"0x131ac1fc680fbc2584b74e5aece1f0d50afe030adf4289613e54935339829496")), // precomputed_sel_op_dc_1
290+
Commitment::infinity(), // precomputed_sel_op_dc_1
303291
Commitment(
304292
uint256_t("0x225d208d9012b15a17b7dac26e737c0d2f9c8bf80de627bd13e1a9c042ede642"),
305293
uint256_t(
@@ -380,14 +368,8 @@ class AvmHardCodedVKAndHash {
380368
uint256_t("0x1530ccb47d1198320c163380a82ca8cbaf87b2d40ede856d21c60535e2251262"),
381369
uint256_t(
382370
"0x29dd7ccea05e6d47a7373ea950a7988caed0d20880612e046af575217a21652a")), // precomputed_sel_op_is_address_4_
383-
Commitment(
384-
uint256_t("0x11b316123744c8602e394b9a558ed664a70d8a7e8f5a3138c9971302c193dd84"),
385-
uint256_t(
386-
"0x08a817c8ab332c7f8b478ec9bddb41a8ca1593c3b8fb85d6236d3eecc2df3b37")), // precomputed_sel_op_is_address_5_
387-
Commitment(
388-
uint256_t("0x11b316123744c8602e394b9a558ed664a70d8a7e8f5a3138c9971302c193dd84"),
389-
uint256_t(
390-
"0x08a817c8ab332c7f8b478ec9bddb41a8ca1593c3b8fb85d6236d3eecc2df3b37")), // precomputed_sel_op_is_address_6_
371+
Commitment::infinity(), // precomputed_sel_op_is_address_5_
372+
Commitment::infinity(), // precomputed_sel_op_is_address_6_
391373
Commitment(
392374
uint256_t("0x1525ae740393f8dec3a1ea8f39f456861afece20561b5870db4291410d2f3429"),
393375
uint256_t(
@@ -436,14 +418,8 @@ class AvmHardCodedVKAndHash {
436418
uint256_t("0x1530ccb47d1198320c163380a82ca8cbaf87b2d40ede856d21c60535e2251262"),
437419
uint256_t(
438420
"0x29dd7ccea05e6d47a7373ea950a7988caed0d20880612e046af575217a21652a")), // precomputed_sel_tag_check_reg_3_
439-
Commitment(
440-
uint256_t("0x11b316123744c8602e394b9a558ed664a70d8a7e8f5a3138c9971302c193dd84"),
441-
uint256_t(
442-
"0x08a817c8ab332c7f8b478ec9bddb41a8ca1593c3b8fb85d6236d3eecc2df3b37")), // precomputed_sel_tag_check_reg_4_
443-
Commitment(
444-
uint256_t("0x11b316123744c8602e394b9a558ed664a70d8a7e8f5a3138c9971302c193dd84"),
445-
uint256_t(
446-
"0x08a817c8ab332c7f8b478ec9bddb41a8ca1593c3b8fb85d6236d3eecc2df3b37")), // precomputed_sel_tag_check_reg_5_
421+
Commitment::infinity(), // precomputed_sel_tag_check_reg_4_
422+
Commitment::infinity(), // precomputed_sel_tag_check_reg_5_
447423
Commitment(
448424
uint256_t("0x2b770f46bb0db9c1447e6010b3ca12f1dc2b2a237ff6d2390d9ddf5a056d09ad"),
449425
uint256_t(

barretenberg/cpp/src/barretenberg/vm2/constraining/relations/instr_fetching.test.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,7 @@ TEST(InstrFetchingConstrainingTest, EcaddWithTraceGen)
9696
Operand::from<uint16_t>(0x127a),
9797
Operand::from<uint16_t>(0x127b),
9898
Operand::from<uint16_t>(0x127c),
99-
Operand::from<uint16_t>(0x127d),
100-
Operand::from<uint16_t>(0x127e),
101-
Operand::from<uint16_t>(0x127f) },
99+
Operand::from<uint16_t>(0x127d), },
102100
};
103101

104102
std::vector<uint8_t> bytecode = ecadd_instruction.serialize();

barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.cpp

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,24 +1466,18 @@ void Execution::poseidon2_permutation(ContextInterface& context, MemoryAddress s
14661466
* @brief ECADD execution opcode handler: Perform an elliptic curve addition and
14671467
* write the result to the destination memory address.
14681468
*
1469-
* TODO(#AVM-266): Remove infinity flags from point representation.
1470-
*
14711469
* @param context The context.
14721470
* @param p_x_addr The resolved address of the x coordinate of the first point.
14731471
* @param p_y_addr The resolved address of the y coordinate of the first point.
1474-
* @param p_inf_addr The resolved address of the infinity flag of the first point.
14751472
* @param q_x_addr The resolved address of the x coordinate of the second point.
14761473
* @param q_y_addr The resolved address of the y coordinate of the second point.
1477-
* @param q_inf_addr The resolved address of the infinity flag of the second point.
14781474
* @param dst_addr The resolved address of the destination memory address.
14791475
*
14801476
* @throws RegisterValidationException if the tags of the input values do not match the expected tags:
14811477
* - tag of the memory value at p_x_addr is not FF.
14821478
* - tag of the memory value at p_y_addr is not FF.
1483-
* - tag of the memory value at p_inf_addr is not U1.
14841479
* - tag of the memory value at q_x_addr is not FF.
14851480
* - tag of the memory value at q_y_addr is not FF.
1486-
* - tag of the memory value at q_inf_addr is not U1.
14871481
* @throws OutOfGasException if the gas limit is exceeded.
14881482
* @throws OpcodeExecutionException if the elliptic curve addition operation fails:
14891483
* - memory write out of bounds.
@@ -1492,10 +1486,8 @@ void Execution::poseidon2_permutation(ContextInterface& context, MemoryAddress s
14921486
void Execution::ecc_add(ContextInterface& context,
14931487
MemoryAddress p_x_addr,
14941488
MemoryAddress p_y_addr,
1495-
MemoryAddress p_inf_addr,
14961489
MemoryAddress q_x_addr,
14971490
MemoryAddress q_y_addr,
1498-
MemoryAddress q_inf_addr,
14991491
MemoryAddress dst_addr)
15001492
{
15011493
BB_BENCH_NAME("Execution::ecc_add");
@@ -1505,26 +1497,17 @@ void Execution::ecc_add(ContextInterface& context,
15051497
// Read the points from memory.
15061498
const auto& p_x = memory.get(p_x_addr);
15071499
const auto& p_y = memory.get(p_y_addr);
1508-
// TODO(#AVM-266): Remove infinity flags from point representation, the below is currently ignored in-circuit.
1509-
const auto& p_inf = memory.get(p_inf_addr);
15101500

15111501
const auto& q_x = memory.get(q_x_addr);
15121502
const auto& q_y = memory.get(q_y_addr);
1513-
// TODO(#AVM-266): Remove infinity flags from point representation, the below is currently ignored in-circuit.
1514-
const auto& q_inf = memory.get(q_inf_addr);
15151503

1516-
set_and_validate_inputs(opcode, { p_x, p_y, p_inf, q_x, q_y, q_inf });
1504+
set_and_validate_inputs(opcode, { p_x, p_y, q_x, q_y });
15171505
get_gas_tracker().consume_gas();
15181506

15191507
// Once inputs are tag checked the conversion to EmbeddedCurvePoint is safe, on curve checks are done in the add
1520-
// method. TODO(#AVM-266): We derive is_infinity from coordinates using the Noir convention of (x=0, y=0) <==>
1521-
// is_infinity. The flag will be removed in future.
1522-
const FF p_x_ff = p_x.as_ff();
1523-
const FF p_y_ff = p_y.as_ff();
1524-
EmbeddedCurvePoint p = EmbeddedCurvePoint(p_x_ff, p_y_ff);
1525-
const FF q_x_ff = q_x.as_ff();
1526-
const FF q_y_ff = q_y.as_ff();
1527-
EmbeddedCurvePoint q = EmbeddedCurvePoint(q_x_ff, q_y_ff);
1508+
// method.
1509+
EmbeddedCurvePoint p = EmbeddedCurvePoint(p_x.as_ff(), p_y.as_ff());
1510+
EmbeddedCurvePoint q = EmbeddedCurvePoint(q_x.as_ff(), q_y.as_ff());
15281511

15291512
try {
15301513
embedded_curve.add(memory, p, q, dst_addr);

barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,8 @@ class Execution : public ExecutionInterface {
173173
void ecc_add(ContextInterface& context,
174174
MemoryAddress p_x_addr,
175175
MemoryAddress p_y_addr,
176-
MemoryAddress p_inf_addr,
177176
MemoryAddress q_x_addr,
178177
MemoryAddress q_y_addr,
179-
MemoryAddress q_inf_addr,
180178
MemoryAddress dst_addr);
181179
void to_radix_be(ContextInterface& context,
182180
MemoryAddress value_addr,

barretenberg/cpp/src/barretenberg/vm2/simulation/gadgets/execution.test.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,10 +1034,8 @@ TEST_F(ExecutionSimulationTest, EccAdd)
10341034
{
10351035
MemoryAddress p_x_addr = 10;
10361036
MemoryAddress p_y_addr = 15;
1037-
MemoryAddress p_is_inf_addr = 25;
10381037
MemoryAddress q_x_addr = 20;
10391038
MemoryAddress q_y_addr = 30;
1040-
MemoryAddress q_is_inf_addr = 35;
10411039
MemoryAddress dst_addr = 40;
10421040

10431041
MemoryValue p_x = MemoryValue::from<FF>(FF("0x04c95d1b26d63d46918a156cae92db1bcbc4072a27ec81dc82ea959abdbcf16a"));
@@ -1049,22 +1047,19 @@ TEST_F(ExecutionSimulationTest, EccAdd)
10491047
EmbeddedCurvePoint q(q_x.as_ff(), q_y.as_ff());
10501048

10511049
// Mock the context and memory interactions
1052-
MemoryValue zero = MemoryValue::from<uint1_t>(0);
10531050
EXPECT_CALL(context, get_memory()).WillRepeatedly(ReturnRef(memory));
10541051
EXPECT_CALL(Const(memory), get(p_x_addr)).WillOnce(ReturnRef(p_x));
10551052
EXPECT_CALL(memory, get(p_y_addr)).WillOnce(ReturnRef(p_y));
1056-
EXPECT_CALL(memory, get(p_is_inf_addr)).WillOnce(ReturnRef(zero)); // p is not infinity
10571053
EXPECT_CALL(memory, get(q_x_addr)).WillOnce(ReturnRef(q_x));
10581054
EXPECT_CALL(memory, get(q_y_addr)).WillOnce(ReturnRef(q_y));
1059-
EXPECT_CALL(memory, get(q_is_inf_addr)).WillOnce(ReturnRef(zero)); // q is not infinity
10601055

10611056
EXPECT_CALL(gas_tracker, consume_gas);
10621057

10631058
// Mock the ECC add operation
10641059
EXPECT_CALL(ecc, add(_, _, _, dst_addr));
10651060

10661061
// Execute the ECC add operation
1067-
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);
1062+
execution.ecc_add(context, p_x_addr, p_y_addr, q_x_addr, q_y_addr, dst_addr);
10681063
}
10691064

10701065
TEST_F(ExecutionSimulationTest, ToRadixBE)

barretenberg/cpp/src/barretenberg/vm2/simulation/lib/serialization.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,8 @@ const std::unordered_map<WireOpCode, std::vector<OperandType>>& get_wire_opcode_
188188
{ OperandType::INDIRECT16,
189189
OperandType::UINT16, // lhs.x
190190
OperandType::UINT16, // lhs.y
191-
OperandType::UINT16, // lhs.is_infinite
192191
OperandType::UINT16, // rhs.x
193192
OperandType::UINT16, // rhs.y
194-
OperandType::UINT16, // rhs.is_infinite
195193
OperandType::UINT16 } }, // dst_offset
196194
// Gadget - Conversion
197195
{ WireOpCode::TORADIXBE,

0 commit comments

Comments
 (0)