You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: barretenberg/cpp/pil/vm2/bytecode/bc_retrieval.pil
+37-27Lines changed: 37 additions & 27 deletions
Original file line number
Diff line number
Diff line change
@@ -3,16 +3,16 @@ include "class_id_derivation.pil";
3
3
4
4
include "../constants_gen.pil";
5
5
include "../precomputed.pil";
6
-
include "../trees/retrieved_bytecodes_tree_check.pil";
6
+
include "../trees/indexed_tree_check.pil";
7
7
8
8
/**
9
9
* This subtrace constrains everything related to "retrieving" a bytecode given an address. It is responsible for proving success or failure of retrieval for a bytecode id
10
10
* and does not fetch the bytes themselves. In practice this means we:
* - Enforced by lookup into contract_instance_retrieval.pil (#[CONTRACT_INSTANCE_RETRIEVAL]), which looks up nullifier_check.pil (#[DEPLOYMENT_NULLIFIER_READ]).
13
+
* - Enforced by lookup into contract_instance_retrieval.pil (#[CONTRACT_INSTANCE_RETRIEVAL]), which looks up indexed_tree_check.pil (#[DEPLOYMENT_NULLIFIER_READ]).
* - Note: for this trace, we only 'care' about the contract instance member current_class_id (not salt, deployer_addr, init_hash), which is validated in
@@ -63,10 +63,10 @@ include "../trees/retrieved_bytecodes_tree_check.pil";
63
63
* TRACE SHAPE: This subtrace retrieves one bytecode instance per row, anchored by the bytecode_id column.
@@ -81,9 +81,9 @@ include "../trees/retrieved_bytecodes_tree_check.pil";
81
81
* (#[CONTRACT_INSTANCE_RETRIEVAL]). Additionally links the state tree roots and enforces that the class id is zero if the
82
82
* instance does not exist. This lookup is crucial since we defer the nullifier, address, and update checks to the contract
83
83
* instance retrieval trace.
84
-
* - retrieved_bytecodes_tree_check.pil: If an instance exists, to constrain whether it is a new class id not yet accessed by this tx (#[IS_NEW_CLASS_CHECK]).
85
-
* If there is no error, to insert the class id into the retrieved bytecodes tree (#[RETRIEVED_BYTECODES_INSERTION]).
86
-
* These cases must form separate lookups to ensure we do not add to the tree when we have hit the bytecode limit.
84
+
* - indexed_tree_check.pil: If an instance exists, to constrain whether it is a new class id not yet accessed by this tx (#[IS_NEW_CLASS_CHECK]).
85
+
* If there is no error, to insert the class id into the retrieved bytecodes tree (#[RETRIEVED_BYTECODES_INSERTION]).
86
+
* These cases must form separate lookups to ensure we do not add to the tree when we have hit the bytecode limit.
87
87
* - class_id_derivation.pil: If there is no error, to constrain correctness of the class id against the contract class member columns of this trace
88
88
* (#[CLASS_ID_DERIVATION]). In terms of this trace's columns, that is:
// Switching on the error column forces the class members to be zero.
169
169
170
170
// Whether we have retrieved the bytecode for this class before (if not, is_new_class == 1 and we insert the bytecode into the tree).
171
-
pol commit is_new_class; // @boolean (by lookup into retrieved_bytecodes_tree_check when instance_exists == 1; constrained to be 0 when instance_exists == 0)
171
+
pol commit is_new_class; // @boolean (by lookup into indexed_tree_check when instance_exists == 1; constrained to be 0 when instance_exists == 0)
172
172
173
173
// Whether we have retrieved the maximum number of different bytecodes for this tx.
174
174
pol commit no_remaining_bytecodes; // @boolean
@@ -233,36 +233,46 @@ should_retrieve {
233
233
// Bytecode Tree Read/Write
234
234
///////////////////////////////
235
235
236
+
// Lookup constant support: Can be removed when we support constants in lookups.
237
+
pol commit retrieved_bytecodes_tree_height;
238
+
sel * (retrieved_bytecodes_tree_height - constants.AVM_RETRIEVED_BYTECODES_TREE_HEIGHT) = 0;
239
+
236
240
// This constrains that is_new_class is on iff the bytecode does not exist in the transient tree (i.e. this
237
241
// bytecode has not been used in this tx).
238
242
// Note: instance_exists can be on for inactive rows, but this lookup below not create side effects, so
239
243
// it is safe to gate by instance_exists rather than sel && instance_exists.
240
244
#[IS_NEW_CLASS_CHECK]
241
245
instance_exists {
242
-
current_class_id,
243
-
is_new_class,
244
-
prev_retrieved_bytecodes_tree_root
245
-
} in retrieved_bytecodes_tree_check.sel {
246
-
retrieved_bytecodes_tree_check.class_id,
247
-
retrieved_bytecodes_tree_check.leaf_not_exists,
248
-
retrieved_bytecodes_tree_check.root
246
+
is_new_class, // not_exists
247
+
current_class_id, // value
248
+
prev_retrieved_bytecodes_tree_root,
249
+
retrieved_bytecodes_tree_height,
250
+
precomputed.zero // sel_silo = 0 (no siloing)
251
+
} in indexed_tree_check.sel {
252
+
indexed_tree_check.not_exists,
253
+
indexed_tree_check.value,
254
+
indexed_tree_check.root,
255
+
indexed_tree_check.tree_height,
256
+
indexed_tree_check.sel_silo
249
257
};
250
258
251
259
// This constrains that if we have retrieved bytecode for a new class, we update the tree correctly.
0 commit comments