@aztec/stdlib 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.
Files changed (76) hide show
  1. package/dest/avm/avm.d.ts +24 -48
  2. package/dest/avm/avm.d.ts.map +1 -1
  3. package/dest/avm/avm_circuit_public_inputs.d.ts +18 -36
  4. package/dest/avm/avm_circuit_public_inputs.d.ts.map +1 -1
  5. package/dest/avm/avm_proving_request.d.ts +27 -54
  6. package/dest/avm/avm_proving_request.d.ts.map +1 -1
  7. package/dest/contract/contract_class.d.ts.map +1 -1
  8. package/dest/contract/contract_class.js +3 -21
  9. package/dest/contract/interfaces/contract_class.d.ts +1 -143
  10. package/dest/contract/interfaces/contract_class.d.ts.map +1 -1
  11. package/dest/contract/interfaces/contract_class.js +0 -5
  12. package/dest/contract/interfaces/contract_data_source.d.ts +3 -3
  13. package/dest/contract/interfaces/contract_data_source.d.ts.map +1 -1
  14. package/dest/hash/hash.d.ts +8 -1
  15. package/dest/hash/hash.d.ts.map +1 -1
  16. package/dest/hash/hash.js +12 -1
  17. package/dest/interfaces/archiver.d.ts.map +1 -1
  18. package/dest/interfaces/archiver.js +1 -1
  19. package/dest/interfaces/prover-client.js +1 -1
  20. package/dest/interfaces/proving-job.d.ts +27 -54
  21. package/dest/interfaces/proving-job.d.ts.map +1 -1
  22. package/dest/kernel/public_call_request.d.ts +14 -19
  23. package/dest/kernel/public_call_request.d.ts.map +1 -1
  24. package/dest/kernel/public_call_request.js +19 -20
  25. package/dest/stats/stats.d.ts +1 -1
  26. package/dest/stats/stats.d.ts.map +1 -1
  27. package/dest/tests/factories.d.ts +2 -2
  28. package/dest/tests/factories.d.ts.map +1 -1
  29. package/dest/tests/factories.js +3 -13
  30. package/dest/tests/mocks.d.ts +3 -4
  31. package/dest/tests/mocks.d.ts.map +1 -1
  32. package/dest/tests/mocks.js +13 -48
  33. package/dest/tx/call_context.d.ts +1 -1
  34. package/dest/tx/hashed_values.d.ts +16 -4
  35. package/dest/tx/hashed_values.d.ts.map +1 -1
  36. package/dest/tx/hashed_values.js +26 -9
  37. package/dest/tx/index.d.ts +1 -1
  38. package/dest/tx/index.d.ts.map +1 -1
  39. package/dest/tx/index.js +1 -1
  40. package/dest/tx/private_execution_result.d.ts +6 -26
  41. package/dest/tx/private_execution_result.d.ts.map +1 -1
  42. package/dest/tx/private_execution_result.js +13 -70
  43. package/dest/tx/proven_tx.d.ts.map +1 -1
  44. package/dest/tx/proven_tx.js +2 -4
  45. package/dest/tx/public_call_request_with_calldata.d.ts +41 -0
  46. package/dest/tx/public_call_request_with_calldata.d.ts.map +1 -0
  47. package/dest/tx/public_call_request_with_calldata.js +57 -0
  48. package/dest/tx/simulated_tx.d.ts.map +1 -1
  49. package/dest/tx/simulated_tx.js +2 -4
  50. package/dest/tx/tx.d.ts +16 -20
  51. package/dest/tx/tx.d.ts.map +1 -1
  52. package/dest/tx/tx.js +56 -42
  53. package/dest/tx/tx_execution_request.js +1 -1
  54. package/package.json +6 -6
  55. package/src/contract/contract_class.ts +7 -26
  56. package/src/contract/interfaces/contract_class.ts +2 -18
  57. package/src/contract/interfaces/contract_data_source.ts +3 -3
  58. package/src/hash/hash.ts +15 -1
  59. package/src/interfaces/archiver.ts +1 -4
  60. package/src/interfaces/prover-client.ts +1 -1
  61. package/src/kernel/public_call_request.ts +22 -27
  62. package/src/stats/stats.ts +1 -1
  63. package/src/tests/factories.ts +3 -24
  64. package/src/tests/mocks.ts +28 -80
  65. package/src/tx/hashed_values.ts +29 -9
  66. package/src/tx/index.ts +1 -1
  67. package/src/tx/private_execution_result.ts +9 -81
  68. package/src/tx/proven_tx.ts +2 -10
  69. package/src/tx/public_call_request_with_calldata.ts +72 -0
  70. package/src/tx/simulated_tx.ts +1 -6
  71. package/src/tx/tx.ts +57 -70
  72. package/src/tx/tx_execution_request.ts +1 -1
  73. package/dest/tx/public_execution_request.d.ts +0 -45
  74. package/dest/tx/public_execution_request.d.ts.map +0 -1
  75. package/dest/tx/public_execution_request.js +0 -72
  76. package/src/tx/public_execution_request.ts +0 -97
