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
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,20 @@ include "update_check.pil";
* caller.exists,
* caller.deployer_addr, // situational - only if caller needs it
* caller.current_class_id,
* caller.init_hash // situational - only if caller needs it
* caller.init_hash, // situational - only if caller needs it
* caller.immutables_hash // situational - only if caller needs it
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Enabled here but only properly used in the PR that adds immutable_hash retrievability as an opcode

* } in contract_instance_retrieval.sel {
* contract_instance_retrieval.address,
* contract_instance_retrieval.nullifier_tree_root,
* contract_instance_retrieval.public_data_tree_root,
* contract_instance_retrieval.exists,
* contract_instance_retrieval.deployer_addr,
* contract_instance_retrieval.current_class_id,
* contract_instance_retrieval.init_hash
* contract_instance_retrieval.init_hash,
* contract_instance_retrieval.immutables_hash
* };
*
* Situational columns (deployer_addr, init_hash) can be omitted if the caller doesn't need
* Situational columns (deployer_addr, init_hash, immutables_hash) can be omitted if the caller doesn't need
* them. When omitted, they are only hinted for address derivation. This is secure because
* incorrect values would break derivation of the given address.
*
Expand Down Expand Up @@ -103,6 +105,7 @@ namespace contract_instance_retrieval;
pol commit current_class_id;
pol commit original_class_id; // HINTED!
pol commit init_hash;
pol commit immutables_hash;

// Current state — these should be looked up and constrained by the caller.
pol commit nullifier_tree_root;
Expand Down Expand Up @@ -242,6 +245,8 @@ namespace contract_instance_retrieval;
sel * (1 - exists) * original_class_id = 0; // technically not needed since original_class_id is hinted, but good for consistency
#[INSTANCE_MEMBER_INIT_HASH_IS_ZERO_IF_DNE]
sel * (1 - exists) * init_hash = 0;
#[INSTANCE_MEMBER_IMMUTABLES_HASH_IS_ZERO_IF_DNE]
sel * (1 - exists) * immutables_hash = 0;

