@aztec/entrypoints 0.0.0-test.1 → 0.0.1-fake-ceab37513c
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 +3 -3
- package/dest/account_entrypoint.d.ts.map +1 -1
- package/dest/account_entrypoint.js +32 -15
- package/dest/default_entrypoint.d.ts +13 -0
- package/dest/default_entrypoint.d.ts.map +1 -0
- package/dest/default_entrypoint.js +35 -0
- package/dest/default_multi_call_entrypoint.d.ts +16 -0
- package/dest/default_multi_call_entrypoint.d.ts.map +1 -0
- package/dest/{dapp_entrypoint.js → default_multi_call_entrypoint.js} +36 -65
- package/dest/encoding.d.ts +121 -0
- package/dest/encoding.d.ts.map +1 -0
- package/dest/encoding.js +145 -0
- package/dest/index.d.ts +4 -1
- package/dest/index.d.ts.map +1 -1
- package/dest/index.js +4 -1
- package/dest/interfaces.d.ts +85 -0
- package/dest/interfaces.d.ts.map +1 -0
- package/dest/interfaces.js +2 -0
- package/dest/payload.d.ts +32 -0
- package/dest/payload.d.ts.map +1 -0
- package/dest/payload.js +27 -0
- package/package.json +20 -14
- package/src/account_entrypoint.ts +39 -18
- package/src/default_entrypoint.ts +51 -0
- package/src/default_multi_call_entrypoint.ts +111 -0
- package/src/encoding.ts +234 -0
- package/src/index.ts +4 -1
- package/src/interfaces.ts +97 -0
- package/src/payload.ts +35 -0
- package/dest/dapp_entrypoint.d.ts +0 -19
- package/dest/dapp_entrypoint.d.ts.map +0 -1
- package/src/dapp_entrypoint.ts +0 -125
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import type { FieldsOf } from '@aztec/foundation/types';
|
|
3
|
+
import type { AuthWitness } from '@aztec/stdlib/auth-witness';
|
|
4
|
+
import type { AztecAddress } from '@aztec/stdlib/aztec-address';
|
|
5
|
+
import type { GasSettings } from '@aztec/stdlib/gas';
|
|
6
|
+
import type { TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
7
|
+
import type { ExecutionPayload } from './payload.js';
|
|
8
|
+
/**
|
|
9
|
+
* General options for the tx execution.
|
|
10
|
+
*/
|
|
11
|
+
export type TxExecutionOptions = {
|
|
12
|
+
/** Whether the transaction can be cancelled. */
|
|
13
|
+
cancellable?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* A nonce to inject into the app payload of the transaction. When used with cancellable=true, this nonce will be
|
|
16
|
+
* used to compute a nullifier that allows cancelling this transaction by submitting a new one with the same nonce
|
|
17
|
+
* but higher fee. The nullifier ensures only one transaction can succeed.
|
|
18
|
+
*/
|
|
19
|
+
txNonce?: Fr;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Creates transaction execution requests out of a set of function calls, a fee payment method and
|
|
23
|
+
* general options for the transaction
|
|
24
|
+
*/
|
|
25
|
+
export interface EntrypointInterface {
|
|
26
|
+
/**
|
|
27
|
+
* Generates an execution request out of set of function calls.
|
|
28
|
+
* @param exec - The execution intents to be run.
|
|
29
|
+
* @param fee - The fee options for the transaction.
|
|
30
|
+
* @param options - Transaction nonce and whether the transaction is cancellable.
|
|
31
|
+
* @returns The authenticated transaction execution request.
|
|
32
|
+
*/
|
|
33
|
+
createTxExecutionRequest(exec: ExecutionPayload, fee: FeeOptions, options: TxExecutionOptions): Promise<TxExecutionRequest>;
|
|
34
|
+
}
|
|
35
|
+
/** Creates authorization witnesses. */
|
|
36
|
+
export interface AuthWitnessProvider {
|
|
37
|
+
/**
|
|
38
|
+
* Computes an authentication witness from either a message hash
|
|
39
|
+
* @param messageHash - The message hash to approve
|
|
40
|
+
* @returns The authentication witness
|
|
41
|
+
*/
|
|
42
|
+
createAuthWit(messageHash: Fr | Buffer): Promise<AuthWitness>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Holds information about how the fee for a transaction is to be paid.
|
|
46
|
+
*/
|
|
47
|
+
export interface FeePaymentMethod {
|
|
48
|
+
/** The asset used to pay the fee. */
|
|
49
|
+
getAsset(): Promise<AztecAddress>;
|
|
50
|
+
/**
|
|
51
|
+
* Returns the data to be added to the final execution request
|
|
52
|
+
* to pay the fee in the given asset
|
|
53
|
+
* @param gasSettings - The gas limits and max fees.
|
|
54
|
+
* @returns The function calls to pay the fee.
|
|
55
|
+
*/
|
|
56
|
+
getExecutionPayload(gasSettings: GasSettings): Promise<ExecutionPayload>;
|
|
57
|
+
/**
|
|
58
|
+
* The expected fee payer for this tx.
|
|
59
|
+
* @param gasSettings - The gas limits and max fees.
|
|
60
|
+
*/
|
|
61
|
+
getFeePayer(gasSettings: GasSettings): Promise<AztecAddress>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Fee payment options for a transaction.
|
|
65
|
+
*/
|
|
66
|
+
export type FeeOptions = {
|
|
67
|
+
/** The fee payment method to use */
|
|
68
|
+
paymentMethod: FeePaymentMethod;
|
|
69
|
+
/** The gas settings */
|
|
70
|
+
gasSettings: GasSettings;
|
|
71
|
+
};
|
|
72
|
+
/** Fee options as set by a user. */
|
|
73
|
+
export type UserFeeOptions = {
|
|
74
|
+
/** The fee payment method to use */
|
|
75
|
+
paymentMethod?: FeePaymentMethod;
|
|
76
|
+
/** The gas settings */
|
|
77
|
+
gasSettings?: Partial<FieldsOf<GasSettings>>;
|
|
78
|
+
/** Percentage to pad the base fee by, if empty, defaults to 0.5 */
|
|
79
|
+
baseFeePadding?: number;
|
|
80
|
+
/** Whether to run an initial simulation of the tx with high gas limit to figure out actual gas settings. */
|
|
81
|
+
estimateGas?: boolean;
|
|
82
|
+
/** Percentage to pad the estimated gas limits by, if empty, defaults to 0.1. Only relevant if estimateGas is set. */
|
|
83
|
+
estimatedGasPadding?: number;
|
|
84
|
+
};
|
|
85
|
+
//# 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,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,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;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,gDAAgD;IAChD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;OAIG;IACH,OAAO,CAAC,EAAE,EAAE,CAAC;CACd,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;;OAMG;IACH,wBAAwB,CACtB,IAAI,EAAE,gBAAgB,EACtB,GAAG,EAAE,UAAU,EACf,OAAO,EAAE,kBAAkB,GAC1B,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;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,qCAAqC;IACrC,QAAQ,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC;IAClC;;;;;OAKG;IACH,mBAAmB,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IACzE;;;OAGG;IACH,WAAW,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CAC9D;AAED;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,oCAAoC;IACpC,aAAa,EAAE,gBAAgB,CAAC;IAChC,uBAAuB;IACvB,WAAW,EAAE,WAAW,CAAC;CAC1B,CAAC;AAGF,oCAAoC;AACpC,MAAM,MAAM,cAAc,GAAG;IAC3B,oCAAoC;IACpC,aAAa,CAAC,EAAE,gBAAgB,CAAC;IACjC,uBAAuB;IACvB,WAAW,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC;IAC7C,mEAAmE;IACnE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,4GAA4G;IAC5G,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,qHAAqH;IACrH,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC"}
|
|
@@ -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"}
|
package/dest/payload.js
ADDED
|
@@ -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.
|
|
5
|
+
"version": "0.0.1-fake-ceab37513c",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
8
|
-
"./
|
|
9
|
-
"./
|
|
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/
|
|
65
|
-
"@aztec/foundation": "0.0.
|
|
66
|
-
"@aztec/protocol-contracts": "0.0.
|
|
67
|
-
"@aztec/stdlib": "0.0.
|
|
70
|
+
"@aztec/constants": "0.0.1-fake-ceab37513c",
|
|
71
|
+
"@aztec/foundation": "0.0.1-fake-ceab37513c",
|
|
72
|
+
"@aztec/protocol-contracts": "0.0.1-fake-ceab37513c",
|
|
73
|
+
"@aztec/stdlib": "0.0.1-fake-ceab37513c",
|
|
68
74
|
"tslib": "^2.4.0"
|
|
69
75
|
},
|
|
70
76
|
"devDependencies": {
|
|
71
|
-
"@jest/globals": "^
|
|
72
|
-
"@types/jest": "^
|
|
73
|
-
"jest": "^
|
|
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.
|
|
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": ">=
|
|
89
|
+
"node": ">=20.10"
|
|
84
90
|
}
|
|
85
91
|
}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import
|
|
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';
|
|
10
4
|
import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
11
5
|
|
|
12
6
|
import { DEFAULT_CHAIN_ID, DEFAULT_VERSION } from './constants.js';
|
|
7
|
+
import { EncodedCallsForEntrypoint, computeCombinedPayloadHash } from './encoding.js';
|
|
8
|
+
import type { AuthWitnessProvider, EntrypointInterface, FeeOptions, TxExecutionOptions } from './interfaces.js';
|
|
9
|
+
import { ExecutionPayload } from './payload.js';
|
|
13
10
|
|
|
14
11
|
/**
|
|
15
12
|
* Implementation for an entrypoint interface that follows the default entrypoint signature
|
|
@@ -23,28 +20,52 @@ export class DefaultAccountEntrypoint implements EntrypointInterface {
|
|
|
23
20
|
private version: number = DEFAULT_VERSION,
|
|
24
21
|
) {}
|
|
25
22
|
|
|
26
|
-
async createTxExecutionRequest(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
async createTxExecutionRequest(
|
|
24
|
+
exec: ExecutionPayload,
|
|
25
|
+
fee: FeeOptions,
|
|
26
|
+
options: TxExecutionOptions,
|
|
27
|
+
): Promise<TxExecutionRequest> {
|
|
28
|
+
// Initial request with calls, authWitnesses and capsules
|
|
29
|
+
const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
|
|
30
|
+
// Global tx options
|
|
31
|
+
const { cancellable, txNonce } = options;
|
|
32
|
+
// Encode the calls for the app
|
|
33
|
+
const appEncodedCalls = await EncodedCallsForEntrypoint.fromAppExecution(calls, txNonce);
|
|
34
|
+
// Get the execution payload for the fee, it includes the calls and potentially authWitnesses
|
|
35
|
+
const { calls: feeCalls, authWitnesses: feeAuthwitnesses } = await fee.paymentMethod.getExecutionPayload(
|
|
36
|
+
fee.gasSettings,
|
|
37
|
+
);
|
|
38
|
+
// Encode the calls for the fee
|
|
39
|
+
const feePayer = await fee.paymentMethod.getFeePayer(fee.gasSettings);
|
|
40
|
+
const isFeePayer = feePayer.equals(this.address);
|
|
41
|
+
const feeEncodedCalls = await EncodedCallsForEntrypoint.fromFeeCalls(feeCalls, isFeePayer);
|
|
30
42
|
|
|
43
|
+
// Obtain the entrypoint hashed args, built from the app and fee encoded calls
|
|
31
44
|
const abi = this.getEntrypointAbi();
|
|
32
|
-
const entrypointHashedArgs = await HashedValues.
|
|
33
|
-
encodeArguments(abi, [
|
|
45
|
+
const entrypointHashedArgs = await HashedValues.fromArgs(
|
|
46
|
+
encodeArguments(abi, [appEncodedCalls, feeEncodedCalls, !!cancellable]),
|
|
34
47
|
);
|
|
35
48
|
|
|
49
|
+
// Generate the combined payload auth witness, by signing the hash of the combined payload
|
|
36
50
|
const combinedPayloadAuthWitness = await this.auth.createAuthWit(
|
|
37
|
-
await computeCombinedPayloadHash(
|
|
51
|
+
await computeCombinedPayloadHash(appEncodedCalls, feeEncodedCalls),
|
|
38
52
|
);
|
|
39
53
|
|
|
54
|
+
// Assemble the tx request
|
|
40
55
|
const txRequest = TxExecutionRequest.from({
|
|
41
56
|
firstCallArgsHash: entrypointHashedArgs.hash,
|
|
42
57
|
origin: this.address,
|
|
43
58
|
functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
|
|
44
59
|
txContext: new TxContext(this.chainId, this.version, fee.gasSettings),
|
|
45
|
-
argsOfCalls: [
|
|
46
|
-
|
|
60
|
+
argsOfCalls: [
|
|
61
|
+
...appEncodedCalls.hashedArguments,
|
|
62
|
+
...feeEncodedCalls.hashedArguments,
|
|
63
|
+
entrypointHashedArgs,
|
|
64
|
+
...extraHashedArgs,
|
|
65
|
+
],
|
|
66
|
+
authWitnesses: [...authWitnesses, ...feeAuthwitnesses, combinedPayloadAuthWitness],
|
|
47
67
|
capsules,
|
|
68
|
+
salt: Fr.random(),
|
|
48
69
|
});
|
|
49
70
|
|
|
50
71
|
return txRequest;
|
|
@@ -96,7 +117,7 @@ export class DefaultAccountEntrypoint implements EntrypointInterface {
|
|
|
96
117
|
},
|
|
97
118
|
},
|
|
98
119
|
},
|
|
99
|
-
{ name: '
|
|
120
|
+
{ name: 'tx_nonce', type: { kind: 'field' } },
|
|
100
121
|
],
|
|
101
122
|
},
|
|
102
123
|
visibility: 'public',
|
|
@@ -139,7 +160,7 @@ export class DefaultAccountEntrypoint implements EntrypointInterface {
|
|
|
139
160
|
},
|
|
140
161
|
},
|
|
141
162
|
},
|
|
142
|
-
{ name: '
|
|
163
|
+
{ name: 'tx_nonce', type: { kind: 'field' } },
|
|
143
164
|
{ name: 'is_fee_payer', type: { kind: 'boolean' } },
|
|
144
165
|
],
|
|
145
166
|
},
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { FunctionType } from '@aztec/stdlib/abi';
|
|
2
|
+
import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
3
|
+
|
|
4
|
+
import type { EntrypointInterface, FeeOptions, TxExecutionOptions } from './interfaces.js';
|
|
5
|
+
import type { ExecutionPayload } from './payload.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Default implementation of the entrypoint interface. It calls a function on a contract directly
|
|
9
|
+
*/
|
|
10
|
+
export class DefaultEntrypoint implements EntrypointInterface {
|
|
11
|
+
constructor(
|
|
12
|
+
private chainId: number,
|
|
13
|
+
private rollupVersion: number,
|
|
14
|
+
) {}
|
|
15
|
+
|
|
16
|
+
async createTxExecutionRequest(
|
|
17
|
+
exec: ExecutionPayload,
|
|
18
|
+
fee: FeeOptions,
|
|
19
|
+
options: TxExecutionOptions,
|
|
20
|
+
): Promise<TxExecutionRequest> {
|
|
21
|
+
if (options.txNonce || options.cancellable !== undefined) {
|
|
22
|
+
throw new Error('TxExecutionOptions are not supported in DefaultEntrypoint');
|
|
23
|
+
}
|
|
24
|
+
// Initial request with calls, authWitnesses and capsules
|
|
25
|
+
const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
|
|
26
|
+
|
|
27
|
+
if (calls.length > 1) {
|
|
28
|
+
throw new Error(`Expected a single call, got ${calls.length}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const call = calls[0];
|
|
32
|
+
|
|
33
|
+
// Hash the arguments for the function call
|
|
34
|
+
const hashedArguments = [await HashedValues.fromArgs(call.args)];
|
|
35
|
+
|
|
36
|
+
if (call.type !== FunctionType.PRIVATE) {
|
|
37
|
+
throw new Error('Public entrypoints are not allowed');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Assemble the tx request
|
|
41
|
+
return new TxExecutionRequest(
|
|
42
|
+
call.to,
|
|
43
|
+
call.selector,
|
|
44
|
+
hashedArguments[0].hash,
|
|
45
|
+
new TxContext(this.chainId, this.rollupVersion, fee.gasSettings),
|
|
46
|
+
[...hashedArguments, ...extraHashedArgs],
|
|
47
|
+
authWitnesses,
|
|
48
|
+
capsules,
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
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 { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
|
|
6
|
+
|
|
7
|
+
import { EncodedCallsForEntrypoint } from './encoding.js';
|
|
8
|
+
import type { EntrypointInterface, FeeOptions } from './interfaces.js';
|
|
9
|
+
import type { ExecutionPayload } from './payload.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Implementation for an entrypoint interface that can execute multiple function calls in a single transaction
|
|
13
|
+
*/
|
|
14
|
+
export class DefaultMultiCallEntrypoint implements EntrypointInterface {
|
|
15
|
+
constructor(
|
|
16
|
+
private chainId: number,
|
|
17
|
+
private version: number,
|
|
18
|
+
private address: AztecAddress = ProtocolContractAddress.MultiCallEntrypoint,
|
|
19
|
+
) {}
|
|
20
|
+
|
|
21
|
+
async createTxExecutionRequest(exec: ExecutionPayload, fee: FeeOptions): Promise<TxExecutionRequest> {
|
|
22
|
+
// Initial request with calls, authWitnesses and capsules
|
|
23
|
+
const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
|
|
24
|
+
|
|
25
|
+
// Get the execution payload for the fee, it includes the calls and potentially authWitnesses
|
|
26
|
+
const {
|
|
27
|
+
calls: feeCalls,
|
|
28
|
+
authWitnesses: feeAuthwitnesses,
|
|
29
|
+
extraHashedArgs: feeExtraHashedArgs,
|
|
30
|
+
} = await fee.paymentMethod.getExecutionPayload(fee.gasSettings);
|
|
31
|
+
|
|
32
|
+
// Encode the calls, including the fee calls
|
|
33
|
+
// (since this entrypoint does not distinguish between app and fee calls)
|
|
34
|
+
const encodedCalls = await EncodedCallsForEntrypoint.fromAppExecution(calls.concat(feeCalls));
|
|
35
|
+
|
|
36
|
+
// Obtain the entrypoint hashed args, built from the encoded calls
|
|
37
|
+
const abi = this.getEntrypointAbi();
|
|
38
|
+
const entrypointHashedArgs = await HashedValues.fromArgs(encodeArguments(abi, [encodedCalls]));
|
|
39
|
+
|
|
40
|
+
// Assemble the tx request
|
|
41
|
+
const txRequest = TxExecutionRequest.from({
|
|
42
|
+
firstCallArgsHash: entrypointHashedArgs.hash,
|
|
43
|
+
origin: this.address,
|
|
44
|
+
functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
|
|
45
|
+
txContext: new TxContext(this.chainId, this.version, fee.gasSettings),
|
|
46
|
+
argsOfCalls: [...encodedCalls.hashedArguments, entrypointHashedArgs, ...extraHashedArgs, ...feeExtraHashedArgs],
|
|
47
|
+
authWitnesses: [...feeAuthwitnesses, ...authWitnesses],
|
|
48
|
+
capsules,
|
|
49
|
+
salt: Fr.random(),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return Promise.resolve(txRequest);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private getEntrypointAbi() {
|
|
56
|
+
return {
|
|
57
|
+
name: 'entrypoint',
|
|
58
|
+
isInitializer: false,
|
|
59
|
+
functionType: 'private',
|
|
60
|
+
isInternal: false,
|
|
61
|
+
isStatic: false,
|
|
62
|
+
parameters: [
|
|
63
|
+
{
|
|
64
|
+
name: 'app_payload',
|
|
65
|
+
type: {
|
|
66
|
+
kind: 'struct',
|
|
67
|
+
path: 'authwit::entrypoint::app::AppPayload',
|
|
68
|
+
fields: [
|
|
69
|
+
{
|
|
70
|
+
name: 'function_calls',
|
|
71
|
+
type: {
|
|
72
|
+
kind: 'array',
|
|
73
|
+
length: 4,
|
|
74
|
+
type: {
|
|
75
|
+
kind: 'struct',
|
|
76
|
+
path: 'authwit::entrypoint::function_call::FunctionCall',
|
|
77
|
+
fields: [
|
|
78
|
+
{ name: 'args_hash', type: { kind: 'field' } },
|
|
79
|
+
{
|
|
80
|
+
name: 'function_selector',
|
|
81
|
+
type: {
|
|
82
|
+
kind: 'struct',
|
|
83
|
+
path: 'authwit::aztec::protocol_types::abis::function_selector::FunctionSelector',
|
|
84
|
+
fields: [{ name: 'inner', type: { kind: 'integer', sign: 'unsigned', width: 32 } }],
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: 'target_address',
|
|
89
|
+
type: {
|
|
90
|
+
kind: 'struct',
|
|
91
|
+
path: 'authwit::aztec::protocol_types::address::AztecAddress',
|
|
92
|
+
fields: [{ name: 'inner', type: { kind: 'field' } }],
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
{ name: 'is_public', type: { kind: 'boolean' } },
|
|
96
|
+
{ name: 'is_static', type: { kind: 'boolean' } },
|
|
97
|
+
],
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
{ name: 'tx_nonce', type: { kind: 'field' } },
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
visibility: 'public',
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
returnTypes: [],
|
|
108
|
+
errorTypes: {},
|
|
109
|
+
} as FunctionAbi;
|
|
110
|
+
}
|
|
111
|
+
}
|