@aztec/entrypoints 0.0.0-test.1 → 0.0.1-commit.b655e406

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.
@@ -0,0 +1,97 @@
1
+ import { GeneratorIndex } from '@aztec/constants';
2
+ import { padArrayEnd } from '@aztec/foundation/collection';
3
+ import { poseidon2HashWithSeparator } from '@aztec/foundation/crypto';
4
+ import { Fr } from '@aztec/foundation/fields';
5
+ import { FunctionCall, FunctionType } from '@aztec/stdlib/abi';
6
+ import { HashedValues } from '@aztec/stdlib/tx';
7
+ // These must match the values defined in:
8
+ // - noir-projects/aztec-nr/aztec/src/entrypoint/app.nr
9
+ const APP_MAX_CALLS = 5;
10
+ /**
11
+ * Entrypoints derive their arguments from the calls that they'll ultimate make.
12
+ * This utility class helps in creating the payload for the entrypoint by taking into
13
+ * account how the calls are encoded and hashed.
14
+ * */ export class EncodedAppEntrypointCalls {
15
+ encodedFunctionCalls;
16
+ hashedArguments;
17
+ generatorIndex;
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 */ generatorIndex, /**
20
+ * A nonce to inject into the payload of the transaction. When used with cancellable=true, this nonce will be
21
+ * used to compute a nullifier that allows cancelling this transaction by submitting a new one with the same nonce
22
+ * but higher fee. The nullifier ensures only one transaction can succeed.
23
+ */ // eslint-disable-next-line camelcase
24
+ tx_nonce){
25
+ this.encodedFunctionCalls = encodedFunctionCalls;
26
+ this.hashedArguments = hashedArguments;
27
+ this.generatorIndex = generatorIndex;
28
+ this.tx_nonce = tx_nonce;
29
+ }
30
+ /* eslint-disable camelcase */ /**
31
+ * The function calls to execute. This uses snake_case naming so that it is compatible with Noir encoding
32
+ * @internal
33
+ */ get function_calls() {
34
+ return this.encodedFunctionCalls;
35
+ }
36
+ /* eslint-enable camelcase */ /**
37
+ * Serializes the payload to an array of fields
38
+ * @returns The fields of the payload
39
+ */ toFields() {
40
+ return [
41
+ ...this.functionCallsToFields(),
42
+ this.tx_nonce
43
+ ];
44
+ }
45
+ /**
46
+ * Hashes the payload
47
+ * @returns The hash of the payload
48
+ */ hash() {
49
+ return poseidon2HashWithSeparator(this.toFields(), this.generatorIndex);
50
+ }
51
+ /** Serializes the function calls to an array of fields. */ functionCallsToFields() {
52
+ return this.encodedFunctionCalls.flatMap((call)=>[
53
+ call.args_hash,
54
+ call.function_selector,
55
+ call.target_address,
56
+ new Fr(call.is_public),
57
+ new Fr(call.hide_msg_sender),
58
+ new Fr(call.is_static)
59
+ ]);
60
+ }
61
+ /**
62
+ * Encodes the functions for the app-portion of a transaction from a set of function calls and a nonce
63
+ * @param functionCalls - The function calls to execute
64
+ * @param txNonce - A nonce used to enable transaction cancellation when cancellable=true. Transactions with the same
65
+ * nonce can be replaced by submitting a new one with a higher fee.
66
+ * @returns The encoded calls
67
+ */ static async create(functionCalls, txNonce = Fr.random()) {
68
+ if (functionCalls.length > APP_MAX_CALLS) {
69
+ throw new Error(`Expected at most ${APP_MAX_CALLS} function calls, got ${functionCalls.length}`);
70
+ }
71
+ const paddedCalls = padArrayEnd(functionCalls, FunctionCall.empty(), APP_MAX_CALLS);
72
+ const encoded = await encode(paddedCalls);
73
+ return new EncodedAppEntrypointCalls(encoded.encodedFunctionCalls, encoded.hashedArguments, GeneratorIndex.SIGNATURE_PAYLOAD, txNonce);
74
+ }
75
+ }
76
+ /** Encodes FunctionCalls for execution, following Noir's convention */ export async function encode(calls) {
77
+ const hashedArguments = [];
78
+ for (const call of calls){
79
+ const hashed = call.type === FunctionType.PUBLIC ? await HashedValues.fromCalldata([
80
+ call.selector.toField(),
81
+ ...call.args
82
+ ]) : await HashedValues.fromArgs(call.args);
83
+ hashedArguments.push(hashed);
84
+ }
85
+ /* eslint-disable camelcase */ const encodedFunctionCalls = calls.map((call, index)=>({
86
+ args_hash: hashedArguments[index].hash,
87
+ function_selector: call.selector.toField(),
88
+ target_address: call.to.toField(),
89
+ is_public: call.type == FunctionType.PUBLIC,
90
+ hide_msg_sender: call.hideMsgSender,
91
+ is_static: call.isStatic
92
+ }));
93
+ return {
94
+ encodedFunctionCalls,
95
+ hashedArguments
96
+ };
97
+ }
package/dest/index.d.ts CHANGED
@@ -6,5 +6,8 @@
6
6
  * @packageDocumentation
