Skip to content

Commit 0eec5d9

Browse files
authored
Merge pull request #573 from AztecProtocol/ir/fix-unsourced-forged-writes
fix(avm)!: comments and leftover columns
2 parents aad115c + 6973df4 commit 0eec5d9

17 files changed

Lines changed: 143 additions & 184 deletions

File tree

barretenberg/cpp/pil/vm2/bytecode/instr_fetching.pil

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ include "../precomputed.pil";
3131
* The operands' encoding is determined per opcode by the WIRE_INSTRUCTION_SPEC in precomputed.pil.
3232
* This specification provides: exec_opcode, instr_size, operand decomposition selectors (sel_op_dc_0..16)
3333
* and tag metadata (sel_has_tag, sel_tag_is_op2). We use the decomposition selectors to transform the
34-
* fetched bytecode bytes (bd0..36) into the operands (addressing_mode, op1..7)).
34+
* fetched bytecode bytes (bd0..36) into the operands (addressing_mode, op1..5).
3535
*
3636
* The remaining work of this trace uses other specification data to handle errors (see ERROR HANDLING).
3737
*
@@ -57,13 +57,13 @@ include "../precomputed.pil";
5757
* sel_instruction_fetching_success {
5858
* pc, bytecode_id, exec_opcode,
5959
* instr_size, addressing_mode,
60-
* op[0], op[1], op[2], op[3], op[4],
61-
op[5], op[6]
60+
* op[0], op[1], op[2],
61+
* op[3], op[4]
6262
* } in instr_fetching.sel {
6363
* instr_fetching.pc, instr_fetching.bytecode_id, instr_fetching.exec_opcode,
6464
* instr_fetching.instr_size, instr_fetching.addressing_mode,
65-
* instr_fetching.op1, instr_fetching.op2, instr_fetching.op3, instr_fetching.op4,
66-
* instr_fetching.op5
65+
* instr_fetching.op1, instr_fetching.op2, instr_fetching.op3,
66+
* instr_fetching.op4, instr_fetching.op5
6767
* };
6868
*
6969
* ERROR HANDLING:

barretenberg/cpp/pil/vm2/execution/addressing.pil

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ include "../gt.pil";
1010
// (permutation/lookup).
1111

1212
// This gadget constrains the resolution of the operands from instruction fetching.
13-
// The input operands are op[0], ..., op[6] (from execution.pil).
14-
// The output operands are rop[0], ..., rop[6] (from execution.pil).
13+
// The input operands are op[0], ..., op[4] (from execution.pil).
14+
// The output operands are rop[0], ..., rop[4] (from execution.pil).
1515
// We guarantee that the resolved operands are either immediates or valid addresses.
1616

1717
// Inputs (from execution.pil):
1818
// - SEL_RESOLVE_ADDRESS (alias for sel_instruction_fetching_success)
19-
// - sel_op_is_address[7] (via exec spec; derived from ExecInstructionSpec.num_addresses)
19+
// - sel_op_is_address[5] (via exec spec; derived from ExecInstructionSpec.num_addresses)
2020
// - addressing_mode (via instruction fetching)
21-
// - op[7] (via instruction fetching)
21+
// - op[5] (via instruction fetching)
2222
// Outputs (to execution.pil):
2323
// - sel_addressing_error
24-
// - rop[7]
24+
// - rop[5]
2525

