Skip to content

Commit 21e39fc

Browse files
committed
chore: docs, clear out old todos
1 parent 13babda commit 21e39fc

3 files changed

Lines changed: 52 additions & 69 deletions

File tree

barretenberg/cpp/pil/vm2/ecc.pil

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,11 @@
22
/**
33
* This subtrace supports point addition over the Grumpkin curve.
44
* Given two points, P & Q, this trace computes R = P + Q.
5-
* PRECONDITIONS: The only assumption here is that the inputs P & Q are points on the Grumpkin curve (note that the Point at Infinity = (0, 0) is considered on the curve):
6-
* Grumpkin Curve Eqn in SW form: Y^2 = X^3 − 17.
5+
* PRECONDITIONS: This trace assumes that the inputs P & Q are points on the Grumpkin curve and infinity points are correctly
6+
* flagged with p_is_inf and/or q_is_inf (note that the Point at Infinity = (0, 0) is considered on the curve):
7+
* Grumpkin Curve Eqn in SW form: Y^2 = X^3 − 17.
78
* Note: Grumpkin forms a 2-cycle with BN254, i.e the base field of one is the scalar field of the other and vice-versa.
89
*
9-
*
10-
* MW NOTE: USING APPROACH 1 BELOW:
11-
* Note that once TODO(#AVM-266) is complete, is_inf will no longer be part of our point representation and we must either:
12-
* - continue to rely on the 'calling' trace to inject a constrained is_inf, or
13-
* - derive is_inf (<==> (X, Y) == (INFINITY_X, INFINITY_Y)) within this trace.
14-
*
1510
* USAGE: This is a non-memory aware subtrace used to constrain point addition as defined above. Each point can be looked up
1611
* by coordinates (lookup as defined in ecc_mem.pil):
1712
* #[INPUT_OUTPUT_ECC_ADD]
@@ -29,8 +24,9 @@
2924
* ecc.r_x, ecc.r_y // Point R
3025
* };
3126
*
32-
* MW NOTE: For now, the calling trace MUST constrain that p_is_inf, q_is_inf above are correct. This is so if we have a calling
33-
* trace in which we know inf would never be an input we can simply use precomputed.zero and avoid wasting gates on deriving is_inf.
27+
* NOTE: For now, the calling trace MUST constrain that p_is_inf, q_is_inf above are correct. This is so if we have a calling
28+
* trace in which we know inf would never be an input we can simply use precomputed.zero and avoid wasting gates on deriving is_inf.
29+
* This follows the same logic for points being on the curve.
3430
*
3531
* TRACE SHAPE: 1 single row per computation (P + Q = R).
3632
*

barretenberg/cpp/pil/vm2/ecc_mem.pil

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,20 @@ include "gt.pil";
44
include "memory.pil";
55
include "precomputed.pil";
66

7-
// TODO(#AVM-266): documentation
8-
97
/**
108
* This handles the memory writes when the ECADD opcode is executed by user code.
119
* Given two points, P & Q, this trace constrains that both exist on the Grumpkin curve
1210
* and the claimed result point, R = P + Q, is written to memory addresses within range.
1311
* A point exists on the curve if it satisfies the curve equation (SW form: Y^2 = X^3 − 17)
14-
* or is the point at infinity, represented by (X, Y) = (0, 0).
12+
* or is the point at infinity, represented by (X, Y) = (INFINITY_X, INFINITY_Y) = (0, 0).
1513
* The reads of P and Q are handled by the registers in the execution trace. The correctness
1614
* of point addition is handled by the ECC subtrace.
1715
*
1816
* This trace writes the resulting embedded curve point to the addresses {dst,
19-
* dst + 1, and dst + 2 }. Embedded curve points consist of the tuple of types
20-
* {x: FF, y: FF, is_inf: U1 }.
17+
* dst + 1 }. Embedded curve points consist of the tuple of types {x: FF, y: FF }.
2118
*
22-
* PRECONDITIONS: Input point coordinates have tag checked FF coordinates and U1 is_inf
23-
* flag (see Memory I/O below for details).
19+
* PRECONDITIONS: Input point coordinates have tag checked FF coordinates (see Memory I/O
20+
* below for details).
2421
*
2522
* USAGE: Dispatching lookup defined in execution.pil:
2623
* #[DISPATCH_TO_ECC_ADD]
@@ -85,17 +82,13 @@ include "precomputed.pil";
8582
*
8683
* This subtrace is connected to the ECC subtrace via a lookup. ECC is used by other subtraces internally
8784
* (e.g. address derivation). Now that the is_inf flag has been removed from noir (noir-lang/noir/#11926/) we consider
88-
* a point to be infinity iff its coordinates are (0, 0); the noir standard representation.
85+
* a point to be infinity iff its coordinates are (0, 0); the noir standard representation (see relations #[P/Q_INF_X/Y_CHECK]).
8986
*
9087
* Note that the point at infinity, O, does not have valid coordinates (a property of SW curves like Grumpkin). We represent it
9188
* as (0, 0) but any (ecc.INFINITY_X, ecc.INFINITY_Y) not satisfying the curve equation will be correctly handled in this trace.
9289
*
93-
* For now, we simply ignore any is_inf flags coming from memory (assigning and not reading the placeholder is_inf_), but
94-
* will eventually remove it from the operands TODO(#AVM-266).
95-
*
96-
* MW NOTE: Still using p_is_inf, q_is_inf just as flags to tell ecc.pil how to treat the points.
97-
* Until #AVM-266, the ECC subtrace still requires a correctly constrained is_inf flag for each point. We derive it within
98-
* this circuit by enforcing (0, 0) <==> is_inf for input points P and Q:
90+
* The ECC subtrace requires a correctly constrained is_inf flag for each point. We derive it within this circuit by enforcing
91+
* (0, 0) <==> is_inf for input points P and Q:
9992
* - (0, 0) ==> is_inf by #[P/Q_ON_CURVE_CHECK] (zero coordinates will fail this relation unless is_inf is set correctly).
10093
* - is_inf ==> (0, 0) by #[P/Q_INF_X/Y_CHECK].
10194
* Resulting infinity points are guaranteed to be (0, 0) by the ECC subtrace (see #[OUTPUT_X_COORD] and #[OUTPUT_Y_COORD]).
@@ -185,9 +178,7 @@ namespace ecc_add_mem;
185178
pol commit sel_should_exec; // @boolean (by definition)
186179
sel_should_exec = sel * (1 - err);
187180

188-
// TODO(#AVM-266): For now, we ensure that the flag being set means that the coordinates are set to our infinity
189-
// representation: (INFINITY_X, INFINITY_Y) = (0, 0). The reverse ((INFINITY_X, INFINITY_Y) ==> is_inf)
190-
// is constrained by #[P/Q_ON_CURVE_CHECK]. Output infinities are already constrained to be (0, 0) in the subtrace.
181+
// Constrains that the infinity flags required for the ecc trace have been set correctly:
191182
#[P_INF_X_CHECK]
192183
sel * p_is_inf * (p_x - ecc.INFINITY_X) = 0;
193184
#[P_INF_Y_CHECK]

barretenberg/cpp/src/barretenberg/vm2/tracegen/ecc_trace.cpp

Lines changed: 38 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void EccTraceBuilder::process_add(const simulation::EventEmitterInterface<simula
149149

150150
// Witness for add operation
151151
{ C::ecc_add_op, add_predicate },
152-
// This is a witness for the result(r) being the point at infinity.
152+
// This is a witness for the result (r) being the point at infinity.
153153
{ C::ecc_result_infinity, result_is_infinity },
154154
// The computed 'slope' between points P and Q.
155155
{ C::ecc_lambda, lambda },
@@ -252,8 +252,6 @@ void EccTraceBuilder::process_scalar_mul(
252252
* @brief Process the ECC add memory events and populate the relevant columns in the trace.
253253
* Corresponds to the memory aware subtrace ecc_mem.pil.
254254
*
255-
* TODO(#AVM-266): Remove is_infinity flag from point representation.
256-
*
257255
* @param events The container of ECC add memory events to process.
258256
* @param trace The trace container.
259257
*/
@@ -273,9 +271,9 @@ void EccTraceBuilder::process_add_with_memory(
273271
// If there is no error, the trace constrains the correctness of the add result R with the ecc subtrace (see
274272
// process_add) via separate add events and the memory reads of the input points with the execution trace's
275273
// #[DISPATCH_TO_ECC_ADD]. The writes are handled in the trace with a permutation to memory (see #[WRITE_MEM_i]
276-
// and interactions perm_ecc_mem_write_mem_i for i = 0, 1, 2).
274+
// and interactions perm_ecc_mem_write_mem_i for i = 0, 1).
277275

278-
// If there is an error, the event has an empty result point (0, 0, false), the add/write lookups/permutations are
276+
// If there is an error, the event has an empty result point (0, 0), the add/write lookups/permutations are
279277
// skipped, and the error flag is set to 1. This flag is checked against sel_opcode_error in #[DISPATCH_TO_ECC_ADD].
280278
for (const auto& event : events) {
281279
// Address cast to uint64_t to capture possible overflow.
@@ -297,43 +295,41 @@ void EccTraceBuilder::process_add_with_memory(
297295

298296
bool error = dst_out_of_range_err || !p_is_on_curve || !q_is_on_curve;
299297

300-
trace.set(
301-
row,
302-
{ {
303-
{ C::ecc_add_mem_sel, 1 },
304-
{ C::ecc_add_mem_execution_clk, event.execution_clk },
305-
{ C::ecc_add_mem_space_id, event.space_id },
306-
// Error handling - dst out of range
307-
{ C::ecc_add_mem_max_mem_addr, AVM_HIGHEST_MEM_ADDRESS },
308-
{ C::ecc_add_mem_sel_dst_out_of_range_err, dst_out_of_range_err ? 1 : 0 },
309-
// Error handling - p is not on curve
310-
{ C::ecc_add_mem_sel_p_not_on_curve_err, !p_is_on_curve ? 1 : 0 },
311-
{ C::ecc_add_mem_p_is_on_curve_eqn, p_is_on_curve_eqn },
312-
{ C::ecc_add_mem_p_is_on_curve_eqn_inv, p_is_on_curve_eqn_inv },
313-
// Error handling - q is not on curve
314-
{ C::ecc_add_mem_sel_q_not_on_curve_err, !q_is_on_curve ? 1 : 0 },
315-
{ C::ecc_add_mem_q_is_on_curve_eqn, q_is_on_curve_eqn },
316-
{ C::ecc_add_mem_q_is_on_curve_eqn_inv, q_is_on_curve_eqn_inv },
317-
// Consolidated error
318-
{ C::ecc_add_mem_err, error ? 1 : 0 },
319-
// Memory Writes
320-
{ C::ecc_add_mem_dst_addr_0_, dst_addr },
321-
{ C::ecc_add_mem_dst_addr_1_, dst_addr + 1 },
322-
// Input - Point P
323-
{ C::ecc_add_mem_p_x, event.p.x() },
324-
{ C::ecc_add_mem_p_y, event.p.y() },
325-
{ C::ecc_add_mem_p_is_inf,
326-
event.p.is_infinity() ? 1 : 0 }, // TODO(#AVM-266): If committed, Will be p.x() == 0 && p.y() == 0
327-
// Input - Point Q
328-
{ C::ecc_add_mem_q_x, event.q.x() },
329-
{ C::ecc_add_mem_q_y, event.q.y() },
330-
{ C::ecc_add_mem_q_is_inf,
331-
event.q.is_infinity() ? 1 : 0 }, // TODO(#AVM-266): If committed, Will be q.x() == 0 && q.y() == 0
332-
// Output
333-
{ C::ecc_add_mem_sel_should_exec, error ? 0 : 1 },
334-
{ C::ecc_add_mem_res_x, event.result.x() },
335-
{ C::ecc_add_mem_res_y, event.result.y() },
336-
} });
298+
trace.set(row,
299+
{ {
300+
{ C::ecc_add_mem_sel, 1 },
301+
{ C::ecc_add_mem_execution_clk, event.execution_clk },
302+
{ C::ecc_add_mem_space_id, event.space_id },
303+
// Error handling - dst out of range
304+
{ C::ecc_add_mem_max_mem_addr, AVM_HIGHEST_MEM_ADDRESS },
305+
{ C::ecc_add_mem_sel_dst_out_of_range_err, dst_out_of_range_err ? 1 : 0 },
306+
// Error handling - p is not on curve
307+
{ C::ecc_add_mem_sel_p_not_on_curve_err, !p_is_on_curve ? 1 : 0 },
308+
{ C::ecc_add_mem_p_is_on_curve_eqn, p_is_on_curve_eqn },
309+
{ C::ecc_add_mem_p_is_on_curve_eqn_inv, p_is_on_curve_eqn_inv },
310+
// Error handling - q is not on curve
311+
{ C::ecc_add_mem_sel_q_not_on_curve_err, !q_is_on_curve ? 1 : 0 },
312+
{ C::ecc_add_mem_q_is_on_curve_eqn, q_is_on_curve_eqn },
313+
{ C::ecc_add_mem_q_is_on_curve_eqn_inv, q_is_on_curve_eqn_inv },
314+
// Consolidated error
315+
{ C::ecc_add_mem_err, error ? 1 : 0 },
316+
// Memory Writes
317+
{ C::ecc_add_mem_dst_addr_0_, dst_addr },
318+
{ C::ecc_add_mem_dst_addr_1_, dst_addr + 1 },
319+
// Input - Point P
320+
{ C::ecc_add_mem_p_x, event.p.x() },
321+
{ C::ecc_add_mem_p_y, event.p.y() },
322+
// Input - Point Q
323+
{ C::ecc_add_mem_q_x, event.q.x() },
324+
{ C::ecc_add_mem_q_y, event.q.y() },
325+
// Input - Infinity flags required for ECC trace
326+
{ C::ecc_add_mem_p_is_inf, event.p.is_infinity() ? 1 : 0 },
327+
{ C::ecc_add_mem_q_is_inf, event.q.is_infinity() ? 1 : 0 },
328+
// Output
329+
{ C::ecc_add_mem_sel_should_exec, error ? 0 : 1 },
330+
{ C::ecc_add_mem_res_x, event.result.x() },
331+
{ C::ecc_add_mem_res_y, event.result.y() },
332+
} });
337333

338334
row++;
339335
}

0 commit comments

Comments
 (0)