Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions barretenberg/cpp/pil/vm2/bytecode/address_derivation.pil
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ namespace address_derivation;

pol commit salted_init_hash;

// It's reused between the partial address and salted initialization hash. Weird.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WEIRD, RIGHT?!

// TODO: We need this temporarily while we dont allow for aliases in the lookup tuple
pol commit salted_init_hash_domain_separator;
sel * (salted_init_hash_domain_separator - constants.DOM_SEP__SALTED_INITIALIZATION_HASH) = 0;

// TODO: We need this temporarily while we dont allow for aliases in the lookup tuple
pol commit partial_address_domain_separator;
sel * (partial_address_domain_separator - constants.DOM_SEP__PARTIAL_ADDRESS) = 0;
Expand All @@ -50,7 +53,7 @@ namespace address_derivation;
sel * (const_thirteen - 13) = 0;

#[SALTED_INITIALIZATION_HASH_POSEIDON2_0]
sel { partial_address_domain_separator, salt, init_hash, salted_init_hash, const_four }
sel { salted_init_hash_domain_separator, salt, init_hash, salted_init_hash, const_four }
in poseidon2_hash.start { poseidon2_hash.input_0, poseidon2_hash.input_1, poseidon2_hash.input_2, poseidon2_hash.output, poseidon2_hash.input_len };

#[SALTED_INITIALIZATION_HASH_POSEIDON2_1]
Expand Down
1 change: 1 addition & 0 deletions barretenberg/cpp/pil/vm2/constants_gen.pil
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ namespace constants;
pol DOM_SEP__PUBLIC_STORAGE_MAP_SLOT = 4015149901;
pol DOM_SEP__PUBLIC_BYTECODE = 260313585;
pol DOM_SEP__CONTRACT_CLASS_ID = 3923495515;
pol DOM_SEP__SALTED_INITIALIZATION_HASH = 2763052992;
pol DOM_SEP__PUBLIC_KEYS_HASH = 777457226;
pol DOM_SEP__PARTIAL_ADDRESS = 2103633018;
pol DOM_SEP__CONTRACT_ADDRESS_V1 = 1788365517;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@
#define DOM_SEP__PUBLIC_STORAGE_MAP_SLOT 4015149901UL
#define DOM_SEP__PUBLIC_BYTECODE 260313585UL
#define DOM_SEP__CONTRACT_CLASS_ID 3923495515UL
#define DOM_SEP__SALTED_INITIALIZATION_HASH 2763052992UL
#define DOM_SEP__PUBLIC_KEYS_HASH 777457226UL
#define DOM_SEP__PARTIAL_ADDRESS 2103633018UL
#define DOM_SEP__CONTRACT_ADDRESS_V1 1788365517UL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ TEST(AddressDerivationConstrainingTest, Basic)

auto instance = testing::random_contract_instance();

FF salted_initialization_hash =
poseidon2::hash({ DOM_SEP__PARTIAL_ADDRESS, instance.salt, instance.initialization_hash, instance.deployer });
FF salted_initialization_hash = poseidon2::hash(
{ DOM_SEP__SALTED_INITIALIZATION_HASH, instance.salt, instance.initialization_hash, instance.deployer });