package/src/tx/tx.ts CHANGED
@@ -10,6 +10,7 @@ import { z } from 'zod';
10
10
  import type { GasSettings } from '../gas/gas_settings.js';
11
11
  import type { GetPublicLogsResponse } from '../interfaces/get_logs_response.js';
12
12
  import type { L2LogsSource } from '../interfaces/l2_logs_source.js';
13
+ import type { PublicCallRequest } from '../kernel/index.js';
13
14
  import type { ScopedLogHash } from '../kernel/log_hash.js';
14
15
  import { PrivateKernelTailCircuitPublicInputs } from '../kernel/private_kernel_tail_circuit_public_inputs.js';
15
16
  import { ContractClassLog } from '../logs/contract_class_log.js';
@@ -17,7 +18,8 @@ import { Gossipable } from '../p2p/gossipable.js';
17
18
  import { TopicType, createTopicString } from '../p2p/topic_type.js';
18
19
  import { ClientIvcProof } from '../proofs/client_ivc_proof.js';
19
20
  import type { TxStats } from '../stats/stats.js';
20
- import { PublicExecutionRequest } from './public_execution_request.js';
21
+ import { HashedValues } from './hashed_values.js';
22
+ import { PublicCallRequestWithCalldata } from './public_call_request_with_calldata.js';
21
23
  import { TxHash } from './tx_hash.js';
22
24
 
23
25
  /**
@@ -27,6 +29,7 @@ export class Tx extends Gossipable {
27
29
  static override p2pTopic: string;
28
30
  // For memoization
29
31
  private txHash: TxHash | undefined;
32
+ private calldataMap: Map<string, Fr[]> | undefined;
30
33
 
31
34
  constructor(
32
35
  /**
@@ -36,7 +39,6 @@ export class Tx extends Gossipable {
36
39
  /**
37
40
  * Proof from the private kernel circuit.
38
41
  * TODO(#7368): This client IVC object currently contains various VKs that will eventually be more like static data.
39
- *
40
42
  */
41
43
  public readonly clientIvcProof: ClientIvcProof,
42
44
  /**
@@ -44,13 +46,9 @@ export class Tx extends Gossipable {
44
46
  */
45
47
  public contractClassLogs: ContractClassLog[],
46
48
  /**
47
- * Enqueued public functions from the private circuit to be run by the sequencer.
49
+ * An array of calldata for the enqueued public function calls and the teardown function call.
48
50
  */
49
- public readonly enqueuedPublicFunctionCalls: PublicExecutionRequest[],
50
- /**
51
- * Public function call to be run by the sequencer as part of teardown.
52
- */
53
- public readonly publicTeardownFunctionCall: PublicExecutionRequest,
51
+ public publicFunctionCalldata: HashedValues[],
54
52
  ) {
55
53
  super();
56
54
  }
@@ -66,29 +64,38 @@ export class Tx extends Gossipable {
66
64
  }
67
65
 
68
66
  hasPublicCalls() {
69
- return this.data.numberOfPublicCallRequests() > 0;
67
+ return this.numberOfPublicCalls() > 0;
70
68
  }