2626
// Errors:
2727
// - sel_base_address_failure: the base address is invalid
@@ -253,7 +253,7 @@ sel_op_do_overflow_check[4] { op_after_relative[4], highest_address, sel_relativ
253253

254254
// Whether a given operand should be indirection-resolved.
255255
// We only do this if the indirect bit is set AND nothing else failed so far (for this operand).
256-
// Recall that from #[NOT_RELATIVE_OR_BASE_FAILURE_NO_OVERFLOW_i] (i = 0, ..., 6), we have:
256+
// Recall that from #[NOT_RELATIVE_OR_BASE_FAILURE_NO_OVERFLOW_i] (i = 0, ..., 4), we have:
257257
// `sel_base_address_failure == 1` ==> `sel_relative_overflow[i] == 0` and therefore they are mutually exclusive.
258258
pol commit sel_apply_indirection[5]; // @boolean (from definition and above remark)
259259
#[INDIRECT_GATING_0]

barretenberg/cpp/pil/vm2/execution/registers.pil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace execution;
1010
// pol commit rw_reg[6]; // Read / Write (only if sel_mem_op_reg[i] = 1)
1111
// pol commit sel_tag_check_reg[6]; // Tag check (only for read)
1212
// pol commit expected_tag_reg[6]; // Expected tag (only if sel_tag_check_reg[i] = 1)
13-
// pol commit rop[6]; // Resolved operands (for read/write), always addresses here.
13+
// pol commit rop[5]; // Resolved operands (for read/write), always addresses here.
1414
//
1515
// Inputs for write, Outputs for read:
1616
// pol commit register[6];

barretenberg/cpp/pil/vm2/memory.pil

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,24 +110,21 @@ sel = 0;
110110

111111
// Permutation selectors (execution/addressing.pil).
112112
pol commit sel_addressing_base; // @boolean
113-
pol commit sel_addressing_indirect[7]; // @boolean
113+
pol commit sel_addressing_indirect[5]; // @boolean
114114
sel_addressing_base * (1 - sel_addressing_base) = 0;
115115
sel_addressing_indirect[0] * (1 - sel_addressing_indirect[0]) = 0;
116116
sel_addressing_indirect[1] * (1 - sel_addressing_indirect[1]) = 0;
117117
sel_addressing_indirect[2] * (1 - sel_addressing_indirect[2]) = 0;
118118
sel_addressing_indirect[3] * (1 - sel_addressing_indirect[3]) = 0;
119119
sel_addressing_indirect[4] * (1 - sel_addressing_indirect[4]) = 0;
120-
sel_addressing_indirect[5] * (1 - sel_addressing_indirect[5]) = 0;
121-
sel_addressing_indirect[6] * (1 - sel_addressing_indirect[6]) = 0;
122120

123121
// Permutation selectors (execution/registers.pil)
124-
pol commit sel_register_op[6]; // @boolean
122+
pol commit sel_register_op[5]; // @boolean
125123
sel_register_op[0] * (1 - sel_register_op[0]) = 0;
126124
sel_register_op[1] * (1 - sel_register_op[1]) = 0;
127125
sel_register_op[2] * (1 - sel_register_op[2]) = 0;
128126
sel_register_op[3] * (1 - sel_register_op[3]) = 0;
129127
sel_register_op[4] * (1 - sel_register_op[4]) = 0;
130-
sel_register_op[5] * (1 - sel_register_op[5]) = 0;
131128

132129
// Permutation selectors (data_copy.pil).
133130
pol commit sel_data_copy_read; // @boolean
@@ -189,10 +186,9 @@ sel_to_radix_write * (1 - sel_to_radix_write) = 0;
189186
sel = // Addressing.
190187
sel_addressing_base
191188
+ sel_addressing_indirect[0] + sel_addressing_indirect[1] + sel_addressing_indirect[2] + sel_addressing_indirect[3]
192-
+ sel_addressing_indirect[4] + sel_addressing_indirect[5] + sel_addressing_indirect[6]
189+
+ sel_addressing_indirect[4]
193190
// Registers.
194191
+ sel_register_op[0] + sel_register_op[1] + sel_register_op[2] + sel_register_op[3] + sel_register_op[4]
195-
+ sel_register_op[5]
196192
// Data Copy.
197193
+ sel_data_copy_read
198194
+ sel_data_copy_write

barretenberg/cpp/pil/vm2/precomputed.pil

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,17 +297,17 @@ pol constant p_decomposition_limb;
297297
// ===== Section 9: Execution instruction spec (EXECUTION_INSTRUCTION_SPEC) =====
298298
// Each valid row encodes: gas costs (L2 opcode, base DA, dynamic L2, dynamic DA),
299299
// per-register flags (memory access, read/write, tag check, expected tag) for 6 registers,
300-
// subtrace/gadget dispatch IDs, dynamic gas ID, and address-operand flags for 7 operands.
300+
// subtrace/gadget dispatch IDs, dynamic gas ID, and address-operand flags for 5 operands.
301301
// Used by the execution subtrace to dispatch and constrain instruction behavior.
302302
//
303303
// Example trace (idx encodes the ExecutionOpCode; array columns use [a,b,...] notation):
304304
//
305-
// idx | sel_exec_spec | opcode_gas | base_da | dyn_l2 | dyn_da | mem_op[0..5] | rw[0..5] | subtrace_id | sub_op_id | dyn_gas_id | is_addr[0..6]
305+
// idx | sel_exec_spec | opcode_gas | base_da | dyn_l2 | dyn_da | mem_op[0..5] | rw[0..5] | subtrace_id | sub_op_id | dyn_gas_id | is_addr[0..4]
306306
// -----------------+---------------+------------+---------+--------+--------+--------------------+--------------------+-------------+-----------+------------+----------------------
307-
// 0 (ADD) | 1 | 12 | 0 | 0 | 0 | [1,1,1,0,0,0] | [0,0,1,0,0,0] | 1 | 1 | 0 | [1,1,1,0,0,0,0]
308-
// 1 (SUB) | 1 | 12 | 0 | 0 | 0 | [1,1,1,0,0,0] | [0,0,1,0,0,0] | 1 | 2 | 0 | [1,1,1,0,0,0,0]
307+
// 0 (ADD) | 1 | 12 | 0 | 0 | 0 | [1,1,1,0,0,0] | [0,0,1,0,0,0] | 1 | 1 | 0 | [1,1,1,0,0]
308+
// 1 (SUB) | 1 | 12 | 0 | 0 | 0 | [1,1,1,0,0,0] | [0,0,1,0,0,0] | 1 | 2 | 0 | [1,1,1,0,0]
309309
// ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ...
310-
// 45 (TORADIXBE) | 1 | 24 | 0 | 3 | 0 | [1,1,1,1,0,0] | [0,0,0,0,0,0] | 13 | 0 | 4 | [1,1,1,1,1,0,0]
310+
// 45 (TORADIXBE) | 1 | 24 | 0 | 3 | 0 | [1,1,1,1,0,0] | [0,0,0,0,0,0] | 13 | 0 | 4 | [1,1,1,1,1]
311311

312312
pol constant sel_exec_spec;
313313
// Gas Costs
@@ -348,9 +348,9 @@ pol constant sel_op_is_address[5];
348348
// 1 | 1 | 3 (operand 0 indirect)
349349
// 3 | 1 | 9 (operand 0 indirect + relative)
350350
// ... | 1 | ...
351-
// 4095 | 1 | 39 (operands 0-5 indirect + relative)
351+
// 1023 | 1 | 33 (operands 0-4 indirect + relative; this is the max gas value for addressing)
352352
// ... | 1 | ...
353-
// 65535 | 1 | 45 (all 7 operands indirect + relative)
353+
// 65535 | 1 | 33 (all bits above operand 4 are ignored, see addressing.pil for why this table still needs to be 16-bits)
354354

355355
pol constant sel_addressing_gas;
356356
pol constant addressing_gas;

barretenberg/cpp/src/barretenberg/aztec/aztec_constants.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179
#define AVM_PUBLIC_INPUTS_COLUMN_2_LENGTH 522
180180
#define AVM_PUBLIC_INPUTS_COLUMN_3_LENGTH 99
181181
#define AVM_PUBLIC_INPUTS_COLUMNS_COMBINED_LENGTH 9989
182-
#define AVM_V2_PROOF_LENGTH_IN_FIELDS 15383
182+
#define AVM_V2_PROOF_LENGTH_IN_FIELDS 15368
183183
#define TX_DA_GAS_OVERHEAD 96
184184
#define PUBLIC_TX_L2_GAS_OVERHEAD 540000
185185
#define AVM_MAX_PROCESSABLE_L2_GAS 6000000

barretenberg/cpp/src/barretenberg/vm2/constraining/recursion/two_layer_avm_recursive_verifier.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
namespace bb::avm2 {
2525

26-
static constexpr size_t NUM_AVM_ULTRA_OPS = 3085;
26+
static constexpr size_t NUM_AVM_ULTRA_OPS = 3082;
2727
static_assert(2 * NUM_AVM_ULTRA_OPS < (1 << CONST_TRANSLATOR_MINI_CIRCUIT_LOG_SIZE) - NUM_DISABLED_ROWS_IN_SUMCHECK,
2828
"AVM ultra ops land in the range reserved for randomness in the Translator mini circuit. If this "
2929
"assertion fails, we need to increase CONST_TRANSLATOR_MINI_CIRCUIT_LOG_SIZE.");

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ TEST(AddressingConstrainingTest, RelativeOverflowCheck)
325325
{ C::execution_sel_op_is_relative_wire_0_, 1 },
326326
{ C::execution_sel_op_is_relative_wire_2_, 1 },
327327
{ C::execution_sel_op_is_relative_wire_4_, 1 },
328-
{ C::execution_sel_op_is_relative_wire_6_, 1 },
329328
{ C::execution_sel_op_is_address_0_, 1 },
330329
{ C::execution_sel_op_is_address_2_, 1 },
331330
{ C::execution_sel_op_is_address_4_, 1 },
@@ -350,7 +349,7 @@ TEST(AddressingConstrainingTest, RelativeOverflowCheck)
350349
});
351350