7
7
  */
8
8
  export * from './account_entrypoint.js';
9
- export * from './dapp_entrypoint.js';
9
+ export * from './interfaces.js';
10
+ export * from './default_entrypoint.js';
11
+ export * from './encoding.js';
12
+ export * from './default_multi_call_entrypoint.js';
10
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,yBAAyB,CAAC;AACxC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC;AAC9B,cAAc,oCAAoC,CAAC"}
package/dest/index.js CHANGED
@@ -5,4 +5,7 @@
5
5
  *
6
6
  * @packageDocumentation
7
7
  */ export * from './account_entrypoint.js';
8
- export * from './dapp_entrypoint.js';
8
+ export * from './interfaces.js';
9
+ export * from './default_entrypoint.js';
10
+ export * from './encoding.js';
11
+ export * from './default_multi_call_entrypoint.js';
@@ -0,0 +1,39 @@
1
+ import type { Fr } from '@aztec/foundation/fields';
2
+ import type { AuthWitness } from '@aztec/stdlib/auth-witness';
3
+ import type { GasSettings } from '@aztec/stdlib/gas';
4
+ import type { TxExecutionRequest } from '@aztec/stdlib/tx';
5
+ import type { ExecutionPayload } from './payload.js';
6
+ /**
7
+ * Information on the connected chain. Used by wallets when constructing transactions to protect against replay
8
+ * attacks.
9
+ */
10
+ export type ChainInfo = {
11
+ /** The L1 chain id */
12
+ chainId: Fr;
13
+ /** The version of the rollup */
14
+ version: Fr;
15
+ };
16
+ /**
17
+ * Creates transaction execution requests out of a set of function calls, a fee payment method and
18
+ * general options for the transaction
19
+ */
20
+ export interface EntrypointInterface {
21
+ /**
22
+ * Generates an execution request out of set of function calls.
23
+ * @param exec - The execution intents to be run.
24
+ * @param gasSettings - The gas settings for the transaction.
25
+ * @param options - Miscellaneous tx options that enable/disable features of the entrypoint
26
+ * @returns The authenticated transaction execution request.
27
+ */
28
+ createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings, options?: any): Promise<TxExecutionRequest>;
29
+ }
30
+ /** Creates authorization witnesses. */
31
+ export interface AuthWitnessProvider {
32
+ /**
33
+ * Computes an authentication witness from either a message hash
34
+ * @param messageHash - The message hash to approve
35
+ * @returns The authentication witness
36
+ */
37
+ createAuthWit(messageHash: Fr | Buffer): Promise<AuthWitness>;
38
+ }
39
+ //# sourceMappingURL=interfaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE3D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAErD;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,sBAAsB;IACtB,OAAO,EAAE,EAAE,CAAC;IACZ,iCAAiC;IACjC,OAAO,EAAE,EAAE,CAAC;CACb,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;;OAMG;IACH,wBAAwB,CACtB,IAAI,EAAE,gBAAgB,EACtB,WAAW,EAAE,WAAW,EACxB,OAAO,CAAC,EAAE,GAAG,GACZ,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAChC;AAED,uCAAuC;AACvC,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,aAAa,CAAC,WAAW,EAAE,EAAE,GAAG,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CAC/D"}
@@ -0,0 +1 @@
1
+ /** Creates authorization witnesses. */ export { };
@@ -0,0 +1,32 @@
1
+ import { FunctionCall } from '@aztec/stdlib/abi';
2
+ import type { AuthWitness } from '@aztec/stdlib/auth-witness';
3
+ import { Capsule, HashedValues } from '@aztec/stdlib/tx';
4
+ /**
5
+ * Represents data necessary to perform an action in the network successfully.
6
+ * This class can be considered Aztec's "minimal execution unit".
7
+ * */
8
+ export declare class ExecutionPayload {
9
+ /** The function calls to be executed. */
10
+ calls: FunctionCall[];
11
+ /** Any transient auth witnesses needed for this execution */
12
+ authWitnesses: AuthWitness[];
13
+ /** Data passed through an oracle for this execution. */
14
+ capsules: Capsule[];
15
+ /** Extra hashed values to be injected in the execution cache */
16
+ extraHashedArgs: HashedValues[];
17
+ constructor(
18
+ /** The function calls to be executed. */
19
+ calls: FunctionCall[],
20
+ /** Any transient auth witnesses needed for this execution */
21
+ authWitnesses: AuthWitness[],
22
+ /** Data passed through an oracle for this execution. */
23
+ capsules: Capsule[],
24
+ /** Extra hashed values to be injected in the execution cache */
25
+ extraHashedArgs?: HashedValues[]);
26
+ static empty(): ExecutionPayload;
27
+ }
28
+ /**
29
+ * Merges an array ExecutionPayloads combining their calls, authWitnesses, capsules and extraArgHashes.
30
+ */
31
+ export declare function mergeExecutionPayloads(requests: ExecutionPayload[]): ExecutionPayload;
32
+ //# sourceMappingURL=payload.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"payload.d.ts","sourceRoot":"","sources":["../src/payload.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEzD;;;KAGK;AACL,qBAAa,gBAAgB;IAEzB,yCAAyC;IAClC,KAAK,EAAE,YAAY,EAAE;IAC5B,6DAA6D;IACtD,aAAa,EAAE,WAAW,EAAE;IACnC,wDAAwD;IACjD,QAAQ,EAAE,OAAO,EAAE;IAC1B,gEAAgE;IACzD,eAAe,EAAE,YAAY,EAAE;;IAPtC,yCAAyC;IAClC,KAAK,EAAE,YAAY,EAAE;IAC5B,6DAA6D;IACtD,aAAa,EAAE,WAAW,EAAE;IACnC,wDAAwD;IACjD,QAAQ,EAAE,OAAO,EAAE;IAC1B,gEAAgE;IACzD,eAAe,GAAE,YAAY,EAAO;IAG7C,MAAM,CAAC,KAAK;CAGb;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,gBAAgB,EAAE,GAAG,gBAAgB,CAMrF"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Represents data necessary to perform an action in the network successfully.
3
+ * This class can be considered Aztec's "minimal execution unit".
4
+ * */ export class ExecutionPayload {
5
+ calls;
6
+ authWitnesses;
7
+ capsules;
8
+ extraHashedArgs;
9
+ constructor(/** The function calls to be executed. */ calls, /** Any transient auth witnesses needed for this execution */ authWitnesses, /** Data passed through an oracle for this execution. */ capsules, /** Extra hashed values to be injected in the execution cache */ extraHashedArgs = []){
10
+ this.calls = calls;
11
+ this.authWitnesses = authWitnesses;
12
+ this.capsules = capsules;
13
+ this.extraHashedArgs = extraHashedArgs;
14
+ }
15
+ static empty() {
16
+ return new ExecutionPayload([], [], []);
17
+ }
18
+ }
19
+ /**
20
+ * Merges an array ExecutionPayloads combining their calls, authWitnesses, capsules and extraArgHashes.
21
+ */ export function mergeExecutionPayloads(requests) {
22
+ const calls = requests.map((r)=>r.calls).flat();
23
+ const combinedAuthWitnesses = requests.map((r)=>r.authWitnesses ?? []).flat();
24
+ const combinedCapsules = requests.map((r)=>r.capsules ?? []).flat();
25
+ const combinedextraHashedArgs = requests.map((r)=>r.extraHashedArgs ?? []).flat();
26
+ return new ExecutionPayload(calls, combinedAuthWitnesses, combinedCapsules, combinedextraHashedArgs);
27
+ }
package/package.json CHANGED
@@ -2,11 +2,15 @@
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.0-test.1",
5
+ "version": "0.0.1-commit.b655e406",
6
6
  "type": "module",
