Skip to content
Closed
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
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/keys/getters/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ mod test {
// partial address
random_keys_and_partial_address[8] = 0x236703e2cb00a182e024e98e9f759231b556d25ff19f98896cebb69e9e678cc9;

let _ = OracleMock::mock("aztec_utl_getPublicKeysAndPartialAddress").returns(Option::some(
let _ = OracleMock::mock("aztec_utl_getPublicKeysAndPartialAddress_v2").returns(Option::some(
random_keys_and_partial_address,
));
let _ = get_public_keys(account);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ mod test {
);
let s_app = compute_app_siloed_shared_secret(raw_shared_secret, contract_address);

let _ = OracleMock::mock("aztec_utl_getSharedSecret").returns(s_app);
let _ = OracleMock::mock("aztec_utl_getSharedSecret_v2").returns(s_app);

// Decrypt the message
let decrypted = AES128::decrypt(encrypted_message, recipient, contract_address).unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::protocol::{
};

// NOTE: this is for use in private only
#[oracle(aztec_utl_getContractInstance)]
#[oracle(aztec_utl_getContractInstance_v2)]
unconstrained fn get_contract_instance_oracle(_address: AztecAddress) -> ContractInstance {}

// NOTE: this is for use in private only
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/oracle/keys.nr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub unconstrained fn get_public_keys_and_partial_address(address: AztecAddress)
try_get_public_keys_and_partial_address(address).expect(f"Public keys not registered for account {address}")
}

#[oracle(aztec_utl_getPublicKeysAndPartialAddress)]
#[oracle(aztec_utl_getPublicKeysAndPartialAddress_v2)]
unconstrained fn get_public_keys_and_partial_address_oracle(_address: AztecAddress) -> Option<[Field; 9]> {}

// TODO(F-498): review naming consistency
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/oracle/shared_secret.nr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::protocol::address::aztec_address::AztecAddress;
use crate::protocol::point::Point;

#[oracle(aztec_utl_getSharedSecret)]
#[oracle(aztec_utl_getSharedSecret_v2)]
unconstrained fn get_shared_secret_oracle(
address: AztecAddress,
ephPk: Point,
Expand Down
2 changes: 1 addition & 1 deletion noir-projects/aztec-nr/aztec/src/oracle/version.nr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/// the PXE and used to provide helpful error messages if a contract calls an oracle that doesn't exist. We don't throw
/// immediately if AZTEC_NR_MINOR > PXE_MINOR because if a contract is updated to use a newer Aztec.nr dependency
/// without actually using any of the new oracles then there is no reason to throw.
pub global ORACLE_VERSION_MAJOR: Field = 23;
pub global ORACLE_VERSION_MAJOR: Field = 22;
pub global ORACLE_VERSION_MINOR: Field = 1;

/// Asserts that the version of the oracle is compatible with the version expected by the contract.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/// the PXE and used to provide helpful error messages if a contract calls an oracle that doesn't exist. We don't throw
/// immediately if AZTEC_NR_MINOR > PXE_MINOR because if a contract is updated to use a newer Aztec.nr dependency
/// without actually using any of the new oracles then there is no reason to throw.
pub global ORACLE_VERSION_MAJOR: Field = 23;
pub global ORACLE_VERSION_MAJOR: Field = 22;
pub global ORACLE_VERSION_MINOR: Field = 1;

/// Asserts that the version of the oracle is compatible with the version expected by the contract.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ fn compute_address_from_partial_and_pub_keys() {
// The following value was generated by `derivation.test.ts`.
// --> Run the test with AZTEC_GENERATE_TEST_DATA=1 flag to update test data.
let expected_computed_address_from_partial_and_pubkeys =
0x04099cc9c76ec56f8d9d5d80af8a8a78ed1f180a123063034b14722a748394bb;
0x2f66081d4bb077fbe8e8abe96a3516a713a3d7e34360b4e985da0da95092b37d;
assert(address.to_field() == expected_computed_address_from_partial_and_pubkeys);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,24 @@ impl Default for PublicKeys {

impl PublicKeys {
pub fn hash(self) -> PublicKeysHash {
// We explicitly serialize with is_infinite=0 for backwards compatibility with contract addresses that were
// computed when Point had the is_infinite field (x, y, is_infinite).
let serialized: [Field; 12] = [
self.npk_m.inner.x,
self.npk_m.inner.y,
0,
self.ivpk_m.inner.x,
self.ivpk_m.inner.y,
0,
self.ovpk_m.inner.x,
self.ovpk_m.inner.y,
0,
self.tpk_m.inner.x,
self.tpk_m.inner.y,
0,
];
PublicKeysHash::from_field(poseidon2_hash_with_separator(
self.serialize(),
serialized,
DOM_SEP__PUBLIC_KEYS_HASH as Field,
))
}
Expand Down Expand Up @@ -139,7 +155,7 @@ mod test {

// The following value was generated by `public_keys.test.ts`.
let expected_public_keys_hash =
0x14347f1d74d892ce45384ca5b69c2070d264e64458ef327ab7b42c850a3d437f;
0x056998309f6c119e4d753e404f94fef859dddfa530a9379634ceb0854b29bf7a;

assert(actual.to_field() == expected_public_keys_hash);
}
Expand All @@ -152,7 +168,7 @@ mod test {

// The following value was generated by `public_keys.test.ts`.
let test_data_default_hash =
0x20c0a5f4c7c5bd4e0f9e7cdb69d16fcb9115d2a77d83701be26f31dde1b3c92e;
0x023547e676dba19784188825b901a0e70d8ad978300d21d6185a54281b734da0;

assert(actual.to_field() == test_data_default_hash);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,74 @@ export function buildLegacyOracleCallbacks(oracle: Oracle): ACIRCallback {
secret: ACVMField[],
): Promise<(ACVMField | ACVMField[])[]> =>
oracle.aztec_utl_getL1ToL2MembershipWitness(contractAddress, messageHash, secret),

// Point serialization changes: old format includes is_infinite field, new format omits it.
// Old getPublicKeysAndPartialAddress returns Option<[Field; 13]> with 4 keys as (x, y, is_infinite) + partial.
// New _v2 returns Option<[Field; 9]> with 4 keys as (x, y) + partial.
// eslint-disable-next-line camelcase
aztec_utl_getPublicKeysAndPartialAddress: async (address: ACVMField[]): Promise<(ACVMField | ACVMField[])[]> => {
const result = await oracle.aztec_utl_getPublicKeysAndPartialAddress_v2(address);
// result is [some, [k0.x, k0.y, k1.x, k1.y, k2.x, k2.y, k3.x, k3.y, partial_address]]
const some = result[0] as ACVMField;
const fields = result[1] as ACVMField[];
if (some === toACVMField(0)) {
// The None case
return [toACVMField(0), Array(13).fill(toACVMField(0))];
}

// Expand each key (x, y) → (x, y, is_infinite) where is_infinite = 1 if x == 0 && y == 0
const expanded: ACVMField[] = [];
for (let i = 0; i < 4; i++) {
// With new Noir infinite point is represented simply as [0, 0] so if x and y are 0 we set the is_infinite flag
// as 1, 0 otherwise.
const x = fields[i * 2];
const y = fields[i * 2 + 1];
const isInfinite = toACVMField(x === toACVMField(0) && y === toACVMField(0) ? 1 : 0);
expanded.push(x, y, isInfinite);
}
expanded.push(fields[8]); // partial_address
return [some, expanded];
},

// Old getSharedSecret takes 5 args (address, ephPK.x, ephPK.y, ephPK.is_infinite, contractAddress).
// New _v2 takes 4 args (without is_infinite).
// eslint-disable-next-line camelcase
aztec_utl_getSharedSecret: (
address: ACVMField[],
ephPKField0: ACVMField[],
ephPKField1: ACVMField[],
ephPKIsInfinite: ACVMField[],
contractAddress: ACVMField[],
): Promise<ACVMField[]> => {
if (
ephPKIsInfinite[0] !== toACVMField(0) &&
(ephPKField0[0] !== toACVMField(0) || ephPKField1[0] !== toACVMField(0))
) {
// We throw an error in case isInfinite flag is 1 and x, y are non-zero as at that would be a bug and it would
// not be possible to map the serialization from old Noir format (infinite point represented as [0, 0, 1]) to
// new Noir format (infinite point represented simply as [0, 0]).
throw new Error('Inconsistent ephemeral public key: is_infinite is set but x or y coordinates are non-zero');
}
return oracle.aztec_utl_getSharedSecret_v2(address, ephPKField0, ephPKField1, contractAddress);
},

// Old getContractInstance returns 16 fields: [salt, deployer, classId, initHash, 4×(x, y, is_infinite)].
// New _v2 returns 12 fields: [salt, deployer, classId, initHash, 4×(x, y)].
// eslint-disable-next-line camelcase
aztec_utl_getContractInstance: async (address: ACVMField[]): Promise<ACVMField[]> => {
const result = await oracle.aztec_utl_getContractInstance_v2(address);
// result is [salt, deployer, classId, initHash, k0.x, k0.y, k1.x, k1.y, k2.x, k2.y, k3.x, k3.y]
// Expand the public keys portion by inserting is_infinite after each (x, y) pair.
const expanded: ACVMField[] = result.slice(0, 4); // salt, deployer, classId, initHash
for (let i = 0; i < 4; i++) {
const x = result[4 + i * 2];
const y = result[4 + i * 2 + 1];
const isInfinite = toACVMField(x === toACVMField(0) && y === toACVMField(0) ? 1 : 0);
expanded.push(x, y, isInfinite);
}
return expanded;
},

// Renames (same signature, different oracle name)
privateNotifySetMinRevertibleSideEffectCounter: (counter: ACVMField[]): Promise<ACVMField[]> =>
oracle.aztec_prv_notifyRevertiblePhaseStart(counter),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class Oracle {
}

// eslint-disable-next-line camelcase
async aztec_utl_getContractInstance([address]: ACVMField[]): Promise<ACVMField[]> {
async aztec_utl_getContractInstance_v2([address]: ACVMField[]): Promise<ACVMField[]> {
const instance = await this.handlerAsUtility().getContractInstance(AztecAddress.fromField(Fr.fromString(address)));

return [
Expand Down Expand Up @@ -327,7 +327,7 @@ export class Oracle {
}

// eslint-disable-next-line camelcase
async aztec_utl_getPublicKeysAndPartialAddress([address]: ACVMField[]): Promise<(ACVMField | ACVMField[])[]> {
async aztec_utl_getPublicKeysAndPartialAddress_v2([address]: ACVMField[]): Promise<(ACVMField | ACVMField[])[]> {
const parsedAddress = AztecAddress.fromField(Fr.fromString(address));
const result = await this.handlerAsUtility().getPublicKeysAndPartialAddress(parsedAddress);

Expand Down Expand Up @@ -811,7 +811,7 @@ export class Oracle {
}

// eslint-disable-next-line camelcase
async aztec_utl_getSharedSecret(
async aztec_utl_getSharedSecret_v2(
[address]: ACVMField[],
[ephPKField0]: ACVMField[],
[ephPKField1]: ACVMField[],
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/pxe/src/oracle_version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/// used to provide helpful error messages if a contract calls an oracle that doesn't exist. We don't throw immediately
/// if AZTEC_NR_MINOR > PXE_MINOR because if a contract is updated to use a newer Aztec.nr dependency without actually
/// using any of the new oracles then there is no reason to throw.
export const ORACLE_VERSION_MAJOR = 23;
export const ORACLE_VERSION_MAJOR = 22;
export const ORACLE_VERSION_MINOR = 1;

/// This hash is computed from the Oracle interface and is used to detect when that interface changes. When it does,
Expand All @@ -19,4 +19,4 @@ export const ORACLE_VERSION_MINOR = 1;
/// - increment only `ORACLE_VERSION_MINOR` if the change is additive (a new oracle was added).
///
/// These constants must be kept in sync between this file and `noir-projects/aztec-nr/aztec/src/oracle/version.nr`.
export const ORACLE_INTERFACE_HASH = '6b67bc582a8b0d8d13287817b33aa664537e71a7263c96f2cd60bd1bb54a56f7';
export const ORACLE_INTERFACE_HASH = '6eeb003706db7eb6af63df232bdca57cd2bd4cf4e1b7493c8758f8f46fa26e42';
4 changes: 2 additions & 2 deletions yarn-project/stdlib/src/keys/derivation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('🔑', () => {
masterTaggingPublicKey,
).hash();
expect(publicKeysHash.toString()).toMatchInlineSnapshot(
`"0x14347f1d74d892ce45384ca5b69c2070d264e64458ef327ab7b42c850a3d437f"`,
`"0x056998309f6c119e4d753e404f94fef859dddfa530a9379634ceb0854b29bf7a"`,
);
// Run with AZTEC_GENERATE_TEST_DATA=1 to update noir test data
updateInlineTestData(
Expand Down Expand Up @@ -57,7 +57,7 @@ describe('🔑', () => {
const publicKeys = new PublicKeys(npkM, ivpkM, ovpkM, tpkM);
const partialAddress = Fr.fromHexString('0x0a7c585381b10f4666044266a02405bf6e01fa564c8517d4ad5823493abd31de');
const address = (await computeAddress(publicKeys, partialAddress)).toString();
expect(address).toMatchInlineSnapshot(`"0x04099cc9c76ec56f8d9d5d80af8a8a78ed1f180a123063034b14722a748394bb"`);
expect(address).toMatchInlineSnapshot(`"0x2f66081d4bb077fbe8e8abe96a3516a713a3d7e34360b4e985da0da95092b37d"`);
// Run with AZTEC_GENERATE_TEST_DATA=1 to update noir test data
updateInlineTestData(
'noir-projects/noir-protocol-circuits/crates/types/src/address/aztec_address.nr',
Expand Down
4 changes: 2 additions & 2 deletions yarn-project/stdlib/src/keys/public_keys.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('PublicKeys', () => {
);
const hash = await keys.hash();
expect(hash.toString()).toMatchInlineSnapshot(
`"0x14347f1d74d892ce45384ca5b69c2070d264e64458ef327ab7b42c850a3d437f"`,
`"0x056998309f6c119e4d753e404f94fef859dddfa530a9379634ceb0854b29bf7a"`,
);
// Run with AZTEC_GENERATE_TEST_DATA=1 to update noir test data
updateInlineTestData(
Expand All @@ -36,7 +36,7 @@ describe('PublicKeys', () => {
const keys = PublicKeys.default();
const hash = await keys.hash();
expect(hash.toString()).toMatchInlineSnapshot(
`"0x20c0a5f4c7c5bd4e0f9e7cdb69d16fcb9115d2a77d83701be26f31dde1b3c92e"`,
`"0x023547e676dba19784188825b901a0e70d8ad978300d21d6185a54281b734da0"`,
);
// Run with AZTEC_GENERATE_TEST_DATA=1 to update noir test data
updateInlineTestData(
Expand Down
26 changes: 15 additions & 11 deletions yarn-project/stdlib/src/keys/public_keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,21 @@ export class PublicKeys {
}

hash() {
return this.isEmpty()
? Fr.ZERO
: poseidon2HashWithSeparator(
[
this.masterNullifierPublicKey,
this.masterIncomingViewingPublicKey,
this.masterOutgoingViewingPublicKey,
this.masterTaggingPublicKey,
],
DomainSeparator.PUBLIC_KEYS_HASH,
);
if (this.isEmpty()) {
return Fr.ZERO;
}
// We explicitly serialize with is_infinite for backwards compatibility with contract addresses that were computed
// when Point had the is_infinite field (x, y, is_infinite).
const pointToFieldsWithIsInfinite = (p: Point) => [p.x, p.y, new Fr(p.isInfinite)];
return poseidon2HashWithSeparator(
[
...pointToFieldsWithIsInfinite(this.masterNullifierPublicKey),
...pointToFieldsWithIsInfinite(this.masterIncomingViewingPublicKey),
...pointToFieldsWithIsInfinite(this.masterOutgoingViewingPublicKey),
...pointToFieldsWithIsInfinite(this.masterTaggingPublicKey),
],
DomainSeparator.PUBLIC_KEYS_HASH,
);
}

isEmpty() {
Expand Down
6 changes: 3 additions & 3 deletions yarn-project/txe/src/rpc_translator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ export class RPCTranslator {
}

// eslint-disable-next-line camelcase
async aztec_utl_getContractInstance(foreignAddress: ForeignCallSingle) {
async aztec_utl_getContractInstance_v2(foreignAddress: ForeignCallSingle) {
const address = addressFromSingle(foreignAddress);

const instance = await this.handlerAsUtility().getContractInstance(address);
Expand All @@ -583,7 +583,7 @@ export class RPCTranslator {
}

// eslint-disable-next-line camelcase
async aztec_utl_getPublicKeysAndPartialAddress(foreignAddress: ForeignCallSingle) {
async aztec_utl_getPublicKeysAndPartialAddress_v2(foreignAddress: ForeignCallSingle) {
const address = addressFromSingle(foreignAddress);

const result = await this.handlerAsUtility().getPublicKeysAndPartialAddress(address);
Expand Down Expand Up @@ -1033,7 +1033,7 @@ export class RPCTranslator {
}

// eslint-disable-next-line camelcase
async aztec_utl_getSharedSecret(
async aztec_utl_getSharedSecret_v2(
foreignAddress: ForeignCallSingle,
foreignEphPKField0: ForeignCallSingle,
foreignEphPKField1: ForeignCallSingle,
Expand Down
Loading