@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.
- package/dest/avm/avm.d.ts +24 -48
- package/dest/avm/avm.d.ts.map +1 -1
- package/dest/avm/avm_circuit_public_inputs.d.ts +18 -36
- package/dest/avm/avm_circuit_public_inputs.d.ts.map +1 -1
- package/dest/avm/avm_proving_request.d.ts +27 -54
- package/dest/avm/avm_proving_request.d.ts.map +1 -1
- package/dest/contract/contract_class.d.ts.map +1 -1
- package/dest/contract/contract_class.js +3 -21
- package/dest/contract/interfaces/contract_class.d.ts +1 -143
- package/dest/contract/interfaces/contract_class.d.ts.map +1 -1
- package/dest/contract/interfaces/contract_class.js +0 -5
- package/dest/contract/interfaces/contract_data_source.d.ts +3 -3
- package/dest/contract/interfaces/contract_data_source.d.ts.map +1 -1
- package/dest/hash/hash.d.ts +8 -1
- package/dest/hash/hash.d.ts.map +1 -1
- package/dest/hash/hash.js +12 -1
- package/dest/interfaces/archiver.d.ts.map +1 -1
- package/dest/interfaces/archiver.js +1 -1
- package/dest/interfaces/prover-client.js +1 -1
- package/dest/interfaces/proving-job.d.ts +27 -54
- package/dest/interfaces/proving-job.d.ts.map +1 -1
- package/dest/kernel/public_call_request.d.ts +14 -19
- package/dest/kernel/public_call_request.d.ts.map +1 -1
- package/dest/kernel/public_call_request.js +19 -20
- package/dest/stats/stats.d.ts +1 -1
- package/dest/stats/stats.d.ts.map +1 -1
- package/dest/tests/factories.d.ts +2 -2
- package/dest/tests/factories.d.ts.map +1 -1
- package/dest/tests/factories.js +3 -13
- package/dest/tests/mocks.d.ts +3 -4
- package/dest/tests/mocks.d.ts.map +1 -1
- package/dest/tests/mocks.js +13 -48
- package/dest/tx/call_context.d.ts +1 -1
- package/dest/tx/hashed_values.d.ts +16 -4
- package/dest/tx/hashed_values.d.ts.map +1 -1
- package/dest/tx/hashed_values.js +26 -9
- package/dest/tx/index.d.ts +1 -1
- package/dest/tx/index.d.ts.map +1 -1
- package/dest/tx/index.js +1 -1
- package/dest/tx/private_execution_result.d.ts +6 -26
- package/dest/tx/private_execution_result.d.ts.map +1 -1
- package/dest/tx/private_execution_result.js +13 -70
- package/dest/tx/proven_tx.d.ts.map +1 -1
- package/dest/tx/proven_tx.js +2 -4
- package/dest/tx/public_call_request_with_calldata.d.ts +41 -0
- package/dest/tx/public_call_request_with_calldata.d.ts.map +1 -0
- package/dest/tx/public_call_request_with_calldata.js +57 -0
- package/dest/tx/simulated_tx.d.ts.map +1 -1
- package/dest/tx/simulated_tx.js +2 -4
- package/dest/tx/tx.d.ts +16 -20
- package/dest/tx/tx.d.ts.map +1 -1
- package/dest/tx/tx.js +56 -42
- package/dest/tx/tx_execution_request.js +1 -1
- package/package.json +6 -6
- package/src/contract/contract_class.ts +7 -26
- package/src/contract/interfaces/contract_class.ts +2 -18
- package/src/contract/interfaces/contract_data_source.ts +3 -3
- package/src/hash/hash.ts +15 -1
- package/src/interfaces/archiver.ts +1 -4
- package/src/interfaces/prover-client.ts +1 -1
- package/src/kernel/public_call_request.ts +22 -27
- package/src/stats/stats.ts +1 -1
- package/src/tests/factories.ts +3 -24
- package/src/tests/mocks.ts +28 -80
- package/src/tx/hashed_values.ts +29 -9
- package/src/tx/index.ts +1 -1
- package/src/tx/private_execution_result.ts +9 -81
- package/src/tx/proven_tx.ts +2 -10
- package/src/tx/public_call_request_with_calldata.ts +72 -0
- package/src/tx/simulated_tx.ts +1 -6
- package/src/tx/tx.ts +57 -70
- package/src/tx/tx_execution_request.ts +1 -1
- package/dest/tx/public_execution_request.d.ts +0 -45
- package/dest/tx/public_execution_request.d.ts.map +0 -1
- package/dest/tx/public_execution_request.js +0 -72
- package/src/tx/public_execution_request.ts +0 -97
package/src/tests/mocks.ts
CHANGED
|
@@ -11,7 +11,6 @@ import { SerializableContractInstance } from '../contract/contract_instance.js';
|
|
|
11
11
|
import type { ContractInstanceWithAddress } from '../contract/index.js';
|
|
12
12
|
import { GasFees } from '../gas/gas_fees.js';
|
|
13
13
|
import { GasSettings } from '../gas/gas_settings.js';
|
|
14
|
-
import { computeVarArgsHash } from '../hash/hash.js';
|
|
15
14
|
import { Nullifier } from '../kernel/nullifier.js';
|
|
16
15
|
import { PrivateCircuitPublicInputs } from '../kernel/private_circuit_public_inputs.js';
|
|
17
16
|
import {
|
|
@@ -26,15 +25,7 @@ import { BlockProposal } from '../p2p/block_proposal.js';
|
|
|
26
25
|
import { ConsensusPayload } from '../p2p/consensus_payload.js';
|
|
27
26
|
import { SignatureDomainSeparator, getHashedSignaturePayloadEthSignedMessage } from '../p2p/signature_utils.js';
|
|
28
27
|
import { ClientIvcProof } from '../proofs/client_ivc_proof.js';
|
|
29
|
-
import {
|
|
30
|
-
BlockHeader,
|
|
31
|
-
CallContext,
|
|
32
|
-
CountedPublicExecutionRequest,
|
|
33
|
-
PrivateCallExecutionResult,
|
|
34
|
-
PrivateExecutionResult,
|
|
35
|
-
PublicExecutionRequest,
|
|
36
|
-
Tx,
|
|
37
|
-
} from '../tx/index.js';
|
|
28
|
+
import { BlockHeader, HashedValues, PrivateCallExecutionResult, PrivateExecutionResult, Tx } from '../tx/index.js';
|
|
38
29
|
import { PublicSimulationOutput } from '../tx/public_simulation_output.js';
|
|
39
30
|
import { TxSimulationResult, accumulatePrivateReturnValues } from '../tx/simulated_tx.js';
|
|
40
31
|
import { TxEffect } from '../tx/tx_effect.js';
|
|
@@ -77,70 +68,20 @@ export const randomUniqueNote = async ({
|
|
|
77
68
|
);
|
|
78
69
|
};
|
|
79
70
|
|
|
80
|
-
export const mockPrivateCallExecutionResult = async (
|
|
81
|
-
seed = 1,
|
|
82
|
-
numberOfNonRevertiblePublicCallRequests = MAX_ENQUEUED_CALLS_PER_TX / 2,
|
|
83
|
-
numberOfRevertiblePublicCallRequests = MAX_ENQUEUED_CALLS_PER_TX / 2,
|
|
84
|
-
hasPublicTeardownCallRequest = false,
|
|
85
|
-
) => {
|
|
86
|
-
const totalPublicCallRequests =
|
|
87
|
-
numberOfNonRevertiblePublicCallRequests +
|
|
88
|
-
numberOfRevertiblePublicCallRequests +
|
|
89
|
-
(hasPublicTeardownCallRequest ? 1 : 0);
|
|
90
|
-
const isForPublic = totalPublicCallRequests > 0;
|
|
91
|
-
let enqueuedPublicFunctionCalls: PublicExecutionRequest[] = [];
|
|
92
|
-
let publicTeardownFunctionCall = PublicExecutionRequest.empty();
|
|
93
|
-
if (isForPublic) {
|
|
94
|
-
const publicCallRequests = times(totalPublicCallRequests, i => makePublicCallRequest(seed + 0x102 + i)).reverse(); // Reverse it so that they are sorted by counters in descending order.
|
|
95
|
-
const publicFunctionArgs = times(totalPublicCallRequests, i => [new Fr(seed + i * 100), new Fr(seed + i * 101)]);
|
|
96
|
-
for (let i = 0; i < publicCallRequests.length; i++) {
|
|
97
|
-
const r = publicCallRequests[i];
|
|
98
|
-
r.argsHash = await computeVarArgsHash(publicFunctionArgs[i]);
|
|
99
|
-
i++;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
if (hasPublicTeardownCallRequest) {
|
|
103
|
-
const request = publicCallRequests.shift()!;
|
|
104
|
-
const args = publicFunctionArgs.shift()!;
|
|
105
|
-
publicTeardownFunctionCall = new PublicExecutionRequest(CallContext.fromFields(request.toFields()), args);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
enqueuedPublicFunctionCalls = publicCallRequests.map(
|
|
109
|
-
(r, i) => new PublicExecutionRequest(CallContext.fromFields(r.toFields()), publicFunctionArgs[i]),
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
return new PrivateCallExecutionResult(
|
|
113
|
-
Buffer.from(''),
|
|
114
|
-
Buffer.from(''),
|
|
115
|
-
new Map(),
|
|
116
|
-
PrivateCircuitPublicInputs.empty(),
|
|
117
|
-
new Map(),
|
|
118
|
-
[],
|
|
119
|
-
new Map(),
|
|
120
|
-
[],
|
|
121
|
-
[],
|
|
122
|
-
enqueuedPublicFunctionCalls.map((call, index) => new CountedPublicExecutionRequest(call, index)),
|
|
123
|
-
publicTeardownFunctionCall,
|
|
124
|
-
[],
|
|
125
|
-
);
|
|
126
|
-
};
|
|
127
|
-
|
|
128
|
-
export const mockPrivateExecutionResult = async (seed = 1) => {
|
|
129
|
-
return new PrivateExecutionResult(await mockPrivateCallExecutionResult(seed), Fr.zero());
|
|
130
|
-
};
|
|
131
|
-
|
|
132
71
|
export const mockTx = async (
|
|
133
72
|
seed = 1,
|
|
134
73
|
{
|
|
135
74
|
numberOfNonRevertiblePublicCallRequests = MAX_ENQUEUED_CALLS_PER_TX / 2,
|
|
136
75
|
numberOfRevertiblePublicCallRequests = MAX_ENQUEUED_CALLS_PER_TX / 2,
|
|
137
76
|
hasPublicTeardownCallRequest = false,
|
|
77
|
+
publicCalldataSize = 2,
|
|
138
78
|
feePayer,
|
|
139
79
|
clientIvcProof = ClientIvcProof.empty(),
|
|
140
80
|
}: {
|
|
141
81
|
numberOfNonRevertiblePublicCallRequests?: number;
|
|
142
82
|
numberOfRevertiblePublicCallRequests?: number;
|
|
143
83
|
hasPublicTeardownCallRequest?: boolean;
|
|
84
|
+
publicCalldataSize?: number;
|
|
144
85
|
feePayer?: AztecAddress;
|
|
145
86
|
clientIvcProof?: ClientIvcProof;
|
|
146
87
|
} = {},
|
|
@@ -155,8 +96,7 @@ export const mockTx = async (
|
|
|
155
96
|
data.constants.txContext.gasSettings = GasSettings.default({ maxFeesPerGas: new GasFees(10, 10) });
|
|
156
97
|
data.feePayer = feePayer ?? (await AztecAddress.random());
|
|
157
98
|
|
|
158
|
-
|
|
159
|
-
let publicTeardownFunctionCall = PublicExecutionRequest.empty();
|
|
99
|
+
const publicFunctionCalldata: HashedValues[] = [];
|
|
160
100
|
if (!isForPublic) {
|
|
161
101
|
data.forRollup!.end.nullifiers[0] = firstNullifier.value;
|
|
162
102
|
} else {
|
|
@@ -166,24 +106,18 @@ export const mockTx = async (
|
|
|
166
106
|
const revertibleBuilder = new PrivateToPublicAccumulatedDataBuilder();
|
|
167
107
|
const nonRevertibleBuilder = new PrivateToPublicAccumulatedDataBuilder();
|
|
168
108
|
|
|
169
|
-
const publicCallRequests = times(totalPublicCallRequests, i => makePublicCallRequest(seed + 0x102 + i))
|
|
170
|
-
const
|
|
109
|
+
const publicCallRequests = times(totalPublicCallRequests, i => makePublicCallRequest(seed + 0x102 + i));
|
|
110
|
+
const calldata = times(totalPublicCallRequests, i => times(publicCalldataSize, j => new Fr(seed + (i * 13 + j))));
|
|
171
111
|
for (let i = 0; i < publicCallRequests.length; i++) {
|
|
172
|
-
const
|
|
173
|
-
|
|
112
|
+
const hashedCalldata = await HashedValues.fromCalldata(calldata[i]);
|
|
113
|
+
publicFunctionCalldata.push(hashedCalldata);
|
|
114
|
+
publicCallRequests[i].calldataHash = hashedCalldata.hash;
|
|
174
115
|
}
|
|
175
116
|
|
|
176
117
|
if (hasPublicTeardownCallRequest) {
|
|
177
|
-
|
|
178
|
-
data.forPublic.publicTeardownCallRequest = request;
|
|
179
|
-
const args = publicFunctionArgs.shift()!;
|
|
180
|
-
publicTeardownFunctionCall = new PublicExecutionRequest(CallContext.fromFields(request.toFields()), args);
|
|
118
|
+
data.forPublic.publicTeardownCallRequest = publicCallRequests.pop()!;
|
|
181
119
|
}
|
|
182
120
|
|
|
183
|
-
enqueuedPublicFunctionCalls = publicCallRequests.map(
|
|
184
|
-
(r, i) => new PublicExecutionRequest(CallContext.fromFields(r.toFields()), publicFunctionArgs[i]),
|
|
185
|
-
);
|
|
186
|
-
|
|
187
121
|
data.forPublic.nonRevertibleAccumulatedData = nonRevertibleBuilder
|
|
188
122
|
.pushNullifier(firstNullifier.value)
|
|
189
123
|
.withPublicCallRequests(publicCallRequests.slice(numberOfRevertiblePublicCallRequests))
|
|
@@ -194,16 +128,30 @@ export const mockTx = async (
|
|
|
194
128
|
.build();
|
|
195
129
|
}
|
|
196
130
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
return tx;
|
|
131
|
+
return new Tx(data, clientIvcProof, [], publicFunctionCalldata);
|
|
200
132
|
};
|
|
201
133
|
|
|
202
134
|
export const mockTxForRollup = (seed = 1) =>
|
|
203
135
|
mockTx(seed, { numberOfNonRevertiblePublicCallRequests: 0, numberOfRevertiblePublicCallRequests: 0 });
|
|
204
136
|
|
|
137
|
+
const emptyPrivateCallExecutionResult = () =>
|
|
138
|
+
new PrivateCallExecutionResult(
|
|
139
|
+
Buffer.from(''),
|
|
140
|
+
Buffer.from(''),
|
|
141
|
+
new Map(),
|
|
142
|
+
PrivateCircuitPublicInputs.empty(),
|
|
143
|
+
new Map(),
|
|
144
|
+
[],
|
|
145
|
+
new Map(),
|
|
146
|
+
[],
|
|
147
|
+
[],
|
|
148
|
+
[],
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const emptyPrivateExecutionResult = () => new PrivateExecutionResult(emptyPrivateCallExecutionResult(), Fr.zero(), []);
|
|
152
|
+
|
|
205
153
|
export const mockSimulatedTx = async (seed = 1) => {
|
|
206
|
-
const privateExecutionResult =
|
|
154
|
+
const privateExecutionResult = emptyPrivateExecutionResult();
|
|
207
155
|
const tx = await mockTx(seed);
|
|
208
156
|
const output = new PublicSimulationOutput(
|
|
209
157
|
undefined,
|
package/src/tx/hashed_values.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
2
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
3
|
+
import type { FieldsOf } from '@aztec/foundation/types';
|
|
3
4
|
|
|
4
5
|
import { z } from 'zod';
|
|
5
6
|
|
|
6
|
-
import { computeVarArgsHash } from '../hash/index.js';
|
|
7
|
+
import { computeCalldataHash, computeVarArgsHash } from '../hash/index.js';
|
|
7
8
|
import { type ZodFor, schemas } from '../schemas/schemas.js';
|
|
8
9
|
import { Vector } from '../types/index.js';
|
|
9
10
|
|
|
@@ -11,7 +12,7 @@ import { Vector } from '../types/index.js';
|
|
|
11
12
|
* A container for storing a list of values and their hash.
|
|
12
13
|
*/
|
|
13
14
|
export class HashedValues {
|
|
14
|
-
|
|
15
|
+
constructor(
|
|
15
16
|
/**
|
|
16
17
|
* Raw values.
|
|
17
18
|
*/
|
|
@@ -22,20 +23,29 @@ export class HashedValues {
|
|
|
22
23
|
public readonly hash: Fr,
|
|
23
24
|
) {}
|
|
24
25
|
|
|
26
|
+
getSize() {
|
|
27
|
+
return this.values.length + 1 /* hash */;
|
|
28
|
+
}
|
|
29
|
+
|
|
25
30
|
static get schema(): ZodFor<HashedValues> {
|
|
26
|
-
return z
|
|
31
|
+
return z
|
|
32
|
+
.object({
|
|
33
|
+
values: z.array(schemas.Fr),
|
|
34
|
+
hash: schemas.Fr,
|
|
35
|
+
})
|
|
36
|
+
.transform(HashedValues.from);
|
|
27
37
|
}
|
|
28
38
|
|
|
29
|
-
|
|
30
|
-
return
|
|
39
|
+
static from(fields: FieldsOf<HashedValues>): HashedValues {
|
|
40
|
+
return new HashedValues(...HashedValues.getFields(fields));
|
|
31
41
|
}
|
|
32
42
|
|
|
33
|
-
static
|
|
34
|
-
return
|
|
43
|
+
static getFields(fields: FieldsOf<HashedValues>) {
|
|
44
|
+
return [fields.values, fields.hash] as const;
|
|
35
45
|
}
|
|
36
46
|
|
|
37
|
-
static
|
|
38
|
-
return new HashedValues(
|
|
47
|
+
static random() {
|
|
48
|
+
return new HashedValues([Fr.random(), Fr.random()], Fr.random());
|
|
39
49
|
}
|
|
40
50
|
|
|
41
51
|
toBuffer() {
|
|
@@ -46,4 +56,14 @@ export class HashedValues {
|
|
|
46
56
|
const reader = BufferReader.asReader(buffer);
|
|
47
57
|
return new HashedValues(reader.readVector(Fr), Fr.fromBuffer(reader));
|
|
48
58
|
}
|
|
59
|
+
|
|
60
|
+
// Computes the hash of input arguments or return values for private functions, or for authwit creation.
|
|
61
|
+
static async fromArgs(args: Fr[]) {
|
|
62
|
+
return new HashedValues(args, await computeVarArgsHash(args));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Computes the hash of calldata for public functions.
|
|
66
|
+
static async fromCalldata(calldata: Fr[]) {
|
|
67
|
+
return new HashedValues(calldata, await computeCalldataHash(calldata));
|
|
68
|
+
}
|
|
49
69
|
}
|
package/src/tx/index.ts
CHANGED
|
@@ -11,7 +11,7 @@ export * from './tx_constant_data.js';
|
|
|
11
11
|
export * from './tx_context.js';
|
|
12
12
|
export * from './tx_request.js';
|
|
13
13
|
export * from './private_execution_result.js';
|
|
14
|
-
export * from './
|
|
14
|
+
export * from './public_call_request_with_calldata.js';
|
|
15
15
|
export * from './tx_hash.js';
|
|
16
16
|
export * from './tx_receipt.js';
|
|
17
17
|
export * from './tx.js';
|
|
@@ -12,7 +12,7 @@ import { sortByCounter } from '../kernel/utils/order_and_comparison.js';
|
|
|
12
12
|
import { ContractClassLog } from '../logs/contract_class_log.js';
|
|
13
13
|
import { Note } from '../note/note.js';
|
|
14
14
|
import { type ZodFor, mapSchema, schemas } from '../schemas/index.js';
|
|
15
|
-
import {
|
|
15
|
+
import { HashedValues } from './hashed_values.js';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* The contents of a new note.
|
|
@@ -67,36 +67,13 @@ export class CountedContractClassLog implements IsEmpty {
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
export class CountedPublicExecutionRequest {
|
|
71
|
-
constructor(public request: PublicExecutionRequest, public counter: number) {}
|
|
72
|
-
|
|
73
|
-
static get schema(): ZodFor<CountedPublicExecutionRequest> {
|
|
74
|
-
return z
|
|
75
|
-
.object({
|
|
76
|
-
request: PublicExecutionRequest.schema,
|
|
77
|
-
counter: schemas.Integer,
|
|
78
|
-
})
|
|
79
|
-
.transform(CountedPublicExecutionRequest.from);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
static from(fields: FieldsOf<CountedPublicExecutionRequest>) {
|
|
83
|
-
return new CountedPublicExecutionRequest(fields.request, fields.counter);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
isEmpty(): boolean {
|
|
87
|
-
return this.request.isEmpty() && !this.counter;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
static async random() {
|
|
91
|
-
return new CountedPublicExecutionRequest(await PublicExecutionRequest.random(), 0);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
70
|
export class PrivateExecutionResult {
|
|
96
71
|
constructor(
|
|
97
72
|
public entrypoint: PrivateCallExecutionResult,
|
|
98
73
|
/** The first non revertible nullifier, or zero if there was none. */
|
|
99
74
|
public firstNullifier: Fr,
|
|
75
|
+
/** An array of calldata for the enqueued public function calls and the teardown function call. */
|
|
76
|
+
public publicFunctionCalldata: HashedValues[],
|
|
100
77
|
) {}
|
|
101
78
|
|
|
102
79
|
static get schema(): ZodFor<PrivateExecutionResult> {
|
|
@@ -104,16 +81,20 @@ export class PrivateExecutionResult {
|
|
|
104
81
|
.object({
|
|
105
82
|
entrypoint: PrivateCallExecutionResult.schema,
|
|
106
83
|
firstNullifier: schemas.Fr,
|
|
84
|
+
publicFunctionCalldata: z.array(HashedValues.schema),
|
|
107
85
|
})
|
|
108
86
|
.transform(PrivateExecutionResult.from);
|
|
109
87
|
}
|
|
110
88
|
|
|
111
89
|
static from(fields: FieldsOf<PrivateExecutionResult>) {
|
|
112
|
-
return new PrivateExecutionResult(fields.entrypoint, fields.firstNullifier);
|
|
90
|
+
return new PrivateExecutionResult(fields.entrypoint, fields.firstNullifier, fields.publicFunctionCalldata);
|
|
113
91
|
}
|
|
114
92
|
|
|
115
93
|
static async random(nested = 1): Promise<PrivateExecutionResult> {
|
|
116
|
-
return new PrivateExecutionResult(await PrivateCallExecutionResult.random(nested), Fr.random()
|
|
94
|
+
return new PrivateExecutionResult(await PrivateCallExecutionResult.random(nested), Fr.random(), [
|
|
95
|
+
HashedValues.random(),
|
|
96
|
+
HashedValues.random(),
|
|
97
|
+
]);
|
|
117
98
|
}
|
|
118
99
|
|
|
119
100
|
/**
|
|
@@ -149,10 +130,6 @@ export class PrivateCallExecutionResult {
|
|
|
149
130
|
public returnValues: Fr[],
|
|
150
131
|
/** The nested executions. */
|
|
151
132
|
public nestedExecutions: PrivateCallExecutionResult[],
|
|
152
|
-
/** Enqueued public function execution requests to be picked up by the sequencer. */
|
|
153
|
-
public enqueuedPublicFunctionCalls: CountedPublicExecutionRequest[],
|
|
154
|
-
/** Public function execution requested for teardown */
|
|
155
|
-
public publicTeardownFunctionCall: PublicExecutionRequest,
|
|
156
133
|
/**
|
|
157
134
|
* Contract class logs emitted during execution of this function call.
|
|
158
135
|
* Note: These are preimages to `contractClassLogsHashes`.
|
|
@@ -172,8 +149,6 @@ export class PrivateCallExecutionResult {
|
|
|
172
149
|
noteHashNullifierCounterMap: mapSchema(z.coerce.number(), z.number()),
|
|
173
150
|
returnValues: z.array(schemas.Fr),
|
|
174
151
|
nestedExecutions: z.array(z.lazy(() => PrivateCallExecutionResult.schema)),
|
|
175
|
-
enqueuedPublicFunctionCalls: z.array(CountedPublicExecutionRequest.schema),
|
|
176
|
-
publicTeardownFunctionCall: PublicExecutionRequest.schema,
|
|
177
152
|
contractClassLogs: z.array(CountedContractClassLog.schema),
|
|
178
153
|
})
|
|
179
154
|
.transform(PrivateCallExecutionResult.from);
|
|
@@ -190,8 +165,6 @@ export class PrivateCallExecutionResult {
|
|
|
190
165
|
fields.noteHashNullifierCounterMap,
|
|
191
166
|
fields.returnValues,
|
|
192
167
|
fields.nestedExecutions,
|
|
193
|
-
fields.enqueuedPublicFunctionCalls,
|
|
194
|
-
fields.publicTeardownFunctionCall,
|
|
195
168
|
fields.contractClassLogs,
|
|
196
169
|
);
|
|
197
170
|
}
|
|
@@ -207,8 +180,6 @@ export class PrivateCallExecutionResult {
|
|
|
207
180
|
new Map([[0, 0]]),
|
|
208
181
|
[Fr.random()],
|
|
209
182
|
await timesParallel(nested, () => PrivateCallExecutionResult.random(0)),
|
|
210
|
-
[await CountedPublicExecutionRequest.random()],
|
|
211
|
-
await PublicExecutionRequest.random(),
|
|
212
183
|
[new CountedContractClassLog(await ContractClassLog.random(), randomInt(10))],
|
|
213
184
|
);
|
|
214
185
|
}
|
|
@@ -257,49 +228,6 @@ export function collectSortedContractClassLogs(execResult: PrivateExecutionResul
|
|
|
257
228
|
return sortedLogs.map(l => l.log);
|
|
258
229
|
}
|
|
259
230
|
|
|
260
|
-
function collectEnqueuedCountedPublicExecutionRequests(
|
|
261
|
-
execResult: PrivateCallExecutionResult,
|
|
262
|
-
): CountedPublicExecutionRequest[] {
|
|
263
|
-
return [
|
|
264
|
-
...execResult.enqueuedPublicFunctionCalls,
|
|
265
|
-
...execResult.nestedExecutions.flatMap(collectEnqueuedCountedPublicExecutionRequests),
|
|
266
|
-
];
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Collect all enqueued public function calls across all nested executions.
|
|
271
|
-
* @param execResult - The topmost execution result.
|
|
272
|
-
* @returns All enqueued public function calls.
|
|
273
|
-
*/
|
|
274
|
-
export function collectEnqueuedPublicFunctionCalls(execResult: PrivateExecutionResult): PublicExecutionRequest[] {
|
|
275
|
-
const countedRequests = collectEnqueuedCountedPublicExecutionRequests(execResult.entrypoint);
|
|
276
|
-
// without the reverse sort, the logs will be in a queue like fashion which is wrong
|
|
277
|
-
// as the kernel processes it like a stack, popping items off and pushing them to output
|
|
278
|
-
return sortByCounter(countedRequests, false).map(r => r.request);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
export function collectPublicTeardownFunctionCall(execResult: PrivateExecutionResult): PublicExecutionRequest {
|
|
282
|
-
const collectPublicTeardownFunctionCallRecursive = (
|
|
283
|
-
callResult: PrivateCallExecutionResult,
|
|
284
|
-
): PublicExecutionRequest[] => {
|
|
285
|
-
return [
|
|
286
|
-
callResult.publicTeardownFunctionCall,
|
|
287
|
-
...callResult.nestedExecutions.flatMap(collectPublicTeardownFunctionCallRecursive),
|
|
288
|
-
].filter(call => !call.isEmpty());
|
|
289
|
-
};
|
|
290
|
-
const teardownCalls = collectPublicTeardownFunctionCallRecursive(execResult.entrypoint);
|
|
291
|
-
|
|
292
|
-
if (teardownCalls.length === 1) {
|
|
293
|
-
return teardownCalls[0];
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
if (teardownCalls.length > 1) {
|
|
297
|
-
throw new Error('Multiple public teardown calls detected');
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
return PublicExecutionRequest.empty();
|
|
301
|
-
}
|
|
302
|
-
|
|
303
231
|
export function getFinalMinRevertibleSideEffectCounter(execResult: PrivateExecutionResult): number {
|
|
304
232
|
const collectFinalMinRevertibleSideEffectCounterRecursive = (callResult: PrivateCallExecutionResult): number => {
|
|
305
233
|
return callResult.nestedExecutions.reduce((counter, exec) => {
|
package/src/tx/proven_tx.ts
CHANGED
|
@@ -4,12 +4,7 @@ import { z } from 'zod';
|
|
|
4
4
|
|
|
5
5
|
import { PrivateKernelTailCircuitPublicInputs } from '../kernel/private_kernel_tail_circuit_public_inputs.js';
|
|
6
6
|
import { ClientIvcProof } from '../proofs/client_ivc_proof.js';
|
|
7
|
-
import {
|
|
8
|
-
PrivateExecutionResult,
|
|
9
|
-
collectEnqueuedPublicFunctionCalls,
|
|
10
|
-
collectPublicTeardownFunctionCall,
|
|
11
|
-
collectSortedContractClassLogs,
|
|
12
|
-
} from './private_execution_result.js';
|
|
7
|
+
import { PrivateExecutionResult, collectSortedContractClassLogs } from './private_execution_result.js';
|
|
13
8
|
import { Tx } from './tx.js';
|
|
14
9
|
|
|
15
10
|
export class TxProvingResult {
|
|
@@ -21,15 +16,12 @@ export class TxProvingResult {
|
|
|
21
16
|
|
|
22
17
|
toTx(): Tx {
|
|
23
18
|
const contractClassLogs = collectSortedContractClassLogs(this.privateExecutionResult);
|
|
24
|
-
const enqueuedPublicFunctions = collectEnqueuedPublicFunctionCalls(this.privateExecutionResult);
|
|
25
|
-
const teardownPublicFunction = collectPublicTeardownFunctionCall(this.privateExecutionResult);
|
|
26
19
|
|
|
27
20
|
const tx = new Tx(
|
|
28
21
|
this.publicInputs,
|
|
29
22
|
this.clientIvcProof,
|
|
30
23
|
contractClassLogs,
|
|
31
|
-
|
|
32
|
-
teardownPublicFunction,
|
|
24
|
+
this.privateExecutionResult.publicFunctionCalldata,
|
|
33
25
|
);
|
|
34
26
|
return tx;
|
|
35
27
|
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Fr } from '@aztec/foundation/fields';
|
|
2
|
+
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
3
|
+
|
|
4
|
+
import { inspect } from 'util';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
|
|
7
|
+
import { FunctionSelector } from '../abi/function_selector.js';
|
|
8
|
+
import { PublicCallRequest } from '../kernel/public_call_request.js';
|
|
9
|
+
import { type ZodFor, schemas } from '../schemas/index.js';
|
|
10
|
+
import { Vector } from '../types/index.js';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The call request of a public function, including the calldata.
|
|
14
|
+
*/
|
|
15
|
+
export class PublicCallRequestWithCalldata {
|
|
16
|
+
constructor(
|
|
17
|
+
/**
|
|
18
|
+
* Request of the public call.
|
|
19
|
+
*/
|
|
20
|
+
public request: PublicCallRequest,
|
|
21
|
+
/**
|
|
22
|
+
* Function selector and arguments of the public call.
|
|
23
|
+
*/
|
|
24
|
+
public calldata: Fr[],
|
|
25
|
+
) {}
|
|
26
|
+
|
|
27
|
+
// Public functions get routed through the dispatch function, whose first argument is the target function selector.
|
|
28
|
+
get functionSelector(): FunctionSelector {
|
|
29
|
+
return FunctionSelector.fromField(this.calldata[0]);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get args(): Fr[] {
|
|
33
|
+
return this.calldata.slice(1);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
static get schema(): ZodFor<PublicCallRequestWithCalldata> {
|
|
37
|
+
return z
|
|
38
|
+
.object({
|
|
39
|
+
request: PublicCallRequest.schema,
|
|
40
|
+
calldata: z.array(schemas.Fr),
|
|
41
|
+
})
|
|
42
|
+
.transform(PublicCallRequestWithCalldata.from);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static from(fields: Pick<PublicCallRequestWithCalldata, 'request' | 'calldata'>): PublicCallRequestWithCalldata {
|
|
46
|
+
return new PublicCallRequestWithCalldata(fields.request, fields.calldata);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
toBuffer() {
|
|
50
|
+
return serializeToBuffer(this.request, new Vector(this.calldata));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static fromBuffer(buffer: Buffer | BufferReader) {
|
|
54
|
+
const reader = BufferReader.asReader(buffer);
|
|
55
|
+
return new PublicCallRequestWithCalldata(PublicCallRequest.fromBuffer(reader), reader.readVector(Fr));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static empty() {
|
|
59
|
+
return new PublicCallRequestWithCalldata(PublicCallRequest.empty(), []);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
isEmpty(): boolean {
|
|
63
|
+
return this.request.isEmpty() && this.calldata.length === 0;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
[inspect.custom]() {
|
|
67
|
+
return `PublicCallRequestWithCalldata {
|
|
68
|
+
request: ${inspect(this.request)}
|
|
69
|
+
calldata: ${this.calldata}
|
|
70
|
+
}`;
|
|
71
|
+
}
|
|
72
|
+
}
|
package/src/tx/simulated_tx.ts
CHANGED
|
@@ -10,8 +10,6 @@ import { ClientIvcProof } from '../proofs/client_ivc_proof.js';
|
|
|
10
10
|
import {
|
|
11
11
|
PrivateCallExecutionResult,
|
|
12
12
|
PrivateExecutionResult,
|
|
13
|
-
collectEnqueuedPublicFunctionCalls,
|
|
14
|
-
collectPublicTeardownFunctionCall,
|
|
15
13
|
collectSortedContractClassLogs,
|
|
16
14
|
} from './private_execution_result.js';
|
|
17
15
|
import { NestedProcessReturnValues, PublicSimulationOutput } from './public_simulation_output.js';
|
|
@@ -29,15 +27,12 @@ export class PrivateSimulationResult {
|
|
|
29
27
|
|
|
30
28
|
toSimulatedTx(): Tx {
|
|
31
29
|
const contractClassLogs = collectSortedContractClassLogs(this.privateExecutionResult);
|
|
32
|
-
const enqueuedPublicFunctions = collectEnqueuedPublicFunctionCalls(this.privateExecutionResult);
|
|
33
|
-
const teardownPublicFunction = collectPublicTeardownFunctionCall(this.privateExecutionResult);
|
|
34
30
|
|
|
35
31
|
const tx = new Tx(
|
|
36
32
|
this.publicInputs,
|
|
37
33
|
ClientIvcProof.empty(),
|
|
38
34
|
contractClassLogs,
|
|
39
|
-
|
|
40
|
-
teardownPublicFunction,
|
|
35
|
+
this.privateExecutionResult.publicFunctionCalldata,
|
|
41
36
|
);
|
|
42
37
|
return tx;
|
|
43
38
|
}
|