7
7
  "exports": {
8
- "./dapp": "./dest/dapp_entrypoint.js",
9
- "./account": "./dest/account_entrypoint.js"
8
+ "./account": "./dest/account_entrypoint.js",
9
+ "./default": "./dest/default_entrypoint.js",
10
+ "./multicall": "./dest/default_multi_call_entrypoint.js",
11
+ "./interfaces": "./dest/interfaces.js",
12
+ "./payload": "./dest/payload.js",
13
+ "./encoding": "./dest/encoding.js"
10
14
  },
11
15
  "typedocOptions": {
12
16
  "entryPoints": [
@@ -20,8 +24,6 @@
20
24
  "build:dev": "tsc -b --watch",
21
25
  "build:ts": "tsc -b",
22
26
  "clean": "rm -rf ./dest .tsbuildinfo",
23
- "formatting": "run -T prettier --check ./src && run -T eslint ./src",
24
- "formatting:fix": "run -T eslint --fix ./src && run -T prettier -w ./src",
25
27
  "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
26
28
  },
27
29
  "inherits": [
@@ -58,21 +60,25 @@
58
60
  "testTimeout": 120000,
59
61
  "setupFiles": [
60
62
  "../../foundation/src/jest/setup.mjs"
63
+ ],
64
+ "testEnvironment": "../../foundation/src/jest/env.mjs",
65
+ "setupFilesAfterEnv": [
66
+ "../../foundation/src/jest/setupAfterEnv.mjs"
61
67
  ]
62
68
  },
63
69
  "dependencies": {
64
- "@aztec/aztec.js": "0.0.0-test.1",
65
- "@aztec/foundation": "0.0.0-test.1",
66
- "@aztec/protocol-contracts": "0.0.0-test.1",
67
- "@aztec/stdlib": "0.0.0-test.1",
70
+ "@aztec/constants": "0.0.1-commit.b655e406",
71
+ "@aztec/foundation": "0.0.1-commit.b655e406",
72
+ "@aztec/protocol-contracts": "0.0.1-commit.b655e406",
73
+ "@aztec/stdlib": "0.0.1-commit.b655e406",
68
74
  "tslib": "^2.4.0"
69
75
  },
70
76
  "devDependencies": {
71
- "@jest/globals": "^29.5.0",
72
- "@types/jest": "^29.5.0",
73
- "jest": "^29.5.0",
77
+ "@jest/globals": "^30.0.0",
78
+ "@types/jest": "^30.0.0",
79
+ "jest": "^30.0.0",
74
80
  "ts-node": "^10.9.1",
75
- "typescript": "^5.0.4"
81
+ "typescript": "^5.3.3"
76
82
  },
77
83
  "files": [
78
84
  "dest",
@@ -80,6 +86,6 @@
80
86
  "!*.test.*"
81
87
  ],
82
88
  "engines": {
83
- "node": ">=18"
89
+ "node": ">=20.10"
84
90
  }
85
91
  }