// Address derivation lookup (only if the nullifier exists or for protocol contract instances).
#[ADDRESS_DERIVATION]
Expand Down
2 changes: 2 additions & 0 deletions barretenberg/cpp/src/barretenberg/vm2/common/avm_io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ struct ContractInstanceHint {
ContractClassId current_contract_class_id;
ContractClassId original_contract_class_id;
FF initialization_hash;
FF immutables_hash;
PublicKeysHint public_keys;

bool operator==(const ContractInstanceHint& other) const = default;
Expand All @@ -146,6 +147,7 @@ struct ContractInstanceHint {
current_contract_class_id,
original_contract_class_id,
initialization_hash,
immutables_hash,
public_keys);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ struct ContractInstance {
ContractClassId current_contract_class_id = 0;
ContractClassId original_contract_class_id = 0;
FF initialization_hash = 0;
PublicKeys public_keys;
FF immutables_hash = 0;
PublicKeys public_keys{};

bool operator==(const ContractInstance& other) const = default;

Expand All @@ -136,6 +137,8 @@ struct ContractInstance {
original_contract_class_id,
"initializationHash",
initialization_hash,
"immutablesHash",
immutables_hash,
"publicKeys",
public_keys);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ ContractInstance create_test_contract_instance(uint32_t salt_value = 123)
.current_contract_class_id = FF(0xdeadbeefULL),
.original_contract_class_id = FF(0xcafebabeULL),
.initialization_hash = FF(0x11111111ULL),
.immutables_hash = FF(0x22222222ULL),
.public_keys =
PublicKeys{
.nullifier_key = { FF(0x100), FF(0x101) },
Expand Down Expand Up @@ -72,6 +73,7 @@ TEST(ContractInstanceRetrievalConstrainingTest, CompleteValidTrace)
const auto current_class_id = FF(0xdeadbeefULL);
const auto original_class_id = FF(0xcafebabeULL);
const auto init_hash = FF(0x11111111ULL);
const auto immutables_hash = FF(0x22222222ULL);
const auto nullifier_key_x = FF(0x100);
const auto nullifier_key_y = FF(0x101);
const auto incoming_viewing_key_x = FF(0x200);
Expand All @@ -92,6 +94,7 @@ TEST(ContractInstanceRetrievalConstrainingTest, CompleteValidTrace)
{ C::contract_instance_retrieval_current_class_id, current_class_id },
{ C::contract_instance_retrieval_original_class_id, original_class_id },
{ C::contract_instance_retrieval_init_hash, init_hash },
{ C::contract_instance_retrieval_immutables_hash, immutables_hash },
{ C::contract_instance_retrieval_public_data_tree_root, public_data_tree_root },
{ C::contract_instance_retrieval_nullifier_tree_root, nullifier_tree_root },
{ C::contract_instance_retrieval_nullifier_tree_height, NULLIFIER_TREE_HEIGHT },
Expand Down Expand Up @@ -147,6 +150,7 @@ TEST(ContractInstanceRetrievalConstrainingTest, MultipleInstancesTrace)
{ C::contract_instance_retrieval_current_class_id, contract_instance.current_contract_class_id },
{ C::contract_instance_retrieval_original_class_id, contract_instance.original_contract_class_id },
{ C::contract_instance_retrieval_init_hash, contract_instance.initialization_hash },
{ C::contract_instance_retrieval_immutables_hash, contract_instance.immutables_hash },
{ C::contract_instance_retrieval_public_data_tree_root, FF(base_public_data_tree_root + i) },
{ C::contract_instance_retrieval_nullifier_tree_root, FF(base_nullifier_tree_root + i) },
{ C::contract_instance_retrieval_nullifier_tree_height, NULLIFIER_TREE_HEIGHT },
Expand Down Expand Up @@ -199,6 +203,7 @@ TEST(ContractInstanceRetrievalConstrainingTest, NonExistentInstanceTrace)
{ C::contract_instance_retrieval_current_class_id, 0 },
{ C::contract_instance_retrieval_original_class_id, 0 },
{ C::contract_instance_retrieval_init_hash, 0 },
{ C::contract_instance_retrieval_immutables_hash, 0 },
{ C::contract_instance_retrieval_public_data_tree_root, public_data_tree_root },
{ C::contract_instance_retrieval_nullifier_tree_root, nullifier_tree_root },
{ C::contract_instance_retrieval_nullifier_tree_height, NULLIFIER_TREE_HEIGHT },
Expand Down Expand Up @@ -242,6 +247,12 @@ TEST(ContractInstanceRetrievalConstrainingTest, NonExistentInstanceTrace)
"INSTANCE_MEMBER_INIT_HASH_IS_ZERO_IF_DNE");
// reset
trace.set(C::contract_instance_retrieval_init_hash, 1, 0);
// mutate immutables_hash
trace.set(C::contract_instance_retrieval_immutables_hash, 1, 1);
EXPECT_THROW_WITH_MESSAGE(check_relation<contract_instance_retrieval>(trace),
"INSTANCE_MEMBER_IMMUTABLES_HASH_IS_ZERO_IF_DNE");
// reset
trace.set(C::contract_instance_retrieval_immutables_hash, 1, 0);
}

TEST(ContractInstanceRetrievalConstrainingTest, MaximumFieldValuesTrace)
Expand All @@ -260,6 +271,7 @@ TEST(ContractInstanceRetrievalConstrainingTest, MaximumFieldValuesTrace)
{ C::contract_instance_retrieval_current_class_id, max_field },
{ C::contract_instance_retrieval_original_class_id, max_field },
{ C::contract_instance_retrieval_init_hash, max_field },
{ C::contract_instance_retrieval_immutables_hash, max_field },
{ C::contract_instance_retrieval_public_data_tree_root, max_field },
{ C::contract_instance_retrieval_nullifier_tree_root, max_field },
{ C::contract_instance_retrieval_nullifier_tree_height, NULLIFIER_TREE_HEIGHT },
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 @@ -141,10 +141,10 @@ namespace bb::avm2 {

struct AvmFlavorVariables {
static constexpr size_t NUM_PRECOMPUTED_ENTITIES = 119;
static constexpr size_t NUM_WITNESS_ENTITIES = 2955;
static constexpr size_t NUM_WITNESS_ENTITIES = 2956;
static constexpr size_t NUM_SHIFTED_ENTITIES = 364;
static constexpr size_t NUM_WIRES = 2511;
static constexpr size_t NUM_ALL_ENTITIES = 3438;
static constexpr size_t NUM_WIRES = 2512;
static constexpr size_t NUM_ALL_ENTITIES = 3439;

// 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,8 +14,8 @@ template <typename FF_> class contract_instance_retrievalImpl {
public:
using FF = FF_;

static constexpr std::array<size_t, 18> SUBRELATION_PARTIAL_LENGTHS = { 3, 3, 3, 2, 3, 3, 5, 3, 3,
3, 3, 4, 4, 4, 4, 4, 4, 3 };
static constexpr std::array<size_t, 19> SUBRELATION_PARTIAL_LENGTHS = { 3, 3, 3, 2, 3, 3, 5, 3, 3, 3,
3, 4, 4, 4, 4, 4, 4, 4, 3 };

template <typename AllEntities> inline static bool skip(const AllEntities& in)
{
Expand Down Expand Up @@ -47,6 +47,7 @@ template <typename FF> class contract_instance_retrieval : public Relation<contr
static constexpr size_t SR_INSTANCE_MEMBER_CLASS_ID_IS_ZERO_IF_DNE = 14;
static constexpr size_t SR_INSTANCE_MEMBER_ORIGINAL_CLASS_ID_IS_ZERO_IF_DNE = 15;
static constexpr size_t SR_INSTANCE_MEMBER_INIT_HASH_IS_ZERO_IF_DNE = 16;
static constexpr size_t SR_INSTANCE_MEMBER_IMMUTABLES_HASH_IS_ZERO_IF_DNE = 17;

static std::string get_subrelation_label(size_t index)
{
Expand All @@ -73,6 +74,8 @@ template <typename FF> class contract_instance_retrieval : public Relation<contr
return "INSTANCE_MEMBER_ORIGINAL_CLASS_ID_IS_ZERO_IF_DNE";
case SR_INSTANCE_MEMBER_INIT_HASH_IS_ZERO_IF_DNE:
return "INSTANCE_MEMBER_INIT_HASH_IS_ZERO_IF_DNE";
case SR_INSTANCE_MEMBER_IMMUTABLES_HASH_IS_ZERO_IF_DNE:
return "INSTANCE_MEMBER_IMMUTABLES_HASH_IS_ZERO_IF_DNE";
}
return std::to_string(index);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,19 @@ void contract_instance_retrievalImpl<FF_>::accumulate(ContainerOverSubrelations&
static_cast<View>(in.get(C::contract_instance_retrieval_init_hash));
std::get<16>(evals) += (tmp * scaling_factor);
}
{
{ // INSTANCE_MEMBER_IMMUTABLES_HASH_IS_ZERO_IF_DNE
using View = typename std::tuple_element_t<17, ContainerOverSubrelations>::View;
auto tmp = static_cast<View>(in.get(C::contract_instance_retrieval_sel)) *
(FF(1) - static_cast<View>(in.get(C::contract_instance_retrieval_exists))) *
static_cast<View>(in.get(C::contract_instance_retrieval_immutables_hash));
std::get<17>(evals) += (tmp * scaling_factor);
}
{
using View = typename std::tuple_element_t<18, ContainerOverSubrelations>::View;
auto tmp = (static_cast<View>(in.get(C::contract_instance_retrieval_should_check_for_update)) -
static_cast<View>(in.get(C::contract_instance_retrieval_should_check_nullifier)) *
static_cast<View>(in.get(C::contract_instance_retrieval_exists)));
std::get<17>(evals) += (tmp * scaling_factor);
std::get<18>(evals) += (tmp * scaling_factor);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ std::optional<ContractInstance> HintingContractsDB::get_contract_instance(const
.current_contract_class_id = instance->current_contract_class_id,
.original_contract_class_id = instance->original_contract_class_id,
.initialization_hash = instance->initialization_hash,
.immutables_hash = instance->immutables_hash,
.public_keys =
PublicKeysHint{ .master_nullifier_public_key = instance->public_keys.nullifier_key,
.master_incoming_viewing_public_key = instance->public_keys.incoming_viewing_key,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ std::optional<ContractInstance> HintedRawContractDB::get_contract_instance(const
.current_contract_class_id = contract_instance_hint.current_contract_class_id,
.original_contract_class_id = contract_instance_hint.original_contract_class_id,
.initialization_hash = contract_instance_hint.initialization_hash,
.immutables_hash = contract_instance_hint.immutables_hash,
.public_keys =
PublicKeys{
.nullifier_key = contract_instance_hint.public_keys.master_nullifier_public_key,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ ContractInstance random_contract_instance()
.current_contract_class_id = FF::random_element(),
.original_contract_class_id = FF::random_element(),
.initialization_hash = FF::random_element(),
.immutables_hash = FF::random_element(),
.public_keys = PublicKeys{
.nullifier_key = AffinePoint::random_element(),
.incoming_viewing_key = AffinePoint::random_element(),
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ void ContractInstanceRetrievalTraceBuilder::process(
{ C::contract_instance_retrieval_original_class_id,
event.contract_instance.original_contract_class_id },
{ C::contract_instance_retrieval_init_hash, event.contract_instance.initialization_hash },
{ C::contract_instance_retrieval_immutables_hash, event.contract_instance.immutables_hash },

// Public keys (hinted)
{ C::contract_instance_retrieval_nullifier_key_x, event.contract_instance.public_keys.nullifier_key.x },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ContractInstance create_test_contract_instance(uint32_t salt_value = 123)
.current_contract_class_id = FF(0xdeadbeefULL),
.original_contract_class_id = FF(0xcafebabeULL),
.initialization_hash = FF(0x11111111ULL),
.immutables_hash = FF(0x22222222ULL),
.public_keys =
PublicKeys{
.nullifier_key = { FF(0x100), FF(0x101) },
Expand Down Expand Up @@ -98,6 +99,7 @@ TEST(ContractInstanceRetrievalTraceGenTest, SingleEvent)
ROW_FIELD_EQ(contract_instance_retrieval_current_class_id, 0xdeadbeefULL),
ROW_FIELD_EQ(contract_instance_retrieval_original_class_id, 0xcafebabeULL),
ROW_FIELD_EQ(contract_instance_retrieval_init_hash, 0x11111111ULL),
ROW_FIELD_EQ(contract_instance_retrieval_immutables_hash, 0x22222222ULL),

// Public keys
ROW_FIELD_EQ(contract_instance_retrieval_nullifier_key_x, 0x100),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,25 @@ pub fn publish_contract_instance_for_public_execution(context: &mut PrivateConte
// ../../yarn-project/node_modules/.bin/aztec-cli codegen
// target/contract_instance_registry_contract-ContractInstanceRegistry.json --nr -o
// ./contracts/contract_instance_registry_contract/src/interface
let mut serialized_args = [0; 16];
let mut serialized_args = [0; 17];
serialized_args[0] = instance.salt;
serialized_args[1] = instance.contract_class_id.to_field();
serialized_args[2] = instance.initialization_hash;
serialized_args[3] = instance.immutables_hash;

let serialized_public_keys = instance.public_keys.serialize();

for i in 0..12 {
serialized_args[i + 3] = serialized_public_keys[i];
serialized_args[i + 4] = serialized_public_keys[i];
}

serialized_args[15] = universal_deploy as Field;
serialized_args[16] = universal_deploy as Field;

let _call_result = context.call_private_function(
CONTRACT_INSTANCE_REGISTRY_CONTRACT_ADDRESS,
comptime {
FunctionSelector::from_signature(
"publish_for_public_execution(Field,(Field),Field,(((Field,Field,bool)),((Field,Field,bool)),((Field,Field,bool)),((Field,Field,bool))),bool)",
"publish_for_public_execution(Field,(Field),Field,Field,(((Field,Field,bool)),((Field,Field,bool)),((Field,Field,bool)),((Field,Field,bool))),bool)",
)
},
serialized_args,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,23 @@ pub contract ContractInstanceRegistry {
salt: Field,
contract_class_id: ContractClassId,
initialization_hash: Field,
immutables_hash: Field,
public_keys: PublicKeys,
deployer: AztecAddress,
}

// Custom serialization is required because we don't want to waste one field for the `is_infinite` flag of public
// key points (public key points will never be the infinity point).
impl ContractInstancePublished {
fn serialize_non_standard(self) -> [Field; 15] {
fn serialize_non_standard(self) -> [Field; 16] {
[
self.CONTRACT_INSTANCE_PUBLISHED_MAGIC_VALUE,
self.address.to_field(),
self.version.to_field(),
self.salt,
self.contract_class_id.to_field(),
self.initialization_hash,
self.immutables_hash,
self.public_keys.npk_m.serialize()[0],
self.public_keys.npk_m.serialize()[1],
self.public_keys.ivpk_m.serialize()[0],
Expand Down Expand Up @@ -77,7 +79,8 @@ pub contract ContractInstanceRegistry {

/// Publishes a new contract instance.
///
/// The caller provides deployment parameters (salt, class_id, init_hash, public_keys, universal_deploy).
/// The caller provides deployment parameters (salt, class_id, init_hash, immutables_hash, public_keys,
/// universal_deploy).
/// The `universal_deploy` flag controls whether the deployer address is bound into the contract address:
/// when true, deployer is zero (anyone can deploy the same instance); when false, deployer is the caller.
///
Expand All @@ -95,6 +98,7 @@ pub contract ContractInstanceRegistry {
salt: Field,
contract_class_id: ContractClassId,
initialization_hash: Field,
immutables_hash: Field,
public_keys: PublicKeys,
universal_deploy: bool,
) -> return_data aztec::protocol::abis::private_circuit_public_inputs::PrivateCircuitPublicInputs {
Expand All @@ -103,7 +107,9 @@ pub contract ContractInstanceRegistry {
// body, I have removed that check.
assert_compatible_oracle_version();

let serialized_params: [Field; 16] = [salt, contract_class_id.to_field(), initialization_hash]
// 4 prefix fields (salt, class_id, init_hash, immutables_hash) + 12 public-key fields + 1 universal_deploy
// flag.
let serialized_params: [Field; 17] = [salt, contract_class_id.to_field(), initialization_hash, immutables_hash]
.concat(public_keys.serialize())
.concat([universal_deploy.to_field()]);

Expand Down Expand Up @@ -146,17 +152,15 @@ pub contract ContractInstanceRegistry {
address,
public_keys,
initialization_hash,
immutables_hash,
salt,
deployer,
version: 1,
version: 2,
};
let payload = event.serialize_non_standard();
debug_log_format("ContractInstancePublished: {}", payload);
// We pad the payload with [0] to match the length required by emit_private_log. Since the log is not
// encrypted, padding with zero rather than a random value is acceptable (we don't care about privacy here).
let padded_log = payload.concat([0]);
let length = payload.len();
context.emit_private_log(padded_log, length);
context.emit_private_log(payload, length);

// MACRO CODE START
context.finish()
Expand Down Expand Up @@ -307,6 +311,7 @@ pub contract ContractInstanceRegistry {
pub _salt: Field,
pub _contract_class_id: ContractClassId,
pub _initialization_hash: Field,
pub _immutables_hash: Field,
pub _public_keys: PublicKeys,
pub _universal_deploy: bool,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub contract ContractInstanceRegistry {
salt: Field,
contract_class_id: ContractClassId,
initialization_hash: Field,
immutables_hash: Field,
public_keys: PublicKeys,
universal_deploy: bool,
) {}
Expand Down
Loading
Loading