@aztec/entrypoints 0.0.1-commit.fce3e4f → 0.0.1-commit.ffe5b04ea
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_entrypoint.d.ts +8 -9
- package/dest/account_entrypoint.d.ts.map +1 -1
- package/dest/account_entrypoint.js +63 -30
- package/dest/default_entrypoint.d.ts +5 -7
- package/dest/default_entrypoint.d.ts.map +1 -1
- package/dest/default_entrypoint.js +16 -9
- package/dest/default_multi_call_entrypoint.d.ts +7 -8
- package/dest/default_multi_call_entrypoint.d.ts.map +1 -1
- package/dest/default_multi_call_entrypoint.js +51 -22
- package/dest/encoding.d.ts +13 -6
- package/dest/encoding.d.ts.map +1 -1
- package/dest/encoding.js +9 -9
- package/dest/interfaces.d.ts +16 -3
- package/dest/interfaces.d.ts.map +1 -1
- package/dest/interfaces.js +1 -1
- package/package.json +9 -9
- package/src/account_entrypoint.ts +70 -29
- package/src/default_entrypoint.ts +26 -9
- package/src/default_multi_call_entrypoint.ts +63 -24
- package/src/encoding.ts +7 -7
- package/src/interfaces.ts +16 -1
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
3
3
|
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
4
|
-
import { TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
5
|
-
import type {
|
|
6
|
-
import type { AuthWitnessProvider, EntrypointInterface } from './interfaces.js';
|
|
4
|
+
import { ExecutionPayload, TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
5
|
+
import type { AuthWitnessProvider, ChainInfo, EntrypointInterface } from './interfaces.js';
|
|
7
6
|
/**
|
|
8
7
|
* The mechanism via which an account contract will pay for a transaction in which it gets invoked.
|
|
9
8
|
*/
|
|
@@ -49,12 +48,12 @@ export type DefaultAccountEntrypointOptions = {
|
|
|
49
48
|
* for an account, which accepts an AppPayload and a FeePayload as defined in noir-libs/aztec-noir/src/entrypoint module
|
|
50
49
|
*/
|
|
51
50
|
export declare class DefaultAccountEntrypoint implements EntrypointInterface {
|
|
51
|
+
#private;
|
|
52
52
|
private address;
|
|
53
53
|
private auth;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings, options: DefaultAccountEntrypointOptions): Promise<TxExecutionRequest>;
|
|
54
|
+
constructor(address: AztecAddress, auth: AuthWitnessProvider);
|
|
55
|
+
createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings, chainInfo: ChainInfo, options: DefaultAccountEntrypointOptions): Promise<TxExecutionRequest>;
|
|
56
|
+
wrapExecutionPayload(exec: ExecutionPayload, options: DefaultAccountEntrypointOptions): Promise<ExecutionPayload>;
|
|
58
57
|
private getEntrypointAbi;
|
|
59
58
|
}
|
|
60
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
59
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWNjb3VudF9lbnRyeXBvaW50LmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvYWNjb3VudF9lbnRyeXBvaW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxFQUFFLEVBQUUsTUFBTSxnQ0FBZ0MsQ0FBQztBQUVwRCxPQUFPLEtBQUssRUFBRSxZQUFZLEVBQUUsTUFBTSw2QkFBNkIsQ0FBQztBQUNoRSxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsTUFBTSxtQkFBbUIsQ0FBQztBQUNyRCxPQUFPLEVBQUUsZ0JBQWdCLEVBQTJCLGtCQUFrQixFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFHakcsT0FBTyxLQUFLLEVBQUUsbUJBQW1CLEV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d.ts","sourceRoot":"","sources":["../src/account_entrypoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"account_entrypoint.d.ts","sourceRoot":"","sources":["../src/account_entrypoint.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AAEpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAA2B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAGjG,OAAO,KAAK,EAAE,mBAAmB,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAE3F;;GAEG;AACH,oBAAY,8BAA8B;IACxC;;OAEG;IACH,QAAQ,IAAI;IACZ;;;;;OAKG;IACH,qBAAqB,IAAI;IACzB;;;;;;;OAOG;IACH,oBAAoB,IAAI;CACzB;AAED;;GAEG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,gDAAgD;IAChD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;OAIG;IACH,OAAO,CAAC,EAAE,EAAE,CAAC;IACb,4GAA4G;IAC5G,uBAAuB,EAAE,8BAA8B,CAAC;CACzD,CAAC;AAEF;;;GAGG;AACH,qBAAa,wBAAyB,YAAW,mBAAmB;;IAEhE,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,IAAI;IAFd,YACU,OAAO,EAAE,YAAY,EACrB,IAAI,EAAE,mBAAmB,EAC/B;IAEE,wBAAwB,CAC5B,IAAI,EAAE,gBAAgB,EACtB,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,+BAA+B,GACvC,OAAO,CAAC,kBAAkB,CAAC,CAgB7B;IAEK,oBAAoB,CACxB,IAAI,EAAE,gBAAgB,EACtB,OAAO,EAAE,+BAA+B,GACvC,OAAO,CAAC,gBAAgB,CAAC,CAuB3B;IAgCD,OAAO,CAAC,gBAAgB;CA2DzB"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
2
|
-
import { FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
|
|
3
|
-
import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
4
|
-
import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import { FunctionCall, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
|
|
3
|
+
import { ExecutionPayload, HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
5
4
|
import { EncodedAppEntrypointCalls } from './encoding.js';
|
|
6
5
|
/**
|
|
7
6
|
* The mechanism via which an account contract will pay for a transaction in which it gets invoked.
|
|
@@ -31,50 +30,84 @@ import { EncodedAppEntrypointCalls } from './encoding.js';
|
|
|
31
30
|
*/ export class DefaultAccountEntrypoint {
|
|
32
31
|
address;
|
|
33
32
|
auth;
|
|
34
|
-
|
|
35
|
-
version;
|
|
36
|
-
constructor(address, auth, chainId = DEFAULT_CHAIN_ID, version = DEFAULT_VERSION){
|
|
33
|
+
constructor(address, auth){
|
|
37
34
|
this.address = address;
|
|
38
35
|
this.auth = auth;
|
|
39
|
-
this.chainId = chainId;
|
|
40
|
-
this.version = version;
|
|
41
36
|
}
|
|
42
|
-
async createTxExecutionRequest(exec, gasSettings, options) {
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
const { cancellable, txNonce, feePaymentMethodOptions } = options;
|
|
47
|
-
// Encode the calls for the app
|
|
48
|
-
const encodedCalls = await EncodedAppEntrypointCalls.create(calls, txNonce);
|
|
49
|
-
// Obtain the entrypoint hashed args, built from the app encoded calls and global options
|
|
50
|
-
const abi = this.getEntrypointAbi();
|
|
51
|
-
const entrypointHashedArgs = await HashedValues.fromArgs(encodeArguments(abi, [
|
|
52
|
-
encodedCalls,
|
|
53
|
-
feePaymentMethodOptions,
|
|
54
|
-
!!cancellable
|
|
55
|
-
]));
|
|
56
|
-
// Generate the payload auth witness, by signing the hash of the payload
|
|
57
|
-
const appPayloadAuthwitness = await this.auth.createAuthWit(await encodedCalls.hash());
|
|
58
|
-
// Assemble the tx request
|
|
37
|
+
async createTxExecutionRequest(exec, gasSettings, chainInfo, options) {
|
|
38
|
+
const { authWitnesses, capsules, extraHashedArgs } = exec;
|
|
39
|
+
const callData = await this.#buildEntrypointCallData(exec, options);
|
|
40
|
+
const entrypointHashedArgs = await HashedValues.fromArgs(callData.encodedArgs);
|
|
59
41
|
const txRequest = TxExecutionRequest.from({
|
|
60
42
|
firstCallArgsHash: entrypointHashedArgs.hash,
|
|
61
43
|
origin: this.address,
|
|
62
|
-
functionSelector:
|
|
63
|
-
txContext: new TxContext(
|
|
44
|
+
functionSelector: callData.functionSelector,
|
|
45
|
+
txContext: new TxContext(chainInfo.chainId.toNumber(), chainInfo.version.toNumber(), gasSettings),
|
|
64
46
|
argsOfCalls: [
|
|
65
|
-
...encodedCalls.hashedArguments,
|
|
47
|
+
...callData.encodedCalls.hashedArguments,
|
|
66
48
|
entrypointHashedArgs,
|
|
67
49
|
...extraHashedArgs
|
|
68
50
|
],
|
|
69
51
|
authWitnesses: [
|
|
70
52
|
...authWitnesses,
|
|
71
|
-
|
|
53
|
+
callData.payloadAuthWitness
|
|
72
54
|
],
|
|
73
55
|
capsules,
|
|
74
56
|
salt: Fr.random()
|
|
75
57
|
});
|
|
76
58
|
return txRequest;
|
|
77
59
|
}
|
|
60
|
+
async wrapExecutionPayload(exec, options) {
|
|
61
|
+
const { authWitnesses, capsules, extraHashedArgs, feePayer } = exec;
|
|
62
|
+
const callData = await this.#buildEntrypointCallData(exec, options);
|
|
63
|
+
// Build the entrypoint function call
|
|
64
|
+
const entrypointCall = FunctionCall.from({
|
|
65
|
+
name: callData.abi.name,
|
|
66
|
+
to: this.address,
|
|
67
|
+
selector: callData.functionSelector,
|
|
68
|
+
type: callData.abi.functionType,
|
|
69
|
+
hideMsgSender: false,
|
|
70
|
+
isStatic: callData.abi.isStatic,
|
|
71
|
+
args: callData.encodedArgs,
|
|
72
|
+
returnTypes: callData.abi.returnTypes
|
|
73
|
+
});
|
|
74
|
+
return new ExecutionPayload([
|
|
75
|
+
entrypointCall
|
|
76
|
+
], [
|
|
77
|
+
callData.payloadAuthWitness,
|
|
78
|
+
...authWitnesses
|
|
79
|
+
], capsules, [
|
|
80
|
+
...callData.encodedCalls.hashedArguments,
|
|
81
|
+
...extraHashedArgs
|
|
82
|
+
], feePayer ?? this.address);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Builds the shared data needed for both creating a tx execution request and wrapping an execution payload.
|
|
86
|
+
* This includes encoding calls, building entrypoint arguments, and creating the authwitness.
|
|
87
|
+
* @param exec - The execution payload containing calls to encode
|
|
88
|
+
* @param options - Account entrypoint options including tx nonce and fee payment method
|
|
89
|
+
* @returns Encoded call data, ABI, function selector, and auth witness
|
|
90
|
+
*/ async #buildEntrypointCallData(exec, options) {
|
|
91
|
+
const { calls } = exec;
|
|
92
|
+
const { cancellable, txNonce, feePaymentMethodOptions } = options;
|
|
93
|
+
const encodedCalls = await EncodedAppEntrypointCalls.create(calls, txNonce);
|
|
94
|
+
const abi = this.getEntrypointAbi();
|
|
95
|
+
const args = [
|
|
96
|
+
encodedCalls,
|
|
97
|
+
feePaymentMethodOptions,
|
|
98
|
+
!!cancellable
|
|
99
|
+
];
|
|
100
|
+
const encodedArgs = encodeArguments(abi, args);
|
|
101
|
+
const functionSelector = await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters);
|
|
102
|
+
const payloadAuthWitness = await this.auth.createAuthWit(await encodedCalls.hash());
|
|
103
|
+
return {
|
|
104
|
+
encodedCalls,
|
|
105
|
+
abi,
|
|
106
|
+
encodedArgs,
|
|
107
|
+
functionSelector,
|
|
108
|
+
payloadAuthWitness
|
|
109
|
+
};
|
|
110
|
+
}
|
|
78
111
|
getEntrypointAbi() {
|
|
79
112
|
return {
|
|
80
113
|
name: 'entrypoint',
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
2
|
-
import {
|
|
3
|
-
import type { EntrypointInterface } from './interfaces.js';
|
|
2
|
+
import { ExecutionPayload, TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
3
|
+
import type { ChainInfo, EntrypointInterface } from './interfaces.js';
|
|
4
4
|
/**
|
|
5
5
|
* Default implementation of the entrypoint interface. It calls a function on a contract directly
|
|
6
6
|
*/
|
|
7
7
|
export declare class DefaultEntrypoint implements EntrypointInterface {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
constructor(chainId: number, rollupVersion: number);
|
|
11
|
-
createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings): Promise<TxExecutionRequest>;
|
|
8
|
+
createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings, chainInfo: ChainInfo): Promise<TxExecutionRequest>;
|
|
9
|
+
wrapExecutionPayload(exec: ExecutionPayload, _options?: any): Promise<ExecutionPayload>;
|
|
12
10
|
}
|
|
13
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
11
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVmYXVsdF9lbnRyeXBvaW50LmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvZGVmYXVsdF9lbnRyeXBvaW50LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUNBLE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBQ3JELE9BQU8sRUFBRSxnQkFBZ0IsRUFBMkIsa0JBQWtCLEVBQUUsTUFBTSxrQkFBa0IsQ0FBQztBQUVqRyxPQUFPLEtBQUssRUFBRSxTQUFTLEVBQUUsbUJBQW1CLEVBQUUsTUFBTSxpQkFBaUIsQ0FBQztBQUV0RTs7R0FFRztBQUNILHFCQUFhLGlCQUFrQixZQUFXLG1CQUFtQjtJQUNyRCx3QkFBd0IsQ0FDNUIsSUFBSSxFQUFFLGdCQUFnQixFQUN0QixXQUFXLEVBQUUsV0FBVyxFQUN4QixTQUFTLEVBQUUsU0FBUyxHQUNuQixPQUFPLENBQUMsa0JBQWtCLENBQUMsQ0EyQjdCO0lBRUssb0JBQW9CLENBQUMsSUFBSSxFQUFFLGdCQUFnQixFQUFFLFFBQVEsQ0FBQyxFQUFFLEdBQUcsR0FBRyxPQUFPLENBQUMsZ0JBQWdCLENBQUMsQ0FnQjVGO0NBQ0YifQ==
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default_entrypoint.d.ts","sourceRoot":"","sources":["../src/default_entrypoint.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"default_entrypoint.d.ts","sourceRoot":"","sources":["../src/default_entrypoint.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAA2B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEjG,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;GAEG;AACH,qBAAa,iBAAkB,YAAW,mBAAmB;IACrD,wBAAwB,CAC5B,IAAI,EAAE,gBAAgB,EACtB,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,kBAAkB,CAAC,CA2B7B;IAEK,oBAAoB,CAAC,IAAI,EAAE,gBAAgB,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAgB5F;CACF"}
|
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
import { FunctionType } from '@aztec/stdlib/abi';
|
|
2
|
-
import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
2
|
+
import { ExecutionPayload, HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
3
3
|
/**
|
|
4
4
|
* Default implementation of the entrypoint interface. It calls a function on a contract directly
|
|
5
5
|
*/ export class DefaultEntrypoint {
|
|
6
|
-
|
|
7
|
-
rollupVersion;
|
|
8
|
-
constructor(chainId, rollupVersion){
|
|
9
|
-
this.chainId = chainId;
|
|
10
|
-
this.rollupVersion = rollupVersion;
|
|
11
|
-
}
|
|
12
|
-
async createTxExecutionRequest(exec, gasSettings) {
|
|
6
|
+
async createTxExecutionRequest(exec, gasSettings, chainInfo) {
|
|
13
7
|
// Initial request with calls, authWitnesses and capsules
|
|
14
8
|
const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
|
|
15
9
|
if (calls.length > 1) {
|
|
@@ -24,9 +18,22 @@ import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
|
24
18
|
throw new Error('Public entrypoints are not allowed');
|
|
25
19
|
}
|
|
26
20
|
// Assemble the tx request
|
|
27
|
-
return new TxExecutionRequest(call.to, call.selector, hashedArguments[0].hash, new TxContext(
|
|
21
|
+
return new TxExecutionRequest(call.to, call.selector, hashedArguments[0].hash, new TxContext(chainInfo.chainId.toNumber(), chainInfo.version.toNumber(), gasSettings), [
|
|
28
22
|
...hashedArguments,
|
|
29
23
|
...extraHashedArgs
|
|
30
24
|
], authWitnesses, capsules);
|
|
31
25
|
}
|
|
26
|
+
async wrapExecutionPayload(exec, _options) {
|
|
27
|
+
if (exec.calls.length !== 1) {
|
|
28
|
+
throw new Error(`DefaultEntrypoint can only wrap a single call, got ${exec.calls.length}`);
|
|
29
|
+
}
|
|
30
|
+
const call = exec.calls[0];
|
|
31
|
+
const hashedArguments = await HashedValues.fromArgs(call.args);
|
|
32
|
+
return new ExecutionPayload([
|
|
33
|
+
call
|
|
34
|
+
], exec.authWitnesses, exec.capsules, [
|
|
35
|
+
hashedArguments,
|
|
36
|
+
...exec.extraHashedArgs
|
|
37
|
+
], exec.feePayer);
|
|
38
|
+
}
|
|
32
39
|
}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
2
2
|
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
3
|
-
import { TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
4
|
-
import type {
|
|
5
|
-
import type { EntrypointInterface } from './interfaces.js';
|
|
3
|
+
import { ExecutionPayload, TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
4
|
+
import type { ChainInfo, EntrypointInterface } from './interfaces.js';
|
|
6
5
|
/**
|
|
7
6
|
* Implementation for an entrypoint interface that can execute multiple function calls in a single transaction
|
|
8
7
|
*/
|
|
9
8
|
export declare class DefaultMultiCallEntrypoint implements EntrypointInterface {
|
|
10
|
-
private
|
|
11
|
-
private version;
|
|
9
|
+
#private;
|
|
12
10
|
private address;
|
|
13
|
-
constructor(
|
|
14
|
-
createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings): Promise<TxExecutionRequest>;
|
|
11
|
+
constructor(address?: AztecAddress);
|
|
12
|
+
createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings, chainInfo: ChainInfo): Promise<TxExecutionRequest>;
|
|
13
|
+
wrapExecutionPayload(exec: ExecutionPayload, _options?: any): Promise<ExecutionPayload>;
|
|
15
14
|
private getEntrypointAbi;
|
|
16
15
|
}
|
|
17
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
16
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGVmYXVsdF9tdWx0aV9jYWxsX2VudHJ5cG9pbnQuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2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,EAA2B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"default_multi_call_entrypoint.d.ts","sourceRoot":"","sources":["../src/default_multi_call_entrypoint.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAA2B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAGjG,OAAO,KAAK,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;GAEG;AACH,qBAAa,0BAA2B,YAAW,mBAAmB;;IACxD,OAAO,CAAC,OAAO;IAA3B,YAAoB,OAAO,GAAE,YAA0D,EAAI;IAErF,wBAAwB,CAC5B,IAAI,EAAE,gBAAgB,EACtB,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,kBAAkB,CAAC,CAiB7B;IAEK,oBAAoB,CAAC,IAAI,EAAE,gBAAgB,EAAE,QAAQ,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAqB5F;IA0BD,OAAO,CAAC,gBAAgB;CAyDzB"}
|
|
@@ -1,37 +1,26 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
3
|
-
import { FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
|
|
4
|
-
import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
3
|
+
import { FunctionCall, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
|
|
4
|
+
import { ExecutionPayload, HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
5
5
|
import { EncodedAppEntrypointCalls } from './encoding.js';
|
|
6
6
|
/**
|
|
7
7
|
* Implementation for an entrypoint interface that can execute multiple function calls in a single transaction
|
|
8
8
|
*/ export class DefaultMultiCallEntrypoint {
|
|
9
|
-
chainId;
|
|
10
|
-
version;
|
|
11
9
|
address;
|
|
12
|
-
constructor(
|
|
13
|
-
this.chainId = chainId;
|
|
14
|
-
this.version = version;
|
|
10
|
+
constructor(address = ProtocolContractAddress.MultiCallEntrypoint){
|
|
15
11
|
this.address = address;
|
|
16
12
|
}
|
|
17
|
-
async createTxExecutionRequest(exec, gasSettings) {
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const encodedCalls = await EncodedAppEntrypointCalls.create(calls);
|
|
22
|
-
// Obtain the entrypoint hashed args, built from the encoded calls
|
|
23
|
-
const abi = this.getEntrypointAbi();
|
|
24
|
-
const entrypointHashedArgs = await HashedValues.fromArgs(encodeArguments(abi, [
|
|
25
|
-
encodedCalls
|
|
26
|
-
]));
|
|
27
|
-
// Assemble the tx request
|
|
13
|
+
async createTxExecutionRequest(exec, gasSettings, chainInfo) {
|
|
14
|
+
const { authWitnesses, capsules, extraHashedArgs } = exec;
|
|
15
|
+
const callData = await this.#buildEntrypointCallData(exec);
|
|
16
|
+
const entrypointHashedArgs = await HashedValues.fromArgs(callData.encodedArgs);
|
|
28
17
|
const txRequest = TxExecutionRequest.from({
|
|
29
18
|
firstCallArgsHash: entrypointHashedArgs.hash,
|
|
30
19
|
origin: this.address,
|
|
31
|
-
functionSelector:
|
|
32
|
-
txContext: new TxContext(
|
|
20
|
+
functionSelector: callData.functionSelector,
|
|
21
|
+
txContext: new TxContext(chainInfo.chainId.toNumber(), chainInfo.version.toNumber(), gasSettings),
|
|
33
22
|
argsOfCalls: [
|
|
34
|
-
...encodedCalls.hashedArguments,
|
|
23
|
+
...callData.encodedCalls.hashedArguments,
|
|
35
24
|
entrypointHashedArgs,
|
|
36
25
|
...extraHashedArgs
|
|
37
26
|
],
|
|
@@ -41,6 +30,46 @@ import { EncodedAppEntrypointCalls } from './encoding.js';
|
|
|
41
30
|
});
|
|
42
31
|
return Promise.resolve(txRequest);
|
|
43
32
|
}
|
|
33
|
+
async wrapExecutionPayload(exec, _options) {
|
|
34
|
+
const { authWitnesses, capsules, extraHashedArgs } = exec;
|
|
35
|
+
const callData = await this.#buildEntrypointCallData(exec);
|
|
36
|
+
const entrypointCall = FunctionCall.from({
|
|
37
|
+
name: callData.abi.name,
|
|
38
|
+
to: this.address,
|
|
39
|
+
selector: callData.functionSelector,
|
|
40
|
+
type: callData.abi.functionType,
|
|
41
|
+
hideMsgSender: false,
|
|
42
|
+
isStatic: callData.abi.isStatic,
|
|
43
|
+
args: callData.encodedArgs,
|
|
44
|
+
returnTypes: callData.abi.returnTypes
|
|
45
|
+
});
|
|
46
|
+
return new ExecutionPayload([
|
|
47
|
+
entrypointCall
|
|
48
|
+
], authWitnesses, capsules, [
|
|
49
|
+
...callData.encodedCalls.hashedArguments,
|
|
50
|
+
...extraHashedArgs
|
|
51
|
+
], exec.feePayer);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Builds the shared data needed for both creating a tx execution request and wrapping an execution payload.
|
|
55
|
+
* This includes encoding calls and building entrypoint arguments.
|
|
56
|
+
* @param exec - The execution payload containing calls to encode
|
|
57
|
+
* @returns Encoded call data, ABI, encoded arguments, and function selector
|
|
58
|
+
*/ async #buildEntrypointCallData(exec) {
|
|
59
|
+
const { calls } = exec;
|
|
60
|
+
const encodedCalls = await EncodedAppEntrypointCalls.create(calls);
|
|
61
|
+
const abi = this.getEntrypointAbi();
|
|
62
|
+
const encodedArgs = encodeArguments(abi, [
|
|
63
|
+
encodedCalls
|
|
64
|
+
]);
|
|
65
|
+
const functionSelector = await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters);
|
|
66
|
+
return {
|
|
67
|
+
encodedCalls,
|
|
68
|
+
abi,
|
|
69
|
+
encodedArgs,
|
|
70
|
+
functionSelector
|
|
71
|
+
};
|
|
72
|
+
}
|
|
44
73
|
getEntrypointAbi() {
|
|
45
74
|
return {
|
|
46
75
|
name: 'entrypoint',
|
package/dest/encoding.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { Tuple } from '@aztec/foundation/serialize';
|
|
3
3
|
import { FunctionCall } from '@aztec/stdlib/abi';
|
|
4
4
|
import { HashedValues } from '@aztec/stdlib/tx';
|
|
5
|
-
declare const APP_MAX_CALLS = 5;
|
|
5
|
+
export declare const APP_MAX_CALLS = 5;
|
|
6
6
|
/** Encoded function call for an Aztec entrypoint */
|
|
7
7
|
export type EncodedFunctionCall = {
|
|
8
8
|
/** Arguments hash for the call. */
|
|
@@ -32,9 +32,17 @@ export type EncodedCalls = {
|
|
|
32
32
|
* account how the calls are encoded and hashed.
|
|
33
33
|
* */
|
|
34
34
|
export declare class EncodedAppEntrypointCalls implements EncodedCalls {
|
|
35
|
+
/** Function calls in the expected format (Noir's convention) */
|
|
35
36
|
encodedFunctionCalls: EncodedFunctionCall[];
|
|
37
|
+
/** The hashed args for the call, ready to be injected in the execution cache */
|
|
36
38
|
hashedArguments: HashedValues[];
|
|
37
|
-
|
|
39
|
+
/** The index of the generator to use for hashing */
|
|
40
|
+
domainSeparator: number;
|
|
41
|
+
/**
|
|
42
|
+
* A nonce to inject into the payload of the transaction. When used with cancellable=true, this nonce will be
|
|
43
|
+
* used to compute a nullifier that allows cancelling this transaction by submitting a new one with the same nonce
|
|
44
|
+
* but higher fee. The nullifier ensures only one transaction can succeed.
|
|
45
|
+
*/
|
|
38
46
|
tx_nonce: Fr;
|
|
39
47
|
constructor(
|
|
40
48
|
/** Function calls in the expected format (Noir's convention) */
|
|
@@ -42,7 +50,7 @@ export declare class EncodedAppEntrypointCalls implements EncodedCalls {
|
|
|
42
50
|
/** The hashed args for the call, ready to be injected in the execution cache */
|
|
43
51
|
hashedArguments: HashedValues[],
|
|
44
52
|
/** The index of the generator to use for hashing */
|
|
45
|
-
|
|
53
|
+
domainSeparator: number,
|
|
46
54
|
/**
|
|
47
55
|
* A nonce to inject into the payload of the transaction. When used with cancellable=true, this nonce will be
|
|
48
56
|
* used to compute a nullifier that allows cancelling this transaction by submitting a new one with the same nonce
|
|
@@ -77,5 +85,4 @@ export declare class EncodedAppEntrypointCalls implements EncodedCalls {
|
|
|
77
85
|
}
|
|
78
86
|
/** Encodes FunctionCalls for execution, following Noir's convention */
|
|
79
87
|
export declare function encode(calls: FunctionCall[]): Promise<EncodedCalls>;
|
|
80
|
-
|
|
81
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZW5jb2RpbmcuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy9lbmNvZGluZy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFHQSxPQUFPLEVBQUUsRUFBRSxFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFDOUMsT0FBTyxLQUFLLEVBQUUsS0FBSyxFQUFFLE1BQU0sNkJBQTZCLENBQUM7QUFDekQsT0FBTyxFQUFFLFlBQVksRUFBZ0IsTUFBTSxtQkFBbUIsQ0FBQztBQUMvRCxPQUFPLEVBQUUsWUFBWSxFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFJaEQsUUFBQSxNQUFNLGFBQWEsSUFBSSxDQUFDO0FBRXhCLG9EQUFvRDtBQUNwRCxNQUFNLE1BQU0sbUJBQW1CLEdBQUc7SUFDaEMsbUNBQW1DO0lBQ25DLG9HQUFvRztJQUNwRyxTQUFTLEVBQUUsRUFBRSxDQUFDO0lBQ2QsdUNBQXVDO0lBQ3ZDLGlCQUFpQixFQUFFLEVBQUUsQ0FBQztJQUN0QixzQ0FBc0M7SUFDdEMsY0FBYyxFQUFFLEVBQUUsQ0FBQztJQUNuQixnREFBZ0Q7SUFDaEQsU0FBUyxFQUFFLE9BQ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FNLENBQUMsS0FBSyxFQUFFLFlBQVksRUFBRSxHQUFHLE9BQU8sQ0FBQyxZQUFZLENBQUMsQ0F3QnpFIn0=
|
package/dest/encoding.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../src/encoding.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,EAAE,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../src/encoding.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AACzD,OAAO,EAAE,YAAY,EAAgB,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAIhD,eAAO,MAAM,aAAa,IAAI,CAAC;AAE/B,oDAAoD;AACpD,MAAM,MAAM,mBAAmB,GAAG;IAChC,mCAAmC;IACnC,oGAAoG;IACpG,SAAS,EAAE,EAAE,CAAC;IACd,uCAAuC;IACvC,iBAAiB,EAAE,EAAE,CAAC;IACtB,sCAAsC;IACtC,cAAc,EAAE,EAAE,CAAC;IACnB,gDAAgD;IAChD,SAAS,EAAE,OAAO,CAAC;IACnB,wGAAwG;IACxG,eAAe,EAAE,OAAO,CAAC;IACzB,2CAA2C;IAC3C,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,sFAAsF;AACtF,MAAM,MAAM,YAAY,GAAG;IACzB,gEAAgE;IAChE,oBAAoB,EAAE,mBAAmB,EAAE,CAAC;IAC5C,gFAAgF;IAChF,eAAe,EAAE,YAAY,EAAE,CAAC;CACjC,CAAC;AAEF;;;;KAIK;AACL,qBAAa,yBAA0B,YAAW,YAAY;IAE1D,gEAAgE;IACzD,oBAAoB,EAAE,mBAAmB,EAAE;IAClD,gFAAgF;IACzE,eAAe,EAAE,YAAY,EAAE;IACtC,oDAAoD;IAC7C,eAAe,EAAE,MAAM;IAC9B;;;;OAIG;IAEI,QAAQ,EAAE,EAAE;IAbrB;IACE,gEAAgE;IACzD,oBAAoB,EAAE,mBAAmB,EAAE;IAClD,gFAAgF;IACzE,eAAe,EAAE,YAAY,EAAE;IACtC,oDAAoD;IAC7C,eAAe,EAAE,MAAM;IAC9B;;;;OAIG;IAEI,QAAQ,EAAE,EAAE,EACjB;IAGJ;;;OAGG;IACH,IAAI,cAAc,0BAEjB;IAGD;;;OAGG;IACH,QAAQ,IAAI,EAAE,EAAE,CAEf;IAED;;;OAGG;IACH,IAAI,gBAEH;IAED,2DAA2D;IAC3D,SAAS,CAAC,qBAAqB,SAS9B;IAED;;;;;;OAMG;IACH,OAAa,MAAM,CACjB,aAAa,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC,YAAY,EAAE,OAAO,aAAa,CAAC,EACzE,OAAO,KAAc,sCAatB;CACF;AAED,uEAAuE;AACvE,wBAAsB,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAwBzE"}
|
package/dest/encoding.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DomainSeparator } from '@aztec/constants';
|
|
2
2
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
3
|
-
import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto';
|
|
4
|
-
import { Fr } from '@aztec/foundation/
|
|
3
|
+
import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
5
|
import { FunctionCall, FunctionType } from '@aztec/stdlib/abi';
|
|
6
6
|
import { HashedValues } from '@aztec/stdlib/tx';
|
|
7
7
|
// These must match the values defined in:
|
|
8
8
|
// - noir-projects/aztec-nr/aztec/src/entrypoint/app.nr
|
|
9
|
-
const APP_MAX_CALLS = 5;
|
|
9
|
+
export const APP_MAX_CALLS = 5;
|
|
10
10
|
/**
|
|
11
11
|
* Entrypoints derive their arguments from the calls that they'll ultimate make.
|
|
12
12
|
* This utility class helps in creating the payload for the entrypoint by taking into
|
|
@@ -14,9 +14,9 @@ const APP_MAX_CALLS = 5;
|
|
|
14
14
|
* */ export class EncodedAppEntrypointCalls {
|
|
15
15
|
encodedFunctionCalls;
|
|
16
16
|
hashedArguments;
|
|
17
|
-
|
|
17
|
+
domainSeparator;
|
|
18
18
|
tx_nonce;
|
|
19
|
-
constructor(/** Function calls in the expected format (Noir's convention) */ encodedFunctionCalls, /** The hashed args for the call, ready to be injected in the execution cache */ hashedArguments, /** The index of the generator to use for hashing */
|
|
19
|
+
constructor(/** Function calls in the expected format (Noir's convention) */ encodedFunctionCalls, /** The hashed args for the call, ready to be injected in the execution cache */ hashedArguments, /** The index of the generator to use for hashing */ domainSeparator, /**
|
|
20
20
|
* A nonce to inject into the payload of the transaction. When used with cancellable=true, this nonce will be
|
|
21
21
|
* used to compute a nullifier that allows cancelling this transaction by submitting a new one with the same nonce
|
|
22
22
|
* but higher fee. The nullifier ensures only one transaction can succeed.
|
|
@@ -24,7 +24,7 @@ const APP_MAX_CALLS = 5;
|
|
|
24
24
|
tx_nonce){
|
|
25
25
|
this.encodedFunctionCalls = encodedFunctionCalls;
|
|
26
26
|
this.hashedArguments = hashedArguments;
|
|
27
|
-
this.
|
|
27
|
+
this.domainSeparator = domainSeparator;
|
|
28
28
|
this.tx_nonce = tx_nonce;
|
|
29
29
|
}
|
|
30
30
|
/* eslint-disable camelcase */ /**
|
|
@@ -46,7 +46,7 @@ const APP_MAX_CALLS = 5;
|
|
|
46
46
|
* Hashes the payload
|
|
47
47
|
* @returns The hash of the payload
|
|
48
48
|
*/ hash() {
|
|
49
|
-
return poseidon2HashWithSeparator(this.toFields(), this.
|
|
49
|
+
return poseidon2HashWithSeparator(this.toFields(), this.domainSeparator);
|
|
50
50
|
}
|
|
51
51
|
/** Serializes the function calls to an array of fields. */ functionCallsToFields() {
|
|
52
52
|
return this.encodedFunctionCalls.flatMap((call)=>[
|
|
@@ -70,7 +70,7 @@ const APP_MAX_CALLS = 5;
|
|
|
70
70
|
}
|
|
71
71
|
const paddedCalls = padArrayEnd(functionCalls, FunctionCall.empty(), APP_MAX_CALLS);
|
|
72
72
|
const encoded = await encode(paddedCalls);
|
|
73
|
-
return new EncodedAppEntrypointCalls(encoded.encodedFunctionCalls, encoded.hashedArguments,
|
|
73
|
+
return new EncodedAppEntrypointCalls(encoded.encodedFunctionCalls, encoded.hashedArguments, DomainSeparator.SIGNATURE_PAYLOAD, txNonce);
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
/** Encodes FunctionCalls for execution, following Noir's convention */ export async function encode(calls) {
|
package/dest/interfaces.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
3
3
|
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
4
4
|
import type { ExecutionPayload, TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
@@ -35,10 +35,23 @@ export interface EntrypointInterface {
|
|
|
35
35
|
* Generates an execution request out of set of function calls.
|
|
36
36
|
* @param exec - The execution intents to be run.
|
|
37
37
|
* @param gasSettings - The gas settings for the transaction.
|
|
38
|
+
* @param chainInfo - Chain information (chainId and version) for replay protection.
|
|
38
39
|
* @param options - Miscellaneous tx options that enable/disable features of the entrypoint
|
|
39
40
|
* @returns The authenticated transaction execution request.
|
|
40
41
|
*/
|
|
41
|
-
createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings, options?: any): Promise<TxExecutionRequest>;
|
|
42
|
+
createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings, chainInfo: ChainInfo, options?: any): Promise<TxExecutionRequest>;
|
|
43
|
+
/**
|
|
44
|
+
* Wraps an execution payload such that it is executed *via* this entrypoint.
|
|
45
|
+
* This returns an ExecutionPayload with the entrypoint as the caller for the wrapped payload.
|
|
46
|
+
* Useful for account self-funding deployments and batching calls beyond the limit
|
|
47
|
+
* of a single entrypoint call.
|
|
48
|
+
*
|
|
49
|
+
* @param exec - The execution payload to wrap
|
|
50
|
+
* @param options - Implementation-specific options
|
|
51
|
+
* @returns A new execution payload with a single call to this entrypoint
|
|
52
|
+
* @throws Error if the payload cannot be wrapped (e.g., exceeds call limit)
|
|
53
|
+
*/
|
|
54
|
+
wrapExecutionPayload(exec: ExecutionPayload, options?: any): Promise<ExecutionPayload>;
|
|
42
55
|
}
|
|
43
56
|
/** Creates authorization witnesses. */
|
|
44
57
|
export interface AuthWitnessProvider {
|
|
@@ -49,4 +62,4 @@ export interface AuthWitnessProvider {
|
|
|
49
62
|
*/
|
|
50
63
|
createAuthWit(messageHash: Fr | Buffer): Promise<AuthWitness>;
|
|
51
64
|
}
|
|
52
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
65
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW50ZXJmYWNlcy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2ludGVyZmFjZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLGdDQUFnQyxDQUFDO0FBQ3BELE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLDRCQUE0QixDQUFDO0FBQzlELE9BQU8sS0FBSyxFQUFFLFdBQVcsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBQ3JELE9BQU8sS0FBSyxFQUFFLGdCQUFnQixFQUFFLGtCQUFrQixFQUFFLE1BQU0sa0JBQWtCLENBQUM7QUFFN0UsT0FBTyxFQUFFLENBQUMsRUFBRSxNQUFNLEtBQUssQ0FBQztBQUV4Qjs7O0dBR0c7QUFDSCxNQUFNLE1BQU0sU0FBUyxHQUFHO0lBQ3RCLHNCQUFzQjtJQUN0QixPQUFPLEVBQUUsRUFBRSxDQUFDO0lBQ1osaUNBQWlDO0lBQ2pDLE9BQU8sRUFBRSxFQUFFLENBQUM7Q0FDYixDQUFDO0FBRUY7O0dBRUc7QUFDSCxlQUFPLE1BQU0sZUFBZTs7Ozs7Ozs7O0VBRzFCLENBQUM7QUFFSDs7O0dBR0c7QUFDSCxNQUFNLFdBQVcsbUJBQW1CO0lBQ2xDOzs7Ozs7O09BT0c7SUFDSCx3QkFBd0IsQ0FDdEIsSUFBSSxFQUFFLGdCQUFnQixFQUN0QixXQUFXLEVBQUUsV0FBVyxFQUN4QixTQUFTLEVBQUUsU0FBUyxFQUNwQixPQUFPLENBQUMsRUFBRSxHQUFHLEdBQ1osT0FBTyxDQUFDLGtCQUFrQixDQUFDLENBQUM7SUFFL0I7Ozs7Ozs7Ozs7T0FVRztJQUNILG9CQUFvQixDQUFDLElBQUksRUFBRSxnQkFBZ0IsRUFBRSxPQUFPLENBQUMsRUFBRSxHQUFHLEdBQUcsT0FBTyxDQUFDLGdCQUFnQixDQUFDLENBQUM7Q0FDeEY7QUFFRCx1Q0FBdUM7QUFDdkMsTUFBTSxXQUFXLG1CQUFtQjtJQUNsQzs7OztPQUlHO0lBQ0gsYUFBYSxDQUFDLFdBQVcsRUFBRSxFQUFFLEdBQUcsTUFBTSxHQUFHLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBQztDQUMvRCJ9
|
package/dest/interfaces.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,gCAAgC,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE7E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,sBAAsB;IACtB,OAAO,EAAE,EAAE,CAAC;IACZ,iCAAiC;IACjC,OAAO,EAAE,EAAE,CAAC;CACb,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe;;;;;;;;;EAG1B,CAAC;AAEH;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;;;OAOG;IACH,wBAAwB,CACtB,IAAI,EAAE,gBAAgB,EACtB,WAAW,EAAE,WAAW,EACxB,SAAS,EAAE,SAAS,EACpB,OAAO,CAAC,EAAE,GAAG,GACZ,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAE/B;;;;;;;;;;OAUG;IACH,oBAAoB,CAAC,IAAI,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CACxF;AAED,uCAAuC;AACvC,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,aAAa,CAAC,WAAW,EAAE,EAAE,GAAG,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CAC/D"}
|
package/dest/interfaces.js
CHANGED
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@aztec/entrypoints",
|
|
3
3
|
"homepage": "https://github.com/AztecProtocol/aztec-packages/tree/master/yarn-project/entrypoints",
|
|
4
4
|
"description": "Implementation of sample contract entrypoints for the Aztec Network",
|
|
5
|
-
"version": "0.0.1-commit.
|
|
5
|
+
"version": "0.0.1-commit.ffe5b04ea",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
8
8
|
"./account": "./dest/account_entrypoint.js",
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
"tsconfig": "./tsconfig.json"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
|
-
"build": "yarn clean &&
|
|
24
|
-
"build:dev": "
|
|
25
|
-
"build:ts": "
|
|
23
|
+
"build": "yarn clean && ../scripts/tsc.sh",
|
|
24
|
+
"build:dev": "../scripts/tsc.sh --watch",
|
|
25
|
+
"build:ts": "../scripts/tsc.sh",
|
|
26
26
|
"clean": "rm -rf ./dest .tsbuildinfo",
|
|
27
27
|
"test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
|
|
28
28
|
},
|
|
@@ -67,17 +67,17 @@
|
|
|
67
67
|
]
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@aztec/constants": "0.0.1-commit.
|
|
71
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
72
|
-
"@aztec/protocol-contracts": "0.0.1-commit.
|
|
73
|
-
"@aztec/stdlib": "0.0.1-commit.
|
|
70
|
+
"@aztec/constants": "0.0.1-commit.ffe5b04ea",
|
|
71
|
+
"@aztec/foundation": "0.0.1-commit.ffe5b04ea",
|
|
72
|
+
"@aztec/protocol-contracts": "0.0.1-commit.ffe5b04ea",
|
|
73
|
+
"@aztec/stdlib": "0.0.1-commit.ffe5b04ea",
|
|
74
74
|
"tslib": "^2.4.0",
|
|
75
75
|
"zod": "^3.23.8"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@jest/globals": "^30.0.0",
|
|
79
79
|
"@types/jest": "^30.0.0",
|
|
80
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
80
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
81
81
|
"jest": "^30.0.0",
|
|
82
82
|
"ts-node": "^10.9.1",
|
|
83
83
|
"typescript": "^5.3.3"
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
2
|
-
import { type FunctionAbi, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
|
+
import { type FunctionAbi, FunctionCall, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
|
|
3
3
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
4
4
|
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
5
|
-
import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
6
|
-
import type { ExecutionPayload } from '@aztec/stdlib/tx';
|
|
5
|
+
import { ExecutionPayload, HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
7
6
|
|
|
8
|
-
import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
|
|
9
7
|
import { EncodedAppEntrypointCalls } from './encoding.js';
|
|
10
|
-
import type { AuthWitnessProvider, EntrypointInterface } from './interfaces.js';
|
|
8
|
+
import type { AuthWitnessProvider, ChainInfo, EntrypointInterface } from './interfaces.js';
|
|
11
9
|
|
|
12
10
|
/**
|
|
13
11
|
* The mechanism via which an account contract will pay for a transaction in which it gets invoked.
|
|
@@ -59,39 +57,24 @@ export class DefaultAccountEntrypoint implements EntrypointInterface {
|
|
|
59
57
|
constructor(
|
|
60
58
|
private address: AztecAddress,
|
|
61
59
|
private auth: AuthWitnessProvider,
|
|
62
|
-
private chainId: number = DEFAULT_CHAIN_ID,
|
|
63
|
-
private version: number = DEFAULT_VERSION,
|
|
64
60
|
) {}
|
|
65
61
|
|
|
66
62
|
async createTxExecutionRequest(
|
|
67
63
|
exec: ExecutionPayload,
|
|
68
64
|
gasSettings: GasSettings,
|
|
65
|
+
chainInfo: ChainInfo,
|
|
69
66
|
options: DefaultAccountEntrypointOptions,
|
|
70
67
|
): Promise<TxExecutionRequest> {
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
const { cancellable, txNonce, feePaymentMethodOptions } = options;
|
|
75
|
-
// Encode the calls for the app
|
|
76
|
-
const encodedCalls = await EncodedAppEntrypointCalls.create(calls, txNonce);
|
|
77
|
-
|
|
78
|
-
// Obtain the entrypoint hashed args, built from the app encoded calls and global options
|
|
79
|
-
const abi = this.getEntrypointAbi();
|
|
80
|
-
const entrypointHashedArgs = await HashedValues.fromArgs(
|
|
81
|
-
encodeArguments(abi, [encodedCalls, feePaymentMethodOptions, !!cancellable]),
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
// Generate the payload auth witness, by signing the hash of the payload
|
|
85
|
-
const appPayloadAuthwitness = await this.auth.createAuthWit(await encodedCalls.hash());
|
|
86
|
-
|
|
87
|
-
// Assemble the tx request
|
|
68
|
+
const { authWitnesses, capsules, extraHashedArgs } = exec;
|
|
69
|
+
const callData = await this.#buildEntrypointCallData(exec, options);
|
|
70
|
+
const entrypointHashedArgs = await HashedValues.fromArgs(callData.encodedArgs);
|
|
88
71
|
const txRequest = TxExecutionRequest.from({
|
|
89
72
|
firstCallArgsHash: entrypointHashedArgs.hash,
|
|
90
73
|
origin: this.address,
|
|
91
|
-
functionSelector:
|
|
92
|
-
txContext: new TxContext(
|
|
93
|
-
argsOfCalls: [...encodedCalls.hashedArguments, entrypointHashedArgs, ...extraHashedArgs],
|
|
94
|
-
authWitnesses: [...authWitnesses,
|
|
74
|
+
functionSelector: callData.functionSelector,
|
|
75
|
+
txContext: new TxContext(chainInfo.chainId.toNumber(), chainInfo.version.toNumber(), gasSettings),
|
|
76
|
+
argsOfCalls: [...callData.encodedCalls.hashedArguments, entrypointHashedArgs, ...extraHashedArgs],
|
|
77
|
+
authWitnesses: [...authWitnesses, callData.payloadAuthWitness],
|
|
95
78
|
capsules,
|
|
96
79
|
salt: Fr.random(),
|
|
97
80
|
});
|
|
@@ -99,6 +82,64 @@ export class DefaultAccountEntrypoint implements EntrypointInterface {
|
|
|
99
82
|
return txRequest;
|
|
100
83
|
}
|
|
101
84
|
|
|
85
|
+
async wrapExecutionPayload(
|
|
86
|
+
exec: ExecutionPayload,
|
|
87
|
+
options: DefaultAccountEntrypointOptions,
|
|
88
|
+
): Promise<ExecutionPayload> {
|
|
89
|
+
const { authWitnesses, capsules, extraHashedArgs, feePayer } = exec;
|
|
90
|
+
const callData = await this.#buildEntrypointCallData(exec, options);
|
|
91
|
+
|
|
92
|
+
// Build the entrypoint function call
|
|
93
|
+
const entrypointCall = FunctionCall.from({
|
|
94
|
+
name: callData.abi.name,
|
|
95
|
+
to: this.address,
|
|
96
|
+
selector: callData.functionSelector,
|
|
97
|
+
type: callData.abi.functionType,
|
|
98
|
+
hideMsgSender: false,
|
|
99
|
+
isStatic: callData.abi.isStatic,
|
|
100
|
+
args: callData.encodedArgs,
|
|
101
|
+
returnTypes: callData.abi.returnTypes,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
return new ExecutionPayload(
|
|
105
|
+
[entrypointCall],
|
|
106
|
+
[callData.payloadAuthWitness, ...authWitnesses],
|
|
107
|
+
capsules,
|
|
108
|
+
[...callData.encodedCalls.hashedArguments, ...extraHashedArgs],
|
|
109
|
+
feePayer ?? this.address,
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Builds the shared data needed for both creating a tx execution request and wrapping an execution payload.
|
|
115
|
+
* This includes encoding calls, building entrypoint arguments, and creating the authwitness.
|
|
116
|
+
* @param exec - The execution payload containing calls to encode
|
|
117
|
+
* @param options - Account entrypoint options including tx nonce and fee payment method
|
|
118
|
+
* @returns Encoded call data, ABI, function selector, and auth witness
|
|
119
|
+
*/
|
|
120
|
+
async #buildEntrypointCallData(exec: ExecutionPayload, options: DefaultAccountEntrypointOptions) {
|
|
121
|
+
const { calls } = exec;
|
|
122
|
+
const { cancellable, txNonce, feePaymentMethodOptions } = options;
|
|
123
|
+
|
|
124
|
+
const encodedCalls = await EncodedAppEntrypointCalls.create(calls, txNonce);
|
|
125
|
+
|
|
126
|
+
const abi = this.getEntrypointAbi();
|
|
127
|
+
const args = [encodedCalls, feePaymentMethodOptions, !!cancellable];
|
|
128
|
+
const encodedArgs = encodeArguments(abi, args);
|
|
129
|
+
|
|
130
|
+
const functionSelector = await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters);
|
|
131
|
+
|
|
132
|
+
const payloadAuthWitness = await this.auth.createAuthWit(await encodedCalls.hash());
|
|
133
|
+
|
|
134
|
+
return {
|
|
135
|
+
encodedCalls,
|
|
136
|
+
abi,
|
|
137
|
+
encodedArgs,
|
|
138
|
+
functionSelector,
|
|
139
|
+
payloadAuthWitness,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
|
|
102
143
|
private getEntrypointAbi() {
|
|
103
144
|
return {
|
|
104
145
|
name: 'entrypoint',
|
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
import { FunctionType } from '@aztec/stdlib/abi';
|
|
2
2
|
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
3
|
-
import {
|
|
3
|
+
import { ExecutionPayload, HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
4
4
|
|
|
5
|
-
import type { EntrypointInterface } from './interfaces.js';
|
|
5
|
+
import type { ChainInfo, EntrypointInterface } from './interfaces.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Default implementation of the entrypoint interface. It calls a function on a contract directly
|
|
9
9
|
*/
|
|
10
10
|
export class DefaultEntrypoint implements EntrypointInterface {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
async createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings): Promise<TxExecutionRequest> {
|
|
11
|
+
async createTxExecutionRequest(
|
|
12
|
+
exec: ExecutionPayload,
|
|
13
|
+
gasSettings: GasSettings,
|
|
14
|
+
chainInfo: ChainInfo,
|
|
15
|
+
): Promise<TxExecutionRequest> {
|
|
17
16
|
// Initial request with calls, authWitnesses and capsules
|
|
18
17
|
const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
|
|
19
18
|
|
|
@@ -35,10 +34,28 @@ export class DefaultEntrypoint implements EntrypointInterface {
|
|
|
35
34
|
call.to,
|
|
36
35
|
call.selector,
|
|
37
36
|
hashedArguments[0].hash,
|
|
38
|
-
new TxContext(
|
|
37
|
+
new TxContext(chainInfo.chainId.toNumber(), chainInfo.version.toNumber(), gasSettings),
|
|
39
38
|
[...hashedArguments, ...extraHashedArgs],
|
|
40
39
|
authWitnesses,
|
|
41
40
|
capsules,
|
|
42
41
|
);
|
|
43
42
|
}
|
|
43
|
+
|
|
44
|
+
async wrapExecutionPayload(exec: ExecutionPayload, _options?: any): Promise<ExecutionPayload> {
|
|
45
|
+
if (exec.calls.length !== 1) {
|
|
46
|
+
throw new Error(`DefaultEntrypoint can only wrap a single call, got ${exec.calls.length}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const call = exec.calls[0];
|
|
50
|
+
|
|
51
|
+
const hashedArguments = await HashedValues.fromArgs(call.args);
|
|
52
|
+
|
|
53
|
+
return new ExecutionPayload(
|
|
54
|
+
[call],
|
|
55
|
+
exec.authWitnesses,
|
|
56
|
+
exec.capsules,
|
|
57
|
+
[hashedArguments, ...exec.extraHashedArgs],
|
|
58
|
+
exec.feePayer,
|
|
59
|
+
);
|
|
60
|
+
}
|
|
44
61
|
}
|
|
@@ -1,42 +1,34 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import { ProtocolContractAddress } from '@aztec/protocol-contracts';
|
|
3
|
-
import { type FunctionAbi, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
|
|
3
|
+
import { type FunctionAbi, FunctionCall, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
|
|
4
4
|
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
5
|
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
6
|
-
import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
7
|
-
import type { ExecutionPayload } from '@aztec/stdlib/tx';
|
|
6
|
+
import { ExecutionPayload, HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
8
7
|
|
|
9
8
|
import { EncodedAppEntrypointCalls } from './encoding.js';
|
|
10
|
-
import type { EntrypointInterface } from './interfaces.js';
|
|
9
|
+
import type { ChainInfo, EntrypointInterface } from './interfaces.js';
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* Implementation for an entrypoint interface that can execute multiple function calls in a single transaction
|
|
14
13
|
*/
|
|
15
14
|
export class DefaultMultiCallEntrypoint implements EntrypointInterface {
|
|
16
|
-
constructor(
|
|
17
|
-
private chainId: number,
|
|
18
|
-
private version: number,
|
|
19
|
-
private address: AztecAddress = ProtocolContractAddress.MultiCallEntrypoint,
|
|
20
|
-
) {}
|
|
15
|
+
constructor(private address: AztecAddress = ProtocolContractAddress.MultiCallEntrypoint) {}
|
|
21
16
|
|
|
22
|
-
async createTxExecutionRequest(
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
async createTxExecutionRequest(
|
|
18
|
+
exec: ExecutionPayload,
|
|
19
|
+
gasSettings: GasSettings,
|
|
20
|
+
chainInfo: ChainInfo,
|
|
21
|
+
): Promise<TxExecutionRequest> {
|
|
22
|
+
const { authWitnesses, capsules, extraHashedArgs } = exec;
|
|
23
|
+
const callData = await this.#buildEntrypointCallData(exec);
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
const encodedCalls = await EncodedAppEntrypointCalls.create(calls);
|
|
28
|
-
|
|
29
|
-
// Obtain the entrypoint hashed args, built from the encoded calls
|
|
30
|
-
const abi = this.getEntrypointAbi();
|
|
31
|
-
const entrypointHashedArgs = await HashedValues.fromArgs(encodeArguments(abi, [encodedCalls]));
|
|
32
|
-
|
|
33
|
-
// Assemble the tx request
|
|
25
|
+
const entrypointHashedArgs = await HashedValues.fromArgs(callData.encodedArgs);
|
|
34
26
|
const txRequest = TxExecutionRequest.from({
|
|
35
27
|
firstCallArgsHash: entrypointHashedArgs.hash,
|
|
36
28
|
origin: this.address,
|
|
37
|
-
functionSelector:
|
|
38
|
-
txContext: new TxContext(
|
|
39
|
-
argsOfCalls: [...encodedCalls.hashedArguments, entrypointHashedArgs, ...extraHashedArgs],
|
|
29
|
+
functionSelector: callData.functionSelector,
|
|
30
|
+
txContext: new TxContext(chainInfo.chainId.toNumber(), chainInfo.version.toNumber(), gasSettings),
|
|
31
|
+
argsOfCalls: [...callData.encodedCalls.hashedArguments, entrypointHashedArgs, ...extraHashedArgs],
|
|
40
32
|
authWitnesses,
|
|
41
33
|
capsules,
|
|
42
34
|
salt: Fr.random(),
|
|
@@ -45,6 +37,53 @@ export class DefaultMultiCallEntrypoint implements EntrypointInterface {
|
|
|
45
37
|
return Promise.resolve(txRequest);
|
|
46
38
|
}
|
|
47
39
|
|
|
40
|
+
async wrapExecutionPayload(exec: ExecutionPayload, _options?: any): Promise<ExecutionPayload> {
|
|
41
|
+
const { authWitnesses, capsules, extraHashedArgs } = exec;
|
|
42
|
+
const callData = await this.#buildEntrypointCallData(exec);
|
|
43
|
+
const entrypointCall = FunctionCall.from({
|
|
44
|
+
name: callData.abi.name,
|
|
45
|
+
to: this.address,
|
|
46
|
+
selector: callData.functionSelector,
|
|
47
|
+
type: callData.abi.functionType,
|
|
48
|
+
hideMsgSender: false,
|
|
49
|
+
isStatic: callData.abi.isStatic,
|
|
50
|
+
args: callData.encodedArgs,
|
|
51
|
+
returnTypes: callData.abi.returnTypes,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
return new ExecutionPayload(
|
|
55
|
+
[entrypointCall],
|
|
56
|
+
authWitnesses,
|
|
57
|
+
capsules,
|
|
58
|
+
[...callData.encodedCalls.hashedArguments, ...extraHashedArgs],
|
|
59
|
+
exec.feePayer,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Builds the shared data needed for both creating a tx execution request and wrapping an execution payload.
|
|
65
|
+
* This includes encoding calls and building entrypoint arguments.
|
|
66
|
+
* @param exec - The execution payload containing calls to encode
|
|
67
|
+
* @returns Encoded call data, ABI, encoded arguments, and function selector
|
|
68
|
+
*/
|
|
69
|
+
async #buildEntrypointCallData(exec: ExecutionPayload) {
|
|
70
|
+
const { calls } = exec;
|
|
71
|
+
|
|
72
|
+
const encodedCalls = await EncodedAppEntrypointCalls.create(calls);
|
|
73
|
+
|
|
74
|
+
const abi = this.getEntrypointAbi();
|
|
75
|
+
const encodedArgs = encodeArguments(abi, [encodedCalls]);
|
|
76
|
+
|
|
77
|
+
const functionSelector = await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters);
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
encodedCalls,
|
|
81
|
+
abi,
|
|
82
|
+
encodedArgs,
|
|
83
|
+
functionSelector,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
48
87
|
private getEntrypointAbi() {
|
|
49
88
|
return {
|
|
50
89
|
name: 'entrypoint',
|
package/src/encoding.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DomainSeparator } from '@aztec/constants';
|
|
2
2
|
import { padArrayEnd } from '@aztec/foundation/collection';
|
|
3
|
-
import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto';
|
|
4
|
-
import { Fr } from '@aztec/foundation/
|
|
3
|
+
import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto/poseidon';
|
|
4
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
5
5
|
import type { Tuple } from '@aztec/foundation/serialize';
|
|
6
6
|
import { FunctionCall, FunctionType } from '@aztec/stdlib/abi';
|
|
7
7
|
import { HashedValues } from '@aztec/stdlib/tx';
|
|
8
8
|
|
|
9
9
|
// These must match the values defined in:
|
|
10
10
|
// - noir-projects/aztec-nr/aztec/src/entrypoint/app.nr
|
|
11
|
-
const APP_MAX_CALLS = 5;
|
|
11
|
+
export const APP_MAX_CALLS = 5;
|
|
12
12
|
|
|
13
13
|
/** Encoded function call for an Aztec entrypoint */
|
|
14
14
|
export type EncodedFunctionCall = {
|
|
@@ -47,7 +47,7 @@ export class EncodedAppEntrypointCalls implements EncodedCalls {
|
|
|
47
47
|
/** The hashed args for the call, ready to be injected in the execution cache */
|
|
48
48
|
public hashedArguments: HashedValues[],
|
|
49
49
|
/** The index of the generator to use for hashing */
|
|
50
|
-
public
|
|
50
|
+
public domainSeparator: number,
|
|
51
51
|
/**
|
|
52
52
|
* A nonce to inject into the payload of the transaction. When used with cancellable=true, this nonce will be
|
|
53
53
|
* used to compute a nullifier that allows cancelling this transaction by submitting a new one with the same nonce
|
|
@@ -80,7 +80,7 @@ export class EncodedAppEntrypointCalls implements EncodedCalls {
|
|
|
80
80
|
* @returns The hash of the payload
|
|
81
81
|
*/
|
|
82
82
|
hash() {
|
|
83
|
-
return poseidon2HashWithSeparator(this.toFields(), this.
|
|
83
|
+
return poseidon2HashWithSeparator(this.toFields(), this.domainSeparator);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
/** Serializes the function calls to an array of fields. */
|
|
@@ -114,7 +114,7 @@ export class EncodedAppEntrypointCalls implements EncodedCalls {
|
|
|
114
114
|
return new EncodedAppEntrypointCalls(
|
|
115
115
|
encoded.encodedFunctionCalls,
|
|
116
116
|
encoded.hashedArguments,
|
|
117
|
-
|
|
117
|
+
DomainSeparator.SIGNATURE_PAYLOAD,
|
|
118
118
|
txNonce,
|
|
119
119
|
);
|
|
120
120
|
}
|
package/src/interfaces.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Fr } from '@aztec/foundation/
|
|
1
|
+
import { Fr } from '@aztec/foundation/curves/bn254';
|
|
2
2
|
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
3
3
|
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
4
4
|
import type { ExecutionPayload, TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
@@ -33,14 +33,29 @@ export interface EntrypointInterface {
|
|
|
33
33
|
* Generates an execution request out of set of function calls.
|
|
34
34
|
* @param exec - The execution intents to be run.
|
|
35
35
|
* @param gasSettings - The gas settings for the transaction.
|
|
36
|
+
* @param chainInfo - Chain information (chainId and version) for replay protection.
|
|
36
37
|
* @param options - Miscellaneous tx options that enable/disable features of the entrypoint
|
|
37
38
|
* @returns The authenticated transaction execution request.
|
|
38
39
|
*/
|
|
39
40
|
createTxExecutionRequest(
|
|
40
41
|
exec: ExecutionPayload,
|
|
41
42
|
gasSettings: GasSettings,
|
|
43
|
+
chainInfo: ChainInfo,
|
|
42
44
|
options?: any,
|
|
43
45
|
): Promise<TxExecutionRequest>;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Wraps an execution payload such that it is executed *via* this entrypoint.
|
|
49
|
+
* This returns an ExecutionPayload with the entrypoint as the caller for the wrapped payload.
|
|
50
|
+
* Useful for account self-funding deployments and batching calls beyond the limit
|
|
51
|
+
* of a single entrypoint call.
|
|
52
|
+
*
|
|
53
|
+
* @param exec - The execution payload to wrap
|
|
54
|
+
* @param options - Implementation-specific options
|
|
55
|
+
* @returns A new execution payload with a single call to this entrypoint
|
|
56
|
+
* @throws Error if the payload cannot be wrapped (e.g., exceeds call limit)
|
|
57
|
+
*/
|
|
58
|
+
wrapExecutionPayload(exec: ExecutionPayload, options?: any): Promise<ExecutionPayload>;
|
|
44
59
|
}
|
|
45
60
|
|
|
46
61
|
/** Creates authorization witnesses. */
|