Conversation
2f45e07 to
f931ff6
Compare
a6fa349 to
50e553c
Compare
f931ff6 to
d7c280c
Compare
d7c280c to
4493428
Compare
0bae325 to
50e553c
Compare
4493428 to
d8c3996
Compare
d8c3996 to
75e3431
Compare
c227e71 to
836cfef
Compare
ca79592 to
399afd7
Compare
399afd7 to
baee102
Compare
fd36eb9 to
1fb7a5f
Compare
323c66e to
1ff8911
Compare
| // If class ID derivation is disabled (instance does not exist), force all members to 0. | ||
| #[CURRENT_CLASS_ID_IS_ZERO_IF_INSTANCE_DOES_NOT_EXIST] | ||
| sel * (1 - instance_exists) * (current_class_id - 0) = 0; | ||
| #[ARTIFACT_HASH_IS_ZERO_IF_INSTANCE_DOES_NOT_EXIST] | ||
| sel * (1 - instance_exists) * (artifact_hash - 0) = 0; | ||
| #[PRIVATE_FUNCTION_ROOT_IS_ZERO_IF_INSTANCE_DOES_NOT_EXIST] | ||
| sel * (1 - instance_exists) * (private_function_root - 0) = 0; | ||
| #[BYTECODE_ID_IS_ZERO_IF_INSTANCE_DOES_NOT_EXIST] | ||
| sel * (1 - instance_exists) * (bytecode_id - 0) = 0; |
There was a problem hiding this comment.
I think these were necessary before but were missing
| TestTraceContainer trace({ { | ||
| { C::execution_next_context_id, 0 }, | ||
| { C::precomputed_first_row, 1 }, | ||
| // Context Stack Rows | ||
| { C::context_stack_sel, 1 }, | ||
| { C::context_stack_entered_context_id, 2 }, | ||
| { C::context_stack_context_id, 1 }, | ||
| { C::context_stack_parent_id, 0 }, | ||
| { C::context_stack_next_pc, 2 }, | ||
| { C::context_stack_msg_sender, 0 }, |
There was a problem hiding this comment.
This big test diff is formatting. I just added bytecode id.
| // Check if we've already processed this bytecode. If so, don't do hashing and decomposition again! | ||
| auto existing_bytecode = bytecodes.find(bytecode_id); | ||
| if (existing_bytecode != bytecodes.end()) { | ||
| // Already processed this bytecode - just emit retrieval event and return | ||
| auto tree_states = merkle_db.get_tree_state(); | ||
| retrieval_events.emit({ | ||
| .bytecode_id = bytecode_id, | ||
| .address = address, | ||
| .current_class_id = current_class_id, | ||
| .contract_class = klass, | ||
| .nullifier_root = tree_states.nullifierTree.tree.root, | ||
| .public_data_tree_root = tree_states.publicDataTree.tree.root, | ||
| }); | ||
| return bytecode_id; | ||
| } | ||
|
|
||
| // First time seeing this bytecode - do hashing and decomposition | ||
| FF computed_commitment = bytecode_hasher.compute_public_bytecode_commitment(bytecode_id, klass.packed_bytecode); | ||
| (void)computed_commitment; // Avoid GCC unused parameter warning when asserts are disabled. | ||
| assert(computed_commitment == klass.public_bytecode_commitment); | ||
|
|
There was a problem hiding this comment.
We could deduplicate bytecode hashing inside of the hasher. But we already need to deduplicate decomposition event-generation here in the bytecode manager, so I thought it was natural to also dedup the call to bytecode hashing here.
| struct BytecodeNotFoundError : public std::runtime_error { | ||
| BytecodeNotFoundError(BytecodeId id, const std::string& message) | ||
| BytecodeNotFoundError(const std::string& message) | ||
| : std::runtime_error(message) | ||
| , bytecode_id(id) | ||
| {} | ||
|
|
||
| BytecodeId bytecode_id; | ||
| }; | ||
|
|
There was a problem hiding this comment.
Cannot include the ID in the error if it is an FF or we get some annoying compilation error about alignment
There was a problem hiding this comment.
oh yeah I remember Ilyas got that as well; I guess it's ok you can stringify it
|
|
||
| using BytecodeId = uint8_t; | ||
| using BytecodeId = FF; | ||
|
|
There was a problem hiding this comment.
Opted to leave this alias, but I'm happy to remove if someone feels strongly otherwise
1ff8911 to
a186e72
Compare
a186e72 to
32b01b3
Compare
barretenberg/cpp/src/barretenberg/vm2/simulation/address_derivation.cpp
Outdated
Show resolved
Hide resolved
barretenberg/cpp/src/barretenberg/vm2/simulation/address_derivation.test.cpp
Outdated
Show resolved
Hide resolved
barretenberg/cpp/src/barretenberg/vm2/simulation/class_id_derivation.cpp
Outdated
Show resolved
Hide resolved
| struct BytecodeNotFoundError : public std::runtime_error { | ||
| BytecodeNotFoundError(BytecodeId id, const std::string& message) | ||
| BytecodeNotFoundError(const std::string& message) | ||
| : std::runtime_error(message) | ||
| , bytecode_id(id) | ||
| {} | ||
|
|
||
| BytecodeId bytecode_id; | ||
| }; | ||
|
|
There was a problem hiding this comment.
oh yeah I remember Ilyas got that as well; I guess it's ok you can stringify it
| // Throws BytecodeNotFoundError if contract not found (for use in temporality group 1) | ||
| virtual BytecodeId get_bytecode_id() = 0; | ||
|
|
||
| // Returns the id of the current bytecode, or nullopt if contract not found. |
There was a problem hiding this comment.
Note to self: "if contract not found."
Does this try to fetch the contract? Or "contract not found" means "nobody tried to fetch yet"?
There was a problem hiding this comment.
It tries to fetch the contract. "Not found" means "contract does not exist". I'll clarify in the comments.
|
|
||
| StrictMock<MockContractDB> contract_db; | ||
| StrictMock<MockHighLevelMerkleDB> merkle_db; | ||
| StrictMock<MockPoseidon2> poseidon2; |
There was a problem hiding this comment.
Feel free to use a FakePoseidon2 if it makes life easier/code cleaner
There was a problem hiding this comment.
Did it for class id and address deriv, but opted not to here for the bytecode manager tests because I'd end up needing to replicate too much of the algorithm in the test.
barretenberg/cpp/src/barretenberg/vm2/simulation/bytecode_manager.test.cpp
Outdated
Show resolved
Hide resolved
barretenberg/cpp/src/barretenberg/vm2/simulation/bytecode_manager.cpp
Outdated
Show resolved
Hide resolved
…te bytecode hashing, instruction fetching, bc decomp
32b01b3 to
7ff82e3
Compare

Discussion, reasoning and alternatives approaches can be found here.
What's done
( bytecode_id, pc )via theevent.get_key()mechanism.Questions
event.get_key()mechanism to deduplicate more (bytecode decomp, hashing, addr deriv, class ID deriv)?event.get_key(), does that mean that we are not deduplicating the PC range check where we could be? (screenshotted)