Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bb::avm2::simulation::AddressDerivation Class Reference

#include <address_derivation.hpp>

Inheritance diagram for bb::avm2::simulation::AddressDerivation:
bb::avm2::simulation::AddressDerivationInterface

Public Member Functions

 AddressDerivation (Poseidon2Interface &poseidon2, EccInterface &ecc, EventEmitterInterface< AddressDerivationEvent > &events)
 
void assert_derivation (const AztecAddress &address, const ContractInstance &instance) override
 Verifies a contract instance's address derivation and emits an AddressDerivationEvent. Corresponds to the subtrace address_derivation.pil.
 
- Public Member Functions inherited from bb::avm2::simulation::AddressDerivationInterface
virtual ~AddressDerivationInterface ()=default
 

Private Attributes

EventEmitterInterface< AddressDerivationEvent > & events
 
Poseidon2Interfaceposeidon2
 
EccInterfaceecc
 
unordered_flat_set< AztecAddresscached_derivations
 

Detailed Description

Definition at line 13 of file address_derivation.hpp.

Constructor & Destructor Documentation

◆ AddressDerivation()

bb::avm2::simulation::AddressDerivation::AddressDerivation ( Poseidon2Interface poseidon2,
EccInterface ecc,
EventEmitterInterface< AddressDerivationEvent > &  events 
)
inline

Definition at line 15 of file address_derivation.hpp.

Member Function Documentation

◆ assert_derivation()

void bb::avm2::simulation::AddressDerivation::assert_derivation ( const AztecAddress address,
const ContractInstance instance 
)
overridevirtual

Verifies a contract instance's address derivation and emits an AddressDerivationEvent. Corresponds to the subtrace address_derivation.pil.

If the address has already been derived, an event has already been emitted and we skip repeating the computation and emission. Otherwise, we compute the address from the instance members using the poseidon2, scalar_mul, and ecc traces, which is given as:

  1. salted_init_hash = Poseidon2(DOM_SEP__SALTED_INITIALIZATION_HASH, salt, init_hash, deployer_addr)
  2. partial_address = Poseidon2(DOM_SEP__PARTIAL_ADDRESS, class_id, salted_init_hash)
  3. public_keys_hash = Poseidon2(DOM_SEP__PUBLIC_KEYS_HASH, [...public_keys.to_fields()])
  4. preaddress = Poseidon2(DOM_SEP__CONTRACT_ADDRESS_V1, public_keys_hash, partial_address)
  5. preaddress_public_key = preaddress * G1 (Grumpkin scalar multiplication)
  6. address = (preaddress_public_key + incoming_viewing_key).x (Grumpkin EC add) and we add the output to the local cache.
Exceptions
Unexpectedexception if
  • the calculated address does not match address.
Parameters
addressThe expected derived address.
instanceThe contract instance containing the address preimage.

Implements bb::avm2::simulation::AddressDerivationInterface.

Definition at line 32 of file address_derivation.cpp.

Member Data Documentation

◆ cached_derivations

unordered_flat_set<AztecAddress> bb::avm2::simulation::AddressDerivation::cached_derivations
private

Definition at line 31 of file address_derivation.hpp.

◆ ecc

EccInterface& bb::avm2::simulation::AddressDerivation::ecc
private

Definition at line 28 of file address_derivation.hpp.

◆ events

EventEmitterInterface<AddressDerivationEvent>& bb::avm2::simulation::AddressDerivation::events
private

Definition at line 26 of file address_derivation.hpp.

◆ poseidon2

Poseidon2Interface& bb::avm2::simulation::AddressDerivation::poseidon2
private

Definition at line 27 of file address_derivation.hpp.


The documentation for this class was generated from the following files: