-
Notifications
You must be signed in to change notification settings - Fork 598
feat(avm): address and class id derivation setup #11354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
barretenberg/cpp/src/barretenberg/vm2/simulation/address_derivation.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #include "barretenberg/vm2/simulation/address_derivation.hpp" | ||
|
|
||
| #include <cassert> | ||
|
|
||
| #include "barretenberg/vm/aztec_constants.hpp" | ||
| #include "barretenberg/vm2/simulation/lib/contract_crypto.hpp" | ||
|
|
||
| namespace bb::avm2::simulation { | ||
|
|
||
| void AddressDerivation::assert_derivation(const AztecAddress& address, const ContractInstance& instance) | ||
| { | ||
| // TODO: Cache and deduplicate. | ||
| // TODO: Use gadget. | ||
| assert(compute_contract_address(instance) == address); | ||
| events.emit({ .address = address, .instance = instance }); | ||
| } | ||
|
|
||
| } // namespace bb::avm2::simulation |
27 changes: 27 additions & 0 deletions
27
barretenberg/cpp/src/barretenberg/vm2/simulation/address_derivation.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #pragma once | ||
|
|
||
| #include "barretenberg/vm2/common/aztec_types.hpp" | ||
| #include "barretenberg/vm2/simulation/events/address_derivation_event.hpp" | ||
| #include "barretenberg/vm2/simulation/events/event_emitter.hpp" | ||
|
|
||
| namespace bb::avm2::simulation { | ||
|
|
||
| class AddressDerivationInterface { | ||
| public: | ||
| virtual ~AddressDerivationInterface() = default; | ||
| virtual void assert_derivation(const AztecAddress& address, const ContractInstance& instance) = 0; | ||
| }; | ||
|
|
||
| class AddressDerivation : public AddressDerivationInterface { | ||
| public: | ||
| AddressDerivation(EventEmitterInterface<AddressDerivationEvent>& events) | ||
| : events(events) | ||
| {} | ||
|
|
||
| void assert_derivation(const AztecAddress& address, const ContractInstance& instance) override; | ||
|
|
||
| private: | ||
| EventEmitterInterface<AddressDerivationEvent>& events; | ||
| }; | ||
|
|
||
| } // namespace bb::avm2::simulation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
barretenberg/cpp/src/barretenberg/vm2/simulation/class_id_derivation.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #include "barretenberg/vm2/simulation/class_id_derivation.hpp" | ||
|
|
||
| #include <cassert> | ||
|
|
||
| #include "barretenberg/vm/aztec_constants.hpp" | ||
| #include "barretenberg/vm2/simulation/lib/contract_crypto.hpp" | ||
|
|
||
| namespace bb::avm2::simulation { | ||
|
|
||
| void ClassIdDerivation::assert_derivation(const ContractClassId& class_id, const ContractClass& klass) | ||
| { | ||
| // TODO: Cache and deduplicate. | ||
| // TODO: Use gadget. | ||
| assert(compute_contract_class_id( | ||
| klass.artifact_hash, klass.private_function_root, klass.public_bytecode_commitment) == class_id); | ||
| events.emit({ .class_id = class_id, .klass = klass }); | ||
| } | ||
|
|
||
| } // namespace bb::avm2::simulation |
27 changes: 27 additions & 0 deletions
27
barretenberg/cpp/src/barretenberg/vm2/simulation/class_id_derivation.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| #pragma once | ||
|
|
||
| #include "barretenberg/vm2/common/aztec_types.hpp" | ||
| #include "barretenberg/vm2/simulation/events/class_id_derivation_event.hpp" | ||
| #include "barretenberg/vm2/simulation/events/event_emitter.hpp" | ||
|
|
||
| namespace bb::avm2::simulation { | ||
|
|
||
| class ClassIdDerivationInterface { | ||
| public: | ||
| virtual ~ClassIdDerivationInterface() = default; | ||
| virtual void assert_derivation(const ContractClassId& class_id, const ContractClass& klass) = 0; | ||
| }; | ||
|
|
||
| class ClassIdDerivation : public ClassIdDerivationInterface { | ||
| public: | ||
| ClassIdDerivation(EventEmitterInterface<ClassIdDerivationEvent>& events) | ||
| : events(events) | ||
| {} | ||
|
|
||
| void assert_derivation(const ContractClassId& class_id, const ContractClass& klass) override; | ||
|
|
||
| private: | ||
| EventEmitterInterface<ClassIdDerivationEvent>& events; | ||
| }; | ||
|
|
||
| } // namespace bb::avm2::simulation |
12 changes: 12 additions & 0 deletions
12
barretenberg/cpp/src/barretenberg/vm2/simulation/events/address_derivation_event.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #pragma once | ||
|
|
||
| #include "barretenberg/vm2/common/aztec_types.hpp" | ||
|
|
||
| namespace bb::avm2::simulation { | ||
|
|
||
| struct AddressDerivationEvent { | ||
| AztecAddress address; | ||
| ContractInstance instance; | ||
| }; | ||
|
|
||
| } // namespace bb::avm2::simulation |
13 changes: 13 additions & 0 deletions
13
barretenberg/cpp/src/barretenberg/vm2/simulation/events/class_id_derivation_event.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #pragma once | ||
|
|
||
| #include "barretenberg/vm2/common/aztec_types.hpp" | ||
|
|
||
| namespace bb::avm2::simulation { | ||
|
|
||
| struct ClassIdDerivationEvent { | ||
| ContractClassId class_id; | ||
| // WARNING: this class has the whole bytecode. Create a new class. | ||
| ContractClass klass; | ||
| }; | ||
|
|
||
| } // namespace bb::avm2::simulation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
barretenberg/cpp/src/barretenberg/vm2/simulation/events/siloing_event.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #pragma once | ||
|
|
||
| #include "barretenberg/vm2/common/field.hpp" | ||
|
|
||
| namespace bb::avm2::simulation { | ||
|
|
||
| enum class SiloingType { NULLIFIER }; | ||
|
|
||
| struct SiloingEvent { | ||
| SiloingType type; | ||
| FF elem; | ||
| FF siloed_by; | ||
| FF siloed_elem; | ||
| }; | ||
|
|
||
| } // namespace bb::avm2::simulation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
barretenberg/cpp/src/barretenberg/vm2/simulation/siloing.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #include "barretenberg/vm2/simulation/siloing.hpp" | ||
|
|
||
| #include "barretenberg/crypto/poseidon2/poseidon2.hpp" | ||
| #include "barretenberg/vm/aztec_constants.hpp" | ||
| #include "barretenberg/vm2/simulation/events/siloing_event.hpp" | ||
|
|
||
| namespace bb::avm2::simulation { | ||
|
|
||
| using Poseidon2 = crypto::Poseidon2<crypto::Poseidon2Bn254ScalarFieldParams>; | ||
|
|
||
| FF Siloing::silo(const FF& generator, const FF& elem, const FF& silo_by, SiloingType type) | ||
| { | ||
| // TODO: Cache and deduplicate. | ||
| // TODO: Use poseidon gadget. | ||
| auto siloed_elem = Poseidon2::hash({ generator, silo_by, elem }); | ||
| events.emit({ .type = type, .elem = elem, .siloed_by = silo_by, .siloed_elem = siloed_elem }); | ||
| return siloed_elem; | ||
| } | ||
|
|
||
| } // namespace bb::avm2::simulation |
33 changes: 33 additions & 0 deletions
33
barretenberg/cpp/src/barretenberg/vm2/simulation/siloing.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #pragma once | ||
|
|
||
| #include "barretenberg/vm/aztec_constants.hpp" | ||
| #include "barretenberg/vm2/common/field.hpp" | ||
| #include "barretenberg/vm2/simulation/events/event_emitter.hpp" | ||
| #include "barretenberg/vm2/simulation/events/siloing_event.hpp" | ||
|
|
||
| namespace bb::avm2::simulation { | ||
|
|
||
| class SiloingInterface { | ||
| public: | ||
| virtual ~SiloingInterface() = default; | ||
| virtual FF silo_nullifier(const FF& nullifier, const FF& silo_by) = 0; | ||
| }; | ||
|
|
||
| class Siloing : public SiloingInterface { | ||
| public: | ||
| Siloing(EventEmitterInterface<SiloingEvent>& events) | ||
| : events(events) | ||
| {} | ||
|
|
||
| FF silo_nullifier(const FF& nullifier, const FF& silo_by) override | ||
| { | ||
| return silo(GENERATOR_INDEX__OUTER_NULLIFIER, nullifier, silo_by, SiloingType::NULLIFIER); | ||
| } | ||
|
|
||
| private: | ||
| FF silo(const FF& generator, const FF& elem, const FF& silo_by, SiloingType type); | ||
|
|
||
| EventEmitterInterface<SiloingEvent>& events; | ||
| }; | ||
|
|
||
| } // namespace bb::avm2::simulation |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might move these checks inside the DB.