@aztec/protocol-contracts 0.0.0-test.1 → 0.0.1-commit.017a351
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/artifacts/ContractClassRegistry.json +3950 -0
- package/artifacts/ContractInstanceRegistry.json +5132 -0
- package/artifacts/FeeJuice.json +5171 -2507
- package/dest/class-registry/contract_class_published_event.d.ts +20 -0
- package/dest/class-registry/contract_class_published_event.d.ts.map +1 -0
- package/dest/class-registry/contract_class_published_event.js +52 -0
- package/dest/class-registry/index.d.ts +6 -0
- package/dest/class-registry/index.d.ts.map +1 -0
- package/dest/class-registry/index.js +15 -0
- package/dest/class-registry/lazy.d.ts +7 -0
- package/dest/class-registry/lazy.d.ts.map +1 -0
- package/dest/class-registry/lazy.js +24 -0
- package/dest/fee-juice/index.d.ts +2 -2
- package/dest/fee-juice/index.d.ts.map +1 -1
- package/dest/fee-juice/index.js +4 -4
- package/dest/fee-juice/lazy.d.ts +1 -1
- package/dest/fee-juice/lazy.js +5 -5
- package/dest/index.d.ts +1 -2
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +0 -1
- package/dest/instance-registry/contract_instance_published_event.d.ts +22 -0
- package/dest/instance-registry/contract_instance_published_event.d.ts.map +1 -0
- package/dest/{instance-deployer/contract_instance_deployed_event.js → instance-registry/contract_instance_published_event.js} +15 -8
- package/dest/instance-registry/contract_instance_updated_event.d.ts +17 -0
- package/dest/instance-registry/contract_instance_updated_event.d.ts.map +1 -0
- package/dest/instance-registry/contract_instance_updated_event.js +35 -0
- package/dest/instance-registry/index.d.ts +7 -0
- package/dest/instance-registry/index.d.ts.map +1 -0
- package/dest/instance-registry/index.js +15 -0
- package/dest/instance-registry/lazy.d.ts +8 -0
- package/dest/{instance-deployer → instance-registry}/lazy.d.ts.map +1 -1
- package/dest/instance-registry/lazy.js +25 -0
- package/dest/make_protocol_contract.d.ts +4 -4
- package/dest/make_protocol_contract.d.ts.map +1 -1
- package/dest/make_protocol_contract.js +30 -14
- package/dest/protocol_contract.d.ts +1 -1
- package/dest/protocol_contract_data.d.ts +23 -16
- package/dest/protocol_contract_data.d.ts.map +1 -1
- package/dest/protocol_contract_data.js +82 -32
- package/dest/provider/bundle.d.ts +1 -1
- package/dest/provider/bundle.d.ts.map +1 -1
- package/dest/provider/bundle.js +6 -12
- package/dest/provider/lazy.d.ts +1 -1
- package/dest/provider/lazy.d.ts.map +1 -1
- package/dest/provider/lazy.js +6 -15
- package/dest/provider/protocol_contracts_provider.d.ts +1 -1
- package/dest/scripts/cleanup_artifacts.js +2 -2
- package/dest/scripts/generate_data.js +96 -56
- package/dest/tests/fixtures.d.ts +3 -7
- package/dest/tests/fixtures.d.ts.map +1 -1
- package/dest/tests/fixtures.js +4 -14
- package/package.json +23 -20
- package/src/class-registry/__snapshots__/README.md +9 -0
- package/src/class-registry/contract_class_published_event.ts +72 -0
- package/src/class-registry/index.ts +21 -0
- package/src/class-registry/lazy.ts +31 -0
- package/src/fee-juice/index.ts +5 -5
- package/src/fee-juice/lazy.ts +5 -5
- package/src/index.ts +0 -1
- package/src/instance-registry/__snapshots__/README.md +9 -0
- package/src/{instance-deployer/contract_instance_deployed_event.ts → instance-registry/contract_instance_published_event.ts} +18 -8
- package/src/{instance-deployer → instance-registry}/contract_instance_updated_event.ts +15 -15
- package/src/instance-registry/index.ts +23 -0
- package/src/instance-registry/lazy.ts +32 -0
- package/src/make_protocol_contract.ts +39 -15
- package/src/protocol_contract_data.ts +70 -32
- package/src/provider/bundle.ts +5 -11
- package/src/provider/lazy.ts +6 -15
- package/src/tests/fixtures.ts +4 -16
- package/artifacts/AuthRegistry.json +0 -2725
- package/artifacts/ContractClassRegisterer.json +0 -7219
- package/artifacts/ContractInstanceDeployer.d.json.ts +0 -5
- package/artifacts/ContractInstanceDeployer.json +0 -2984
- package/artifacts/MultiCallEntrypoint.d.json.ts +0 -5
- package/artifacts/MultiCallEntrypoint.json +0 -2005
- package/artifacts/Router.d.json.ts +0 -5
- package/artifacts/Router.json +0 -3798
- package/dest/auth-registry/index.d.ts +0 -5
- package/dest/auth-registry/index.d.ts.map +0 -1
- package/dest/auth-registry/index.js +0 -13
- package/dest/auth-registry/lazy.d.ts +0 -6
- package/dest/auth-registry/lazy.d.ts.map +0 -1
- package/dest/auth-registry/lazy.js +0 -23
- package/dest/build_protocol_contract_tree.d.ts +0 -10
- package/dest/build_protocol_contract_tree.d.ts.map +0 -1
- package/dest/build_protocol_contract_tree.js +0 -20
- package/dest/class-registerer/contract_class_registered_event.d.ts +0 -18
- package/dest/class-registerer/contract_class_registered_event.d.ts.map +0 -1
- package/dest/class-registerer/contract_class_registered_event.js +0 -63
- package/dest/class-registerer/index.d.ts +0 -8
- package/dest/class-registerer/index.d.ts.map +0 -1
- package/dest/class-registerer/index.js +0 -17
- package/dest/class-registerer/lazy.d.ts +0 -9
- package/dest/class-registerer/lazy.d.ts.map +0 -1
- package/dest/class-registerer/lazy.js +0 -26
- package/dest/class-registerer/private_function_broadcasted_event.d.ts +0 -46
- package/dest/class-registerer/private_function_broadcasted_event.d.ts.map +0 -1
- package/dest/class-registerer/private_function_broadcasted_event.js +0 -85
- package/dest/class-registerer/unconstrained_function_broadcasted_event.d.ts +0 -40
- package/dest/class-registerer/unconstrained_function_broadcasted_event.d.ts.map +0 -1
- package/dest/class-registerer/unconstrained_function_broadcasted_event.js +0 -81
- package/dest/instance-deployer/contract_instance_deployed_event.d.ts +0 -20
- package/dest/instance-deployer/contract_instance_deployed_event.d.ts.map +0 -1
- package/dest/instance-deployer/contract_instance_updated_event.d.ts +0 -16
- package/dest/instance-deployer/contract_instance_updated_event.d.ts.map +0 -1
- package/dest/instance-deployer/contract_instance_updated_event.js +0 -36
- package/dest/instance-deployer/index.d.ts +0 -7
- package/dest/instance-deployer/index.d.ts.map +0 -1
- package/dest/instance-deployer/index.js +0 -15
- package/dest/instance-deployer/lazy.d.ts +0 -8
- package/dest/instance-deployer/lazy.js +0 -25
- package/dest/multi-call-entrypoint/index.d.ts +0 -5
- package/dest/multi-call-entrypoint/index.d.ts.map +0 -1
- package/dest/multi-call-entrypoint/index.js +0 -13
- package/dest/multi-call-entrypoint/lazy.d.ts +0 -6
- package/dest/multi-call-entrypoint/lazy.d.ts.map +0 -1
- package/dest/multi-call-entrypoint/lazy.js +0 -23
- package/dest/protocol_contract_tree.d.ts +0 -7
- package/dest/protocol_contract_tree.d.ts.map +0 -1
- package/dest/protocol_contract_tree.js +0 -34
- package/dest/router/index.d.ts +0 -5
- package/dest/router/index.d.ts.map +0 -1
- package/dest/router/index.js +0 -13
- package/dest/router/lazy.d.ts +0 -6
- package/dest/router/lazy.d.ts.map +0 -1
- package/dest/router/lazy.js +0 -23
- package/src/auth-registry/index.ts +0 -18
- package/src/auth-registry/lazy.ts +0 -29
- package/src/build_protocol_contract_tree.ts +0 -29
- package/src/class-registerer/contract_class_registered_event.ts +0 -83
- package/src/class-registerer/index.ts +0 -25
- package/src/class-registerer/lazy.ts +0 -33
- package/src/class-registerer/private_function_broadcasted_event.ts +0 -105
- package/src/class-registerer/unconstrained_function_broadcasted_event.ts +0 -99
- package/src/instance-deployer/index.ts +0 -23
- package/src/instance-deployer/lazy.ts +0 -32
- package/src/multi-call-entrypoint/index.ts +0 -18
- package/src/multi-call-entrypoint/lazy.ts +0 -29
- package/src/protocol_contract_tree.ts +0 -44
- package/src/router/index.ts +0 -18
- package/src/router/lazy.ts +0 -29
- /package/artifacts/{AuthRegistry.d.json.ts → ContractClassRegistry.d.json.ts} +0 -0
- /package/artifacts/{ContractClassRegisterer.d.json.ts → ContractInstanceRegistry.d.json.ts} +0 -0
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { loadContractArtifact } from '@aztec/stdlib/abi';
|
|
2
|
-
import ContractInstanceDeployerJson from '../../artifacts/ContractInstanceDeployer.json' assert {
|
|
3
|
-
type: 'json'
|
|
4
|
-
};
|
|
5
|
-
import { makeProtocolContract } from '../make_protocol_contract.js';
|
|
6
|
-
export * from './contract_instance_deployed_event.js';
|
|
7
|
-
export * from './contract_instance_updated_event.js';
|
|
8
|
-
export const ContractInstanceDeployerArtifact = loadContractArtifact(ContractInstanceDeployerJson);
|
|
9
|
-
let protocolContract;
|
|
10
|
-
/** Returns the canonical deployment of the contract. */ export async function getCanonicalInstanceDeployer() {
|
|
11
|
-
if (!protocolContract) {
|
|
12
|
-
protocolContract = await makeProtocolContract('ContractInstanceDeployer', ContractInstanceDeployerArtifact);
|
|
13
|
-
}
|
|
14
|
-
return protocolContract;
|
|
15
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { type ContractArtifact } from '@aztec/stdlib/abi';
|
|
2
|
-
import type { ProtocolContract } from '../protocol_contract.js';
|
|
3
|
-
export * from './contract_instance_deployed_event.js';
|
|
4
|
-
export * from './contract_instance_updated_event.js';
|
|
5
|
-
export declare function getContractInstanceDeployerArtifact(): Promise<ContractArtifact>;
|
|
6
|
-
/** Returns the canonical deployment of the auth registry. */
|
|
7
|
-
export declare function getCanonicalInstanceDeployer(): Promise<ProtocolContract>;
|
|
8
|
-
//# sourceMappingURL=lazy.d.ts.map
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { loadContractArtifact } from '@aztec/stdlib/abi';
|
|
2
|
-
import { makeProtocolContract } from '../make_protocol_contract.js';
|
|
3
|
-
export * from './contract_instance_deployed_event.js';
|
|
4
|
-
export * from './contract_instance_updated_event.js';
|
|
5
|
-
let protocolContract;
|
|
6
|
-
let protocolContractArtifact;
|
|
7
|
-
export async function getContractInstanceDeployerArtifact() {
|
|
8
|
-
if (!protocolContractArtifact) {
|
|
9
|
-
// Cannot assert this import as it's incompatible with browsers
|
|
10
|
-
// https://caniuse.com/mdn-javascript_statements_import_import_assertions_type_json
|
|
11
|
-
// Use the new "with" syntax once supported by firefox
|
|
12
|
-
// https://caniuse.com/mdn-javascript_statements_import_import_attributes_type_json
|
|
13
|
-
// In the meantime, this lazy import is INCOMPATIBLE WITH NODEJS
|
|
14
|
-
const { default: contractInstanceDeployerJson } = await import('../../artifacts/ContractInstanceDeployer.json');
|
|
15
|
-
protocolContractArtifact = loadContractArtifact(contractInstanceDeployerJson);
|
|
16
|
-
}
|
|
17
|
-
return protocolContractArtifact;
|
|
18
|
-
}
|
|
19
|
-
/** Returns the canonical deployment of the auth registry. */ export async function getCanonicalInstanceDeployer() {
|
|
20
|
-
if (!protocolContract) {
|
|
21
|
-
const contractInstanceDeployerArtifact = await getContractInstanceDeployerArtifact();
|
|
22
|
-
protocolContract = await makeProtocolContract('ContractInstanceDeployer', contractInstanceDeployerArtifact);
|
|
23
|
-
}
|
|
24
|
-
return protocolContract;
|
|
25
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { ProtocolContract } from '../protocol_contract.js';
|
|
2
|
-
export declare const MultiCallEntrypointArtifact: import("@aztec/stdlib/abi").ContractArtifact;
|
|
3
|
-
/** Returns the canonical deployment of the contract. */
|
|
4
|
-
export declare function getCanonicalMultiCallEntrypoint(): Promise<ProtocolContract>;
|
|
5
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/multi-call-entrypoint/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,eAAO,MAAM,2BAA2B,8CAAwE,CAAC;AAIjH,wDAAwD;AACxD,wBAAsB,+BAA+B,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAKjF"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { loadContractArtifact } from '@aztec/stdlib/abi';
|
|
2
|
-
import MultiCallEntrypointJson from '../../artifacts/MultiCallEntrypoint.json' assert {
|
|
3
|
-
type: 'json'
|
|
4
|
-
};
|
|
5
|
-
import { makeProtocolContract } from '../make_protocol_contract.js';
|
|
6
|
-
export const MultiCallEntrypointArtifact = loadContractArtifact(MultiCallEntrypointJson);
|
|
7
|
-
let protocolContract;
|
|
8
|
-
/** Returns the canonical deployment of the contract. */ export async function getCanonicalMultiCallEntrypoint() {
|
|
9
|
-
if (!protocolContract) {
|
|
10
|
-
protocolContract = await makeProtocolContract('MultiCallEntrypoint', MultiCallEntrypointArtifact);
|
|
11
|
-
}
|
|
12
|
-
return protocolContract;
|
|
13
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type ContractArtifact } from '@aztec/stdlib/abi';
|
|
2
|
-
import type { ProtocolContract } from '../protocol_contract.js';
|
|
3
|
-
export declare function getMultiCallEntrypointArtifact(): Promise<ContractArtifact>;
|
|
4
|
-
/** Returns the canonical deployment of the auth registry. */
|
|
5
|
-
export declare function getCanonicalMultiCallEntrypoint(): Promise<ProtocolContract>;
|
|
6
|
-
//# sourceMappingURL=lazy.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lazy.d.ts","sourceRoot":"","sources":["../../src/multi-call-entrypoint/lazy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAwB,MAAM,mBAAmB,CAAC;AAGhF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAKhE,wBAAsB,8BAA8B,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAWhF;AAED,6DAA6D;AAC7D,wBAAsB,+BAA+B,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAMjF"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { loadContractArtifact } from '@aztec/stdlib/abi';
|
|
2
|
-
import { makeProtocolContract } from '../make_protocol_contract.js';
|
|
3
|
-
let protocolContract;
|
|
4
|
-
let protocolContractArtifact;
|
|
5
|
-
export async function getMultiCallEntrypointArtifact() {
|
|
6
|
-
if (!protocolContractArtifact) {
|
|
7
|
-
// Cannot assert this import as it's incompatible with browsers
|
|
8
|
-
// https://caniuse.com/mdn-javascript_statements_import_import_assertions_type_json
|
|
9
|
-
// Use the new "with" syntax once supported by firefox
|
|
10
|
-
// https://caniuse.com/mdn-javascript_statements_import_import_attributes_type_json
|
|
11
|
-
// In the meantime, this lazy import is INCOMPATIBLE WITH NODEJS
|
|
12
|
-
const { default: multiCallEntrypointJson } = await import('../../artifacts/MultiCallEntrypoint.json');
|
|
13
|
-
protocolContractArtifact = loadContractArtifact(multiCallEntrypointJson);
|
|
14
|
-
}
|
|
15
|
-
return protocolContractArtifact;
|
|
16
|
-
}
|
|
17
|
-
/** Returns the canonical deployment of the auth registry. */ export async function getCanonicalMultiCallEntrypoint() {
|
|
18
|
-
if (!protocolContract) {
|
|
19
|
-
const multiCallEntrypointArtifact = await getMultiCallEntrypointArtifact();
|
|
20
|
-
protocolContract = await makeProtocolContract('MultiCallEntrypoint', multiCallEntrypointArtifact);
|
|
21
|
-
}
|
|
22
|
-
return protocolContract;
|
|
23
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
2
|
-
import type { ProtocolContractLeafPreimage } from '@aztec/stdlib/trees';
|
|
3
|
-
export declare function getProtocolContractLeafAndMembershipWitness(contractAddress: AztecAddress, computedAddress: AztecAddress): Promise<{
|
|
4
|
-
lowLeaf: ProtocolContractLeafPreimage;
|
|
5
|
-
witness: import("@aztec/foundation/trees").MembershipWitness<3>;
|
|
6
|
-
}>;
|
|
7
|
-
//# sourceMappingURL=protocol_contract_tree.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"protocol_contract_tree.d.ts","sourceRoot":"","sources":["../src/protocol_contract_tree.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,qBAAqB,CAAC;AAsBxE,wBAAsB,2CAA2C,CAC/D,eAAe,EAAE,YAAY,EAC7B,eAAe,EAAE,YAAY;;;GAe9B"}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { poseidon2Hash } from '@aztec/foundation/crypto';
|
|
2
|
-
import { buildProtocolContractTree } from './build_protocol_contract_tree.js';
|
|
3
|
-
import { isProtocolContract } from './protocol_contract.js';
|
|
4
|
-
import { ProtocolContractAddress, ProtocolContractLeaves, protocolContractNames } from './protocol_contract_data.js';
|
|
5
|
-
let protocolContractTree;
|
|
6
|
-
async function getTree() {
|
|
7
|
-
if (!protocolContractTree) {
|
|
8
|
-
const leaves = protocolContractNames.map((name)=>({
|
|
9
|
-
address: ProtocolContractAddress[name],
|
|
10
|
-
leaf: ProtocolContractLeaves[name]
|
|
11
|
-
}));
|
|
12
|
-
protocolContractTree = await buildProtocolContractTree(leaves);
|
|
13
|
-
}
|
|
14
|
-
return protocolContractTree;
|
|
15
|
-
}
|
|
16
|
-
// Computed address can be different from contract address due to upgrades
|
|
17
|
-
export async function getProtocolContractLeafAndMembershipWitness(contractAddress, computedAddress) {
|
|
18
|
-
const tree = await getTree();
|
|
19
|
-
let lowLeaf;
|
|
20
|
-
let witness;
|
|
21
|
-
if (isProtocolContract(contractAddress)) {
|
|
22
|
-
const index = contractAddress.toField().toNumber();
|
|
23
|
-
lowLeaf = tree.leafPreimages[index];
|
|
24
|
-
witness = tree.getMembershipWitness(index);
|
|
25
|
-
} else {
|
|
26
|
-
lowLeaf = tree.getLowLeaf(computedAddress.toBigInt());
|
|
27
|
-
const hashed = (await poseidon2Hash(lowLeaf.toHashInputs())).toBuffer();
|
|
28
|
-
witness = tree.getMembershipWitness(hashed);
|
|
29
|
-
}
|
|
30
|
-
return {
|
|
31
|
-
lowLeaf,
|
|
32
|
-
witness
|
|
33
|
-
};
|
|
34
|
-
}
|
package/dest/router/index.d.ts
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { ProtocolContract } from '../protocol_contract.js';
|
|
2
|
-
export declare const RouterArtifact: import("@aztec/stdlib/abi").ContractArtifact;
|
|
3
|
-
/** Returns the canonical deployment of the contract. */
|
|
4
|
-
export declare function getCanonicalRouter(): Promise<ProtocolContract>;
|
|
5
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/router/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,eAAO,MAAM,cAAc,8CAA2D,CAAC;AAIvF,wDAAwD;AACxD,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAKpE"}
|
package/dest/router/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { loadContractArtifact } from '@aztec/stdlib/abi';
|
|
2
|
-
import RouterJson from '../../artifacts/Router.json' assert {
|
|
3
|
-
type: 'json'
|
|
4
|
-
};
|
|
5
|
-
import { makeProtocolContract } from '../make_protocol_contract.js';
|
|
6
|
-
export const RouterArtifact = loadContractArtifact(RouterJson);
|
|
7
|
-
let protocolContract;
|
|
8
|
-
/** Returns the canonical deployment of the contract. */ export async function getCanonicalRouter() {
|
|
9
|
-
if (!protocolContract) {
|
|
10
|
-
protocolContract = await makeProtocolContract('Router', RouterArtifact);
|
|
11
|
-
}
|
|
12
|
-
return protocolContract;
|
|
13
|
-
}
|
package/dest/router/lazy.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type ContractArtifact } from '@aztec/stdlib/abi';
|
|
2
|
-
import type { ProtocolContract } from '../protocol_contract.js';
|
|
3
|
-
export declare function getRouterArtifact(): Promise<ContractArtifact>;
|
|
4
|
-
/** Returns the canonical deployment of the auth registry. */
|
|
5
|
-
export declare function getCanonicalRouter(): Promise<ProtocolContract>;
|
|
6
|
-
//# sourceMappingURL=lazy.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lazy.d.ts","sourceRoot":"","sources":["../../src/router/lazy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAwB,MAAM,mBAAmB,CAAC;AAGhF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAKhE,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAWnE;AAED,6DAA6D;AAC7D,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAMpE"}
|
package/dest/router/lazy.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { loadContractArtifact } from '@aztec/stdlib/abi';
|
|
2
|
-
import { makeProtocolContract } from '../make_protocol_contract.js';
|
|
3
|
-
let protocolContract;
|
|
4
|
-
let protocolContractArtifact;
|
|
5
|
-
export async function getRouterArtifact() {
|
|
6
|
-
if (!protocolContractArtifact) {
|
|
7
|
-
// Cannot assert this import as it's incompatible with browsers
|
|
8
|
-
// https://caniuse.com/mdn-javascript_statements_import_import_assertions_type_json
|
|
9
|
-
// Use the new "with" syntax once supported by firefox
|
|
10
|
-
// https://caniuse.com/mdn-javascript_statements_import_import_attributes_type_json
|
|
11
|
-
// In the meantime, this lazy import is INCOMPATIBLE WITH NODEJS
|
|
12
|
-
const { default: routerJson } = await import('../../artifacts/Router.json');
|
|
13
|
-
protocolContractArtifact = loadContractArtifact(routerJson);
|
|
14
|
-
}
|
|
15
|
-
return protocolContractArtifact;
|
|
16
|
-
}
|
|
17
|
-
/** Returns the canonical deployment of the auth registry. */ export async function getCanonicalRouter() {
|
|
18
|
-
if (!protocolContract) {
|
|
19
|
-
const routerArtifact = await getRouterArtifact();
|
|
20
|
-
protocolContract = await makeProtocolContract('Router', routerArtifact);
|
|
21
|
-
}
|
|
22
|
-
return protocolContract;
|
|
23
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { loadContractArtifact } from '@aztec/stdlib/abi';
|
|
2
|
-
import type { NoirCompiledContract } from '@aztec/stdlib/noir';
|
|
3
|
-
|
|
4
|
-
import AuthRegistryJson from '../../artifacts/AuthRegistry.json' assert { type: 'json' };
|
|
5
|
-
import { makeProtocolContract } from '../make_protocol_contract.js';
|
|
6
|
-
import type { ProtocolContract } from '../protocol_contract.js';
|
|
7
|
-
|
|
8
|
-
let protocolContract: ProtocolContract;
|
|
9
|
-
|
|
10
|
-
export const AuthRegistryArtifact = loadContractArtifact(AuthRegistryJson as NoirCompiledContract);
|
|
11
|
-
|
|
12
|
-
/** Returns the canonical deployment of the auth registry. */
|
|
13
|
-
export async function getCanonicalAuthRegistry(): Promise<ProtocolContract> {
|
|
14
|
-
if (!protocolContract) {
|
|
15
|
-
protocolContract = await makeProtocolContract('AuthRegistry', AuthRegistryArtifact);
|
|
16
|
-
}
|
|
17
|
-
return protocolContract;
|
|
18
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { type ContractArtifact, loadContractArtifact } from '@aztec/stdlib/abi';
|
|
2
|
-
|
|
3
|
-
import { makeProtocolContract } from '../make_protocol_contract.js';
|
|
4
|
-
import type { ProtocolContract } from '../protocol_contract.js';
|
|
5
|
-
|
|
6
|
-
let protocolContract: ProtocolContract;
|
|
7
|
-
let protocolContractArtifact: ContractArtifact;
|
|
8
|
-
|
|
9
|
-
export async function getAuthRegistryArtifact(): Promise<ContractArtifact> {
|
|
10
|
-
if (!protocolContractArtifact) {
|
|
11
|
-
// Cannot assert this import as it's incompatible with browsers
|
|
12
|
-
// https://caniuse.com/mdn-javascript_statements_import_import_assertions_type_json
|
|
13
|
-
// Use the new "with" syntax once supported by firefox
|
|
14
|
-
// https://caniuse.com/mdn-javascript_statements_import_import_attributes_type_json
|
|
15
|
-
// In the meantime, this lazy import is INCOMPATIBLE WITH NODEJS
|
|
16
|
-
const { default: authRegistryJson } = await import('../../artifacts/AuthRegistry.json');
|
|
17
|
-
protocolContractArtifact = loadContractArtifact(authRegistryJson);
|
|
18
|
-
}
|
|
19
|
-
return protocolContractArtifact;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** Returns the canonical deployment of the auth registry. */
|
|
23
|
-
export async function getCanonicalAuthRegistry(): Promise<ProtocolContract> {
|
|
24
|
-
if (!protocolContract) {
|
|
25
|
-
const authRegistryArtifact = await getAuthRegistryArtifact();
|
|
26
|
-
protocolContract = await makeProtocolContract('AuthRegistry', authRegistryArtifact);
|
|
27
|
-
}
|
|
28
|
-
return protocolContract;
|
|
29
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { MAX_PROTOCOL_CONTRACTS, PROTOCOL_CONTRACT_TREE_HEIGHT } from '@aztec/constants';
|
|
2
|
-
import { poseidon2Hash } from '@aztec/foundation/crypto';
|
|
3
|
-
import type { Fr } from '@aztec/foundation/fields';
|
|
4
|
-
import { type IndexedMerkleTree, IndexedMerkleTreeCalculator } from '@aztec/foundation/trees';
|
|
5
|
-
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
6
|
-
import { ProtocolContractLeafPreimage } from '@aztec/stdlib/trees';
|
|
7
|
-
|
|
8
|
-
export async function buildProtocolContractTree(
|
|
9
|
-
contracts: { address: AztecAddress; leaf: Fr }[],
|
|
10
|
-
): Promise<IndexedMerkleTree<ProtocolContractLeafPreimage, typeof PROTOCOL_CONTRACT_TREE_HEIGHT>> {
|
|
11
|
-
const hasher = {
|
|
12
|
-
hash: async (l: Buffer, r: Buffer) => (await poseidon2Hash([l, r])).toBuffer(),
|
|
13
|
-
hashInputs: async (i: Buffer[]) => (await poseidon2Hash(i)).toBuffer(),
|
|
14
|
-
};
|
|
15
|
-
const calculator = await IndexedMerkleTreeCalculator.create(
|
|
16
|
-
PROTOCOL_CONTRACT_TREE_HEIGHT,
|
|
17
|
-
hasher,
|
|
18
|
-
ProtocolContractLeafPreimage,
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
const leaves = new Array(MAX_PROTOCOL_CONTRACTS).fill(Buffer.alloc(32));
|
|
22
|
-
|
|
23
|
-
for (const contract of contracts) {
|
|
24
|
-
const index = contract.address.toField().toNumber();
|
|
25
|
-
leaves[index] = contract.leaf.toBuffer();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return calculator.computeTree(leaves);
|
|
29
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { PUBLIC_DISPATCH_SELECTOR } from '@aztec/constants';
|
|
2
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
3
|
-
import { FieldReader } from '@aztec/foundation/serialize';
|
|
4
|
-
import { FunctionSelector, bufferFromFields } from '@aztec/stdlib/abi';
|
|
5
|
-
import {
|
|
6
|
-
type ContractClassPublic,
|
|
7
|
-
type PublicFunction,
|
|
8
|
-
computeContractClassId,
|
|
9
|
-
computePublicBytecodeCommitment,
|
|
10
|
-
} from '@aztec/stdlib/contract';
|
|
11
|
-
import type { ContractClassLog } from '@aztec/stdlib/logs';
|
|
12
|
-
|
|
13
|
-
import { REGISTERER_CONTRACT_CLASS_REGISTERED_TAG } from '../protocol_contract_data.js';
|
|
14
|
-
|
|
15
|
-
/** Event emitted from the ContractClassRegisterer. */
|
|
16
|
-
export class ContractClassRegisteredEvent {
|
|
17
|
-
constructor(
|
|
18
|
-
public readonly contractClassId: Fr,
|
|
19
|
-
public readonly version: number,
|
|
20
|
-
public readonly artifactHash: Fr,
|
|
21
|
-
public readonly privateFunctionsRoot: Fr,
|
|
22
|
-
public readonly packedPublicBytecode: Buffer,
|
|
23
|
-
) {}
|
|
24
|
-
|
|
25
|
-
static isContractClassRegisteredEvent(log: ContractClassLog) {
|
|
26
|
-
return log.fields[0].equals(REGISTERER_CONTRACT_CLASS_REGISTERED_TAG);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
static fromLog(log: ContractClassLog) {
|
|
30
|
-
const reader = new FieldReader(log.fields.slice(1));
|
|
31
|
-
const contractClassId = reader.readField();
|
|
32
|
-
const version = reader.readField().toNumber();
|
|
33
|
-
const artifactHash = reader.readField();
|
|
34
|
-
const privateFunctionsRoot = reader.readField();
|
|
35
|
-
const packedPublicBytecode = bufferFromFields(reader.readFieldArray(log.fields.slice(1).length - reader.cursor));
|
|
36
|
-
|
|
37
|
-
return new ContractClassRegisteredEvent(
|
|
38
|
-
contractClassId,
|
|
39
|
-
version,
|
|
40
|
-
artifactHash,
|
|
41
|
-
privateFunctionsRoot,
|
|
42
|
-
packedPublicBytecode,
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
async toContractClassPublic(): Promise<ContractClassPublic> {
|
|
47
|
-
const computedClassId = await computeContractClassId({
|
|
48
|
-
artifactHash: this.artifactHash,
|
|
49
|
-
privateFunctionsRoot: this.privateFunctionsRoot,
|
|
50
|
-
publicBytecodeCommitment: await computePublicBytecodeCommitment(this.packedPublicBytecode),
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
if (!computedClassId.equals(this.contractClassId)) {
|
|
54
|
-
throw new Error(
|
|
55
|
-
`Invalid contract class id: computed ${computedClassId.toString()} but event broadcasted ${this.contractClassId.toString()}`,
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (this.version !== 1) {
|
|
60
|
-
throw new Error(`Unexpected contract class version ${this.version}`);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// TODO(https://github.com/AztecProtocol/aztec-packages/issues/8985): Remove public functions.
|
|
64
|
-
const publicFunctions: PublicFunction[] = [];
|
|
65
|
-
if (this.packedPublicBytecode.length > 0) {
|
|
66
|
-
publicFunctions.push({
|
|
67
|
-
selector: FunctionSelector.fromField(new Fr(PUBLIC_DISPATCH_SELECTOR)),
|
|
68
|
-
bytecode: this.packedPublicBytecode,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
id: this.contractClassId,
|
|
74
|
-
artifactHash: this.artifactHash,
|
|
75
|
-
packedBytecode: this.packedPublicBytecode,
|
|
76
|
-
privateFunctionsRoot: this.privateFunctionsRoot,
|
|
77
|
-
publicFunctions: publicFunctions,
|
|
78
|
-
version: this.version,
|
|
79
|
-
privateFunctions: [],
|
|
80
|
-
unconstrainedFunctions: [],
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { loadContractArtifact } from '@aztec/stdlib/abi';
|
|
2
|
-
import type { NoirCompiledContract } from '@aztec/stdlib/noir';
|
|
3
|
-
|
|
4
|
-
import ContractClassRegistererJson from '../../artifacts/ContractClassRegisterer.json' assert { type: 'json' };
|
|
5
|
-
import { makeProtocolContract } from '../make_protocol_contract.js';
|
|
6
|
-
import type { ProtocolContract } from '../protocol_contract.js';
|
|
7
|
-
|
|
8
|
-
export * from './contract_class_registered_event.js';
|
|
9
|
-
export * from './private_function_broadcasted_event.js';
|
|
10
|
-
export * from './unconstrained_function_broadcasted_event.js';
|
|
11
|
-
|
|
12
|
-
export const ContractClassRegistererArtifact = loadContractArtifact(
|
|
13
|
-
ContractClassRegistererJson as NoirCompiledContract,
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
let protocolContract: ProtocolContract;
|
|
17
|
-
|
|
18
|
-
/** Returns the canonical deployment of the contract. */
|
|
19
|
-
export async function getCanonicalClassRegisterer(): Promise<ProtocolContract> {
|
|
20
|
-
if (!protocolContract) {
|
|
21
|
-
const artifact = ContractClassRegistererArtifact;
|
|
22
|
-
protocolContract = await makeProtocolContract('ContractClassRegisterer', artifact);
|
|
23
|
-
}
|
|
24
|
-
return protocolContract;
|
|
25
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { type ContractArtifact, loadContractArtifact } from '@aztec/stdlib/abi';
|
|
2
|
-
|
|
3
|
-
import { makeProtocolContract } from '../make_protocol_contract.js';
|
|
4
|
-
import type { ProtocolContract } from '../protocol_contract.js';
|
|
5
|
-
|
|
6
|
-
export * from './contract_class_registered_event.js';
|
|
7
|
-
export * from './private_function_broadcasted_event.js';
|
|
8
|
-
export * from './unconstrained_function_broadcasted_event.js';
|
|
9
|
-
|
|
10
|
-
let protocolContract: ProtocolContract;
|
|
11
|
-
let protocolContractArtifact: ContractArtifact;
|
|
12
|
-
|
|
13
|
-
export async function getContractClassRegistererArtifact(): Promise<ContractArtifact> {
|
|
14
|
-
if (!protocolContractArtifact) {
|
|
15
|
-
// Cannot assert this import as it's incompatible with browsers
|
|
16
|
-
// https://caniuse.com/mdn-javascript_statements_import_import_assertions_type_json
|
|
17
|
-
// Use the new "with" syntax once supported by firefox
|
|
18
|
-
// https://caniuse.com/mdn-javascript_statements_import_import_attributes_type_json
|
|
19
|
-
// In the meantime, this lazy import is INCOMPATIBLE WITH NODEJS
|
|
20
|
-
const { default: contractClassRegistererJson } = await import('../../artifacts/ContractClassRegisterer.json');
|
|
21
|
-
protocolContractArtifact = loadContractArtifact(contractClassRegistererJson);
|
|
22
|
-
}
|
|
23
|
-
return protocolContractArtifact;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/** Returns the canonical deployment of the auth registry. */
|
|
27
|
-
export async function getCanonicalClassRegisterer(): Promise<ProtocolContract> {
|
|
28
|
-
if (!protocolContract) {
|
|
29
|
-
const contractClassRegistererArtifact = await getContractClassRegistererArtifact();
|
|
30
|
-
protocolContract = await makeProtocolContract('ContractClassRegisterer', contractClassRegistererArtifact);
|
|
31
|
-
}
|
|
32
|
-
return protocolContract;
|
|
33
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ARTIFACT_FUNCTION_TREE_MAX_HEIGHT,
|
|
3
|
-
FUNCTION_TREE_HEIGHT,
|
|
4
|
-
MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS,
|
|
5
|
-
} from '@aztec/constants';
|
|
6
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
7
|
-
import type { Tuple } from '@aztec/foundation/serialize';
|
|
8
|
-
import { FieldReader } from '@aztec/foundation/serialize';
|
|
9
|
-
import { FunctionSelector, bufferFromFields } from '@aztec/stdlib/abi';
|
|
10
|
-
import type { ExecutablePrivateFunctionWithMembershipProof, PrivateFunction } from '@aztec/stdlib/contract';
|
|
11
|
-
import type { ContractClassLog } from '@aztec/stdlib/logs';
|
|
12
|
-
|
|
13
|
-
import { REGISTERER_PRIVATE_FUNCTION_BROADCASTED_TAG } from '../protocol_contract_data.js';
|
|
14
|
-
|
|
15
|
-
/** Event emitted from the ContractClassRegisterer. */
|
|
16
|
-
export class PrivateFunctionBroadcastedEvent {
|
|
17
|
-
constructor(
|
|
18
|
-
public readonly contractClassId: Fr,
|
|
19
|
-
public readonly artifactMetadataHash: Fr,
|
|
20
|
-
public readonly unconstrainedFunctionsArtifactTreeRoot: Fr,
|
|
21
|
-
public readonly privateFunctionTreeSiblingPath: Tuple<Fr, typeof FUNCTION_TREE_HEIGHT>,
|
|
22
|
-
public readonly privateFunctionTreeLeafIndex: number,
|
|
23
|
-
public readonly artifactFunctionTreeSiblingPath: Tuple<Fr, typeof ARTIFACT_FUNCTION_TREE_MAX_HEIGHT>,
|
|
24
|
-
public readonly artifactFunctionTreeLeafIndex: number,
|
|
25
|
-
public readonly privateFunction: BroadcastedPrivateFunction,
|
|
26
|
-
) {}
|
|
27
|
-
|
|
28
|
-
static isPrivateFunctionBroadcastedEvent(log: ContractClassLog) {
|
|
29
|
-
return log.fields[0].equals(REGISTERER_PRIVATE_FUNCTION_BROADCASTED_TAG);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
static fromLog(log: ContractClassLog) {
|
|
33
|
-
const reader = new FieldReader(log.fields.slice(1));
|
|
34
|
-
const event = PrivateFunctionBroadcastedEvent.fromFields(reader);
|
|
35
|
-
while (!reader.isFinished()) {
|
|
36
|
-
const field = reader.readField();
|
|
37
|
-
if (!field.isZero()) {
|
|
38
|
-
throw new Error(`Unexpected data after parsing PrivateFunctionBroadcastedEvent: ${field.toString()}`);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return event;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
static fromFields(fields: Fr[] | FieldReader) {
|
|
46
|
-
const reader = FieldReader.asReader(fields);
|
|
47
|
-
const contractClassId = reader.readField();
|
|
48
|
-
const artifactMetadataHash = reader.readField();
|
|
49
|
-
const unconstrainedFunctionsArtifactTreeRoot = reader.readField();
|
|
50
|
-
const privateFunctionTreeSiblingPath = reader.readFieldArray(FUNCTION_TREE_HEIGHT);
|
|
51
|
-
const privateFunctionTreeLeafIndex = reader.readField().toNumber();
|
|
52
|
-
const artifactFunctionTreeSiblingPath = reader.readFieldArray(ARTIFACT_FUNCTION_TREE_MAX_HEIGHT);
|
|
53
|
-
const artifactFunctionTreeLeafIndex = reader.readField().toNumber();
|
|
54
|
-
const privateFunction = BroadcastedPrivateFunction.fromFields(reader);
|
|
55
|
-
|
|
56
|
-
return new PrivateFunctionBroadcastedEvent(
|
|
57
|
-
contractClassId,
|
|
58
|
-
artifactMetadataHash,
|
|
59
|
-
unconstrainedFunctionsArtifactTreeRoot,
|
|
60
|
-
privateFunctionTreeSiblingPath,
|
|
61
|
-
privateFunctionTreeLeafIndex,
|
|
62
|
-
artifactFunctionTreeSiblingPath,
|
|
63
|
-
artifactFunctionTreeLeafIndex,
|
|
64
|
-
privateFunction,
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
toFunctionWithMembershipProof(): ExecutablePrivateFunctionWithMembershipProof {
|
|
69
|
-
return {
|
|
70
|
-
...this.privateFunction,
|
|
71
|
-
bytecode: this.privateFunction.bytecode,
|
|
72
|
-
functionMetadataHash: this.privateFunction.metadataHash,
|
|
73
|
-
artifactMetadataHash: this.artifactMetadataHash,
|
|
74
|
-
unconstrainedFunctionsArtifactTreeRoot: this.unconstrainedFunctionsArtifactTreeRoot,
|
|
75
|
-
privateFunctionTreeSiblingPath: this.privateFunctionTreeSiblingPath,
|
|
76
|
-
privateFunctionTreeLeafIndex: this.privateFunctionTreeLeafIndex,
|
|
77
|
-
artifactTreeSiblingPath: this.artifactFunctionTreeSiblingPath.filter(fr => !fr.isZero()),
|
|
78
|
-
artifactTreeLeafIndex: this.artifactFunctionTreeLeafIndex,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export class BroadcastedPrivateFunction implements PrivateFunction {
|
|
84
|
-
constructor(
|
|
85
|
-
/** Selector of the function. Calculated as the hash of the method name and parameters. The specification of this is not enforced by the protocol. */
|
|
86
|
-
public readonly selector: FunctionSelector,
|
|
87
|
-
/** Artifact metadata hash */
|
|
88
|
-
public readonly metadataHash: Fr,
|
|
89
|
-
/** Hash of the verification key associated to this private function. */
|
|
90
|
-
public readonly vkHash: Fr,
|
|
91
|
-
/** ACIR and Brillig bytecode */
|
|
92
|
-
public readonly bytecode: Buffer,
|
|
93
|
-
) {}
|
|
94
|
-
|
|
95
|
-
static fromFields(fields: Fr[] | FieldReader) {
|
|
96
|
-
const reader = FieldReader.asReader(fields);
|
|
97
|
-
const selector = FunctionSelector.fromField(reader.readField());
|
|
98
|
-
const metadataHash = reader.readField();
|
|
99
|
-
const vkHash = reader.readField();
|
|
100
|
-
// The '* 1' removes the 'Type instantiation is excessively deep and possibly infinite. ts(2589)' err
|
|
101
|
-
const encodedBytecode = reader.readFieldArray(MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS * 1);
|
|
102
|
-
const bytecode = bufferFromFields(encodedBytecode);
|
|
103
|
-
return new BroadcastedPrivateFunction(selector, metadataHash, vkHash, bytecode);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ARTIFACT_FUNCTION_TREE_MAX_HEIGHT,
|
|
3
|
-
MAX_PACKED_BYTECODE_SIZE_PER_UNCONSTRAINED_FUNCTION_IN_FIELDS,
|
|
4
|
-
} from '@aztec/constants';
|
|
5
|
-
import { removeArrayPaddingEnd } from '@aztec/foundation/collection';
|
|
6
|
-
import { Fr } from '@aztec/foundation/fields';
|
|
7
|
-
import type { Tuple } from '@aztec/foundation/serialize';
|
|
8
|
-
import { FieldReader } from '@aztec/foundation/serialize';
|
|
9
|
-
import { FunctionSelector, bufferFromFields } from '@aztec/stdlib/abi';
|
|
10
|
-
import type { UnconstrainedFunction, UnconstrainedFunctionWithMembershipProof } from '@aztec/stdlib/contract';
|
|
11
|
-
import type { ContractClassLog } from '@aztec/stdlib/logs';
|
|
12
|
-
|
|
13
|
-
import { REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_TAG } from '../protocol_contract_data.js';
|
|
14
|
-
|
|
15
|
-
/** Event emitted from the ContractClassRegisterer. */
|
|
16
|
-
export class UnconstrainedFunctionBroadcastedEvent {
|
|
17
|
-
constructor(
|
|
18
|
-
public readonly contractClassId: Fr,
|
|
19
|
-
public readonly artifactMetadataHash: Fr,
|
|
20
|
-
public readonly privateFunctionsArtifactTreeRoot: Fr,
|
|
21
|
-
public readonly artifactFunctionTreeSiblingPath: Tuple<Fr, typeof ARTIFACT_FUNCTION_TREE_MAX_HEIGHT>,
|
|
22
|
-
public readonly artifactFunctionTreeLeafIndex: number,
|
|
23
|
-
public readonly unconstrainedFunction: BroadcastedUnconstrainedFunction,
|
|
24
|
-
) {}
|
|
25
|
-
|
|
26
|
-
static isUnconstrainedFunctionBroadcastedEvent(log: ContractClassLog) {
|
|
27
|
-
return log.fields[0].equals(REGISTERER_UNCONSTRAINED_FUNCTION_BROADCASTED_TAG);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
static fromLog(log: ContractClassLog) {
|
|
31
|
-
const reader = new FieldReader(log.fields.slice(1));
|
|
32
|
-
const event = UnconstrainedFunctionBroadcastedEvent.fromFields(reader);
|
|
33
|
-
while (!reader.isFinished()) {
|
|
34
|
-
const field = reader.readField();
|
|
35
|
-
if (!field.isZero()) {
|
|
36
|
-
throw new Error(`Unexpected data after parsing UnconstrainedFunctionBroadcastedEvent: ${field.toString()}`);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return event;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
static fromFields(fields: Fr[] | FieldReader) {
|
|
44
|
-
const reader = FieldReader.asReader(fields);
|
|
45
|
-
const contractClassId = reader.readField();
|
|
46
|
-
const artifactMetadataHash = reader.readField();
|
|
47
|
-
const privateFunctionsArtifactTreeRoot = reader.readField();
|
|
48
|
-
const artifactFunctionTreeSiblingPath = reader.readFieldArray(ARTIFACT_FUNCTION_TREE_MAX_HEIGHT);
|
|
49
|
-
const artifactFunctionTreeLeafIndex = reader.readField().toNumber();
|
|
50
|
-
const unconstrainedFunction = BroadcastedUnconstrainedFunction.fromFields(reader);
|
|
51
|
-
|
|
52
|
-
return new UnconstrainedFunctionBroadcastedEvent(
|
|
53
|
-
contractClassId,
|
|
54
|
-
artifactMetadataHash,
|
|
55
|
-
privateFunctionsArtifactTreeRoot,
|
|
56
|
-
artifactFunctionTreeSiblingPath,
|
|
57
|
-
artifactFunctionTreeLeafIndex,
|
|
58
|
-
unconstrainedFunction,
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
toFunctionWithMembershipProof(): UnconstrainedFunctionWithMembershipProof {
|
|
63
|
-
// We should be able to safely remove the zero elements that pad the variable-length sibling path,
|
|
64
|
-
// since a sibling with value zero can only occur on the tree leaves, so the sibling path will never end
|
|
65
|
-
// in a zero. The only exception is a tree with depth 2 with one non-zero leaf, where the sibling path would
|
|
66
|
-
// be a single zero element, but in that case the artifact tree should be just the single leaf.
|
|
67
|
-
const artifactTreeSiblingPath = removeArrayPaddingEnd(this.artifactFunctionTreeSiblingPath, Fr.isZero);
|
|
68
|
-
return {
|
|
69
|
-
...this.unconstrainedFunction,
|
|
70
|
-
bytecode: this.unconstrainedFunction.bytecode,
|
|
71
|
-
functionMetadataHash: this.unconstrainedFunction.metadataHash,
|
|
72
|
-
artifactMetadataHash: this.artifactMetadataHash,
|
|
73
|
-
privateFunctionsArtifactTreeRoot: this.privateFunctionsArtifactTreeRoot,
|
|
74
|
-
artifactTreeSiblingPath,
|
|
75
|
-
artifactTreeLeafIndex: this.artifactFunctionTreeLeafIndex,
|
|
76
|
-
};
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export class BroadcastedUnconstrainedFunction implements UnconstrainedFunction {
|
|
81
|
-
constructor(
|
|
82
|
-
/** Selector of the function. Calculated as the hash of the method name and parameters. The specification of this is not enforced by the protocol. */
|
|
83
|
-
public readonly selector: FunctionSelector,
|
|
84
|
-
/** Artifact metadata hash */
|
|
85
|
-
public readonly metadataHash: Fr,
|
|
86
|
-
/** Brillig bytecode */
|
|
87
|
-
public readonly bytecode: Buffer,
|
|
88
|
-
) {}
|
|
89
|
-
|
|
90
|
-
static fromFields(fields: Fr[] | FieldReader) {
|
|
91
|
-
const reader = FieldReader.asReader(fields);
|
|
92
|
-
const selector = FunctionSelector.fromField(reader.readField());
|
|
93
|
-
const metadataHash = reader.readField();
|
|
94
|
-
// The '* 1' removes the 'Type instantiation is excessively deep and possibly infinite. ts(2589)' err
|
|
95
|
-
const encodedBytecode = reader.readFieldArray(MAX_PACKED_BYTECODE_SIZE_PER_UNCONSTRAINED_FUNCTION_IN_FIELDS * 1);
|
|
96
|
-
const bytecode = bufferFromFields(encodedBytecode);
|
|
97
|
-
return new BroadcastedUnconstrainedFunction(selector, metadataHash, bytecode);
|
|
98
|
-
}
|
|
99
|
-
}
|