71
69
 
72
- getNonRevertiblePublicExecutionRequests(): PublicExecutionRequest[] {
73
- const numRevertible = this.data.numberOfRevertiblePublicCallRequests();
74
- return this.enqueuedPublicFunctionCalls.slice(numRevertible);
70
+ numberOfPublicCalls() {
71
+ return this.data.numberOfPublicCallRequests();
75
72
  }
76
73
 
77
- getRevertiblePublicExecutionRequests(): PublicExecutionRequest[] {
78
- const numRevertible = this.data.numberOfRevertiblePublicCallRequests();
79
- return this.enqueuedPublicFunctionCalls.slice(0, numRevertible);
74
+ getNonRevertiblePublicCallRequestsWithCalldata(): PublicCallRequestWithCalldata[] {
75
+ return this.data.getNonRevertiblePublicCallRequests().map(r => this.#combinePublicCallRequestWithCallData(r));
80
76
  }
81
77
 
82
- getPublicTeardownExecutionRequest(): PublicExecutionRequest | undefined {
83
- return this.publicTeardownFunctionCall.isEmpty() ? undefined : this.publicTeardownFunctionCall;
78
+ getRevertiblePublicCallRequestsWithCalldata(): PublicCallRequestWithCalldata[] {
79
+ return this.data.getRevertiblePublicCallRequests().map(r => this.#combinePublicCallRequestWithCallData(r));
84
80
  }
85
81
 
86
- getTotalPublicArgsCount(): number {
87
- let count = this.enqueuedPublicFunctionCalls.reduce((acc, execRequest) => acc + execRequest.args.length, 0);
88
- if (!this.publicTeardownFunctionCall.isEmpty()) {
89
- count += this.publicTeardownFunctionCall.args.length;
90
- }
91
- return count;
82
+ getTeardownPublicCallRequestWithCalldata(): PublicCallRequestWithCalldata | undefined {
83
+ const request = this.data.getTeardownPublicCallRequest();
84
+ return request ? this.#combinePublicCallRequestWithCallData(request) : undefined;
85
+ }
86
+
87
+ getPublicCallRequestsWithCalldata(): PublicCallRequestWithCalldata[] {
88
+ const teardown = this.data.getTeardownPublicCallRequest();
89
+ const callRequests = [
90
+ ...this.data.getNonRevertiblePublicCallRequests(),
91
+ ...this.data.getRevertiblePublicCallRequests(),
92
+ ...(teardown ? [teardown] : []),
93
+ ];
94
+ return callRequests.map(r => this.#combinePublicCallRequestWithCallData(r));
95
+ }
96
+
97
+ getTotalPublicCalldataCount(): number {
98
+ return this.publicFunctionCalldata.reduce((accum, cd) => accum + cd.values.length, 0);
92
99
  }
93
100
 
94
101
  getGasSettings(): GasSettings {
@@ -106,21 +113,7 @@ export class Tx extends Gossipable {
106
113
  reader.readObject(PrivateKernelTailCircuitPublicInputs),
107
114
  reader.readObject(ClientIvcProof),
108
115
  reader.readVectorUint8Prefix(ContractClassLog),
109
- reader.readVectorUint8Prefix(PublicExecutionRequest),
110
- reader.readObject(PublicExecutionRequest),
111
- );
112
- }
113
-
114
- static newWithTxData(
115
- data: PrivateKernelTailCircuitPublicInputs,
116
- publicTeardownExecutionRequest?: PublicExecutionRequest,
117
- ) {
118
- return new Tx(
119
- data,
120
- ClientIvcProof.empty(),
121
- [],
122
- [],
123
- publicTeardownExecutionRequest ? publicTeardownExecutionRequest : PublicExecutionRequest.empty(),
116
+ reader.readVectorUint8Prefix(HashedValues),
124
117
  );
125
118
  }
126
119
 
@@ -133,8 +126,7 @@ export class Tx extends Gossipable {
133
126
  this.data,
134
127
  this.clientIvcProof,
135
128
  serializeArrayOfBufferableToVector(this.contractClassLogs, 1),
136
- serializeArrayOfBufferableToVector(this.enqueuedPublicFunctionCalls, 1),
137
- this.publicTeardownFunctionCall,
129
+ serializeArrayOfBufferableToVector(this.publicFunctionCalldata, 1),
138
130
  ]);
139
131
  }
140
132
 
@@ -144,20 +136,13 @@ export class Tx extends Gossipable {
144
136
  data: PrivateKernelTailCircuitPublicInputs.schema,
145
137
  clientIvcProof: ClientIvcProof.schema,
146
138
  contractClassLogs: z.array(ContractClassLog.schema),
147
- enqueuedPublicFunctionCalls: z.array(PublicExecutionRequest.schema),
148
- publicTeardownFunctionCall: PublicExecutionRequest.schema,
139
+ publicFunctionCalldata: z.array(HashedValues.schema),
149
140
  })
150
141
  .transform(Tx.from);
151
142
  }
152
143
 
153
144
  static from(fields: FieldsOf<Tx>) {
154
- return new Tx(
155
- fields.data,
156
- fields.clientIvcProof,
157
- fields.contractClassLogs,
158
- fields.enqueuedPublicFunctionCalls,
159
- fields.publicTeardownFunctionCall,
160
- );
145
+ return new Tx(fields.data, fields.clientIvcProof, fields.contractClassLogs, fields.publicFunctionCalldata);
161
146
  }
162
147
 
163
148
  /**
@@ -229,6 +214,16 @@ export class Tx extends Gossipable {
229
214
  this.txHash = hash;
230
215
  }
231
216
 
217
+ getCalldataMap(): Map<string, Fr[]> {
218
+ if (!this.calldataMap) {
219
+ const calldataMap = new Map();
220
+ this.publicFunctionCalldata.forEach(cd => calldataMap.set(cd.hash.toString(), cd.values));
221
+ this.calldataMap = calldataMap;
222
+ }
223
+
224
+ return this.calldataMap;
225
+ }
226
+
232
227
  /** Returns stats about this tx. */
233
228
  async getStats(): Promise<TxStats> {
234
229
  return {
@@ -245,12 +240,7 @@ export class Tx extends Gossipable {
245
240
 
246
241
  feePaymentMethod:
247
242
  // needsSetup? then we pay through a fee payment contract
248
- this.data.forPublic?.needsSetup
249
- ? // if the first call is to `approve_public_authwit`, then it's a public payment
250
- this.data.getNonRevertiblePublicCallRequests().at(-1)!.functionSelector.toField().toBigInt() === 0x43417bb1n
251
- ? 'fpc_public'
252
- : 'fpc_private'
253
- : 'fee_juice',
243
+ this.data.forPublic?.needsSetup ? 'fpc' : 'fee_juice',
254
244
  };
255
245
  }
256
246
 
@@ -259,8 +249,7 @@ export class Tx extends Gossipable {
259
249
  this.data.getSize() +
260
250
  this.clientIvcProof.clientIvcProofBuffer.length +
261
251
  arraySerializedSizeOfNonEmpty(this.contractClassLogs) +
262
- arraySerializedSizeOfNonEmpty(this.enqueuedPublicFunctionCalls) +
263
- arraySerializedSizeOfNonEmpty([this.publicTeardownFunctionCall])
252
+ this.publicFunctionCalldata.reduce((accum, cd) => accum + cd.getSize(), 0)
264
253
  );
265
254
  }
266
255
 
@@ -304,17 +293,8 @@ export class Tx extends Gossipable {
304
293
  const publicInputs = PrivateKernelTailCircuitPublicInputs.fromBuffer(tx.data.toBuffer());
305
294
  const clientIvcProof = ClientIvcProof.fromBuffer(tx.clientIvcProof.toBuffer());
306
295
  const contractClassLogs = tx.contractClassLogs.map(x => ContractClassLog.fromBuffer(x.toBuffer()));
307
- const enqueuedPublicFunctionCalls = tx.enqueuedPublicFunctionCalls.map(x =>
308
- PublicExecutionRequest.fromBuffer(x.toBuffer()),
309
- );
310
- const publicTeardownFunctionCall = PublicExecutionRequest.fromBuffer(tx.publicTeardownFunctionCall.toBuffer());
311
- const clonedTx = new Tx(
312
- publicInputs,
313
- clientIvcProof,
314
- contractClassLogs,
315
- enqueuedPublicFunctionCalls,
316
- publicTeardownFunctionCall,
317
- );
296
+ const publicFunctionCalldata = tx.publicFunctionCalldata.map(cd => HashedValues.fromBuffer(cd.toBuffer()));
297
+ const clonedTx = new Tx(publicInputs, clientIvcProof, contractClassLogs, publicFunctionCalldata);
318
298
  if (tx.txHash) {
319
299
  clonedTx.setTxHash(TxHash.fromBuffer(tx.txHash.toBuffer()));
320
300
  }
@@ -332,8 +312,7 @@ export class Tx extends Gossipable {
332
312
  PrivateKernelTailCircuitPublicInputs.emptyWithNullifier(),
333
313
  randomProof ? ClientIvcProof.random() : ClientIvcProof.empty(),
334
314
  [await ContractClassLog.random()],
335
- [await PublicExecutionRequest.random()],
336
- await PublicExecutionRequest.random(),
315
+ [HashedValues.random()],
337
316
  );
338
317
  }
339
318
 
@@ -354,6 +333,14 @@ export class Tx extends Gossipable {
354
333
  public async filterRevertedLogs() {
355
334
  this.contractClassLogs = await this.getSplitContractClassLogs(false);
356
335
  }
336
+
337
+ #combinePublicCallRequestWithCallData(request: PublicCallRequest) {
338
+ const calldataMap = this.getCalldataMap();
339
+ // Assume empty calldata if nothing is given for the hash.
340
+ // The verification of calldata vs hash should be handled outside of this class.
341
+ const calldata = calldataMap.get(request.calldataHash.toString()) ?? [];
342
+ return new PublicCallRequestWithCalldata(request, calldata);
343
+ }
357
344
  }
358
345
 
359
346
  /** Utility type for an entity that has a hash property for a txhash */
@@ -153,7 +153,7 @@ export class TxExecutionRequest {
153
153
  FunctionSelector.random(),
154
154
  Fr.random(),
155
155
  TxContext.empty(),
156
- [await HashedValues.random()],
156
+ [HashedValues.random()],
157
157
  [AuthWitness.random()],
158
158
  [
159
159
  new Capsule(await AztecAddress.random(), Fr.random(), [Fr.random(), Fr.random()]),
@@ -1,45 +0,0 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
- /// <reference types="node" resolution-mode="require"/>
4
- import { Fr } from '@aztec/foundation/fields';
5
- import { BufferReader } from '@aztec/foundation/serialize';
6
- import type { FieldsOf } from '@aztec/foundation/types';
7
- import { inspect } from 'util';
8
- import { PublicCallRequest } from '../kernel/public_call_request.js';
9
- import { type ZodFor } from '../schemas/index.js';
10
- import { CallContext } from './call_context.js';
11
- /**
12
- * The execution request of a public function.
13
- */
14
- export declare class PublicExecutionRequest {
15
- /**
16
- * Context of the public call.
17
- */
18
- callContext: CallContext;
19
- /**
20
- * Function arguments.
21
- */
22
- args: Fr[];
23
- constructor(
24
- /**
25
- * Context of the public call.
26
- */
27
- callContext: CallContext,
28
- /**
29
- * Function arguments.
30
- */
31
- args: Fr[]);
32
- getSize(): number;
33
- toBuffer(): Buffer;
34
- static get schema(): ZodFor<PublicExecutionRequest>;
35
- static fromBuffer(buffer: Buffer | BufferReader): PublicExecutionRequest;
36
- static from(fields: FieldsOf<PublicExecutionRequest>): PublicExecutionRequest;
37
- static getFields(fields: FieldsOf<PublicExecutionRequest>): readonly [CallContext, Fr[]];
38
- static empty(): PublicExecutionRequest;
39
- static random(): Promise<PublicExecutionRequest>;
40
- isEmpty(): boolean;
41
- isForCallRequest(callRequest: PublicCallRequest): Promise<boolean>;
42
- toCallRequest(): Promise<PublicCallRequest>;
43
- [inspect.custom](): string;
44
- }
45
- //# sourceMappingURL=public_execution_request.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"public_execution_request.d.ts","sourceRoot":"","sources":["../../src/tx/public_execution_request.ts"],"names":[],"mappings":";;;AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,0BAA0B,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAqB,MAAM,6BAA6B,CAAC;AAC9E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAI/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,EAAE,KAAK,MAAM,EAAW,MAAM,qBAAqB,CAAC;AAE3D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;GAEG;AACH,qBAAa,sBAAsB;IAE/B;;OAEG;IACI,WAAW,EAAE,WAAW;IAC/B;;OAEG;IACI,IAAI,EAAE,EAAE,EAAE;;IAPjB;;OAEG;IACI,WAAW,EAAE,WAAW;IAC/B;;OAEG;IACI,IAAI,EAAE,EAAE,EAAE;IAGnB,OAAO;IAIP,QAAQ;IAIR,MAAM,KAAK,MAAM,IAAI,MAAM,CAAC,sBAAsB,CAAC,CAOlD;IAED,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY;IAK/C,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,sBAAsB,CAAC,GAAG,sBAAsB;IAI7E,MAAM,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,sBAAsB,CAAC;IAIzD,MAAM,CAAC,KAAK;WAIC,MAAM;IAInB,OAAO,IAAI,OAAO;IAIZ,gBAAgB,CAAC,WAAW,EAAE,iBAAiB;IAU/C,aAAa,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAUjD,CAAC,OAAO,CAAC,MAAM,CAAC;CAMjB"}
@@ -1,72 +0,0 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
3
- import { inspect } from 'util';
4
- import { z } from 'zod';
5
- import { computeVarArgsHash } from '../hash/index.js';
6
- import { PublicCallRequest } from '../kernel/public_call_request.js';
7
- import { schemas } from '../schemas/index.js';
8
- import { Vector } from '../types/index.js';
9
- import { CallContext } from './call_context.js';
10
- /**
11
- * The execution request of a public function.
12
- */ export class PublicExecutionRequest {
13
- callContext;
14
- args;
15
- constructor(/**
16
- * Context of the public call.
17
- */ callContext, /**
18
- * Function arguments.
19
- */ args){
20
- this.callContext = callContext;
21
- this.args = args;
22
- }
23
- getSize() {
24
- return this.isEmpty() ? 0 : this.toBuffer().length;
25
- }
26
- toBuffer() {
27
- return serializeToBuffer(this.callContext, new Vector(this.args));
28
- }
29
- static get schema() {
30
- return z.object({
31
- callContext: CallContext.schema,
32
- args: z.array(schemas.Fr)
33
- }).transform(PublicExecutionRequest.from);
34
- }
35
- static fromBuffer(buffer) {
36
- const reader = BufferReader.asReader(buffer);
37
- return new PublicExecutionRequest(CallContext.fromBuffer(reader), reader.readVector(Fr));
38
- }
39
- static from(fields) {
40
- return new PublicExecutionRequest(...PublicExecutionRequest.getFields(fields));
41
- }
42
- static getFields(fields) {
43
- return [
44
- fields.callContext,
45
- fields.args
46
- ];
47
- }
48
- static empty() {
49
- return new PublicExecutionRequest(CallContext.empty(), []);
50
- }
51
- static async random() {
52
- return new PublicExecutionRequest(await CallContext.random(), [
53
- Fr.random(),
54
- Fr.random()
55
- ]);
56
- }
57
- isEmpty() {
58
- return this.callContext.isEmpty() && this.args.length === 0;
59
- }
60
- async isForCallRequest(callRequest) {
61
- return this.callContext.msgSender.equals(callRequest.msgSender) && this.callContext.contractAddress.equals(callRequest.contractAddress) && this.callContext.functionSelector.equals(callRequest.functionSelector) && this.callContext.isStaticCall == callRequest.isStaticCall && (await computeVarArgsHash(this.args)).equals(callRequest.argsHash);
62
- }
63
- async toCallRequest() {
64
- return new PublicCallRequest(this.callContext.msgSender, this.callContext.contractAddress, this.callContext.functionSelector, this.callContext.isStaticCall, await computeVarArgsHash(this.args));
65
- }
66
- [inspect.custom]() {
67
- return `PublicExecutionRequest {
68
- callContext: ${inspect(this.callContext)}
69
- args: ${this.args}
70
- }`;
71
- }
72
- }
@@ -1,97 +0,0 @@
1
- import { Fr } from '@aztec/foundation/fields';
2
- import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
3
- import type { FieldsOf } from '@aztec/foundation/types';
4
-
5
- import { inspect } from 'util';
6
- import { z } from 'zod';
7
-
8
- import { computeVarArgsHash } from '../hash/index.js';
9
- import { PublicCallRequest } from '../kernel/public_call_request.js';
10
- import { type ZodFor, schemas } from '../schemas/index.js';
11
- import { Vector } from '../types/index.js';
12
- import { CallContext } from './call_context.js';
13
-
14
- /**
15
- * The execution request of a public function.
16
- */
17
- export class PublicExecutionRequest {
18
- constructor(
19
- /**
20
- * Context of the public call.
21
- */
22
- public callContext: CallContext,
23
- /**
24
- * Function arguments.
25
- */
26
- public args: Fr[],
27
- ) {}
28
-
29
- getSize() {
30
- return this.isEmpty() ? 0 : this.toBuffer().length;
31
- }
32
-
33
- toBuffer() {
34
- return serializeToBuffer(this.callContext, new Vector(this.args));
35
- }
36
-
37
- static get schema(): ZodFor<PublicExecutionRequest> {
38
- return z
39
- .object({
40
- callContext: CallContext.schema,
41
- args: z.array(schemas.Fr),
42
- })
43
- .transform(PublicExecutionRequest.from);
44
- }
45
-
46
- static fromBuffer(buffer: Buffer | BufferReader) {
47
- const reader = BufferReader.asReader(buffer);
48
- return new PublicExecutionRequest(CallContext.fromBuffer(reader), reader.readVector(Fr));
49
- }
50
-
51
- static from(fields: FieldsOf<PublicExecutionRequest>): PublicExecutionRequest {
52
- return new PublicExecutionRequest(...PublicExecutionRequest.getFields(fields));
53
- }
54
-
55
- static getFields(fields: FieldsOf<PublicExecutionRequest>) {
56
- return [fields.callContext, fields.args] as const;
57
- }
58
-
59
- static empty() {
60
- return new PublicExecutionRequest(CallContext.empty(), []);
61
- }
62
-
63
- static async random() {
64
- return new PublicExecutionRequest(await CallContext.random(), [Fr.random(), Fr.random()]);
65
- }
66
-
67
- isEmpty(): boolean {
68
- return this.callContext.isEmpty() && this.args.length === 0;
69
- }
70
-
71
- async isForCallRequest(callRequest: PublicCallRequest) {
72
- return (
73
- this.callContext.msgSender.equals(callRequest.msgSender) &&
74
- this.callContext.contractAddress.equals(callRequest.contractAddress) &&
75
- this.callContext.functionSelector.equals(callRequest.functionSelector) &&
76
- this.callContext.isStaticCall == callRequest.isStaticCall &&
77
- (await computeVarArgsHash(this.args)).equals(callRequest.argsHash)
78
- );
79
- }
80
-
81
- async toCallRequest(): Promise<PublicCallRequest> {
82
- return new PublicCallRequest(
83
- this.callContext.msgSender,
84
- this.callContext.contractAddress,
85
- this.callContext.functionSelector,
86
- this.callContext.isStaticCall,
87
- await computeVarArgsHash(this.args),
88
- );
89
- }
90
-
91
- [inspect.custom]() {
92
- return `PublicExecutionRequest {
93
- callContext: ${inspect(this.callContext)}
94
- args: ${this.args}
95
- }`;
96
- }
97
- }