@aztec/aztec.js 0.71.0 → 0.73.0
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/dest/account/contract.d.ts +1 -1
- package/dest/account/contract.d.ts.map +1 -1
- package/dest/account_manager/deploy_account_method.js +7 -7
- package/dest/account_manager/index.d.ts +9 -6
- package/dest/account_manager/index.d.ts.map +1 -1
- package/dest/account_manager/index.js +28 -18
- package/dest/api/ethereum.d.ts +2 -1
- package/dest/api/ethereum.d.ts.map +1 -1
- package/dest/api/ethereum.js +3 -2
- package/dest/barretenberg-threads.wasm.gz +0 -0
- package/dest/barretenberg.wasm.gz +0 -0
- package/dest/contract/base_contract_interaction.d.ts.map +1 -1
- package/dest/contract/base_contract_interaction.js +3 -2
- package/dest/contract/contract.js +2 -2
- package/dest/contract/contract_base.d.ts +2 -2
- package/dest/contract/contract_base.d.ts.map +1 -1
- package/dest/contract/contract_base.js +2 -2
- package/dest/contract/contract_function_interaction.d.ts +1 -1
- package/dest/contract/contract_function_interaction.d.ts.map +1 -1
- package/dest/contract/contract_function_interaction.js +4 -4
- package/dest/contract/deploy_method.d.ts +2 -2
- package/dest/contract/deploy_method.d.ts.map +1 -1
- package/dest/contract/deploy_method.js +19 -19
- package/dest/contract/deploy_proven_tx.d.ts +2 -2
- package/dest/contract/deploy_proven_tx.d.ts.map +1 -1
- package/dest/contract/deploy_proven_tx.js +4 -4
- package/dest/contract/deploy_sent_tx.d.ts +4 -4
- package/dest/contract/deploy_sent_tx.d.ts.map +1 -1
- package/dest/contract/deploy_sent_tx.js +9 -7
- package/dest/contract/proven_tx.d.ts.map +1 -1
- package/dest/contract/proven_tx.js +3 -3
- package/dest/contract/sent_tx.d.ts +3 -3
- package/dest/contract/sent_tx.d.ts.map +1 -1
- package/dest/contract/sent_tx.js +4 -4
- package/dest/deployment/broadcast_function.d.ts +1 -1
- package/dest/deployment/broadcast_function.d.ts.map +1 -1
- package/dest/deployment/broadcast_function.js +23 -14
- package/dest/deployment/deploy_instance.d.ts +1 -1
- package/dest/deployment/deploy_instance.d.ts.map +1 -1
- package/dest/deployment/deploy_instance.js +3 -3
- package/dest/deployment/protocol_contracts.d.ts +2 -2
- package/dest/deployment/protocol_contracts.d.ts.map +1 -1
- package/dest/deployment/protocol_contracts.js +5 -5
- package/dest/deployment/register_class.js +3 -3
- package/dest/entrypoint/default_entrypoint.d.ts.map +1 -1
- package/dest/entrypoint/default_entrypoint.js +3 -3
- package/dest/entrypoint/default_multi_call_entrypoint.d.ts.map +1 -1
- package/dest/entrypoint/default_multi_call_entrypoint.js +5 -5
- package/dest/entrypoint/payload.d.ts +22 -7
- package/dest/entrypoint/payload.d.ts.map +1 -1
- package/dest/entrypoint/payload.js +35 -28
- package/dest/fee/fee_juice_payment_method_with_claim.d.ts.map +1 -1
- package/dest/fee/fee_juice_payment_method_with_claim.js +6 -5
- package/dest/fee/private_fee_payment_method.js +8 -8
- package/dest/fee/public_fee_payment_method.js +20 -21
- package/dest/index.d.ts +4 -5
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +4 -5
- package/dest/main.js +2 -0
- package/dest/main.js.LICENSE.txt +25 -0
- package/dest/rpc_clients/pxe_client.d.ts +1 -1
- package/dest/rpc_clients/pxe_client.d.ts.map +1 -1
- package/dest/utils/abi_types.d.ts +3 -1
- package/dest/utils/abi_types.d.ts.map +1 -1
- package/dest/utils/anvil_test_watcher.d.ts +5 -1
- package/dest/utils/anvil_test_watcher.d.ts.map +1 -1
- package/dest/utils/anvil_test_watcher.js +47 -7
- package/dest/utils/authwit.d.ts +3 -3
- package/dest/utils/authwit.d.ts.map +1 -1
- package/dest/utils/authwit.js +9 -5
- package/dest/utils/chain_monitor.d.ts +2 -1
- package/dest/utils/chain_monitor.d.ts.map +1 -1
- package/dest/utils/chain_monitor.js +7 -2
- package/dest/utils/cheat_codes.d.ts +5 -2
- package/dest/utils/cheat_codes.d.ts.map +1 -1
- package/dest/utils/cheat_codes.js +9 -2
- package/dest/utils/l1_contracts.d.ts +1 -1
- package/dest/utils/l1_contracts.d.ts.map +1 -1
- package/dest/utils/portal_manager.d.ts +2 -2
- package/dest/utils/portal_manager.d.ts.map +1 -1
- package/dest/utils/portal_manager.js +8 -8
- package/dest/utils/pub_key.d.ts +1 -1
- package/dest/utils/pub_key.d.ts.map +1 -1
- package/dest/wallet/account_wallet.d.ts +1 -1
- package/dest/wallet/account_wallet.d.ts.map +1 -1
- package/dest/wallet/account_wallet.js +9 -9
- package/dest/wallet/account_wallet_with_private_key.d.ts +1 -1
- package/dest/wallet/account_wallet_with_private_key.d.ts.map +1 -1
- package/dest/wallet/account_wallet_with_private_key.js +3 -3
- package/dest/wallet/base_wallet.d.ts +8 -12
- package/dest/wallet/base_wallet.d.ts.map +1 -1
- package/dest/wallet/base_wallet.js +13 -25
- package/package.json +10 -9
- package/src/account/contract.ts +1 -1
- package/src/account_manager/deploy_account_method.ts +6 -6
- package/src/account_manager/index.ts +34 -25
- package/src/api/ethereum.ts +2 -1
- package/src/contract/base_contract_interaction.ts +3 -1
- package/src/contract/contract.ts +1 -1
- package/src/contract/contract_base.ts +2 -2
- package/src/contract/contract_function_interaction.ts +3 -3
- package/src/contract/deploy_method.ts +20 -20
- package/src/contract/deploy_proven_tx.ts +2 -2
- package/src/contract/deploy_sent_tx.ts +7 -5
- package/src/contract/proven_tx.ts +0 -2
- package/src/contract/sent_tx.ts +4 -4
- package/src/deployment/broadcast_function.ts +28 -14
- package/src/deployment/deploy_instance.ts +5 -2
- package/src/deployment/protocol_contracts.ts +4 -4
- package/src/deployment/register_class.ts +2 -2
- package/src/entrypoint/default_entrypoint.ts +2 -2
- package/src/entrypoint/default_multi_call_entrypoint.ts +4 -4
- package/src/entrypoint/payload.ts +53 -25
- package/src/fee/fee_juice_payment_method_with_claim.ts +6 -5
- package/src/fee/private_fee_payment_method.ts +7 -7
- package/src/fee/public_fee_payment_method.ts +23 -23
- package/src/index.ts +3 -5
- package/src/utils/abi_types.ts +4 -1
- package/src/utils/anvil_test_watcher.ts +54 -6
- package/src/utils/authwit.ts +9 -5
- package/src/utils/chain_monitor.ts +8 -2
- package/src/utils/cheat_codes.ts +11 -2
- package/src/utils/l1_contracts.ts +1 -1
- package/src/utils/portal_manager.ts +8 -8
- package/src/utils/pub_key.ts +1 -1
- package/src/wallet/account_wallet.ts +12 -11
- package/src/wallet/account_wallet_with_private_key.ts +2 -2
- package/src/wallet/base_wallet.ts +17 -27
- package/dest/api/init.d.ts +0 -7
- package/dest/api/init.d.ts.map +0 -1
- package/dest/api/init.js +0 -10
- package/src/api/init.ts +0 -10
|
@@ -100,7 +100,7 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
|
|
|
100
100
|
// in case the initializer is public. This hints at the need of having "transient" contracts scoped to a
|
|
101
101
|
// simulation, so we can run the simulation with a set of contracts, but only "commit" them to the wallet
|
|
102
102
|
// once this tx has gone through.
|
|
103
|
-
await this.wallet.registerContract({ artifact: this.artifact, instance: this.getInstance(options) });
|
|
103
|
+
await this.wallet.registerContract({ artifact: this.artifact, instance: await this.getInstance(options) });
|
|
104
104
|
|
|
105
105
|
const bootstrap = await this.getInitializeFunctionCalls(options);
|
|
106
106
|
|
|
@@ -124,7 +124,7 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
|
|
|
124
124
|
* @param options - Deployment options.
|
|
125
125
|
*/
|
|
126
126
|
public async register(options: DeployOptions = {}): Promise<TContract> {
|
|
127
|
-
const instance = this.getInstance(options);
|
|
127
|
+
const instance = await this.getInstance(options);
|
|
128
128
|
await this.wallet.registerContract({ artifact: this.artifact, instance });
|
|
129
129
|
return this.postDeployCtor(instance.address, this.wallet);
|
|
130
130
|
}
|
|
@@ -140,11 +140,11 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
|
|
|
140
140
|
const calls: FunctionCall[] = [];
|
|
141
141
|
|
|
142
142
|
// Set contract instance object so it's available for populating the DeploySendTx object
|
|
143
|
-
const instance = this.getInstance(options);
|
|
143
|
+
const instance = await this.getInstance(options);
|
|
144
144
|
|
|
145
145
|
// Obtain contract class from artifact and check it matches the reported one by the instance.
|
|
146
146
|
// TODO(@spalladino): We're unnecessarily calculating the contract class multiple times here.
|
|
147
|
-
const contractClass = getContractClassFromArtifact(this.artifact);
|
|
147
|
+
const contractClass = await getContractClassFromArtifact(this.artifact);
|
|
148
148
|
if (!instance.contractClassId.equals(contractClass.id)) {
|
|
149
149
|
throw new Error(
|
|
150
150
|
`Contract class mismatch when deploying contract: got ${instance.contractClassId.toString()} from instance and ${contractClass.id.toString()} from artifact`,
|
|
@@ -153,7 +153,7 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
|
|
|
153
153
|
|
|
154
154
|
// Register the contract class if it hasn't been published already.
|
|
155
155
|
if (!options.skipClassRegistration) {
|
|
156
|
-
if (await this.wallet.
|
|
156
|
+
if ((await this.wallet.getContractClassMetadata(contractClass.id)).isContractClassPubliclyRegistered) {
|
|
157
157
|
this.log.debug(
|
|
158
158
|
`Skipping registration of already registered contract class ${contractClass.id.toString()} for ${instance.address.toString()}`,
|
|
159
159
|
);
|
|
@@ -161,13 +161,15 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
|
|
|
161
161
|
this.log.info(
|
|
162
162
|
`Creating request for registering contract class ${contractClass.id.toString()} as part of deployment for ${instance.address.toString()}`,
|
|
163
163
|
);
|
|
164
|
-
|
|
164
|
+
const registerContractClassInteraction = await registerContractClass(this.wallet, this.artifact);
|
|
165
|
+
calls.push(await registerContractClassInteraction.request());
|
|
165
166
|
}
|
|
166
167
|
}
|
|
167
168
|
|
|
168
169
|
// Deploy the contract via the instance deployer.
|
|
169
170
|
if (!options.skipPublicDeployment) {
|
|
170
|
-
|
|
171
|
+
const deploymentInteraction = await deployInstance(this.wallet, instance);
|
|
172
|
+
calls.push(await deploymentInteraction.request());
|
|
171
173
|
}
|
|
172
174
|
|
|
173
175
|
return { calls };
|
|
@@ -178,10 +180,10 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
|
|
|
178
180
|
* @param options - Deployment options.
|
|
179
181
|
* @returns - An array of function calls.
|
|
180
182
|
*/
|
|
181
|
-
protected getInitializeFunctionCalls(
|
|
183
|
+
protected async getInitializeFunctionCalls(
|
|
182
184
|
options: DeployOptions,
|
|
183
185
|
): Promise<Pick<ExecutionRequestInit, 'calls' | 'authWitnesses' | 'hashedArguments'>> {
|
|
184
|
-
const { address } = this.getInstance(options);
|
|
186
|
+
const { address } = await this.getInstance(options);
|
|
185
187
|
const calls: FunctionCall[] = [];
|
|
186
188
|
if (this.constructorArtifact && !options.skipInitialization) {
|
|
187
189
|
const constructorCall = new ContractFunctionInteraction(
|
|
@@ -190,9 +192,9 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
|
|
|
190
192
|
this.constructorArtifact,
|
|
191
193
|
this.args,
|
|
192
194
|
);
|
|
193
|
-
calls.push(constructorCall.request());
|
|
195
|
+
calls.push(await constructorCall.request());
|
|
194
196
|
}
|
|
195
|
-
return
|
|
197
|
+
return { calls };
|
|
196
198
|
}
|
|
197
199
|
|
|
198
200
|
/**
|
|
@@ -205,11 +207,8 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
|
|
|
205
207
|
*/
|
|
206
208
|
public override send(options: DeployOptions = {}): DeploySentTx<TContract> {
|
|
207
209
|
const txHashPromise = super.send(options).getTxHash();
|
|
208
|
-
|
|
209
|
-
this.
|
|
210
|
-
`Sent deployment tx of ${this.artifact.name} contract with deployment address ${instance.address.toString()}`,
|
|
211
|
-
);
|
|
212
|
-
return new DeploySentTx(this.wallet, txHashPromise, this.postDeployCtor, instance);
|
|
210
|
+
this.log.debug(`Sent deployment tx of ${this.artifact.name} contract`);
|
|
211
|
+
return new DeploySentTx(this.wallet, txHashPromise, this.postDeployCtor, () => this.getInstance(options));
|
|
213
212
|
}
|
|
214
213
|
|
|
215
214
|
/**
|
|
@@ -218,9 +217,9 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
|
|
|
218
217
|
* @param options - An object containing various deployment options.
|
|
219
218
|
* @returns An instance object.
|
|
220
219
|
*/
|
|
221
|
-
public getInstance(options: DeployOptions = {}): ContractInstanceWithAddress {
|
|
220
|
+
public async getInstance(options: DeployOptions = {}): Promise<ContractInstanceWithAddress> {
|
|
222
221
|
if (!this.instance) {
|
|
223
|
-
this.instance = getContractInstanceFromDeployParams(this.artifact, {
|
|
222
|
+
this.instance = await getContractInstanceFromDeployParams(this.artifact, {
|
|
224
223
|
constructorArgs: this.args,
|
|
225
224
|
salt: options.contractAddressSalt,
|
|
226
225
|
publicKeys: this.publicKeys,
|
|
@@ -238,8 +237,9 @@ export class DeployMethod<TContract extends ContractBase = Contract> extends Bas
|
|
|
238
237
|
*/
|
|
239
238
|
public override async prove(options: DeployOptions): Promise<DeployProvenTx<TContract>> {
|
|
240
239
|
const txProvingResult = await this.proveInternal(options);
|
|
241
|
-
|
|
242
|
-
|
|
240
|
+
return new DeployProvenTx(this.wallet, txProvingResult.toTx(), this.postDeployCtor, () =>
|
|
241
|
+
this.getInstance(options),
|
|
242
|
+
);
|
|
243
243
|
}
|
|
244
244
|
|
|
245
245
|
/**
|
|
@@ -14,7 +14,7 @@ export class DeployProvenTx<TContract extends Contract = Contract> extends Prove
|
|
|
14
14
|
wallet: PXE | Wallet,
|
|
15
15
|
tx: Tx,
|
|
16
16
|
private postDeployCtor: (address: AztecAddress, wallet: Wallet) => Promise<TContract>,
|
|
17
|
-
private
|
|
17
|
+
private instanceGetter: () => Promise<ContractInstanceWithAddress>,
|
|
18
18
|
) {
|
|
19
19
|
super(wallet, tx);
|
|
20
20
|
}
|
|
@@ -27,6 +27,6 @@ export class DeployProvenTx<TContract extends Contract = Contract> extends Prove
|
|
|
27
27
|
return this.wallet.sendTx(this.getPlainDataTx());
|
|
28
28
|
})();
|
|
29
29
|
|
|
30
|
-
return new DeploySentTx(this.wallet, promise, this.postDeployCtor, this.
|
|
30
|
+
return new DeploySentTx(this.wallet, promise, this.postDeployCtor, this.instanceGetter);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -30,8 +30,8 @@ export class DeploySentTx<TContract extends Contract = Contract> extends SentTx
|
|
|
30
30
|
wallet: PXE | Wallet,
|
|
31
31
|
txHashPromise: Promise<TxHash>,
|
|
32
32
|
private postDeployCtor: (address: AztecAddress, wallet: Wallet) => Promise<TContract>,
|
|
33
|
-
/**
|
|
34
|
-
public
|
|
33
|
+
/** A getter for the deployed contract instance */
|
|
34
|
+
public instanceGetter: () => Promise<ContractInstanceWithAddress>,
|
|
35
35
|
) {
|
|
36
36
|
super(wallet, txHashPromise);
|
|
37
37
|
}
|
|
@@ -43,7 +43,8 @@ export class DeploySentTx<TContract extends Contract = Contract> extends SentTx
|
|
|
43
43
|
*/
|
|
44
44
|
public async deployed(opts?: DeployedWaitOpts): Promise<TContract> {
|
|
45
45
|
const receipt = await this.wait(opts);
|
|
46
|
-
|
|
46
|
+
const instance = await this.instanceGetter();
|
|
47
|
+
this.log.info(`Contract ${instance.address.toString()} successfully deployed.`);
|
|
47
48
|
return receipt.contract;
|
|
48
49
|
}
|
|
49
50
|
|
|
@@ -58,12 +59,13 @@ export class DeploySentTx<TContract extends Contract = Contract> extends SentTx
|
|
|
58
59
|
return { ...receipt, contract };
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
protected getContractObject(wallet?: Wallet): Promise<TContract> {
|
|
62
|
+
protected async getContractObject(wallet?: Wallet): Promise<TContract> {
|
|
62
63
|
const isWallet = (pxe: PXE | Wallet): pxe is Wallet => !!(pxe as Wallet).createTxExecutionRequest;
|
|
63
64
|
const contractWallet = wallet ?? (isWallet(this.pxe) && this.pxe);
|
|
64
65
|
if (!contractWallet) {
|
|
65
66
|
throw new Error(`A wallet is required for creating a contract instance`);
|
|
66
67
|
}
|
|
67
|
-
|
|
68
|
+
const instance = await this.instanceGetter();
|
|
69
|
+
return this.postDeployCtor(instance.address, contractWallet) as Promise<TContract>;
|
|
68
70
|
}
|
|
69
71
|
}
|
|
@@ -11,7 +11,6 @@ export class ProvenTx extends Tx {
|
|
|
11
11
|
super(
|
|
12
12
|
tx.data,
|
|
13
13
|
tx.clientIvcProof,
|
|
14
|
-
tx.unencryptedLogs,
|
|
15
14
|
tx.contractClassLogs,
|
|
16
15
|
tx.enqueuedPublicFunctionCalls,
|
|
17
16
|
tx.publicTeardownFunctionCall,
|
|
@@ -23,7 +22,6 @@ export class ProvenTx extends Tx {
|
|
|
23
22
|
return new Tx(
|
|
24
23
|
this.data,
|
|
25
24
|
this.clientIvcProof,
|
|
26
|
-
this.unencryptedLogs,
|
|
27
25
|
this.contractClassLogs,
|
|
28
26
|
this.enqueuedPublicFunctionCalls,
|
|
29
27
|
this.publicTeardownFunctionCall,
|
package/src/contract/sent_tx.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type GetPublicLogsResponse, type PXE, type TxHash, type TxReceipt, TxStatus } from '@aztec/circuit-types';
|
|
2
2
|
import { retryUntil } from '@aztec/foundation/retry';
|
|
3
3
|
import { type FieldsOf } from '@aztec/foundation/types';
|
|
4
4
|
|
|
@@ -87,13 +87,13 @@ export class SentTx {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
/**
|
|
90
|
-
* Gets
|
|
90
|
+
* Gets public logs emitted by this tx.
|
|
91
91
|
* @remarks This function will wait for the tx to be mined if it hasn't been already.
|
|
92
92
|
* @returns The requested logs.
|
|
93
93
|
*/
|
|
94
|
-
public async
|
|
94
|
+
public async getPublicLogs(): Promise<GetPublicLogsResponse> {
|
|
95
95
|
await this.wait();
|
|
96
|
-
return this.pxe.
|
|
96
|
+
return this.pxe.getPublicLogs({ txHash: await this.getTxHash() });
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
protected async waitForReceipt(opts?: WaitOpts): Promise<TxReceipt> {
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
createUnconstrainedFunctionMembershipProof,
|
|
7
7
|
getContractClassFromArtifact,
|
|
8
8
|
} from '@aztec/circuits.js';
|
|
9
|
-
import { type ContractArtifact,
|
|
9
|
+
import { type ContractArtifact, FunctionSelector, FunctionType, bufferAsFields } from '@aztec/foundation/abi';
|
|
10
10
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
11
11
|
import { Fr } from '@aztec/foundation/fields';
|
|
12
12
|
|
|
@@ -28,8 +28,15 @@ export async function broadcastPrivateFunction(
|
|
|
28
28
|
artifact: ContractArtifact,
|
|
29
29
|
selector: FunctionSelector,
|
|
30
30
|
): Promise<ContractFunctionInteraction> {
|
|
31
|
-
const contractClass = getContractClassFromArtifact(artifact);
|
|
32
|
-
const
|
|
31
|
+
const contractClass = await getContractClassFromArtifact(artifact);
|
|
32
|
+
const privateFunctions = artifact.functions.filter(fn => fn.functionType === FunctionType.PRIVATE);
|
|
33
|
+
const functionsAndSelectors = await Promise.all(
|
|
34
|
+
privateFunctions.map(async fn => ({
|
|
35
|
+
f: fn,
|
|
36
|
+
selector: await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters),
|
|
37
|
+
})),
|
|
38
|
+
);
|
|
39
|
+
const privateFunctionArtifact = functionsAndSelectors.find(fn => selector.equals(fn.selector))?.f;
|
|
33
40
|
if (!privateFunctionArtifact) {
|
|
34
41
|
throw new Error(`Private function with selector ${selector.toString()} not found`);
|
|
35
42
|
}
|
|
@@ -42,9 +49,9 @@ export async function broadcastPrivateFunction(
|
|
|
42
49
|
unconstrainedFunctionsArtifactTreeRoot,
|
|
43
50
|
privateFunctionTreeSiblingPath,
|
|
44
51
|
privateFunctionTreeLeafIndex,
|
|
45
|
-
} = createPrivateFunctionMembershipProof(selector, artifact);
|
|
52
|
+
} = await createPrivateFunctionMembershipProof(selector, artifact);
|
|
46
53
|
|
|
47
|
-
const vkHash = computeVerificationKeyHash(privateFunctionArtifact);
|
|
54
|
+
const vkHash = await computeVerificationKeyHash(privateFunctionArtifact);
|
|
48
55
|
const bytecode = bufferAsFields(
|
|
49
56
|
privateFunctionArtifact.bytecode,
|
|
50
57
|
MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS,
|
|
@@ -52,7 +59,7 @@ export async function broadcastPrivateFunction(
|
|
|
52
59
|
|
|
53
60
|
await wallet.addCapsule(bytecode);
|
|
54
61
|
|
|
55
|
-
const registerer = getRegistererContract(wallet);
|
|
62
|
+
const registerer = await getRegistererContract(wallet);
|
|
56
63
|
return Promise.resolve(
|
|
57
64
|
registerer.methods.broadcast_private_function(
|
|
58
65
|
contractClass.id,
|
|
@@ -82,14 +89,18 @@ export async function broadcastUnconstrainedFunction(
|
|
|
82
89
|
artifact: ContractArtifact,
|
|
83
90
|
selector: FunctionSelector,
|
|
84
91
|
): Promise<ContractFunctionInteraction> {
|
|
85
|
-
const contractClass = getContractClassFromArtifact(artifact);
|
|
86
|
-
const
|
|
87
|
-
|
|
92
|
+
const contractClass = await getContractClassFromArtifact(artifact);
|
|
93
|
+
const unconstrainedFunctions = artifact.functions.filter(fn => fn.functionType === FunctionType.UNCONSTRAINED);
|
|
94
|
+
const unconstrainedFunctionsAndSelectors = await Promise.all(
|
|
95
|
+
unconstrainedFunctions.map(async fn => ({
|
|
96
|
+
f: fn,
|
|
97
|
+
selector: await FunctionSelector.fromNameAndParameters(fn.name, fn.parameters),
|
|
98
|
+
})),
|
|
88
99
|
);
|
|
89
|
-
|
|
100
|
+
const unconstrainedFunctionArtifact = unconstrainedFunctionsAndSelectors.find(fn => selector.equals(fn.selector))?.f;
|
|
101
|
+
if (!unconstrainedFunctionArtifact) {
|
|
90
102
|
throw new Error(`Unconstrained function with selector ${selector.toString()} not found`);
|
|
91
103
|
}
|
|
92
|
-
const functionArtifact = artifact.functions[functionArtifactIndex];
|
|
93
104
|
|
|
94
105
|
const {
|
|
95
106
|
artifactMetadataHash,
|
|
@@ -97,13 +108,16 @@ export async function broadcastUnconstrainedFunction(
|
|
|
97
108
|
artifactTreeSiblingPath,
|
|
98
109
|
functionMetadataHash,
|
|
99
110
|
privateFunctionsArtifactTreeRoot,
|
|
100
|
-
} = createUnconstrainedFunctionMembershipProof(selector, artifact);
|
|
111
|
+
} = await createUnconstrainedFunctionMembershipProof(selector, artifact);
|
|
101
112
|
|
|
102
|
-
const bytecode = bufferAsFields(
|
|
113
|
+
const bytecode = bufferAsFields(
|
|
114
|
+
unconstrainedFunctionArtifact.bytecode,
|
|
115
|
+
MAX_PACKED_BYTECODE_SIZE_PER_PRIVATE_FUNCTION_IN_FIELDS,
|
|
116
|
+
);
|
|
103
117
|
|
|
104
118
|
await wallet.addCapsule(bytecode);
|
|
105
119
|
|
|
106
|
-
const registerer = getRegistererContract(wallet);
|
|
120
|
+
const registerer = await getRegistererContract(wallet);
|
|
107
121
|
return registerer.methods.broadcast_unconstrained_function(
|
|
108
122
|
contractClass.id,
|
|
109
123
|
artifactMetadataHash,
|
|
@@ -9,8 +9,11 @@ import { getDeployerContract } from './protocol_contracts.js';
|
|
|
9
9
|
* @param wallet - The wallet to use for the deployment.
|
|
10
10
|
* @param instance - The instance to deploy.
|
|
11
11
|
*/
|
|
12
|
-
export function deployInstance(
|
|
13
|
-
|
|
12
|
+
export async function deployInstance(
|
|
13
|
+
wallet: Wallet,
|
|
14
|
+
instance: ContractInstanceWithAddress,
|
|
15
|
+
): Promise<ContractFunctionInteraction> {
|
|
16
|
+
const deployerContract = await getDeployerContract(wallet);
|
|
14
17
|
const { salt, contractClassId, publicKeys, deployer } = instance;
|
|
15
18
|
const isUniversalDeploy = deployer.isZero();
|
|
16
19
|
if (!isUniversalDeploy && !wallet.getAddress().equals(deployer)) {
|
|
@@ -5,13 +5,13 @@ import { UnsafeContract } from '../contract/unsafe_contract.js';
|
|
|
5
5
|
import { type Wallet } from '../wallet/index.js';
|
|
6
6
|
|
|
7
7
|
/** Returns a Contract wrapper for the class registerer. */
|
|
8
|
-
export function getRegistererContract(wallet: Wallet) {
|
|
9
|
-
const { artifact, instance } = getCanonicalClassRegisterer();
|
|
8
|
+
export async function getRegistererContract(wallet: Wallet) {
|
|
9
|
+
const { artifact, instance } = await getCanonicalClassRegisterer();
|
|
10
10
|
return new UnsafeContract(instance, artifact, wallet);
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
/** Returns a Contract wrapper for the instance deployer. */
|
|
14
|
-
export function getDeployerContract(wallet: Wallet) {
|
|
15
|
-
const { artifact, instance } = getCanonicalInstanceDeployer();
|
|
14
|
+
export async function getDeployerContract(wallet: Wallet) {
|
|
15
|
+
const { artifact, instance } = await getCanonicalInstanceDeployer();
|
|
16
16
|
return new UnsafeContract(instance, artifact, wallet);
|
|
17
17
|
}
|
|
@@ -18,9 +18,9 @@ export async function registerContractClass(
|
|
|
18
18
|
emitPublicBytecode = defaultEmitPublicBytecode,
|
|
19
19
|
): Promise<ContractFunctionInteraction> {
|
|
20
20
|
const { artifactHash, privateFunctionsRoot, publicBytecodeCommitment, packedBytecode } =
|
|
21
|
-
getContractClassFromArtifact(artifact);
|
|
21
|
+
await getContractClassFromArtifact(artifact);
|
|
22
22
|
const encodedBytecode = bufferAsFields(packedBytecode, MAX_PACKED_PUBLIC_BYTECODE_SIZE_IN_FIELDS);
|
|
23
|
-
const registerer = getRegistererContract(wallet);
|
|
23
|
+
const registerer = await getRegistererContract(wallet);
|
|
24
24
|
await wallet.addCapsule(encodedBytecode);
|
|
25
25
|
return registerer.methods.register(artifactHash, privateFunctionsRoot, publicBytecodeCommitment, emitPublicBytecode);
|
|
26
26
|
}
|
|
@@ -10,7 +10,7 @@ import { type EntrypointInterface, type ExecutionRequestInit } from './entrypoin
|
|
|
10
10
|
export class DefaultEntrypoint implements EntrypointInterface {
|
|
11
11
|
constructor(private chainId: number, private protocolVersion: number) {}
|
|
12
12
|
|
|
13
|
-
createTxExecutionRequest(exec: ExecutionRequestInit): Promise<TxExecutionRequest> {
|
|
13
|
+
async createTxExecutionRequest(exec: ExecutionRequestInit): Promise<TxExecutionRequest> {
|
|
14
14
|
const { fee, calls, authWitnesses = [], hashedArguments = [] } = exec;
|
|
15
15
|
|
|
16
16
|
if (calls.length > 1) {
|
|
@@ -23,7 +23,7 @@ export class DefaultEntrypoint implements EntrypointInterface {
|
|
|
23
23
|
throw new Error('Public entrypoints are not allowed');
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
const entrypointHashedValues = HashedValues.fromValues(call.args);
|
|
26
|
+
const entrypointHashedValues = await HashedValues.fromValues(call.args);
|
|
27
27
|
const txContext = new TxContext(this.chainId, this.protocolVersion, fee.gasSettings);
|
|
28
28
|
return Promise.resolve(
|
|
29
29
|
new TxExecutionRequest(
|
|
@@ -14,16 +14,16 @@ export class DefaultMultiCallEntrypoint implements EntrypointInterface {
|
|
|
14
14
|
private address: AztecAddress = ProtocolContractAddress.MultiCallEntrypoint,
|
|
15
15
|
) {}
|
|
16
16
|
|
|
17
|
-
createTxExecutionRequest(executions: ExecutionRequestInit): Promise<TxExecutionRequest> {
|
|
17
|
+
async createTxExecutionRequest(executions: ExecutionRequestInit): Promise<TxExecutionRequest> {
|
|
18
18
|
const { fee, calls, authWitnesses = [], hashedArguments = [] } = executions;
|
|
19
|
-
const payload = EntrypointPayload.fromAppExecution(calls);
|
|
19
|
+
const payload = await EntrypointPayload.fromAppExecution(calls);
|
|
20
20
|
const abi = this.getEntrypointAbi();
|
|
21
|
-
const entrypointHashedArgs = HashedValues.fromValues(encodeArguments(abi, [payload]));
|
|
21
|
+
const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [payload]));
|
|
22
22
|
|
|
23
23
|
const txRequest = TxExecutionRequest.from({
|
|
24
24
|
firstCallArgsHash: entrypointHashedArgs.hash,
|
|
25
25
|
origin: this.address,
|
|
26
|
-
functionSelector: FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
|
|
26
|
+
functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
|
|
27
27
|
txContext: new TxContext(this.chainId, this.version, fee.gasSettings),
|
|
28
28
|
argsOfCalls: [...payload.hashedArguments, ...hashedArguments, entrypointHashedArgs],
|
|
29
29
|
authWitnesses,
|
|
@@ -24,6 +24,8 @@ export type UserFeeOptions = {
|
|
|
24
24
|
paymentMethod?: FeePaymentMethod;
|
|
25
25
|
/** The gas settings */
|
|
26
26
|
gasSettings?: Partial<FieldsOf<GasSettings>>;
|
|
27
|
+
/** Percentage to pad the base fee by, if empty, defaults to 0.5 */
|
|
28
|
+
baseFeePadding?: number;
|
|
27
29
|
/** Whether to run an initial simulation of the tx with high gas limit to figure out actual gas settings. */
|
|
28
30
|
estimateGas?: boolean;
|
|
29
31
|
/** Percentage to pad the estimated gas limits by, if empty, defaults to 0.1. Only relevant if estimateGas is set. */
|
|
@@ -54,19 +56,22 @@ type EncodedFunctionCall = {
|
|
|
54
56
|
|
|
55
57
|
/** Assembles an entrypoint payload */
|
|
56
58
|
export abstract class EntrypointPayload {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
protected constructor(
|
|
60
|
+
private functionCalls: EncodedFunctionCall[],
|
|
61
|
+
private _hashedArguments: HashedValues[],
|
|
62
|
+
private generatorIndex: number,
|
|
63
|
+
private _nonce: Fr,
|
|
64
|
+
) {}
|
|
65
|
+
|
|
66
|
+
protected static async create(functionCalls: FunctionCall[]) {
|
|
67
|
+
const hashedArguments: HashedValues[] = [];
|
|
63
68
|
for (const call of functionCalls) {
|
|
64
|
-
|
|
69
|
+
hashedArguments.push(await HashedValues.fromValues(call.args));
|
|
65
70
|
}
|
|
66
71
|
|
|
67
72
|
/* eslint-disable camelcase */
|
|
68
|
-
|
|
69
|
-
args_hash:
|
|
73
|
+
const encodedFunctionCalls = functionCalls.map((call, index) => ({
|
|
74
|
+
args_hash: hashedArguments[index].hash,
|
|
70
75
|
function_selector: call.selector.toField(),
|
|
71
76
|
target_address: call.to.toField(),
|
|
72
77
|
is_public: call.type == FunctionType.PUBLIC,
|
|
@@ -74,8 +79,10 @@ export abstract class EntrypointPayload {
|
|
|
74
79
|
}));
|
|
75
80
|
/* eslint-enable camelcase */
|
|
76
81
|
|
|
77
|
-
|
|
78
|
-
|
|
82
|
+
return {
|
|
83
|
+
encodedFunctionCalls,
|
|
84
|
+
hashedArguments,
|
|
85
|
+
};
|
|
79
86
|
}
|
|
80
87
|
|
|
81
88
|
/* eslint-disable camelcase */
|
|
@@ -84,7 +91,7 @@ export abstract class EntrypointPayload {
|
|
|
84
91
|
* @internal
|
|
85
92
|
*/
|
|
86
93
|
get function_calls() {
|
|
87
|
-
return this
|
|
94
|
+
return this.functionCalls;
|
|
88
95
|
}
|
|
89
96
|
/* eslint-enable camelcase */
|
|
90
97
|
|
|
@@ -93,14 +100,14 @@ export abstract class EntrypointPayload {
|
|
|
93
100
|
* @internal
|
|
94
101
|
*/
|
|
95
102
|
get nonce() {
|
|
96
|
-
return this
|
|
103
|
+
return this._nonce;
|
|
97
104
|
}
|
|
98
105
|
|
|
99
106
|
/**
|
|
100
107
|
* The hashed arguments for the function calls
|
|
101
108
|
*/
|
|
102
109
|
get hashedArguments() {
|
|
103
|
-
return this
|
|
110
|
+
return this._hashedArguments;
|
|
104
111
|
}
|
|
105
112
|
|
|
106
113
|
/**
|
|
@@ -114,12 +121,12 @@ export abstract class EntrypointPayload {
|
|
|
114
121
|
* @returns The hash of the payload
|
|
115
122
|
*/
|
|
116
123
|
hash() {
|
|
117
|
-
return poseidon2HashWithSeparator(this.toFields(), this
|
|
124
|
+
return poseidon2HashWithSeparator(this.toFields(), this.generatorIndex);
|
|
118
125
|
}
|
|
119
126
|
|
|
120
127
|
/** Serializes the function calls to an array of fields. */
|
|
121
128
|
protected functionCallsToFields() {
|
|
122
|
-
return this
|
|
129
|
+
return this.functionCalls.flatMap(call => [
|
|
123
130
|
call.args_hash,
|
|
124
131
|
call.function_selector,
|
|
125
132
|
call.target_address,
|
|
@@ -133,8 +140,9 @@ export abstract class EntrypointPayload {
|
|
|
133
140
|
* @param functionCalls - The function calls to execute
|
|
134
141
|
* @returns The execution payload
|
|
135
142
|
*/
|
|
136
|
-
static fromFunctionCalls(functionCalls: FunctionCall[]) {
|
|
137
|
-
|
|
143
|
+
static async fromFunctionCalls(functionCalls: FunctionCall[]) {
|
|
144
|
+
const { encodedFunctionCalls, hashedArguments } = await this.create(functionCalls);
|
|
145
|
+
return new AppEntrypointPayload(encodedFunctionCalls, hashedArguments, 0, Fr.random());
|
|
138
146
|
}
|
|
139
147
|
|
|
140
148
|
/**
|
|
@@ -143,12 +151,13 @@ export abstract class EntrypointPayload {
|
|
|
143
151
|
* @param nonce - The nonce for the payload, used to emit a nullifier identifying the call
|
|
144
152
|
* @returns The execution payload
|
|
145
153
|
*/
|
|
146
|
-
static fromAppExecution(functionCalls: FunctionCall[] | Tuple<FunctionCall, 4>, nonce = Fr.random()) {
|
|
154
|
+
static async fromAppExecution(functionCalls: FunctionCall[] | Tuple<FunctionCall, 4>, nonce = Fr.random()) {
|
|
147
155
|
if (functionCalls.length > APP_MAX_CALLS) {
|
|
148
156
|
throw new Error(`Expected at most ${APP_MAX_CALLS} function calls, got ${functionCalls.length}`);
|
|
149
157
|
}
|
|
150
158
|
const paddedCalls = padArrayEnd(functionCalls, FunctionCall.empty(), APP_MAX_CALLS);
|
|
151
|
-
|
|
159
|
+
const { encodedFunctionCalls, hashedArguments } = await this.create(paddedCalls);
|
|
160
|
+
return new AppEntrypointPayload(encodedFunctionCalls, hashedArguments, GeneratorIndex.SIGNATURE_PAYLOAD, nonce);
|
|
152
161
|
}
|
|
153
162
|
|
|
154
163
|
/**
|
|
@@ -162,7 +171,14 @@ export abstract class EntrypointPayload {
|
|
|
162
171
|
const feePayer = await feeOpts?.paymentMethod.getFeePayer(feeOpts?.gasSettings);
|
|
163
172
|
const isFeePayer = !!feePayer && feePayer.equals(sender);
|
|
164
173
|
const paddedCalls = padArrayEnd(calls, FunctionCall.empty(), FEE_MAX_CALLS);
|
|
165
|
-
|
|
174
|
+
const { encodedFunctionCalls, hashedArguments } = await this.create(paddedCalls);
|
|
175
|
+
return new FeeEntrypointPayload(
|
|
176
|
+
encodedFunctionCalls,
|
|
177
|
+
hashedArguments,
|
|
178
|
+
GeneratorIndex.FEE_PAYLOAD,
|
|
179
|
+
Fr.random(),
|
|
180
|
+
isFeePayer,
|
|
181
|
+
);
|
|
166
182
|
}
|
|
167
183
|
}
|
|
168
184
|
|
|
@@ -177,8 +193,14 @@ class AppEntrypointPayload extends EntrypointPayload {
|
|
|
177
193
|
class FeeEntrypointPayload extends EntrypointPayload {
|
|
178
194
|
#isFeePayer: boolean;
|
|
179
195
|
|
|
180
|
-
constructor(
|
|
181
|
-
|
|
196
|
+
constructor(
|
|
197
|
+
functionCalls: EncodedFunctionCall[],
|
|
198
|
+
hashedArguments: HashedValues[],
|
|
199
|
+
generatorIndex: number,
|
|
200
|
+
nonce: Fr,
|
|
201
|
+
isFeePayer: boolean,
|
|
202
|
+
) {
|
|
203
|
+
super(functionCalls, hashedArguments, generatorIndex, nonce);
|
|
182
204
|
this.#isFeePayer = isFeePayer;
|
|
183
205
|
}
|
|
184
206
|
|
|
@@ -200,6 +222,12 @@ class FeeEntrypointPayload extends EntrypointPayload {
|
|
|
200
222
|
* @param feePayload - A fee payload.
|
|
201
223
|
* @returns A hash of a combined payload.
|
|
202
224
|
*/
|
|
203
|
-
export function computeCombinedPayloadHash(
|
|
204
|
-
|
|
225
|
+
export async function computeCombinedPayloadHash(
|
|
226
|
+
appPayload: AppEntrypointPayload,
|
|
227
|
+
feePayload: FeeEntrypointPayload,
|
|
228
|
+
): Promise<Fr> {
|
|
229
|
+
return poseidon2HashWithSeparator(
|
|
230
|
+
[await appPayload.hash(), await feePayload.hash()],
|
|
231
|
+
GeneratorIndex.COMBINED_PAYLOAD,
|
|
232
|
+
);
|
|
205
233
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type FunctionCall } from '@aztec/circuit-types';
|
|
2
2
|
import { type AztecAddress, Fr, FunctionSelector } from '@aztec/circuits.js';
|
|
3
|
-
import { FunctionType } from '@aztec/foundation/abi';
|
|
3
|
+
import { FunctionType, U128 } from '@aztec/foundation/abi';
|
|
4
4
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
5
5
|
import { getCanonicalFeeJuice } from '@aztec/protocol-contracts/fee-juice';
|
|
6
6
|
|
|
@@ -22,9 +22,10 @@ export class FeeJuicePaymentMethodWithClaim extends FeeJuicePaymentMethod {
|
|
|
22
22
|
* Creates a function call to pay the fee in Fee Juice.
|
|
23
23
|
* @returns A function call
|
|
24
24
|
*/
|
|
25
|
-
override getFunctionCalls(): Promise<FunctionCall[]> {
|
|
26
|
-
const
|
|
27
|
-
|
|
25
|
+
override async getFunctionCalls(): Promise<FunctionCall[]> {
|
|
26
|
+
const canonicalFeeJuice = await getCanonicalFeeJuice();
|
|
27
|
+
const selector = await FunctionSelector.fromNameAndParameters(
|
|
28
|
+
canonicalFeeJuice.artifact.functions.find(f => f.name === 'claim')!,
|
|
28
29
|
);
|
|
29
30
|
|
|
30
31
|
return Promise.resolve([
|
|
@@ -35,7 +36,7 @@ export class FeeJuicePaymentMethodWithClaim extends FeeJuicePaymentMethod {
|
|
|
35
36
|
isStatic: false,
|
|
36
37
|
args: [
|
|
37
38
|
this.sender.toField(),
|
|
38
|
-
this.claim.claimAmount,
|
|
39
|
+
...new U128(this.claim.claimAmount).toFields(),
|
|
39
40
|
this.claim.claimSecret,
|
|
40
41
|
new Fr(this.claim.messageLeafIndex),
|
|
41
42
|
],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type FunctionCall } from '@aztec/circuit-types';
|
|
2
2
|
import { type GasSettings } from '@aztec/circuits.js';
|
|
3
|
-
import { FunctionSelector, FunctionType } from '@aztec/foundation/abi';
|
|
3
|
+
import { FunctionSelector, FunctionType, U128 } from '@aztec/foundation/abi';
|
|
4
4
|
import { type AztecAddress } from '@aztec/foundation/aztec-address';
|
|
5
5
|
import { Fr } from '@aztec/foundation/fields';
|
|
6
6
|
|
|
@@ -88,15 +88,15 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod {
|
|
|
88
88
|
async getFunctionCalls(gasSettings: GasSettings): Promise<FunctionCall[]> {
|
|
89
89
|
// We assume 1:1 exchange rate between fee juice and token. But in reality you would need to convert feeLimit
|
|
90
90
|
// (maxFee) to be in token denomination.
|
|
91
|
-
const maxFee = this.setMaxFeeToOne ?
|
|
91
|
+
const maxFee = new U128(this.setMaxFeeToOne ? 1n : gasSettings.getFeeLimit().toBigInt());
|
|
92
92
|
const nonce = Fr.random();
|
|
93
93
|
|
|
94
94
|
await this.wallet.createAuthWit({
|
|
95
95
|
caller: this.paymentContract,
|
|
96
96
|
action: {
|
|
97
|
-
name: '
|
|
98
|
-
args: [this.wallet.getAddress().toField(), maxFee, nonce],
|
|
99
|
-
selector: FunctionSelector.fromSignature('
|
|
97
|
+
name: 'transfer_to_public',
|
|
98
|
+
args: [this.wallet.getAddress().toField(), this.paymentContract.toField(), ...maxFee.toFields(), nonce],
|
|
99
|
+
selector: await FunctionSelector.fromSignature('transfer_to_public((Field),(Field),(Field,Field),Field)'),
|
|
100
100
|
type: FunctionType.PRIVATE,
|
|
101
101
|
isStatic: false,
|
|
102
102
|
to: await this.getAsset(),
|
|
@@ -108,10 +108,10 @@ export class PrivateFeePaymentMethod implements FeePaymentMethod {
|
|
|
108
108
|
{
|
|
109
109
|
name: 'fee_entrypoint_private',
|
|
110
110
|
to: this.paymentContract,
|
|
111
|
-
selector: FunctionSelector.fromSignature('fee_entrypoint_private(Field,Field)'),
|
|
111
|
+
selector: await FunctionSelector.fromSignature('fee_entrypoint_private((Field,Field),Field)'),
|
|
112
112
|
type: FunctionType.PRIVATE,
|
|
113
113
|
isStatic: false,
|
|
114
|
-
args: [maxFee, nonce],
|
|
114
|
+
args: [...maxFee.toFields(), nonce],
|
|
115
115
|
returnTypes: [],
|
|
116
116
|
},
|
|
117
117
|
];
|