@aztec/entrypoints 0.82.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.
@@ -31,7 +31,7 @@ import { EncodedCallsForEntrypoint, computeCombinedPayloadHash } from './encodin
31
31
  const feeEncodedCalls = await EncodedCallsForEntrypoint.fromFeeCalls(feeCalls, isFeePayer);
32
32
  // Obtain the entrypoint hashed args, built from the app and fee encoded calls
33
33
  const abi = this.getEntrypointAbi();
34
- const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [
34
+ const entrypointHashedArgs = await HashedValues.fromArgs(encodeArguments(abi, [
35
35
  appEncodedCalls,
36
36
  feeEncodedCalls,
37
37
  !!cancellable
@@ -33,7 +33,7 @@ import { EncodedCallsForEntrypoint } from './encoding.js';
33
33
  const encodedCalls = await EncodedCallsForEntrypoint.fromFunctionCalls(calls);
34
34
  // Obtain the entrypoint hashed args, built from the function call and the user's address
35
35
  const abi = this.getEntrypointAbi();
36
- const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [
36
+ const entrypointHashedArgs = await HashedValues.fromArgs(encodeArguments(abi, [
37
37
  encodedCalls,
38
38
  this.userAddress
39
39
  ]));
@@ -21,7 +21,7 @@ import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
21
21
  const call = calls[0];
22
22
  // Hash the arguments for the function call
23
23
  const hashedArguments = [
24
- await HashedValues.fromValues(call.args)
24
+ await HashedValues.fromArgs(call.args)
25
25
  ];
26
26
  if (call.type !== FunctionType.PRIVATE) {
27
27
  throw new Error('Public entrypoints are not allowed');
@@ -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
+ }
@@ -6,7 +6,8 @@ declare const APP_MAX_CALLS = 4;
6
6
  declare const FEE_MAX_CALLS = 2;
7
7
  /** Encoded function call for an Aztec entrypoint */
8
8
  export type EncodedFunctionCall = {
9
- /** Arguments hash for the call */
9
+ /** Arguments hash for the call. */
10
+ /** This should be the calldata hash `hash([function_selector, ...args])` if `is_public` is true. */
10
11
  args_hash: Fr;
11
12
  /** Selector of the function to call */
12
13
  function_selector: Fr;
@@ -1 +1 @@
1
- {"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../src/encoding.ts"],"names":[],"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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"}
package/dest/encoding.js CHANGED
@@ -119,7 +119,11 @@ const FEE_MAX_CALLS = 2;
119
119
  /** Encodes FunctionCalls for execution, following Noir's convention */ export async function encode(calls) {
120
120
  const hashedArguments = [];
121
121
  for (const call of calls){
122
- hashedArguments.push(await HashedValues.fromValues(call.args));
122
+ const hashed = call.type === FunctionType.PUBLIC ? await HashedValues.fromCalldata([
123
+ call.selector.toField(),
124
+ ...call.args
125
+ ]) : await HashedValues.fromArgs(call.args);
126
+ hashedArguments.push(hashed);
123
127
  }
124
128
  /* eslint-disable camelcase */ const encodedFunctionCalls = calls.map((call, index)=>({
125
129
  args_hash: hashedArguments[index].hash,
package/dest/index.d.ts CHANGED
@@ -10,4 +10,5 @@ export * from './dapp_entrypoint.js';
10
10
  export * from './interfaces.js';
11
11
  export * from './default_entrypoint.js';
12
12
  export * from './encoding.js';
13
+ export * from './default_multi_call_entrypoint.js';
13
14
  //# 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;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC;AAC9B,cAAc,oCAAoC,CAAC"}
package/dest/index.js CHANGED
@@ -9,3 +9,4 @@ export * from './dapp_entrypoint.js';
9
9
  export * from './interfaces.js';
10
10
  export * from './default_entrypoint.js';
11
11
  export * from './encoding.js';
12
+ export * from './default_multi_call_entrypoint.js';
package/package.json CHANGED
@@ -2,12 +2,13 @@
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.82.0",
5
+ "version": "0.82.1-alpha-testnet.1",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  "./dapp": "./dest/dapp_entrypoint.js",
9
9
  "./account": "./dest/account_entrypoint.js",
10
10
  "./default": "./dest/default_entrypoint.js",
11
+ "./multicall": "./dest/default_multi_call_entrypoint.js",
11
12
  "./interfaces": "./dest/interfaces.js",
12
13
  "./payload": "./dest/payload.js",
13
14
  "./encoding": "./dest/encoding.js"
@@ -65,10 +66,10 @@
65
66
  ]
66
67
  },
67
68
  "dependencies": {
68
- "@aztec/constants": "0.82.0",
69
- "@aztec/foundation": "0.82.0",
70
- "@aztec/protocol-contracts": "0.82.0",
71
- "@aztec/stdlib": "0.82.0",
69
+ "@aztec/constants": "0.82.1-alpha-testnet.1",
70
+ "@aztec/foundation": "0.82.1-alpha-testnet.1",
71
+ "@aztec/protocol-contracts": "0.82.1-alpha-testnet.1",
72
+ "@aztec/stdlib": "0.82.1-alpha-testnet.1",
72
73
  "tslib": "^2.4.0"
73
74
  },
74
75
  "devDependencies": {
@@ -41,7 +41,7 @@ export class DefaultAccountEntrypoint implements EntrypointInterface {
41
41
 
42
42
  // Obtain the entrypoint hashed args, built from the app and fee encoded calls
43
43
  const abi = this.getEntrypointAbi();
44
- const entrypointHashedArgs = await HashedValues.fromValues(
44
+ const entrypointHashedArgs = await HashedValues.fromArgs(
45
45
  encodeArguments(abi, [appEncodedCalls, feeEncodedCalls, !!cancellable]),
46
46
  );
47
47
 
@@ -41,7 +41,7 @@ export class DefaultDappEntrypoint implements EntrypointInterface {
41
41
 
42
42
  // Obtain the entrypoint hashed args, built from the function call and the user's address
43
43
  const abi = this.getEntrypointAbi();
44
- const entrypointHashedArgs = await HashedValues.fromValues(encodeArguments(abi, [encodedCalls, this.userAddress]));
44
+ const entrypointHashedArgs = await HashedValues.fromArgs(encodeArguments(abi, [encodedCalls, this.userAddress]));
45
45
 
46
46
  // Construct an auth witness for the entrypoint, by signing the hash of the action to perform
47
47
  // (the dapp calls a function on the user's behalf)
@@ -28,7 +28,7 @@ export class DefaultEntrypoint implements EntrypointInterface {
28
28
  const call = calls[0];
29
29
 
30
30
  // Hash the arguments for the function call
31
- const hashedArguments = [await HashedValues.fromValues(call.args)];
31
+ const hashedArguments = [await HashedValues.fromArgs(call.args)];
32
32
 
33
33
  if (call.type !== FunctionType.PRIVATE) {
34
34
  throw new Error('Public entrypoints are not allowed');
@@ -0,0 +1,109 @@
1
+ import { ProtocolContractAddress } from '@aztec/protocol-contracts';
2
+ import { type FunctionAbi, FunctionSelector, encodeArguments } from '@aztec/stdlib/abi';
3
+ import type { AztecAddress } from '@aztec/stdlib/aztec-address';
4
+ import { HashedValues, TxContext, TxExecutionRequest } from '@aztec/stdlib/tx';
5
+
6
+ import { EncodedCallsForEntrypoint } from './encoding.js';
7
+ import type { EntrypointInterface, FeeOptions } from './interfaces.js';
8
+ import type { ExecutionPayload } from './payload.js';
9
+
10
+ /**
11
+ * Implementation for an entrypoint interface that can execute multiple function calls in a single transaction
12
+ */
13
+ export class DefaultMultiCallEntrypoint implements EntrypointInterface {
14
+ constructor(
15
+ private chainId: number,
16
+ private version: number,
17
+ private address: AztecAddress = ProtocolContractAddress.MultiCallEntrypoint,
18
+ ) {}
19
+
20
+ async createTxExecutionRequest(exec: ExecutionPayload, fee: FeeOptions): Promise<TxExecutionRequest> {
21
+ // Initial request with calls, authWitnesses and capsules
22
+ const { calls, authWitnesses, capsules, extraHashedArgs } = exec;
23
+
24
+ // Get the execution payload for the fee, it includes the calls and potentially authWitnesses
25
+ const {
26
+ calls: feeCalls,
27
+ authWitnesses: feeAuthwitnesses,
28
+ extraHashedArgs: feeExtraHashedArgs,
29
+ } = await fee.paymentMethod.getExecutionPayload(fee.gasSettings);
30
+
31
+ // Encode the calls, including the fee calls
32
+ // (since this entrypoint does not distinguish between app and fee calls)
33
+ const encodedCalls = await EncodedCallsForEntrypoint.fromAppExecution(calls.concat(feeCalls));
34
+
35
+ // Obtain the entrypoint hashed args, built from the encoded calls
36
+ const abi = this.getEntrypointAbi();
37
+ const entrypointHashedArgs = await HashedValues.fromArgs(encodeArguments(abi, [encodedCalls]));
38
+
39
+ // Assemble the tx request
40
+ const txRequest = TxExecutionRequest.from({
41
+ firstCallArgsHash: entrypointHashedArgs.hash,
42
+ origin: this.address,
43
+ functionSelector: await FunctionSelector.fromNameAndParameters(abi.name, abi.parameters),
44
+ txContext: new TxContext(this.chainId, this.version, fee.gasSettings),
45
+ argsOfCalls: [...encodedCalls.hashedArguments, entrypointHashedArgs, ...extraHashedArgs, ...feeExtraHashedArgs],
46
+ authWitnesses: [...feeAuthwitnesses, ...authWitnesses],
47
+ capsules,
48
+ });
49
+
50
+ return Promise.resolve(txRequest);
51
+ }
52
+
53
+ private getEntrypointAbi() {
54
+ return {
55
+ name: 'entrypoint',
56
+ isInitializer: false,
57
+ functionType: 'private',
58
+ isInternal: false,
59
+ isStatic: false,
60
+ parameters: [
61
+ {
62
+ name: 'app_payload',
63
+ type: {
64
+ kind: 'struct',
65
+ path: 'authwit::entrypoint::app::AppPayload',
66
+ fields: [
67
+ {
68
+ name: 'function_calls',
69
+ type: {
70
+ 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
+ returnTypes: [],
106
+ errorTypes: {},
107
+ } as FunctionAbi;
108
+ }
109
+ }
package/src/encoding.ts CHANGED
@@ -15,7 +15,8 @@ const FEE_MAX_CALLS = 2;
15
15
  /* eslint-disable camelcase */
16
16
  /** Encoded function call for an Aztec entrypoint */
17
17
  export type EncodedFunctionCall = {
18
- /** Arguments hash for the call */
18
+ /** Arguments hash for the call. */
19
+ /** This should be the calldata hash `hash([function_selector, ...args])` if `is_public` is true. */
19
20
  args_hash: Fr;
20
21
  /** Selector of the function to call */
21
22
  function_selector: Fr;
@@ -206,7 +207,11 @@ export async function computeCombinedPayloadHash(
206
207
  export async function encode(calls: FunctionCall[]): Promise<EncodedCalls> {
207
208
  const hashedArguments: HashedValues[] = [];
208
209
  for (const call of calls) {
209
- hashedArguments.push(await HashedValues.fromValues(call.args));
210
+ const hashed =
211
+ call.type === FunctionType.PUBLIC
212
+ ? await HashedValues.fromCalldata([call.selector.toField(), ...call.args])
213
+ : await HashedValues.fromArgs(call.args);
214
+ hashedArguments.push(hashed);
210
215
  }
211
216
 
212
217
  /* eslint-disable camelcase */
package/src/index.ts CHANGED
@@ -11,3 +11,4 @@ export * from './dapp_entrypoint.js';
11
11
  export * from './interfaces.js';
12
12
  export * from './default_entrypoint.js';
13
13
  export * from './encoding.js';
14
+ export * from './default_multi_call_entrypoint.js';