FF partial_address =
poseidon2::hash({ DOM_SEP__PARTIAL_ADDRESS, instance.original_contract_class_id, salted_initialization_hash });
Expand Down
10 changes: 5 additions & 5 deletions barretenberg/cpp/src/barretenberg/vm2/generated/columns.hpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ namespace bb::avm2 {

struct AvmFlavorVariables {
static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 123;
static constexpr size_t NUM_WITNESS_ENTITIES = 3088;
static constexpr size_t NUM_WITNESS_ENTITIES = 3089;
static constexpr size_t NUM_SHIFTED_ENTITIES = 359;
static constexpr size_t NUM_WIRES = 2620;
static constexpr size_t NUM_ALL_ENTITIES = 3570;
static constexpr size_t NUM_WIRES = 2621;
static constexpr size_t NUM_ALL_ENTITIES = 3571;

// Need to be templated for recursive verifier
template <typename FF_>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ template <typename FF_> class address_derivationImpl {
public:
using FF = FF_;

static constexpr std::array<size_t, 10> SUBRELATION_PARTIAL_LENGTHS = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 };
static constexpr std::array<size_t, 11> SUBRELATION_PARTIAL_LENGTHS = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 };

template <typename AllEntities> inline static bool skip(const AllEntities& in)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ void address_derivationImpl<FF_>::accumulate(ContainerOverSubrelations& evals,
const auto constants_GRUMPKIN_ONE_X = FF(1);
const auto constants_GRUMPKIN_ONE_Y =
FF(uint256_t{ 9457493854555940652UL, 3253583849847263892UL, 14921373847124204899UL, 2UL });
const auto constants_DOM_SEP__SALTED_INITIALIZATION_HASH = FF(2763052992UL);
const auto constants_DOM_SEP__PUBLIC_KEYS_HASH = FF(777457226);
const auto constants_DOM_SEP__PARTIAL_ADDRESS = FF(2103633018);
const auto constants_DOM_SEP__CONTRACT_ADDRESS_V1 = FF(1788365517);
Expand All @@ -31,60 +32,67 @@ void address_derivationImpl<FF_>::accumulate(ContainerOverSubrelations& evals,
{
using View = typename std::tuple_element_t<1, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::address_derivation_sel)) *
(static_cast<View>(in.get(C::address_derivation_partial_address_domain_separator)) -
CView(constants_DOM_SEP__PARTIAL_ADDRESS));
(static_cast<View>(in.get(C::address_derivation_salted_init_hash_domain_separator)) -
CView(constants_DOM_SEP__SALTED_INITIALIZATION_HASH));
std::get<1>(evals) += (tmp * scaling_factor);
}
{
using View = typename std::tuple_element_t<2, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::address_derivation_sel)) *
(static_cast<View>(in.get(C::address_derivation_const_two)) - FF(2));
(static_cast<View>(in.get(C::address_derivation_partial_address_domain_separator)) -
CView(constants_DOM_SEP__PARTIAL_ADDRESS));
std::get<2>(evals) += (tmp * scaling_factor);
}
{
using View = typename std::tuple_element_t<3, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::address_derivation_sel)) *
(static_cast<View>(in.get(C::address_derivation_const_three)) - FF(3));
(static_cast<View>(in.get(C::address_derivation_const_two)) - FF(2));
std::get<3>(evals) += (tmp * scaling_factor);
}
{
using View = typename std::tuple_element_t<4, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::address_derivation_sel)) *
(static_cast<View>(in.get(C::address_derivation_const_four)) - FF(4));
(static_cast<View>(in.get(C::address_derivation_const_three)) - FF(3));
std::get<4>(evals) += (tmp * scaling_factor);
}
{
using View = typename std::tuple_element_t<5, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::address_derivation_sel)) *
(static_cast<View>(in.get(C::address_derivation_const_thirteen)) - FF(13));
(static_cast<View>(in.get(C::address_derivation_const_four)) - FF(4));
std::get<5>(evals) += (tmp * scaling_factor);
}
{
using View = typename std::tuple_element_t<6, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::address_derivation_sel)) *
(static_cast<View>(in.get(C::address_derivation_public_keys_hash_domain_separator)) -
CView(constants_DOM_SEP__PUBLIC_KEYS_HASH));
(static_cast<View>(in.get(C::address_derivation_const_thirteen)) - FF(13));
std::get<6>(evals) += (tmp * scaling_factor);
}
{
using View = typename std::tuple_element_t<7, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::address_derivation_sel)) *
(static_cast<View>(in.get(C::address_derivation_preaddress_domain_separator)) -
CView(constants_DOM_SEP__CONTRACT_ADDRESS_V1));
(static_cast<View>(in.get(C::address_derivation_public_keys_hash_domain_separator)) -
CView(constants_DOM_SEP__PUBLIC_KEYS_HASH));
std::get<7>(evals) += (tmp * scaling_factor);
}
{
using View = typename std::tuple_element_t<8, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::address_derivation_sel)) *
(static_cast<View>(in.get(C::address_derivation_g1_x)) - CView(constants_GRUMPKIN_ONE_X));
(static_cast<View>(in.get(C::address_derivation_preaddress_domain_separator)) -
CView(constants_DOM_SEP__CONTRACT_ADDRESS_V1));
std::get<8>(evals) += (tmp * scaling_factor);
}
{
using View = typename std::tuple_element_t<9, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::address_derivation_sel)) *
(static_cast<View>(in.get(C::address_derivation_g1_y)) - CView(constants_GRUMPKIN_ONE_Y));
(static_cast<View>(in.get(C::address_derivation_g1_x)) - CView(constants_GRUMPKIN_ONE_X));
std::get<9>(evals) += (tmp * scaling_factor);
}
{
using View = typename std::tuple_element_t<10, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::address_derivation_sel)) *
(static_cast<View>(in.get(C::address_derivation_g1_y)) - CView(constants_GRUMPKIN_ONE_Y));
std::get<10>(evals) += (tmp * scaling_factor);
}
}

} // namespace bb::avm2
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct lookup_address_derivation_salted_initialization_hash_poseidon2_0_settings
static constexpr Column COUNTS = Column::lookup_address_derivation_salted_initialization_hash_poseidon2_0_counts;
static constexpr Column INVERSES = Column::lookup_address_derivation_salted_initialization_hash_poseidon2_0_inv;
static constexpr std::array<ColumnAndShifts, LOOKUP_TUPLE_SIZE> SRC_COLUMNS = {
ColumnAndShifts::address_derivation_partial_address_domain_separator,
ColumnAndShifts::address_derivation_salted_init_hash_domain_separator,
ColumnAndShifts::address_derivation_salt,
ColumnAndShifts::address_derivation_init_hash,
ColumnAndShifts::address_derivation_salted_init_hash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ void AddressDerivation::assert_derivation(const AztecAddress& address, const Con
}

// First time seeing this address - do the actual derivation
FF salted_initialization_hash =
poseidon2.hash({ DOM_SEP__PARTIAL_ADDRESS, instance.salt, instance.initialization_hash, instance.deployer });
FF salted_initialization_hash = poseidon2.hash(
{ DOM_SEP__SALTED_INITIALIZATION_HASH, instance.salt, instance.initialization_hash, instance.deployer });

FF partial_address =
poseidon2.hash({ DOM_SEP__PARTIAL_ADDRESS, instance.original_contract_class_id, salted_initialization_hash });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ TEST(AvmSimulationAddressDerivationTest, Positive)
ContractInstance instance = testing::random_contract_instance();
AztecAddress derived_address = compute_contract_address(instance);
std::vector<FF> salted_init_hash_inputs = {
DOM_SEP__PARTIAL_ADDRESS, instance.salt, instance.initialization_hash, instance.deployer
DOM_SEP__SALTED_INITIALIZATION_HASH, instance.salt, instance.initialization_hash, instance.deployer
};
FF salted_init_hash = poseidon2::hash(salted_init_hash_inputs);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ FF hash_public_keys(const PublicKeys& public_keys)

FF compute_contract_address(const ContractInstance& contract_instance)
{
FF salted_initialization_hash = poseidon2::hash({ DOM_SEP__PARTIAL_ADDRESS,
FF salted_initialization_hash = poseidon2::hash({ DOM_SEP__SALTED_INITIALIZATION_HASH,
contract_instance.salt,
contract_instance.initialization_hash,
contract_instance.deployer });
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void AddressDerivationTraceBuilder::process(
{ C::address_derivation_tagging_key_y, event.instance.public_keys.tagging_key.y },
{ C::address_derivation_address, event.address },
{ C::address_derivation_salted_init_hash, event.salted_initialization_hash },
{ C::address_derivation_salted_init_hash_domain_separator, DOM_SEP__SALTED_INITIALIZATION_HASH },
{ C::address_derivation_partial_address_domain_separator, DOM_SEP__PARTIAL_ADDRESS },
{ C::address_derivation_const_two, 2 },
{ C::address_derivation_const_three, 3 },
Expand Down
Loading