352351
// GT trace.
353-
for (uint32_t i = 0; i < 7; i++) {
352+
for (uint32_t i = 0; i < AVM_MAX_OPERANDS; i++) {
354353
trace.set(C::gt_sel, i, 1);
355354
trace.set(C::gt_input_a, i, resolved_addrs[i]);
356355
trace.set(C::gt_input_b, i, AVM_HIGHEST_MEM_ADDRESS);

barretenberg/cpp/src/barretenberg/vm2/generated/columns.hpp

Lines changed: 5 additions & 5 deletions
Large diffs are not rendered by default.

barretenberg/cpp/src/barretenberg/vm2/generated/flavor_variables.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ namespace bb::avm2 {
141141

142142
struct AvmFlavorVariables {
143143
static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 117;
144-
static constexpr size_t NUM_WITNESS_ENTITIES = 2925;
144+
static constexpr size_t NUM_WITNESS_ENTITIES = 2922;
145145
static constexpr size_t NUM_SHIFTED_ENTITIES = 364;
146-
static constexpr size_t NUM_WIRES = 2488;
147-
static constexpr size_t NUM_ALL_ENTITIES = 3406;
146+
static constexpr size_t NUM_WIRES = 2485;
147+
static constexpr size_t NUM_ALL_ENTITIES = 3403;
148148

149149
// Need to be templated for recursive verifier
150150
template <typename FF_>

0 commit comments

Comments
 (0)