@aztec/entrypoints 0.81.0 → 0.82.1-alpha-testnet.1

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.
@@ -1,7 +1,7 @@
1
- import type { AuthWitnessProvider } from '@aztec/aztec.js/account';
2
- import { type EntrypointInterface, type ExecutionRequestInit } from '@aztec/aztec.js/entrypoint';
3
1
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
2
  import { TxExecutionRequest } from '@aztec/stdlib/tx';
3
+ import type { AuthWitnessProvider, EntrypointInterface, FeeOptions, TxExecutionOptions } from './interfaces.js';
4
+ import { ExecutionPayload } from './payload.js';
5
5
  /**
6
6
  * Implementation for an entrypoint interface that follows the default entrypoint signature
7
7
  * for an account, which accepts an AppPayload and a FeePayload as defined in noir-libs/aztec-noir/src/entrypoint module
@@ -12,7 +12,7 @@ export declare class DefaultAccountEntrypoint implements EntrypointInterface {
12
12
  private chainId;
13
13
  private version;
14
14
  constructor(address: AztecAddress, auth: AuthWitnessProvider, chainId?: number, version?: number);
15
- createTxExecutionRequest(exec: ExecutionRequestInit): Promise<TxExecutionRequest>;
15
+ createTxExecutionRequest(exec: ExecutionPayload, fee: FeeOptions, options: TxExecutionOptions): Promise<TxExecutionRequest>;
16
16
  private getEntrypointAbi;
17
17
  }
18
18
  //# sourceMappingURL=account_entrypoint.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"account_entrypoint.d.ts","sourceRoot":"","sources":["../src/account_entrypoint.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EACL,KAAK,mBAAmB,EAExB,KAAK,oBAAoB,EAE1B,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAA2B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAI/E;;;GAGG;AACH,qBAAa,wBAAyB,YAAW,mBAAmB;IAEhE,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,OAAO;gBAHP,OAAO,EAAE,YAAY,EACrB,IAAI,EAAE,mBAAmB,EACzB,OAAO,GAAE,MAAyB,EAClC,OAAO,GAAE,MAAwB;IAGrC,wBAAwB,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IA2BvF,OAAO,CAAC,gBAAgB;CAqGzB"}
1
+ {"version":3,"file":"account_entrypoint.d.ts","sourceRoot":"","sources":["../src/account_entrypoint.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAA2B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAI/E,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAChH,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD;;;GAGG;AACH,qBAAa,wBAAyB,YAAW,mBAAmB;IAEhE,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,OAAO;gBAHP,OAAO,EAAE,YAAY,EACrB,IAAI,EAAE,mBAAmB,EACzB,OAAO,GAAE,MAAyB,EAClC,OAAO,GAAE,MAAwB;IAGrC,wBAAwB,CAC5B,IAAI,EAAE,gBAAgB,EACtB,GAAG,EAAE,UAAU,EACf,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,kBAAkB,CAAC;IA8C9B,OAAO,CAAC,gBAAgB;CAqGzB"}
@@ -1,7 +1,7 @@
1
- import { EntrypointPayload, computeCombinedPayloadHash } from '@aztec/aztec.js/entrypoint';
2
1
  import { FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
3
2
  import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
4
3
  import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
4
+ import { EncodedCallsForEntrypoint, computeCombinedPayloadHash } from './encoding.js';
5
5
  /**
6
6
  * Implementation for an entrypoint interface that follows the default entrypoint signature
7
7
  * for an account, which accepts an AppPayload and a FeePayload as defined in noir-libs/aztec-noir/src/entrypoint module
@@ -16,29 +16,43 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
16
16
  this.chainId = chainId;
17
17
  this.version = version;
18
18
  }
19
- async createTxExecutionRequest(exec) {
20
- const { calls, fee, nonce, cancellable, authWitnesses = [], capsules = [] } = exec;
21
- const appPayload = await EntrypointPayload.fromAppExecution(calls, nonce);
22
- const feePayload = await EntrypointPayload.fromFeeOptions(this.address, fee);
19
+ async createTxExecutionRequest(exec, fee, options) {
20
+ // Initial request with calls, authWitnesses and capsules
21
+ const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
22
+ // Global tx options
23
+ const { cancellable, nonce } = options;
24
+ // Encode the calls for the app
25
+ const appEncodedCalls = await EncodedCallsForEntrypoint.fromAppExecution(calls, nonce);
26
+ // Get the execution payload for the fee, it includes the calls and potentially authWitnesses
27
+ const { calls: feeCalls, authWitnesses: feeAuthwitnesses } = await fee.paymentMethod.getExecutionPayload(fee.gasSettings);
28
+ // Encode the calls for the fee
29
+ const feePayer = await fee.paymentMethod.getFeePayer(fee.gasSettings);
30
+ const isFeePayer = feePayer.equals(this.address);
31
+ const feeEncodedCalls = await EncodedCallsForEntrypoint.fromFeeCalls(feeCalls, isFeePayer);
32
+ // Obtain the entrypoint hashed args, built from the app and fee encoded calls
23
33
  const abi = this.getEntrypointAbi();
24
- const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [
25
- appPayload,
26
- feePayload,
34
+ const entrypointHashedArgs = await HashedValues.fromArgs(encodeArguments(abi, [
35
+ appEncodedCalls,
36
+ feeEncodedCalls,
27
37
  !!cancellable
28
38
  ]));
29
- const combinedPayloadAuthWitness = await this.auth.createAuthWit(await computeCombinedPayloadHash(appPayload, feePayload));
39
+ // Generate the combined payload auth witness, by signing the hash of the combined payload
40
+ const combinedPayloadAuthWitness = await this.auth.createAuthWit(await computeCombinedPayloadHash(appEncodedCalls, feeEncodedCalls));
41
+ // Assemble the tx request
30
42
  const txRequest = TxExecutionRequest.from({
31
43
  firstCallArgsHash: entrypointHashedArgs.hash,
32
44
  origin: this.address,
33
45
  functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
34
46
  txContext: new TxContext(this.chainId, this.version, fee.gasSettings),
35
47
  argsOfCalls: [
36
- ...appPayload.hashedArguments,
37
- ...feePayload.hashedArguments,
38
- entrypointHashedArgs
48
+ ...appEncodedCalls.hashedArguments,
49
+ ...feeEncodedCalls.hashedArguments,
50
+ entrypointHashedArgs,
51
+ ...extraHashedArgs
39
52
  ],
40
53
  authWitnesses: [
41
54
  ...authWitnesses,
55
+ ...feeAuthwitnesses,
42
56
  combinedPayloadAuthWitness
43
57
  ],
44
58
  capsules
@@ -1,7 +1,7 @@
1
- import type { AuthWitnessProvider } from '@aztec/aztec.js/account';
2
- import { type EntrypointInterface, type ExecutionRequestInit } from '@aztec/aztec.js/entrypoint';
3
1
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
2
  import { TxExecutionRequest } from '@aztec/stdlib/tx';
3
+ import type { AuthWitnessProvider, EntrypointInterface, FeeOptions, TxExecutionOptions } from './interfaces.js';
4
+ import { ExecutionPayload } from './payload.js';
5
5
  /**
6
6
  * Implementation for an entrypoint interface that follows the default entrypoint signature
7
7
  * for an account, which accepts an AppPayload and a FeePayload as defined in noir-libs/aztec-noir/src/entrypoint module
@@ -13,7 +13,7 @@ export declare class DefaultDappEntrypoint implements EntrypointInterface {
13
13
  private chainId;
14
14
  private version;
15
15
  constructor(userAddress: AztecAddress, userAuthWitnessProvider: AuthWitnessProvider, dappEntrypointAddress: AztecAddress, chainId?: number, version?: number);
16
- createTxExecutionRequest(exec: ExecutionRequestInit): Promise<TxExecutionRequest>;
16
+ createTxExecutionRequest(exec: ExecutionPayload, fee: FeeOptions, options: TxExecutionOptions): Promise<TxExecutionRequest>;
17
17
  private getEntrypointAbi;
18
18
  }
19
19
  //# sourceMappingURL=dapp_entrypoint.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dapp_entrypoint.d.ts","sourceRoot":"","sources":["../src/dapp_entrypoint.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AACnE,OAAO,EAAE,KAAK,mBAAmB,EAAqB,KAAK,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AAEpH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAA2B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAI/E;;;GAGG;AACH,qBAAa,qBAAsB,YAAW,mBAAmB;IAE7D,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,uBAAuB;IAC/B,OAAO,CAAC,qBAAqB;IAC7B,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,OAAO;gBAJP,WAAW,EAAE,YAAY,EACzB,uBAAuB,EAAE,mBAAmB,EAC5C,qBAAqB,EAAE,YAAY,EACnC,OAAO,GAAE,MAAyB,EAClC,OAAO,GAAE,MAAwB;IAGrC,wBAAwB,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAqCvF,OAAO,CAAC,gBAAgB;CAiEzB"}
1
+ {"version":3,"file":"dapp_entrypoint.d.ts","sourceRoot":"","sources":["../src/dapp_entrypoint.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAA2B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAI/E,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAChH,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD;;;GAGG;AACH,qBAAa,qBAAsB,YAAW,mBAAmB;IAE7D,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,uBAAuB;IAC/B,OAAO,CAAC,qBAAqB;IAC7B,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,OAAO;gBAJP,WAAW,EAAE,YAAY,EACzB,uBAAuB,EAAE,mBAAmB,EAC5C,qBAAqB,EAAE,YAAY,EACnC,OAAO,GAAE,MAAyB,EAClC,OAAO,GAAE,MAAwB;IAGrC,wBAAwB,CAC5B,IAAI,EAAE,gBAAgB,EACtB,GAAG,EAAE,UAAU,EACf,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,kBAAkB,CAAC;IAiD9B,OAAO,CAAC,gBAAgB;CAiEzB"}
@@ -1,8 +1,9 @@
1
- import { Fr, computeAuthWitMessageHash, computeInnerAuthWitHash } from '@aztec/aztec.js';
2
- import { EntrypointPayload } from '@aztec/aztec.js/entrypoint';
3
- import { FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import { FunctionSelector, FunctionType, encodeArguments } from '@aztec/stdlib/abi';
3
+ import { computeInnerAuthWitHash, computeOuterAuthWitHash } from '@aztec/stdlib/auth-witness';
4
4
  import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
5
5
  import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
6
+ import { EncodedCallsForEntrypoint } from './encoding.js';
6
7
  /**
7
8
  * Implementation for an entrypoint interface that follows the default entrypoint signature
8
9
  * for an account, which accepts an AppPayload and a FeePayload as defined in noir-libs/aztec-noir/src/entrypoint module
@@ -19,17 +20,25 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
19
20
  this.chainId = chainId;
20
21
  this.version = version;
21
22
  }
22
- async createTxExecutionRequest(exec) {
23
- const { calls, fee, authWitnesses = [], capsules = [] } = exec;
23
+ async createTxExecutionRequest(exec, fee, options) {
24
+ if (options.nonce || options.cancellable !== undefined) {
25
+ throw new Error('TxExecutionOptions are not supported in DappEntrypoint');
26
+ }
27
+ // Initial request with calls, authWitnesses and capsules
28
+ const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
24
29
  if (calls.length !== 1) {
25
30
  throw new Error(`Expected exactly 1 function call, got ${calls.length}`);
26
31
  }
27
- const payload = await EntrypointPayload.fromFunctionCalls(calls);
32
+ // Encode the function call the dapp is ultimately going to invoke
33
+ const encodedCalls = await EncodedCallsForEntrypoint.fromFunctionCalls(calls);
34
+ // Obtain the entrypoint hashed args, built from the function call and the user's address
28
35
  const abi = this.getEntrypointAbi();
29
- const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [
30
- payload,
36
+ const entrypointHashedArgs = await HashedValues.fromArgs(encodeArguments(abi, [
37
+ encodedCalls,
31
38
  this.userAddress
32
39
  ]));
40
+ // Construct an auth witness for the entrypoint, by signing the hash of the action to perform
41
+ // (the dapp calls a function on the user's behalf)
33
42
  const functionSelector = await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters);
34
43
  // Default msg_sender for entrypoints is now Fr.max_value rather than 0 addr (see #7190 & #7404)
35
44
  const innerHash = await computeInnerAuthWitHash([
@@ -37,26 +46,22 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
37
46
  functionSelector.toField(),
38
47
  entrypointHashedArgs.hash
39
48
  ]);
40
- const outerHash = await computeAuthWitMessageHash({
41
- consumer: this.dappEntrypointAddress,
42
- innerHash
43
- }, {
44
- chainId: new Fr(this.chainId),
45
- version: new Fr(this.version)
46
- });
47
- const authWitness = await this.userAuthWitnessProvider.createAuthWit(outerHash);
49
+ const outerHash = await computeOuterAuthWitHash(this.dappEntrypointAddress, new Fr(this.chainId), new Fr(this.version), innerHash);
50
+ const entypointAuthwitness = await this.userAuthWitnessProvider.createAuthWit(outerHash);
51
+ // Assemble the tx request
48
52
  const txRequest = TxExecutionRequest.from({
49
53
  firstCallArgsHash: entrypointHashedArgs.hash,
50
54
  origin: this.dappEntrypointAddress,
51
55
  functionSelector,
52
56
  txContext: new TxContext(this.chainId, this.version, fee.gasSettings),
53
57
  argsOfCalls: [
54
- ...payload.hashedArguments,
55
- entrypointHashedArgs
58
+ ...encodedCalls.hashedArguments,
59
+ entrypointHashedArgs,
60
+ ...extraHashedArgs
56
61
  ],
57
62
  authWitnesses: [
58
- ...authWitnesses,
59
- authWitness
63
+ entypointAuthwitness,
64
+ ...authWitnesses
60
65
  ],
61
66
  capsules
62
67
  });
@@ -66,7 +71,7 @@ import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
66
71
  return {
67
72
  name: 'entrypoint',
68
73
  isInitializer: false,
69
- functionType: 'private',
74
+ functionType: FunctionType.PRIVATE,
70
75
  isInternal: false,
71
76
  isStatic: false,
72
77
  parameters: [
@@ -0,0 +1,13 @@
1
+ import { TxExecutionRequest } from '@aztec/stdlib/tx';
2
+ import type { EntrypointInterface, FeeOptions, TxExecutionOptions } from './interfaces.js';
3
+ import type { ExecutionPayload } from './payload.js';
4
+ /**
5
+ * Default implementation of the entrypoint interface. It calls a function on a contract directly
6
+ */
7
+ export declare class DefaultEntrypoint implements EntrypointInterface {
8
+ private chainId;
9
+ private protocolVersion;
10
+ constructor(chainId: number, protocolVersion: number);
11
+ createTxExecutionRequest(exec: ExecutionPayload, fee: FeeOptions, options: TxExecutionOptions): Promise<TxExecutionRequest>;
12
+ }
13
+ //# sourceMappingURL=default_entrypoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default_entrypoint.d.ts","sourceRoot":"","sources":["../src/default_entrypoint.ts"],"names":[],"mappings":"AACA,OAAO,EAA2B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE/E,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC3F,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD;;GAEG;AACH,qBAAa,iBAAkB,YAAW,mBAAmB;IAC/C,OAAO,CAAC,OAAO;IAAU,OAAO,CAAC,eAAe;gBAAxC,OAAO,EAAE,MAAM,EAAU,eAAe,EAAE,MAAM;IAE9D,wBAAwB,CAC5B,IAAI,EAAE,gBAAgB,EACtB,GAAG,EAAE,UAAU,EACf,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,kBAAkB,CAAC;CA+B/B"}
@@ -0,0 +1,35 @@
1
+ import { FunctionType } from '@aztec/stdlib/abi';
2
+ import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
3
+ /**
4
+ * Default implementation of the entrypoint interface. It calls a function on a contract directly
5
+ */ export class DefaultEntrypoint {
6
+ chainId;
7
+ protocolVersion;
8
+ constructor(chainId, protocolVersion){
9
+ this.chainId = chainId;
10
+ this.protocolVersion = protocolVersion;
11
+ }
12
+ async createTxExecutionRequest(exec, fee, options) {
13
+ if (options.nonce || options.cancellable !== undefined) {
14
+ throw new Error('TxExecutionOptions are not supported in DefaultEntrypoint');
15
+ }
16
+ // Initial request with calls, authWitnesses and capsules
17
+ const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
18
+ if (calls.length > 1) {
19
+ throw new Error(`Expected a single call, got ${calls.length}`);
20
+ }
21
+ const call = calls[0];
22
+ // Hash the arguments for the function call
23
+ const hashedArguments = [
24
+ await HashedValues.fromArgs(call.args)
25
+ ];
26
+ if (call.type !== FunctionType.PRIVATE) {
27
+ throw new Error('Public entrypoints are not allowed');
28
+ }
29
+ // Assemble the tx request
30
+ return new TxExecutionRequest(call.to, call.selector, hashedArguments[0].hash, new TxContext(this.chainId, this.protocolVersion, fee.gasSettings), [
31
+ ...hashedArguments,
32
+ ...extraHashedArgs
33
+ ], authWitnesses, capsules);
34
+ }
35
+ }
@@ -0,0 +1,16 @@
1
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
2
+ import { TxExecutionRequest } from '@aztec/stdlib/tx';
3
+ import type { EntrypointInterface, FeeOptions } from './interfaces.js';
4
+ import type { ExecutionPayload } from './payload.js';
5
+ /**
6
+ * Implementation for an entrypoint interface that can execute multiple function calls in a single transaction
7
+ */
8
+ export declare class DefaultMultiCallEntrypoint implements EntrypointInterface {
9
+ private chainId;
10
+ private version;
11
+ private address;
12
+ constructor(chainId: number, version: number, address?: AztecAddress);
13
+ createTxExecutionRequest(exec: ExecutionPayload, fee: FeeOptions): Promise<TxExecutionRequest>;
14
+ private getEntrypointAbi;
15
+ }
16
+ //# sourceMappingURL=default_multi_call_entrypoint.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default_multi_call_entrypoint.d.ts","sourceRoot":"","sources":["../src/default_multi_call_entrypoint.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAA2B,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAG/E,OAAO,KAAK,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD;;GAEG;AACH,qBAAa,0BAA2B,YAAW,mBAAmB;IAElE,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,OAAO;gBAFP,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,OAAO,GAAE,YAA0D;IAGvE,wBAAwB,CAAC,IAAI,EAAE,gBAAgB,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAiCpG,OAAO,CAAC,gBAAgB;CAwDzB"}
@@ -0,0 +1,141 @@
1
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
2
+ import { FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
3
+ import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
4
+ import { EncodedCallsForEntrypoint } from './encoding.js';
5
+ /**
6
+ * Implementation for an entrypoint interface that can execute multiple function calls in a single transaction
7
+ */ export class DefaultMultiCallEntrypoint {
8
+ chainId;
9
+ version;
10
+ address;
11
+ constructor(chainId, version, address = ProtocolContractAddress.MultiCallEntrypoint){
12
+ this.chainId = chainId;
13
+ this.version = version;
14
+ this.address = address;
15
+ }
16
+ async createTxExecutionRequest(exec, fee) {
17
+ // Initial request with calls, authWitnesses and capsules
18
+ const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
19
+ // Get the execution payload for the fee, it includes the calls and potentially authWitnesses
20
+ const { calls: feeCalls, authWitnesses: feeAuthwitnesses, extraHashedArgs: feeExtraHashedArgs } = await fee.paymentMethod.getExecutionPayload(fee.gasSettings);
21
+ // Encode the calls, including the fee calls
22
+ // (since this entrypoint does not distinguish between app and fee calls)
23
+ const encodedCalls = await EncodedCallsForEntrypoint.fromAppExecution(calls.concat(feeCalls));
24
+ // Obtain the entrypoint hashed args, built from the encoded calls
25
+ const abi = this.getEntrypointAbi();
26
+ const entrypointHashedArgs = await HashedValues.fromArgs(encodeArguments(abi, [
27
+ encodedCalls
28
+ ]));
29
+ // Assemble the tx request
30
+ const txRequest = TxExecutionRequest.from({
31
+ firstCallArgsHash: entrypointHashedArgs.hash,
32
+ origin: this.address,
33
+ functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
34
+ txContext: new TxContext(this.chainId, this.version, fee.gasSettings),
35
+ argsOfCalls: [
36
+ ...encodedCalls.hashedArguments,
37
+ entrypointHashedArgs,
38
+ ...extraHashedArgs,
39
+ ...feeExtraHashedArgs
40
+ ],
41
+ authWitnesses: [
42
+ ...feeAuthwitnesses,
43
+ ...authWitnesses
44
+ ],
45
+ capsules
46
+ });
47
+ return Promise.resolve(txRequest);
48
+ }
49
+ getEntrypointAbi() {
50
+ return {
51
+ name: 'entrypoint',
52
+ isInitializer: false,
53
+ functionType: 'private',
54
+ isInternal: false,
55
+ isStatic: false,
56
+ parameters: [
57
+ {
58
+ name: 'app_payload',
59
+ type: {
60
+ kind: 'struct',
61
+ path: 'authwit::entrypoint::app::AppPayload',
62
+ fields: [
63
+ {
64
+ name: 'function_calls',
65
+ type: {
66
+ kind: 'array',
67
+ length: 4,
68
+ type: {
69
+ kind: 'struct',
70
+ path: 'authwit::entrypoint::function_call::FunctionCall',
71
+ fields: [
72
+ {
73
+ name: 'args_hash',
74
+ type: {
75
+ kind: 'field'
76
+ }
77
+ },
78
+ {
79
+ name: 'function_selector',
80
+ type: {
81
+ kind: 'struct',
82
+ path: 'authwit::aztec::protocol_types::abis::function_selector::FunctionSelector',
83
+ fields: [
84
+ {
85
+ name: 'inner',
86
+ type: {
87
+ kind: 'integer',
88
+ sign: 'unsigned',
89
+ width: 32
90
+ }
91
+ }
92
+ ]
93
+ }
94
+ },
95
+ {
96
+ name: 'target_address',
97
+ type: {
98
+ kind: 'struct',
99
+ path: 'authwit::aztec::protocol_types::address::AztecAddress',
100
+ fields: [
101
+ {
102
+ name: 'inner',
103
+ type: {
104
+ kind: 'field'
105
+ }
106
+ }
107
+ ]
108
+ }
109
+ },
110
+ {
111
+ name: 'is_public',
112
+ type: {
113
+ kind: 'boolean'
114
+ }
115
+ },
116
+ {
117
+ name: 'is_static',
118
+ type: {
119
+ kind: 'boolean'
120
+ }
121
+ }
122
+ ]
123
+ }
124
+ }
125
+ },
126
+ {
127
+ name: 'nonce',
128
+ type: {
129
+ kind: 'field'
130
+ }
131
+ }
132
+ ]
133
+ },
134
+ visibility: 'public'
135
+ }
136
+ ],
137
+ returnTypes: [],
138
+ errorTypes: {}
139
+ };
140
+ }
141
+ }
@@ -0,0 +1,112 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import type { Tuple } from '@aztec/foundation/serialize';
3
+ import { FunctionCall } from '@aztec/stdlib/abi';
4
+ import { HashedValues } from '@aztec/stdlib/tx';
5
+ declare const APP_MAX_CALLS = 4;
6
+ declare const FEE_MAX_CALLS = 2;
7
+ /** Encoded function call for an Aztec entrypoint */
8
+ export type EncodedFunctionCall = {
9
+ /** Arguments hash for the call. */
10
+ /** This should be the calldata hash `hash([function_selector, ...args])` if `is_public` is true. */
11
+ args_hash: Fr;
12
+ /** Selector of the function to call */
13
+ function_selector: Fr;
14
+ /** Address of the contract to call */
15
+ target_address: Fr;
16
+ /** Whether the function is public or private */
17
+ is_public: boolean;
18
+ /** Whether the function can alter state */
19
+ is_static: boolean;
20
+ };
21
+ /** Type that represents function calls ready to be sent to a circuit for execution */
22
+ export type EncodedCalls = {
23
+ /** Function calls in the expected format (Noir's convention) */
24
+ encodedFunctionCalls: EncodedFunctionCall[];
25
+ /** The hashed args for the call, ready to be injected in the execution cache */
26
+ hashedArguments: HashedValues[];
27
+ };
28
+ /**
29
+ * Entrypoints derive their arguments from the calls that they'll ultimate make.
30
+ * This utility class helps in creating the payload for the entrypoint by taking into
31
+ * account how the calls are encoded and hashed.
32
+ * */
33
+ export declare abstract class EncodedCallsForEntrypoint implements EncodedCalls {
34
+ /** Function calls in the expected format (Noir's convention) */
35
+ encodedFunctionCalls: EncodedFunctionCall[];
36
+ /** The hashed args for the call, ready to be injected in the execution cache */
37
+ hashedArguments: HashedValues[];
38
+ /** The index of the generator to use for hashing */
39
+ generatorIndex: number;
40
+ /** The nonce for the payload, used to emit a nullifier identifying the call */
41
+ nonce: Fr;
42
+ constructor(
43
+ /** Function calls in the expected format (Noir's convention) */
44
+ encodedFunctionCalls: EncodedFunctionCall[],
45
+ /** The hashed args for the call, ready to be injected in the execution cache */
46
+ hashedArguments: HashedValues[],
47
+ /** The index of the generator to use for hashing */
48
+ generatorIndex: number,
49
+ /** The nonce for the payload, used to emit a nullifier identifying the call */
50
+ nonce: Fr);
51
+ /**
52
+ * The function calls to execute. This uses snake_case naming so that it is compatible with Noir encoding
53
+ * @internal
54
+ */
55
+ get function_calls(): EncodedFunctionCall[];
56
+ /**
57
+ * Serializes the payload to an array of fields
58
+ * @returns The fields of the payload
59
+ */
60
+ abstract toFields(): Fr[];
61
+ /**
62
+ * Hashes the payload
63
+ * @returns The hash of the payload
64
+ */
65
+ hash(): Promise<Fr>;
66
+ /** Serializes the function calls to an array of fields. */
67
+ protected functionCallsToFields(): Fr[];
68
+ /**
69
+ * Encodes a set of function calls for a dapp entrypoint
70
+ * @param functionCalls - The function calls to execute
71
+ * @returns The encoded calls
72
+ */
73
+ static fromFunctionCalls(functionCalls: FunctionCall[]): Promise<EncodedAppEntrypointCalls>;
74
+ /**
75
+ * Encodes the functions for the app-portion of a transaction from a set of function calls and a nonce
76
+ * @param functionCalls - The function calls to execute
77
+ * @param nonce - The nonce for the payload, used to emit a nullifier identifying the call
78
+ * @returns The encoded calls
79
+ */
80
+ static fromAppExecution(functionCalls: FunctionCall[] | Tuple<FunctionCall, typeof APP_MAX_CALLS>, nonce?: Fr): Promise<EncodedAppEntrypointCalls>;
81
+ /**
82
+ * Creates an encoded set of functions to pay the fee for a transaction
83
+ * @param functionCalls - The calls generated by the payment method
84
+ * @param isFeePayer - Whether the sender should be appointed as fee payer
85
+ * @returns The encoded calls
86
+ */
87
+ static fromFeeCalls(functionCalls: FunctionCall[] | Tuple<FunctionCall, typeof FEE_MAX_CALLS>, isFeePayer: boolean): Promise<EncodedFeeEntrypointCalls>;
88
+ }
89
+ /** Encoded calls for app phase execution. */
90
+ export declare class EncodedAppEntrypointCalls extends EncodedCallsForEntrypoint {
91
+ constructor(encodedFunctionCalls: EncodedFunctionCall[], hashedArguments: HashedValues[], generatorIndex: number, nonce: Fr);
92
+ toFields(): Fr[];
93
+ }
94
+ /** Encoded calls for fee payment */
95
+ export declare class EncodedFeeEntrypointCalls extends EncodedCallsForEntrypoint {
96
+ #private;
97
+ constructor(encodedFunctionCalls: EncodedFunctionCall[], hashedArguments: HashedValues[], generatorIndex: number, nonce: Fr, isFeePayer: boolean);
98
+ toFields(): Fr[];
99
+ /** Whether the sender should be appointed as fee payer. */
100
+ get is_fee_payer(): boolean;
101
+ }
102
+ /**
103
+ * Computes a hash of a combined set of app and fee calls.
104
+ * @param appCalls - A set of app calls.
105
+ * @param feeCalls - A set of calls used to pay fees.
106
+ * @returns A hash of a combined call set.
107
+ */
108
+ export declare function computeCombinedPayloadHash(appPayload: EncodedAppEntrypointCalls, feePayload: EncodedFeeEntrypointCalls): Promise<Fr>;
109
+ /** Encodes FunctionCalls for execution, following Noir's convention */
110
+ export declare function encode(calls: FunctionCall[]): Promise<EncodedCalls>;
111
+ export {};
112
+ //# sourceMappingURL=encoding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../src/encoding.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,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,QAAA,MAAM,aAAa,IAAI,CAAC;AAExB,QAAA,MAAM,aAAa,IAAI,CAAC;AAGxB,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,2CAA2C;IAC3C,SAAS,EAAE,OAAO,CAAC;CACpB,CAAC;AAGF,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,8BAAsB,yBAA0B,YAAW,YAAY;IAEnE,gEAAgE;IACzD,oBAAoB,EAAE,mBAAmB,EAAE;IAClD,gFAAgF;IACzE,eAAe,EAAE,YAAY,EAAE;IACtC,oDAAoD;IAC7C,cAAc,EAAE,MAAM;IAC7B,+EAA+E;IACxE,KAAK,EAAE,EAAE;;IAPhB,gEAAgE;IACzD,oBAAoB,EAAE,mBAAmB,EAAE;IAClD,gFAAgF;IACzE,eAAe,EAAE,YAAY,EAAE;IACtC,oDAAoD;IAC7C,cAAc,EAAE,MAAM;IAC7B,+EAA+E;IACxE,KAAK,EAAE,EAAE;IAIlB;;;OAGG;IACH,IAAI,cAAc,0BAEjB;IAGD;;;OAGG;IACH,QAAQ,CAAC,QAAQ,IAAI,EAAE,EAAE;IAEzB;;;OAGG;IACH,IAAI;IAIJ,2DAA2D;IAC3D,SAAS,CAAC,qBAAqB;IAU/B;;;;OAIG;WACU,iBAAiB,CAAC,aAAa,EAAE,YAAY,EAAE;IAK5D;;;;;OAKG;WACU,gBAAgB,CAC3B,aAAa,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC,YAAY,EAAE,OAAO,aAAa,CAAC,EACzE,KAAK,KAAc;IAerB;;;;;OAKG;WACU,YAAY,CACvB,aAAa,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC,YAAY,EAAE,OAAO,aAAa,CAAC,EACzE,UAAU,EAAE,OAAO;CAYtB;AAED,6CAA6C;AAC7C,qBAAa,yBAA0B,SAAQ,yBAAyB;gBAEpE,oBAAoB,EAAE,mBAAmB,EAAE,EAC3C,eAAe,EAAE,YAAY,EAAE,EAC/B,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,EAAE;IAKF,QAAQ,IAAI,EAAE,EAAE;CAG1B;AAED,oCAAoC;AACpC,qBAAa,yBAA0B,SAAQ,yBAAyB;;gBAIpE,oBAAoB,EAAE,mBAAmB,EAAE,EAC3C,eAAe,EAAE,YAAY,EAAE,EAC/B,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,EAAE,EACT,UAAU,EAAE,OAAO;IAMZ,QAAQ,IAAI,EAAE,EAAE;IAKzB,2DAA2D;IAC3D,IAAI,YAAY,YAEf;CAEF;AAED;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAC9C,UAAU,EAAE,yBAAyB,EACrC,UAAU,EAAE,yBAAyB,GACpC,OAAO,CAAC,EAAE,CAAC,CAKb;AAED,uEAAuE;AACvE,wBAAsB,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAuBzE"}