@@ -1,15 +1,55 @@
1
- import type { AuthWitnessProvider } from '@aztec/aztec.js/account';
2
- import {
3
- type EntrypointInterface,
4
- EntrypointPayload,
5
- type ExecutionRequestInit,
6
- computeCombinedPayloadHash,
7
- } from '@aztec/aztec.js/entrypoint';
1
+ import { Fr } from '@aztec/foundation/fields';
8
2
  import { type FunctionAbi, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
9
3
  import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import type { GasSettings } from '@aztec/stdlib/gas';
10
5
  import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
11
6
 
12
7
  import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
8
+ import { EncodedAppEntrypointCalls } from './encoding.js';
9
+ import type { AuthWitnessProvider, EntrypointInterface } from './interfaces.js';
10
+ import { ExecutionPayload } from './payload.js';
11
+
12
+ /**
13
+ * The mechanism via which an account contract will pay for a transaction in which it gets invoked.
14
+ */
15
+ export enum AccountFeePaymentMethodOptions {
16
+ /**
17
+ * Signals that some other contract is in charge of paying the fee, nothing needs to be done.
18
+ */
19
+ EXTERNAL = 0,
20
+ /**
21
+ * Used to make the account contract publicly pay for the transaction with its own fee juice balance,
22
+ * **which it must already have prior to this transaction**.
23
+ *
24
+ * The contract will set itself as the fee payer and end the setup phase.
25
+ */
26
+ PREEXISTING_FEE_JUICE = 1,
27
+ /**
28
+ * Used to make the account contract publicly pay for the transaction with its own fee juice balance
29
+ * **which is being claimed in the same transaction**.
30
+ *
31
+ * The contract will set itself as the fee payer but not end setup phase - this is done by the Fee Juice
32
+ * contract after enqueuing a public call, which unlike most public calls is whitelisted by the nodes
33
+ * to be executable during the setup phase.
34
+ */
35
+ FEE_JUICE_WITH_CLAIM = 2,
36
+ }
37
+
38
+ /**
39
+ * General options for the tx execution.
40
+ */
41
+ export type DefaultAccountEntrypointOptions = {
42
+ /** Whether the transaction can be cancelled. */
43
+ cancellable?: boolean;
44
+ /**
45
+ * A nonce to inject into the app payload of the transaction. When used with cancellable=true, this nonce will be
46
+ * used to compute a nullifier that allows cancelling this transaction by submitting a new one with the same nonce
47
+ * but higher fee. The nullifier ensures only one transaction can succeed.
48
+ */
49
+ txNonce?: Fr;
50
+ /** Options that configure how the account contract behaves depending on the fee payment method of the tx */
51
+ feePaymentMethodOptions: AccountFeePaymentMethodOptions;
52
+ };
13
53
 
14
54
  /**
15
55
  * Implementation for an entrypoint interface that follows the default entrypoint signature
@@ -23,28 +63,37 @@ export class DefaultAccountEntrypoint implements EntrypointInterface {
23
63
  private version: number = DEFAULT_VERSION,
24
64
  ) {}
25
65
 
26
- async createTxExecutionRequest(exec: ExecutionRequestInit): Promise<TxExecutionRequest> {
27
- const { calls, fee, nonce, cancellable, capsules = [] } = exec;
28
- const appPayload = await EntrypointPayload.fromAppExecution(calls, nonce);
29
- const feePayload = await EntrypointPayload.fromFeeOptions(this.address, fee);
66
+ async createTxExecutionRequest(
67
+ exec: ExecutionPayload,
68
+ gasSettings: GasSettings,
69
+ options: DefaultAccountEntrypointOptions,
70
+ ): Promise<TxExecutionRequest> {
71
+ // Initial request with calls, authWitnesses and capsules
72
+ const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
73
+ // Global tx options
74
+ const { cancellable, txNonce, feePaymentMethodOptions } = options;
75
+ // Encode the calls for the app
76
+ const encodedCalls = await EncodedAppEntrypointCalls.create(calls, txNonce);
30
77
 
78
+ // Obtain the entrypoint hashed args, built from the app encoded calls and global options
31
79
  const abi = this.getEntrypointAbi();
32
- const entrypointHashedArgs = await HashedValues.fromValues(
33
- encodeArguments(abi, [appPayload, feePayload, !!cancellable]),
80
+ const entrypointHashedArgs = await HashedValues.fromArgs(
81
+ encodeArguments(abi, [encodedCalls, feePaymentMethodOptions, !!cancellable]),
34
82
  );
35
83
 
36
- const combinedPayloadAuthWitness = await this.auth.createAuthWit(
37
- await computeCombinedPayloadHash(appPayload, feePayload),
38
- );
84
+ // Generate the payload auth witness, by signing the hash of the payload
85
+ const appPayloadAuthwitness = await this.auth.createAuthWit(await encodedCalls.hash());
39
86
 
87
+ // Assemble the tx request
40
88
  const txRequest = TxExecutionRequest.from({
41
89
  firstCallArgsHash: entrypointHashedArgs.hash,
42
90
  origin: this.address,
43
91
  functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
44
- txContext: new TxContext(this.chainId, this.version, fee.gasSettings),
45
- argsOfCalls: [...appPayload.hashedArguments, ...feePayload.hashedArguments, entrypointHashedArgs],
46
- authWitnesses: [combinedPayloadAuthWitness],
92
+ txContext: new TxContext(this.chainId, this.version, gasSettings),
93
+ argsOfCalls: [...encodedCalls.hashedArguments, entrypointHashedArgs, ...extraHashedArgs],
94
+ authWitnesses: [...authWitnesses, appPayloadAuthwitness],
47
95
  capsules,
96
+ salt: Fr.random(),
48
97
  });
49
98
 
50
99
  return txRequest;
@@ -68,50 +117,7 @@ export class DefaultAccountEntrypoint implements EntrypointInterface {
68
117
  name: 'function_calls',
69
118
  type: {
70
119
  kind: 'array',
71
- length: 4,
72
- type: {
73
- kind: 'struct',
74
- path: 'authwit::entrypoint::function_call::FunctionCall',
75
- fields: [
76
- { name: 'args_hash', type: { kind: 'field' } },
77
- {
78
- name: 'function_selector',
79
- type: {
80
- kind: 'struct',
81
- path: 'authwit::aztec::protocol_types::abis::function_selector::FunctionSelector',
82
- fields: [{ name: 'inner', type: { kind: 'integer', sign: 'unsigned', width: 32 } }],
83
- },
84
- },
85
- {
86
- name: 'target_address',
87
- type: {
88
- kind: 'struct',
89
- path: 'authwit::aztec::protocol_types::address::AztecAddress',
90
- fields: [{ name: 'inner', type: { kind: 'field' } }],
91
- },
92
- },
93
- { name: 'is_public', type: { kind: 'boolean' } },
94
- { name: 'is_static', type: { kind: 'boolean' } },
95
- ],
96
- },
97
- },
98
- },
99
- { name: 'nonce', type: { kind: 'field' } },
100
- ],
101
- },
102
- visibility: 'public',
103
- },
104
- {
105
- name: 'fee_payload',
106
- type: {
107
- kind: 'struct',
108
- path: 'authwit::entrypoint::fee::FeePayload',
109
- fields: [
110
- {
111
- name: 'function_calls',
112
- type: {
113
- kind: 'array',
114
- length: 2,
120
+ length: 5,
115
121
  type: {
116
122
  kind: 'struct',
117
123
  path: 'authwit::entrypoint::function_call::FunctionCall',
@@ -134,17 +140,18 @@ export class DefaultAccountEntrypoint implements EntrypointInterface {
134
140
  },
135
141
  },
136
142
  { name: 'is_public', type: { kind: 'boolean' } },
143
+ { name: 'hide_msg_sender', type: { kind: 'boolean' } },
137
144
  { name: 'is_static', type: { kind: 'boolean' } },
138
145
  ],
139
146
  },
140
147
  },
141
148
  },
142
- { name: 'nonce', type: { kind: 'field' } },
143
- { name: 'is_fee_payer', type: { kind: 'boolean' } },
149
+ { name: 'tx_nonce', type: { kind: 'field' } },
144
150
  ],
145
151
  },
146
152
  visibility: 'public',
147
153
  },
154
+ { name: 'fee_payment_method', type: { kind: 'integer', sign: 'unsigned', width: 8 } },
148
155
  { name: 'cancellable', type: { kind: 'boolean' } },
149
156
  ],
150
157
  returnTypes: [],
@@ -0,0 +1,45 @@
1
+ import { FunctionType } from '@aztec/stdlib/abi';
2
+ import type { GasSettings } from '@aztec/stdlib/gas';
3
+ import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
4
+
5
+ import type { EntrypointInterface } from './interfaces.js';
6
+ import type { ExecutionPayload } from './payload.js';
7
+
8
+ /**
9
+ * Default implementation of the entrypoint interface. It calls a function on a contract directly
10
+ */
11
+ export class DefaultEntrypoint implements EntrypointInterface {
12
+ constructor(
13
+ private chainId: number,
14
+ private rollupVersion: number,
15
+ ) {}
16
+
17
+ async createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings): Promise<TxExecutionRequest> {
18
+ // Initial request with calls, authWitnesses and capsules
19
+ const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
20
+
21
+ if (calls.length > 1) {
22
+ throw new Error(`Expected a single call, got ${calls.length}`);
23
+ }
24
+
25
+ const call = calls[0];
26
+
27
+ // Hash the arguments for the function call
28
+ const hashedArguments = [await HashedValues.fromArgs(call.args)];
29
+
30
+ if (call.type !== FunctionType.PRIVATE) {
31
+ throw new Error('Public entrypoints are not allowed');
32
+ }
33
+
34
+ // Assemble the tx request
35
+ return new TxExecutionRequest(
36
+ call.to,
37
+ call.selector,
38
+ hashedArguments[0].hash,
39
+ new TxContext(this.chainId, this.rollupVersion, gasSettings),
40
+ [...hashedArguments, ...extraHashedArgs],
41
+ authWitnesses,
42
+ capsules,
43
+ );
44
+ }
45
+ }
@@ -0,0 +1,105 @@
1
+ import { Fr } from '@aztec/foundation/fields';
2
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
3
+ import { type FunctionAbi, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
4
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
5
+ import type { GasSettings } from '@aztec/stdlib/gas';
6
+ import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
7
+
8
+ import { EncodedAppEntrypointCalls } from './encoding.js';
9
+ import type { EntrypointInterface } from './interfaces.js';
10
+ import type { ExecutionPayload } from './payload.js';
11
+
12
+ /**
13
+ * Implementation for an entrypoint interface that can execute multiple function calls in a single transaction
14
+ */
15
+ export class DefaultMultiCallEntrypoint implements EntrypointInterface {
16
+ constructor(
17
+ private chainId: number,
18
+ private version: number,
19
+ private address: AztecAddress = ProtocolContractAddress.MultiCallEntrypoint,
20
+ ) {}
21
+
22
+ async createTxExecutionRequest(exec: ExecutionPayload, gasSettings: GasSettings): Promise<TxExecutionRequest> {
23
+ // Initial request with calls, authWitnesses and capsules
24
+ const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
25
+
26
+ // Encode the calls for the app
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
34
+ const txRequest = TxExecutionRequest.from({
35
+ firstCallArgsHash: entrypointHashedArgs.hash,
36
+ origin: this.address,
37
+ functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
38
+ txContext: new TxContext(this.chainId, this.version, gasSettings),
39
+ argsOfCalls: [...encodedCalls.hashedArguments, entrypointHashedArgs, ...extraHashedArgs],
40
+ authWitnesses,
41
+ capsules,
42
+ salt: Fr.random(),
43
+ });
44
+
45
+ return Promise.resolve(txRequest);
46
+ }
47
+
48
+ private getEntrypointAbi() {
49
+ return {
50
+ name: 'entrypoint',
51
+ isInitializer: false,
52
+ functionType: 'private',
53
+ isInternal: false,
54
+ isStatic: false,
55
+ parameters: [
56
+ {
57
+ name: 'app_payload',
58
+ type: {
59
+ kind: 'struct',
60
+ path: 'authwit::entrypoint::app::AppPayload',
61
+ fields: [
62
+ {
63
+ name: 'function_calls',
64
+ type: {
65
+ kind: 'array',
66
+ length: 5,
67
+ type: {
68
+ kind: 'struct',
69
+ path: 'authwit::entrypoint::function_call::FunctionCall',
70
+ fields: [
71
+ { name: 'args_hash', type: { kind: 'field' } },
72
+ {
73
+ name: 'function_selector',
74
+ type: {
75
+ kind: 'struct',
76
+ path: 'authwit::aztec::protocol_types::abis::function_selector::FunctionSelector',
77
+ fields: [{ name: 'inner', type: { kind: 'integer', sign: 'unsigned', width: 32 } }],
78
+ },
79
+ },
80
+ {
81
+ name: 'target_address',
82
+ type: {
83
+ kind: 'struct',
84
+ path: 'authwit::aztec::protocol_types::address::AztecAddress',
85
+ fields: [{ name: 'inner', type: { kind: 'field' } }],
86
+ },
87
+ },
88
+ { name: 'is_public', type: { kind: 'boolean' } },
89
+ { name: 'hide_msg_sender', type: { kind: 'boolean' } },
90
+ { name: 'is_static', type: { kind: 'boolean' } },
91
+ ],
92
+ },
93
+ },
94
+ },
95
+ { name: 'tx_nonce', type: { kind: 'field' } },
96
+ ],
97
+ },
98
+ visibility: 'public',
99
+ },
100
+ ],
101
+ returnTypes: [],
102
+ errorTypes: {},
103
+ } as FunctionAbi;
104
+ }
105
+ }