Skip to content

Commit 1d51a07

Browse files
authored
feat: merge-train/avm (#17097)
BEGIN_COMMIT_OVERRIDE chore(avm)!: skippable review (#17065) feat(avm)!: add protocol contract root to pub inputs (#17078) END_COMMIT_OVERRIDE
2 parents 886c1f9 + 20c395d commit 1d51a07

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1731
-1400
lines changed

barretenberg/cpp/pil/vm2/bitwise.pil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ sel * (1 - sel) = 0;
4848

4949
// No relations will be checked if this identity is satisfied.
5050
#[skippable_if]
51-
sel + last = 0; // They are both boolean so it corresponds to sel == 0 AND last == 0.
51+
sel = 0;
5252

5353
pol commit start; // Identifies when we want to capture the output to the main trace.
5454
// Must be constrained as a boolean as any selector used in a lookup/permutation.

barretenberg/cpp/pil/vm2/constants_gen.pil

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -102,51 +102,52 @@ namespace constants;
102102
pol AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_COINBASE_ROW_IDX = 5;
103103
pol AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_FEE_RECIPIENT_ROW_IDX = 6;
104104
pol AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_GAS_FEES_ROW_IDX = 7;
105-
pol AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_ROW_IDX = 8;
106-
pol AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_L1_TO_L2_MESSAGE_TREE_ROW_IDX = 8;
107-
pol AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_NOTE_HASH_TREE_ROW_IDX = 9;
108-
pol AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_NULLIFIER_TREE_ROW_IDX = 10;
109-
pol AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_PUBLIC_DATA_TREE_ROW_IDX = 11;
110-
pol AVM_PUBLIC_INPUTS_START_GAS_USED_ROW_IDX = 12;
111-
pol AVM_PUBLIC_INPUTS_GAS_SETTINGS_ROW_IDX = 13;
112-
pol AVM_PUBLIC_INPUTS_GAS_SETTINGS_GAS_LIMITS_ROW_IDX = 13;
113-
pol AVM_PUBLIC_INPUTS_GAS_SETTINGS_TEARDOWN_GAS_LIMITS_ROW_IDX = 14;
114-
pol AVM_PUBLIC_INPUTS_FEE_PAYER_ROW_IDX = 18;
115-
pol AVM_PUBLIC_INPUTS_PUBLIC_SETUP_CALL_REQUESTS_ROW_IDX = 22;
116-
pol AVM_PUBLIC_INPUTS_PUBLIC_APP_LOGIC_CALL_REQUESTS_ROW_IDX = 54;
117-
pol AVM_PUBLIC_INPUTS_PUBLIC_TEARDOWN_CALL_REQUEST_ROW_IDX = 86;
118-
pol AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_ARRAY_LENGTHS_ROW_IDX = 87;
119-
pol AVM_PUBLIC_INPUTS_PREVIOUS_REVERTIBLE_ACCUMULATED_DATA_ARRAY_LENGTHS_ROW_IDX = 90;
120-
pol AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_ROW_IDX = 93;
121-
pol AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_NOTE_HASHES_ROW_IDX = 93;
122-
pol AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_NULLIFIERS_ROW_IDX = 157;
123-
pol AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_L2_TO_L1_MSGS_ROW_IDX = 221;
124-
pol AVM_PUBLIC_INPUTS_PREVIOUS_REVERTIBLE_ACCUMULATED_DATA_ROW_IDX = 229;
125-
pol AVM_PUBLIC_INPUTS_PREVIOUS_REVERTIBLE_ACCUMULATED_DATA_NOTE_HASHES_ROW_IDX = 229;
126-
pol AVM_PUBLIC_INPUTS_PREVIOUS_REVERTIBLE_ACCUMULATED_DATA_NULLIFIERS_ROW_IDX = 293;
127-
pol AVM_PUBLIC_INPUTS_PREVIOUS_REVERTIBLE_ACCUMULATED_DATA_L2_TO_L1_MSGS_ROW_IDX = 357;
128-
pol AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_ROW_IDX = 365;
129-
pol AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_L1_TO_L2_MESSAGE_TREE_ROW_IDX = 365;
130-
pol AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_NOTE_HASH_TREE_ROW_IDX = 366;
131-
pol AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_NULLIFIER_TREE_ROW_IDX = 367;
132-
pol AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_PUBLIC_DATA_TREE_ROW_IDX = 368;
133-
pol AVM_PUBLIC_INPUTS_END_GAS_USED_ROW_IDX = 369;
134-
pol AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_NOTE_HASHES_ROW_IDX = 370;
135-
pol AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_NULLIFIERS_ROW_IDX = 371;
136-
pol AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_L2_TO_L1_MSGS_ROW_IDX = 372;
137-
pol AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_PUBLIC_LOGS_ROW_IDX = 373;
138-
pol AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_PUBLIC_DATA_WRITES_ROW_IDX = 374;
139-
pol AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ROW_IDX = 375;
140-
pol AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_NOTE_HASHES_ROW_IDX = 375;
141-
pol AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_NULLIFIERS_ROW_IDX = 439;
142-
pol AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_L2_TO_L1_MSGS_ROW_IDX = 503;
143-
pol AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_PUBLIC_LOGS_ROW_IDX = 511;
144-
pol AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_PUBLIC_DATA_WRITES_ROW_IDX = 615;
145-
pol AVM_PUBLIC_INPUTS_TRANSACTION_FEE_ROW_IDX = 679;
146-
pol AVM_PUBLIC_INPUTS_REVERTED_ROW_IDX = 680;
147-
pol AVM_PUBLIC_INPUTS_COLUMNS_MAX_LENGTH = 681;
105+
pol AVM_PUBLIC_INPUTS_PROTOCOL_CONTRACT_TREE_ROOT = 8;
106+
pol AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_ROW_IDX = 9;
107+
pol AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_L1_TO_L2_MESSAGE_TREE_ROW_IDX = 9;
108+
pol AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_NOTE_HASH_TREE_ROW_IDX = 10;
109+
pol AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_NULLIFIER_TREE_ROW_IDX = 11;
110+
pol AVM_PUBLIC_INPUTS_START_TREE_SNAPSHOTS_PUBLIC_DATA_TREE_ROW_IDX = 12;
111+
pol AVM_PUBLIC_INPUTS_START_GAS_USED_ROW_IDX = 13;
112+
pol AVM_PUBLIC_INPUTS_GAS_SETTINGS_ROW_IDX = 14;
113+
pol AVM_PUBLIC_INPUTS_GAS_SETTINGS_GAS_LIMITS_ROW_IDX = 14;
114+
pol AVM_PUBLIC_INPUTS_GAS_SETTINGS_TEARDOWN_GAS_LIMITS_ROW_IDX = 15;
115+
pol AVM_PUBLIC_INPUTS_FEE_PAYER_ROW_IDX = 19;
116+
pol AVM_PUBLIC_INPUTS_PUBLIC_SETUP_CALL_REQUESTS_ROW_IDX = 23;
117+
pol AVM_PUBLIC_INPUTS_PUBLIC_APP_LOGIC_CALL_REQUESTS_ROW_IDX = 55;
118+
pol AVM_PUBLIC_INPUTS_PUBLIC_TEARDOWN_CALL_REQUEST_ROW_IDX = 87;
119+
pol AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_ARRAY_LENGTHS_ROW_IDX = 88;
120+
pol AVM_PUBLIC_INPUTS_PREVIOUS_REVERTIBLE_ACCUMULATED_DATA_ARRAY_LENGTHS_ROW_IDX = 91;
121+
pol AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_ROW_IDX = 94;
122+
pol AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_NOTE_HASHES_ROW_IDX = 94;
123+
pol AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_NULLIFIERS_ROW_IDX = 158;
124+
pol AVM_PUBLIC_INPUTS_PREVIOUS_NON_REVERTIBLE_ACCUMULATED_DATA_L2_TO_L1_MSGS_ROW_IDX = 222;
125+
pol AVM_PUBLIC_INPUTS_PREVIOUS_REVERTIBLE_ACCUMULATED_DATA_ROW_IDX = 230;
126+
pol AVM_PUBLIC_INPUTS_PREVIOUS_REVERTIBLE_ACCUMULATED_DATA_NOTE_HASHES_ROW_IDX = 230;
127+
pol AVM_PUBLIC_INPUTS_PREVIOUS_REVERTIBLE_ACCUMULATED_DATA_NULLIFIERS_ROW_IDX = 294;
128+
pol AVM_PUBLIC_INPUTS_PREVIOUS_REVERTIBLE_ACCUMULATED_DATA_L2_TO_L1_MSGS_ROW_IDX = 358;
129+
pol AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_ROW_IDX = 366;
130+
pol AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_L1_TO_L2_MESSAGE_TREE_ROW_IDX = 366;
131+
pol AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_NOTE_HASH_TREE_ROW_IDX = 367;
132+
pol AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_NULLIFIER_TREE_ROW_IDX = 368;
133+
pol AVM_PUBLIC_INPUTS_END_TREE_SNAPSHOTS_PUBLIC_DATA_TREE_ROW_IDX = 369;
134+
pol AVM_PUBLIC_INPUTS_END_GAS_USED_ROW_IDX = 370;
135+
pol AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_NOTE_HASHES_ROW_IDX = 371;
136+
pol AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_NULLIFIERS_ROW_IDX = 372;
137+
pol AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_L2_TO_L1_MSGS_ROW_IDX = 373;
138+
pol AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_PUBLIC_LOGS_ROW_IDX = 374;
139+
pol AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ARRAY_LENGTHS_PUBLIC_DATA_WRITES_ROW_IDX = 375;
140+
pol AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_ROW_IDX = 376;
141+
pol AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_NOTE_HASHES_ROW_IDX = 376;
142+
pol AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_NULLIFIERS_ROW_IDX = 440;
143+
pol AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_L2_TO_L1_MSGS_ROW_IDX = 504;
144+
pol AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_PUBLIC_LOGS_ROW_IDX = 512;
145+
pol AVM_PUBLIC_INPUTS_AVM_ACCUMULATED_DATA_PUBLIC_DATA_WRITES_ROW_IDX = 616;
146+
pol AVM_PUBLIC_INPUTS_TRANSACTION_FEE_ROW_IDX = 680;
147+
pol AVM_PUBLIC_INPUTS_REVERTED_ROW_IDX = 681;
148+
pol AVM_PUBLIC_INPUTS_COLUMNS_MAX_LENGTH = 682;
148149
pol AVM_NUM_PUBLIC_INPUT_COLUMNS = 4;
149-
pol AVM_PUBLIC_INPUTS_COLUMNS_COMBINED_LENGTH = 2724;
150+
pol AVM_PUBLIC_INPUTS_COLUMNS_COMBINED_LENGTH = 2728;
150151
pol AVM_PC_SIZE_IN_BITS = 32;
151152
pol AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_HEIGHT = 6;
152153
pol AVM_WRITTEN_PUBLIC_DATA_SLOTS_TREE_INITIAL_ROOT = 18291678969210913367302010540259942201271604198321103848479209155223586227821;

barretenberg/cpp/pil/vm2/docs/skippable.md

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
## Introduction
44

5-
For each sub-trace defined in a .pil file, one can optionally add so-called "skippable" condition which allows to improve performance on prover side whenever the "skippable" condition is satisfied. It basically skips some accumulation computation in sumcheck protocol to all sub-relations pertaining to the sub-trace. More on how to define a valid "skippable" condition in the next section. We emphasize that the "skippable" mechanism does not change the behavior of the verifier and therefore does not present any security risk about soundness, i.e., it does not help a malicious prover to prove a wrong statement even if the "skippable" condition is too relaxed. What can however happen is that the verification fails when it should not (perfect completeness is not guarenteed anymore if we wrongly skip).
5+
For each sub-trace defined in a .pil file, one can optionally add so-called "skippable" condition which allows to improve performance on prover side whenever the "skippable" condition is satisfied. It basically skips some accumulation computation in sumcheck protocol to all sub-relations pertaining to the sub-trace. Here a "sub-trace" can be virtual or not, i.e., each virtual sub-trace has their own skippable condition (which might be the same though). More on how to define a valid "skippable" condition in the next section. We emphasize that the "skippable" mechanism does not change the behavior of the verifier and therefore does not present any security risk about soundness, i.e., it does not help a malicious prover to prove a wrong statement even if the "skippable" condition is too relaxed. What can however happen is that the verification fails when it should not (perfect completeness is not guaranteed anymore if we wrongly skip).
66

77
## Explanations
88

9-
A sub-trace contains a list of algebraic sub-relations/equations which must be satisfied. We do not consider lookups nor permutations in this discussion.
9+
A sub-trace contains a list of algebraic sub-relations/equations which must be satisfied. We do not consider lookups nor permutations in this discussion (they are using the same skippable condition defined in interactions_base.hpp consisting in skipping when the inverse column entry is zero).
1010

11-
A valid "skippable" condition is a condition defined on some columns which guarantee that the accumulation in sumcheck rounds will be zero for this sub-trace, i.e., any sub-relation contribution will be zero. This means that the sub-relation is satisfied with columns values accumulated during sumcheck rounds.
11+
A valid "skippable" condition is a condition defined on some columns which guarantee that the accumulation in sumcheck rounds will be zero for this sub-trace, i.e., any sub-relation contribution will be zero. This means that the sub-relation is satisfied (equal to zero) with columns values accumulated during sumcheck rounds.
1212

1313
## Strong Skippable Condition
1414

@@ -26,24 +26,58 @@ We name such a condition "strong" and show in next section that this can be rela
2626
## Valid Relaxed Skippable Condition
2727

2828
At each round of the sumcheck protocol, two contiguous rows are "merged".
29-
For each column, the merging consist in computing the following based on a challenge $\alpha$ (random value over FF):
29+
For each column, the merging step consists in computing the following based on a challenge $\alpha$ (random value over FF):
3030
$$ ColMerged{_i} = (1 - \alpha) \cdot Col_i + \alpha \cdot Col_{i+1} $$
3131

3232
for every even i ($Col_i$ denotes the ith row element of $Col$).
3333
Then, each "merged value" is evaluated in your sub-relation.
3434
Note that $ColMerged_i$ is more or less random except when $Col_i$ and $Col_{i+1}$ are zeros.
3535
Assume that for a given sub-relation all $ColMerged_i$ are "random" except for the term satisfying the skippable condition. Then it will evaluate to zero and can be effectively skipped. (Assuming the strong definition of skippable where the skippable condition can nullify a sub-relation no matter what are the other values.)
36-
Now, one can leverage on the fact that we are using our witness generator to use the skippable in a more generous manner by leveraging columns that are guaranteed to be zero whenever the skippable condition is true and that this particular column being zero nullifies a sub-relation (in other words the column entry is multiplicative factor of the sub-relation).
36+
Now, one can leverage on the fact that we are using our witness generator to use the skippable in a more generous manner by taking advantage of columns that are guaranteed to be zero whenever the skippable condition is true and that this specific column being zero nullifies a sub-relation (in other words the column entry is a multiplicative factor of the sub-relation).
3737
Let us take an example of a subtrace with two subrelations over columns $a$, $b$, $c$:
3838

3939
$$
40-
a \cdot (b+c) = 0
40+
a \cdot (b + c) = 0
4141
$$
4242

4343
$$
44-
b \cdot (1- b) = 0
44+
b \cdot (1 - b) = 0
4545
$$
4646

4747
Skippable condition $a == 0$.
48-
Strictly speaking, the skippable condition does not algebraically nullifies the second equation ($b$ is almost a free variable)
49-
However, if we assume that our witness generator will always set $b = 0$ whenever $a== 0$, then we are fine. Namely, for every pair of contiguous rows with skippable condition being satisfied, the merged row will be skippable. For these two rows, we know that $b == 0$ and that the merged row entry will be zero as well. Therefore, contribution for the second sub-relation can be skipped.
48+
Strictly speaking, the skippable condition does not algebraically nullify the second equation ($b$ is almost a free variable).
49+
However, if we know that our witness generator will always set $b = 0$ whenever $a == 0$, then we are fine. Namely, for every pair of contiguous rows with skippable condition being satisfied, the merged row will be skippable. For these two rows, we know that $b == 0$ and that the merged row entry will be zero as well. Therefore, contribution for the second sub-relation can be skipped.
50+
51+
WARNING: If $a == 0$ would imply $b == 1$, this would not work even though $b == 1$ satisfy the second relation. Namely, after merging two rows, $b$ would be randomized and the second relation would not be satisfied but the merged $a$ value would be zero and wrongly satisfy the skippable condition.
52+
53+
## Special Case with First Row and Empty Sub-trace
54+
55+
We discuss another little optimization specific to the very first row which is mostly empty when we use sub-relations involving shifted values. Usually, the activation selector $sel$ is not set for this row but the fixed selector "precomputed.first_row" is active.
56+
57+
Assume that our sub-trace is empty (except the first fixed row) i.e., 'sel == 0' for every row. It would be desirable to be able to use the standard skippable condition $sel == 0$. This is possible if $sel' == 0$ and $sel == 0$ guarantee to nullify
58+
all sub-relations.
59+
60+
The reason is that the skippable mechanism applies simultaneously over the two contiguous rows which will be merged. In other words, the contribution will be skipped if the skippable condition holds on both rows. For the skippable condition
61+
$sel == 0$, this means that if the second row is skippable the first row must have $sel' == 0$. As the very first row is merged with the second one in the first round, this applies.
62+
63+
If the skippable mechanism were not simultaneous over the two rows then the first row might have been discarded wrongly.
64+
65+
As an example from memory.pil:
66+
67+
$(1 - precomputed.firstRow) * (1 - sel) * sel' = 0;$
68+
69+
Even if "precomputed.first_row" becomes randomized, we can rely on $sel'$ to nullify this sub-relation. Therefore, $sel == 0$ is a valid skippable condition.
70+
71+
## Leveraging Contiguous Trace
72+
73+
Our trace generation always create some contiguous trace, i.e., as soon as a row is inactive ($sel == 0), the next row is inactive. We can leverage this property when working with the skippable condition.
74+
75+
Example from bitwise.pil:
76+
77+
$(op_{id'} - op_{id}) * (1 - last) = 0;$
78+
79+
We know that our trace generation will fill $op_{id} == 0$ on inactive rows and we can deduce from trace continuity that $op_{id'} == 0$ and therefore this relation will be nullified whenever the skippable condition $sel == 0$ holds.
80+
81+
## TLDR
82+
83+
Due to the randomization of non-zero elements by merging two rows, we emphasize that the only skippable conditions which make sense are enforcing some column values to be zero such as $sel = 0$ or $sel_{1} + sel_{2} + ... = 0$. The latter should only be used when the trace generation enforces that $sel_{i} == 0$ for all $i$'s in order to satisfy this condition. This is the case for boolean selectors.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ include "../gt.pil";
3030
// This is a virtual gadget, which is part of the execution trace.
3131
namespace execution;
3232

33+
// We skip if sel_bytecode_retrieval_success == 0 or sel_instruction_fetching_success == 0.
3334
#[skippable_if]
3435
SEL_SHOULD_RESOLVE_ADDRESS = 0;
3536

barretenberg/cpp/pil/vm2/keccak_memory.pil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ sel * (1 - sel) = 0;
8888

8989
// No relations will be checked if this identity is satisfied.
9090
#[skippable_if]
91-
sel + last = 0;
91+
sel = 0;
9292

9393
pol commit start_read;
9494
start_read * (1 - start_read) = 0;

barretenberg/cpp/pil/vm2/keccakf1600.pil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ sel * (1 - sel) = 0;
7474

7575
// No relations will be checked if this identity is satisfied.
7676
#[skippable_if]
77-
sel + last = 0;
77+
sel = 0;
7878

7979
// error is defined below after round function
8080
pol commit sel_no_error;

barretenberg/cpp/pil/vm2/memory.pil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pol commit max_bits; // Number of bits corresponding to the tag. (Retrieved from
5353
// +-----+-----------+-------+-----+-------------+----------------------+----------+--------------+-------------+
5454

5555
#[skippable_if]
56-
sel + precomputed.first_row = 0;
56+
sel = 0;
5757

5858
// Permutation selectors (execution/addressing.pil).
5959
pol commit sel_addressing_base;

barretenberg/cpp/pil/vm2/protocol_contract.pil

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,29 @@
11
include "./trees/merkle_check.pil";
22
include "precomputed.pil";
3+
include "public_inputs.pil";
34
include "constants_gen.pil";
45
include "poseidon2_hash.pil";
56

7+
/**
8+
* This internal gadget constrains the retrieval of the derived address given the
9+
* canonical address of a protocol contract.
10+
* It computes the leaf hash using the preimage {canonical_addr, derived_addr} and
11+
* performs the membership check against the protocol contract tree.
12+
* The use of the correct tree is guaranteed by a constrained lookup of the root used
13+
* in the membership check with the root contained in the public inputs.
14+
* The root in the public inputs is constrained by upstream circuits (and eventually L1)
15+
*
16+
* N.B: We do not currently support non-membership checks, however this can be updated to
17+
* support non-membership checks.
18+
*
19+
* Usage (from contract_instance_retrieval.pil):
20+
* contract_instance_retrieval.is_protocol_contract {
21+
* contract_instance_retrieval.address,
22+
* contract_instance_retrieval.derived_address
23+
* } in
24+
* sel { canonical_address, derived_address };
25+
*
26+
*/
627
namespace protocol_contract;
728

829
pol commit sel;
@@ -14,7 +35,14 @@ namespace protocol_contract;
1435
pol commit canonical_address;
1536
pol commit derived_address;
1637

17-
pol commit root; // todo(ilyas): this needs to be constrained against public inputs
38+
pol commit pi_index; // todo: while we don't support constants in lookups
39+
sel * (pi_index - constants.AVM_PUBLIC_INPUTS_PROTOCOL_CONTRACT_TREE_ROOT) = 0;
40+
pol commit root;
41+
#[PUBLIC_INPUT_PROTOCOL_CONTRACT_ROOT]
42+
sel { pi_index, root }
43+
in
44+
public_inputs.sel { precomputed.clk, public_inputs.cols[0] };
45+
1846
pol commit tree_depth; // todo: while we don't support constants in lookups
1947
sel * (constants.PROTOCOL_CONTRACT_TREE_HEIGHT - tree_depth) = 0;
2048

barretenberg/cpp/src/barretenberg/vm2/common/avm_inputs.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ std::vector<std::vector<FF>> PublicInputs::to_columns() const
144144
cols[0][AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_FEE_RECIPIENT_ROW_IDX] = globalVariables.feeRecipient;
145145
set_gas_fees_in_cols(globalVariables.gasFees, cols, AVM_PUBLIC_INPUTS_GLOBAL_VARIABLES_GAS_FEES_ROW_IDX);
146146

147+
// Protocol Contract Tree Root
148+
cols[0][AVM_PUBLIC_INPUTS_PROTOCOL_CONTRACT_TREE_ROOT] = protocolContractTreeRoot;
149+
147150
// Start tree snapshots
148151
set_snapshot_in_cols(startTreeSnapshots.l1ToL2MessageTree,
149152
cols,

barretenberg/cpp/src/barretenberg/vm2/common/avm_inputs.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct PublicInputs {
2828
///////////////////////////////////
2929
// Inputs
3030
GlobalVariables globalVariables;
31+
FF protocolContractTreeRoot;
3132
TreeSnapshots startTreeSnapshots;
3233
Gas startGasUsed;
3334
GasSettings gasSettings;
@@ -86,6 +87,7 @@ struct PublicInputs {
8687
bool operator==(const PublicInputs& other) const = default;
8788

8889
MSGPACK_FIELDS(globalVariables,
90+
protocolContractTreeRoot,
8991
startTreeSnapshots,
9092
startGasUsed,
9193
gasSettings,

0 commit comments

Comments
 (0)