-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(avm): address and class id derivation setup (#11354)
Boilerplate/guardrails.
- Loading branch information
Showing
18 changed files
with
265 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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.
5f3cffc
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.
Possible performance regression was detected for benchmark 'C++ Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
1.05
.wasmClientIVCBench/Full/6
82166.71326399999
ms/iter75709.889634
ms/iter1.09
This comment was automatically generated by workflow using github-action-benchmark.
CC: @ludamad @codygunton