@aztec/stdlib 0.0.1-commit.9b94fc1 → 0.0.1-commit.d3ec352c
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 +187 -24
- package/dest/avm/avm.d.ts.map +1 -1
- package/dest/avm/avm.js +174 -20
- package/dest/avm/avm_circuit_public_inputs.d.ts +5 -3
- package/dest/avm/avm_circuit_public_inputs.d.ts.map +1 -1
- package/dest/avm/avm_proving_request.d.ts +9 -5
- package/dest/avm/avm_proving_request.d.ts.map +1 -1
- package/dest/block/block_parameter.d.ts +5 -0
- package/dest/block/block_parameter.d.ts.map +1 -0
- package/dest/block/block_parameter.js +6 -0
- package/dest/block/in_block.d.ts +12 -9
- package/dest/block/in_block.d.ts.map +1 -1
- package/dest/block/in_block.js +3 -3
- package/dest/block/index.d.ts +1 -1
- package/dest/block/index.js +1 -1
- package/dest/block/l2_block.d.ts +5 -5
- package/dest/block/l2_block.d.ts.map +1 -1
- package/dest/block/l2_block.js +3 -2
- package/dest/block/l2_block_code_to_purge.js +3 -3
- package/dest/block/l2_block_header.d.ts +3 -3
- package/dest/block/l2_block_header.d.ts.map +1 -1
- package/dest/block/l2_block_info.d.ts +15 -10
- package/dest/block/l2_block_info.d.ts.map +1 -1
- package/dest/block/l2_block_info.js +7 -6
- package/dest/block/l2_block_new.d.ts +6 -4
- package/dest/block/l2_block_new.d.ts.map +1 -1
- package/dest/block/l2_block_new.js +4 -1
- package/dest/block/l2_block_source.d.ts +63 -97
- package/dest/block/l2_block_source.d.ts.map +1 -1
- package/dest/block/l2_block_source.js +5 -11
- package/dest/block/l2_block_stream/l2_block_stream.d.ts +1 -1
- package/dest/block/l2_block_stream/l2_block_stream.d.ts.map +1 -1
- package/dest/block/l2_block_stream/l2_block_stream.js +4 -3
- package/dest/block/l2_block_stream/l2_tips_memory_store.d.ts +3 -2
- package/dest/block/l2_block_stream/l2_tips_memory_store.d.ts.map +1 -1
- package/dest/block/l2_block_stream/l2_tips_memory_store.js +4 -2
- package/dest/block/test/l2_tips_store_test_suite.d.ts +1 -1
- package/dest/block/test/l2_tips_store_test_suite.d.ts.map +1 -1
- package/dest/block/test/l2_tips_store_test_suite.js +6 -4
- package/dest/checkpoint/checkpoint.d.ts +14 -11
- package/dest/checkpoint/checkpoint.d.ts.map +1 -1
- package/dest/checkpoint/checkpoint.js +5 -5
- package/dest/checkpoint/published_checkpoint.d.ts +5 -3
- package/dest/checkpoint/published_checkpoint.d.ts.map +1 -1
- package/dest/contract/interfaces/contract_data_source.d.ts +3 -2
- package/dest/contract/interfaces/contract_data_source.d.ts.map +1 -1
- package/dest/interfaces/archiver.d.ts +1 -1
- package/dest/interfaces/archiver.d.ts.map +1 -1
- package/dest/interfaces/archiver.js +15 -9
- package/dest/interfaces/aztec-node.d.ts +29 -24
- package/dest/interfaces/aztec-node.d.ts.map +1 -1
- package/dest/interfaces/aztec-node.js +25 -23
- package/dest/interfaces/block-builder.d.ts +3 -2
- package/dest/interfaces/block-builder.d.ts.map +1 -1
- package/dest/interfaces/epoch-prover.d.ts +4 -4
- package/dest/interfaces/epoch-prover.d.ts.map +1 -1
- package/dest/interfaces/get_logs_response.d.ts +5 -3
- package/dest/interfaces/get_logs_response.d.ts.map +1 -1
- package/dest/interfaces/l2_logs_source.d.ts +4 -3
- package/dest/interfaces/l2_logs_source.d.ts.map +1 -1
- package/dest/interfaces/merkle_tree_operations.d.ts +3 -2
- package/dest/interfaces/merkle_tree_operations.d.ts.map +1 -1
- package/dest/interfaces/proving-job.d.ts +9 -5
- package/dest/interfaces/proving-job.d.ts.map +1 -1
- package/dest/interfaces/tx_provider.d.ts +3 -3
- package/dest/interfaces/tx_provider.d.ts.map +1 -1
- package/dest/interfaces/world_state.d.ts +9 -26
- package/dest/interfaces/world_state.d.ts.map +1 -1
- package/dest/interfaces/world_state.js +4 -3
- package/dest/logs/extended_public_log.d.ts +5 -3
- package/dest/logs/extended_public_log.d.ts.map +1 -1
- package/dest/logs/log_id.d.ts +8 -5
- package/dest/logs/log_id.d.ts.map +1 -1
- package/dest/logs/log_id.js +5 -4
- package/dest/logs/tx_scoped_l2_log.d.ts +10 -7
- package/dest/logs/tx_scoped_l2_log.d.ts.map +1 -1
- package/dest/logs/tx_scoped_l2_log.js +4 -3
- package/dest/messaging/l1_to_l2_message_source.d.ts +10 -3
- package/dest/messaging/l1_to_l2_message_source.d.ts.map +1 -1
- package/dest/messaging/l2_to_l1_membership.d.ts +4 -3
- package/dest/messaging/l2_to_l1_membership.d.ts.map +1 -1
- package/dest/note/note_dao.d.ts +9 -5
- package/dest/note/note_dao.d.ts.map +1 -1
- package/dest/note/note_dao.js +12 -7
- package/dest/note/notes_filter.d.ts +3 -1
- package/dest/note/notes_filter.d.ts.map +1 -1
- package/dest/note/notes_filter.js +1 -0
- package/dest/rollup/checkpoint_header.d.ts +2 -2
- package/dest/rollup/checkpoint_header.d.ts.map +1 -1
- package/dest/rollup/checkpoint_header.js +1 -1
- package/dest/tests/factories.js +5 -5
- package/dest/tests/mocks.d.ts +1 -1
- package/dest/tests/mocks.d.ts.map +1 -1
- package/dest/tests/mocks.js +2 -1
- package/dest/tx/block_header.d.ts +4 -4
- package/dest/tx/block_header.d.ts.map +1 -1
- package/dest/tx/content_commitment.d.ts +3 -2
- package/dest/tx/content_commitment.d.ts.map +1 -1
- package/dest/tx/content_commitment.js +10 -2
- package/dest/tx/global_variables.d.ts +13 -11
- package/dest/tx/global_variables.d.ts.map +1 -1
- package/dest/tx/global_variables.js +6 -6
- package/dest/tx/indexed_tx_effect.d.ts +8 -5
- package/dest/tx/indexed_tx_effect.d.ts.map +1 -1
- package/dest/tx/indexed_tx_effect.js +2 -1
- package/dest/tx/private_execution_result.d.ts +3 -3
- package/dest/tx/private_execution_result.d.ts.map +1 -1
- package/dest/tx/processed_tx.d.ts +2 -2
- package/dest/tx/processed_tx.d.ts.map +1 -1
- package/dest/tx/processed_tx.js +4 -1
- package/dest/tx/tx.d.ts +2 -2
- package/dest/tx/tx.d.ts.map +1 -1
- package/dest/tx/tx.js +1 -0
- package/dest/tx/tx_receipt.d.ts +4 -3
- package/dest/tx/tx_receipt.d.ts.map +1 -1
- package/dest/tx/tx_receipt.js +2 -1
- package/package.json +9 -9
- package/src/avm/avm.ts +238 -23
- package/src/block/block_parameter.ts +8 -0
- package/src/block/in_block.ts +13 -9
- package/src/block/index.ts +1 -1
- package/src/block/l2_block.ts +10 -5
- package/src/block/l2_block_code_to_purge.ts +3 -3
- package/src/block/l2_block_info.ts +10 -9
- package/src/block/l2_block_new.ts +8 -3
- package/src/block/l2_block_source.ts +40 -22
- package/src/block/l2_block_stream/l2_block_stream.ts +10 -5
- package/src/block/l2_block_stream/l2_tips_memory_store.ts +5 -2
- package/src/block/test/l2_tips_store_test_suite.ts +8 -3
- package/src/checkpoint/checkpoint.ts +7 -7
- package/src/contract/interfaces/contract_data_source.ts +2 -1
- package/src/interfaces/archiver.ts +18 -9
- package/src/interfaces/aztec-node.ts +61 -46
- package/src/interfaces/block-builder.ts +2 -1
- package/src/interfaces/epoch-prover.ts +3 -3
- package/src/interfaces/l2_logs_source.ts +3 -2
- package/src/interfaces/merkle_tree_operations.ts +2 -1
- package/src/interfaces/tx_provider.ts +2 -2
- package/src/interfaces/world_state.ts +12 -11
- package/src/logs/log_id.ts +6 -5
- package/src/logs/tx_scoped_l2_log.ts +5 -4
- package/src/messaging/l1_to_l2_message_source.ts +10 -2
- package/src/messaging/l2_to_l1_membership.ts +3 -2
- package/src/note/note_dao.ts +15 -5
- package/src/note/notes_filter.ts +3 -0
- package/src/rollup/checkpoint_header.ts +4 -2
- package/src/tests/factories.ts +4 -4
- package/src/tests/mocks.ts +2 -1
- package/src/tx/block_header.ts +2 -2
- package/src/tx/content_commitment.ts +11 -2
- package/src/tx/global_variables.ts +8 -8
- package/src/tx/indexed_tx_effect.ts +4 -3
- package/src/tx/private_execution_result.ts +2 -2
- package/src/tx/processed_tx.ts +8 -2
- package/src/tx/tx.ts +2 -1
- package/src/tx/tx_receipt.ts +3 -2
- package/dest/block/l2_block_number.d.ts +0 -5
- package/dest/block/l2_block_number.d.ts.map +0 -1
- package/dest/block/l2_block_number.js +0 -6
- package/src/block/l2_block_number.ts +0 -8
package/src/avm/avm.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { jsonParseWithSchema, jsonStringify } from '@aztec/foundation/json-rpc';
|
|
|
4
4
|
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
|
|
7
|
+
import { FunctionSelector } from '../abi/index.js';
|
|
7
8
|
import { AztecAddress } from '../aztec-address/index.js';
|
|
8
9
|
import { AllContractDeploymentData, ContractDeploymentData } from '../contract/index.js';
|
|
9
10
|
import { SimulationError } from '../errors/simulation_error.js';
|
|
@@ -28,6 +29,7 @@ import {
|
|
|
28
29
|
TreeSnapshots,
|
|
29
30
|
type Tx,
|
|
30
31
|
} from '../tx/index.js';
|
|
32
|
+
import { TxExecutionPhase } from '../tx/processed_tx.js';
|
|
31
33
|
import { WorldStateRevision } from '../world-state/world_state_revision.js';
|
|
32
34
|
import { AvmCircuitPublicInputs } from './avm_circuit_public_inputs.js';
|
|
33
35
|
import { serializeWithMessagePack } from './message_pack.js';
|
|
@@ -1042,17 +1044,146 @@ export class AvmCircuitInputs {
|
|
|
1042
1044
|
}
|
|
1043
1045
|
}
|
|
1044
1046
|
|
|
1047
|
+
// Metadata about a given (enqueued or external) call.
|
|
1048
|
+
export class CallStackMetadata {
|
|
1049
|
+
constructor(
|
|
1050
|
+
public phase: TxExecutionPhase,
|
|
1051
|
+
public contractAddress: Fr,
|
|
1052
|
+
public callerPc: number,
|
|
1053
|
+
public calldata: Fr[],
|
|
1054
|
+
public isStaticCall: boolean,
|
|
1055
|
+
public gasLimit: Gas,
|
|
1056
|
+
public output: Fr[], // returndata or revertdata.
|
|
1057
|
+
public internalCallStackAtExit: number[], // At return/revert time. Last one is exit PC.
|
|
1058
|
+
public haltingMessage: string | undefined,
|
|
1059
|
+
public reverted: boolean,
|
|
1060
|
+
public nested: CallStackMetadata[],
|
|
1061
|
+
public numNestedCalls: number, // This will be different from the size of the nested vector if we went past some limit.
|
|
1062
|
+
) {}
|
|
1063
|
+
|
|
1064
|
+
static get schema(): ZodFor<CallStackMetadata> {
|
|
1065
|
+
return z
|
|
1066
|
+
.object({
|
|
1067
|
+
phase: z.nativeEnum(TxExecutionPhase),
|
|
1068
|
+
contractAddress: Fr.schema,
|
|
1069
|
+
callerPc: z.number(),
|
|
1070
|
+
calldata: Fr.schema.array(),
|
|
1071
|
+
isStaticCall: z.boolean(),
|
|
1072
|
+
gasLimit: Gas.schema,
|
|
1073
|
+
output: Fr.schema.array(),
|
|
1074
|
+
internalCallStackAtExit: z.number().array(),
|
|
1075
|
+
haltingMessage: NullishToUndefined(z.string()),
|
|
1076
|
+
reverted: z.boolean(),
|
|
1077
|
+
nested: CallStackMetadata.schema.array(),
|
|
1078
|
+
numNestedCalls: z.number(),
|
|
1079
|
+
})
|
|
1080
|
+
.transform(
|
|
1081
|
+
({
|
|
1082
|
+
phase,
|
|
1083
|
+
contractAddress,
|
|
1084
|
+
callerPc,
|
|
1085
|
+
calldata,
|
|
1086
|
+
isStaticCall,
|
|
1087
|
+
gasLimit,
|
|
1088
|
+
output,
|
|
1089
|
+
internalCallStackAtExit,
|
|
1090
|
+
haltingMessage,
|
|
1091
|
+
reverted,
|
|
1092
|
+
nested,
|
|
1093
|
+
numNestedCalls,
|
|
1094
|
+
}) =>
|
|
1095
|
+
new CallStackMetadata(
|
|
1096
|
+
phase,
|
|
1097
|
+
contractAddress,
|
|
1098
|
+
callerPc,
|
|
1099
|
+
calldata,
|
|
1100
|
+
isStaticCall,
|
|
1101
|
+
gasLimit,
|
|
1102
|
+
output,
|
|
1103
|
+
internalCallStackAtExit,
|
|
1104
|
+
haltingMessage,
|
|
1105
|
+
reverted,
|
|
1106
|
+
nested,
|
|
1107
|
+
numNestedCalls,
|
|
1108
|
+
),
|
|
1109
|
+
);
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
/**
|
|
1113
|
+
* Creates a CallStackMetadata from a plain object without Zod validation.
|
|
1114
|
+
* This method is optimized for performance and skips validation, making it suitable
|
|
1115
|
+
* for deserializing trusted data (e.g., from C++ via MessagePack).
|
|
1116
|
+
* @param obj - Plain object containing CallStackMetadata fields
|
|
1117
|
+
* @returns A CallStackMetadata instance
|
|
1118
|
+
*/
|
|
1119
|
+
static fromPlainObject(obj: any): CallStackMetadata {
|
|
1120
|
+
if (obj instanceof CallStackMetadata) {
|
|
1121
|
+
return obj;
|
|
1122
|
+
}
|
|
1123
|
+
return new CallStackMetadata(
|
|
1124
|
+
obj.phase,
|
|
1125
|
+
Fr.fromPlainObject(obj.contractAddress),
|
|
1126
|
+
obj.callerPc,
|
|
1127
|
+
obj.calldata.map((f: any) => Fr.fromPlainObject(f)),
|
|
1128
|
+
obj.isStaticCall,
|
|
1129
|
+
Gas.fromPlainObject(obj.gasLimit),
|
|
1130
|
+
obj.output.map((f: any) => Fr.fromPlainObject(f)),
|
|
1131
|
+
obj.internalCallStackAtExit.map((p: any) => Number(p)),
|
|
1132
|
+
obj.haltingMessage,
|
|
1133
|
+
obj.reverted,
|
|
1134
|
+
obj.nested.map((n: any) => CallStackMetadata.fromPlainObject(n)),
|
|
1135
|
+
obj.numNestedCalls,
|
|
1136
|
+
);
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
public getRevertReason(): SimulationError | undefined {
|
|
1140
|
+
const failingCall = this.findDeepestRevert([this]);
|
|
1141
|
+
|
|
1142
|
+
if (!failingCall) {
|
|
1143
|
+
return undefined;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
const { stack, leaf } = failingCall;
|
|
1147
|
+
const aztecCallStack = stack.map(call => ({
|
|
1148
|
+
contractAddress: AztecAddress.fromField(call.contractAddress),
|
|
1149
|
+
functionSelector: call.calldata.length > 0 ? FunctionSelector.fromField(call.calldata[0]) : undefined,
|
|
1150
|
+
}));
|
|
1151
|
+
|
|
1152
|
+
// The Noir call stack is the internal call stack at exit of the failing call
|
|
1153
|
+
const noirCallStack = leaf.internalCallStackAtExit.map(pc => `0.${pc}`);
|
|
1154
|
+
|
|
1155
|
+
return new SimulationError(
|
|
1156
|
+
leaf.haltingMessage ?? 'Transaction reverted',
|
|
1157
|
+
aztecCallStack,
|
|
1158
|
+
leaf.output,
|
|
1159
|
+
noirCallStack,
|
|
1160
|
+
);
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
private findDeepestRevert(
|
|
1164
|
+
calls: CallStackMetadata[],
|
|
1165
|
+
parentStack: CallStackMetadata[] = [],
|
|
1166
|
+
): { stack: CallStackMetadata[]; leaf: CallStackMetadata } | undefined {
|
|
1167
|
+
for (const call of calls) {
|
|
1168
|
+
if (call.reverted) {
|
|
1169
|
+
const nested = this.findDeepestRevert(call.nested, [...parentStack, call]);
|
|
1170
|
+
return nested || { stack: [...parentStack, call], leaf: call };
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
return undefined;
|
|
1174
|
+
}
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1045
1177
|
export class PublicTxResult {
|
|
1046
1178
|
constructor(
|
|
1047
1179
|
// Simulation result.
|
|
1048
1180
|
public gasUsed: GasUsed,
|
|
1049
1181
|
public revertCode: RevertCode,
|
|
1050
|
-
public revertReason: SimulationError | undefined, // Revert reason, if any
|
|
1051
1182
|
// These are only guaranteed to be present if the simulator is configured to collect them.
|
|
1052
|
-
//
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1183
|
+
// TODO(fcarreiro): Remove NestedProcessReturnValues[] once we migrate to the C++ simulator.
|
|
1184
|
+
public callStackMetadata:
|
|
1185
|
+
| CallStackMetadata[] // One per enqueued call. All phases.
|
|
1186
|
+
| NestedProcessReturnValues[], // One per enqueued call. App logic only.
|
|
1056
1187
|
public logs: DebugLog[] | undefined,
|
|
1057
1188
|
// For the proving request.
|
|
1058
1189
|
public hints: AvmExecutionHints | undefined,
|
|
@@ -1068,8 +1199,7 @@ export class PublicTxResult {
|
|
|
1068
1199
|
billedGas: Gas.empty(),
|
|
1069
1200
|
},
|
|
1070
1201
|
RevertCode.OK,
|
|
1071
|
-
/*
|
|
1072
|
-
/*appLogicReturnValues=*/ [],
|
|
1202
|
+
/*callStackMetadata=*/ [] as CallStackMetadata[],
|
|
1073
1203
|
/*logs=*/ [],
|
|
1074
1204
|
/*hints=*/ AvmExecutionHints.empty(),
|
|
1075
1205
|
/*publicInputs=*/ AvmCircuitPublicInputs.empty(),
|
|
@@ -1082,37 +1212,122 @@ export class PublicTxResult {
|
|
|
1082
1212
|
gasUsed: schemas.GasUsed,
|
|
1083
1213
|
revertCode: RevertCode.schema,
|
|
1084
1214
|
revertReason: NullishToUndefined(SimulationError.schema),
|
|
1085
|
-
|
|
1215
|
+
callStackMetadata: z.union([CallStackMetadata.schema.array(), NestedProcessReturnValues.schema.array()]),
|
|
1086
1216
|
logs: NullishToUndefined(DebugLog.schema.array()),
|
|
1087
1217
|
// For the proving request.
|
|
1088
1218
|
publicInputs: AvmCircuitPublicInputs.schema,
|
|
1089
1219
|
hints: NullishToUndefined(AvmExecutionHints.schema),
|
|
1090
1220
|
})
|
|
1091
1221
|
.transform(
|
|
1092
|
-
({ gasUsed, revertCode,
|
|
1093
|
-
new PublicTxResult(
|
|
1094
|
-
gasUsed,
|
|
1095
|
-
revertCode as RevertCode,
|
|
1096
|
-
revertReason,
|
|
1097
|
-
appLogicReturnValues,
|
|
1098
|
-
logs,
|
|
1099
|
-
hints,
|
|
1100
|
-
publicInputs,
|
|
1101
|
-
),
|
|
1222
|
+
({ gasUsed, revertCode, callStackMetadata, logs, hints, publicInputs }) =>
|
|
1223
|
+
new PublicTxResult(gasUsed, revertCode as RevertCode, callStackMetadata, logs, hints, publicInputs),
|
|
1102
1224
|
);
|
|
1103
1225
|
}
|
|
1104
1226
|
|
|
1227
|
+
/**
|
|
1228
|
+
* Creates a PublicTxResult from a plain object without Zod validation.
|
|
1229
|
+
* This method is optimized for performance and skips validation, making it suitable
|
|
1230
|
+
* for deserializing trusted data (e.g., from C++ via MessagePack).
|
|
1231
|
+
* @param obj - Plain object containing PublicTxResult fields
|
|
1232
|
+
* @returns A PublicTxResult instance
|
|
1233
|
+
*/
|
|
1105
1234
|
static fromPlainObject(obj: any): PublicTxResult {
|
|
1106
1235
|
return new PublicTxResult(
|
|
1107
1236
|
GasUsed.fromPlainObject(obj.gasUsed),
|
|
1108
1237
|
RevertCode.fromPlainObject(obj.revertCode),
|
|
1109
|
-
|
|
1110
|
-
/*appLogicReturnValues=*/ obj.appLogicReturnValues.map(NestedProcessReturnValues.fromPlainObject),
|
|
1238
|
+
obj.callStackMetadata.map(CallStackMetadata.fromPlainObject), // Always CallStackMetadata[] from MessagePack.
|
|
1111
1239
|
obj.logs?.map(DebugLog.fromPlainObject),
|
|
1112
1240
|
obj.hints ? AvmExecutionHints.fromPlainObject(obj.hints) : undefined,
|
|
1113
1241
|
AvmCircuitPublicInputs.fromPlainObject(obj.publicInputs),
|
|
1114
1242
|
);
|
|
1115
1243
|
}
|
|
1244
|
+
|
|
1245
|
+
/** Returns one level of return values for the app logic phase, one per enqueued call. */
|
|
1246
|
+
public getAppLogicReturnValues(): NestedProcessReturnValues[] {
|
|
1247
|
+
if (this.callStackMetadata.every(metadata => metadata instanceof CallStackMetadata)) {
|
|
1248
|
+
return this.callStackMetadata
|
|
1249
|
+
.filter(metadata => metadata.phase === TxExecutionPhase.APP_LOGIC)
|
|
1250
|
+
.map(metadata => new NestedProcessReturnValues(metadata.output));
|
|
1251
|
+
} else {
|
|
1252
|
+
return (this.callStackMetadata as NestedProcessReturnValues[]).map(
|
|
1253
|
+
metadata => new NestedProcessReturnValues(metadata.values, metadata.nested),
|
|
1254
|
+
);
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
public findRevertReason(): SimulationError | undefined {
|
|
1259
|
+
if (this.revertCode.isOK()) {
|
|
1260
|
+
return undefined;
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
const callStackMetadata = this.callStackMetadata;
|
|
1264
|
+
// TODO(fcarreiro): Remove this after migration to the C++ simulator.
|
|
1265
|
+
// If the "stack" comes from TS, it will have this field.
|
|
1266
|
+
if ((callStackMetadata as any).revertReason !== undefined) {
|
|
1267
|
+
return (callStackMetadata as any).revertReason;
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
// Handle CallStackMetadata[].
|
|
1271
|
+
let revertReason: SimulationError | undefined = undefined;
|
|
1272
|
+
for (const call of callStackMetadata) {
|
|
1273
|
+
revertReason = (call as CallStackMetadata).getRevertReason();
|
|
1274
|
+
if (revertReason) {
|
|
1275
|
+
break;
|
|
1276
|
+
}
|
|
1277
|
+
}
|
|
1278
|
+
return revertReason;
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
export class CollectionLimitsConfig {
|
|
1283
|
+
constructor(
|
|
1284
|
+
public readonly maxDebugLogMemoryReads: number,
|
|
1285
|
+
public readonly maxCalldataSizeInFields: number,
|
|
1286
|
+
public readonly maxReturndataSizeInFields: number,
|
|
1287
|
+
public readonly maxCallStackDepth: number,
|
|
1288
|
+
public readonly maxCallStackItems: number,
|
|
1289
|
+
) {}
|
|
1290
|
+
|
|
1291
|
+
static from(obj: Partial<CollectionLimitsConfig>): CollectionLimitsConfig {
|
|
1292
|
+
return new CollectionLimitsConfig(
|
|
1293
|
+
obj.maxDebugLogMemoryReads ?? DEFAULT_MAX_DEBUG_LOG_MEMORY_READS,
|
|
1294
|
+
obj.maxCalldataSizeInFields ?? 300,
|
|
1295
|
+
obj.maxReturndataSizeInFields ?? 300,
|
|
1296
|
+
obj.maxCallStackDepth ?? 5,
|
|
1297
|
+
obj.maxCallStackItems ?? 100,
|
|
1298
|
+
);
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
static empty() {
|
|
1302
|
+
return CollectionLimitsConfig.from({});
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
static get schema() {
|
|
1306
|
+
return z
|
|
1307
|
+
.object({
|
|
1308
|
+
maxDebugLogMemoryReads: z.number(),
|
|
1309
|
+
maxCalldataSizeInFields: z.number(),
|
|
1310
|
+
maxReturndataSizeInFields: z.number(),
|
|
1311
|
+
maxCallStackDepth: z.number(),
|
|
1312
|
+
maxCallStackItems: z.number(),
|
|
1313
|
+
})
|
|
1314
|
+
.transform(
|
|
1315
|
+
({
|
|
1316
|
+
maxDebugLogMemoryReads,
|
|
1317
|
+
maxCalldataSizeInFields,
|
|
1318
|
+
maxReturndataSizeInFields,
|
|
1319
|
+
maxCallStackDepth,
|
|
1320
|
+
maxCallStackItems,
|
|
1321
|
+
}) =>
|
|
1322
|
+
new CollectionLimitsConfig(
|
|
1323
|
+
maxDebugLogMemoryReads,
|
|
1324
|
+
maxCalldataSizeInFields,
|
|
1325
|
+
maxReturndataSizeInFields,
|
|
1326
|
+
maxCallStackDepth,
|
|
1327
|
+
maxCallStackItems,
|
|
1328
|
+
),
|
|
1329
|
+
);
|
|
1330
|
+
}
|
|
1116
1331
|
}
|
|
1117
1332
|
|
|
1118
1333
|
export class PublicSimulatorConfig {
|
|
@@ -1122,8 +1337,8 @@ export class PublicSimulatorConfig {
|
|
|
1122
1337
|
public readonly collectCallMetadata: boolean, // appLogicReturnValues.
|
|
1123
1338
|
public readonly collectHints: boolean, // hints.
|
|
1124
1339
|
public readonly collectDebugLogs: boolean, // logs.
|
|
1125
|
-
public readonly maxDebugLogMemoryReads: number,
|
|
1126
1340
|
public readonly collectStatistics: boolean, // timings etc.
|
|
1341
|
+
public readonly collectionLimits: CollectionLimitsConfig,
|
|
1127
1342
|
) {}
|
|
1128
1343
|
|
|
1129
1344
|
static from(obj: Partial<PublicSimulatorConfig>): PublicSimulatorConfig {
|
|
@@ -1133,8 +1348,8 @@ export class PublicSimulatorConfig {
|
|
|
1133
1348
|
obj.collectCallMetadata ?? false,
|
|
1134
1349
|
obj.collectHints ?? false,
|
|
1135
1350
|
obj.collectDebugLogs ?? false,
|
|
1136
|
-
obj.maxDebugLogMemoryReads ?? DEFAULT_MAX_DEBUG_LOG_MEMORY_READS,
|
|
1137
1351
|
obj.collectStatistics ?? false,
|
|
1352
|
+
obj.collectionLimits ?? CollectionLimitsConfig.empty(),
|
|
1138
1353
|
);
|
|
1139
1354
|
}
|
|
1140
1355
|
|
|
@@ -1150,8 +1365,8 @@ export class PublicSimulatorConfig {
|
|
|
1150
1365
|
collectCallMetadata: z.boolean(),
|
|
1151
1366
|
collectHints: z.boolean(),
|
|
1152
1367
|
collectDebugLogs: z.boolean(),
|
|
1153
|
-
maxDebugLogMemoryReads: z.number(),
|
|
1154
1368
|
collectStatistics: z.boolean(),
|
|
1369
|
+
collectionLimits: CollectionLimitsConfig.schema,
|
|
1155
1370
|
})
|
|
1156
1371
|
.transform(PublicSimulatorConfig.from);
|
|
1157
1372
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BlockNumberSchema } from '@aztec/foundation/branded-types';
|
|
2
|
+
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
|
+
export const BlockParameterSchema = z.union([BlockNumberSchema, z.literal('latest')]);
|
|
6
|
+
|
|
7
|
+
/** Block parameter - either a specific BlockNumber or 'latest' */
|
|
8
|
+
export type BlockParameter = z.infer<typeof BlockParameterSchema>;
|
package/src/block/in_block.ts
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
|
+
import { BlockNumber, BlockNumberSchema } from '@aztec/foundation/branded-types';
|
|
2
|
+
|
|
1
3
|
import { type ZodTypeAny, z } from 'zod';
|
|
2
4
|
|
|
3
|
-
import { schemas } from '../schemas/index.js';
|
|
4
5
|
import { L2BlockHash } from './block_hash.js';
|
|
5
6
|
import type { L2Block } from './l2_block.js';
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
l2BlockNumber: number;
|
|
8
|
+
export type InBlock = {
|
|
9
|
+
l2BlockNumber: BlockNumber;
|
|
10
10
|
l2BlockHash: L2BlockHash;
|
|
11
|
-
data: T;
|
|
12
11
|
};
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
// Note: If you expand this type with indexInBlock, then delete `IndexedTxEffect` and use this type instead.
|
|
14
|
+
export type DataInBlock<T> = {
|
|
15
|
+
data: T;
|
|
16
|
+
} & InBlock;
|
|
17
|
+
|
|
18
|
+
export function randomInBlock<T>(data: T): DataInBlock<T> {
|
|
15
19
|
return {
|
|
16
20
|
data,
|
|
17
|
-
l2BlockNumber: Math.floor(Math.random() * 1000),
|
|
21
|
+
l2BlockNumber: BlockNumber(Math.floor(Math.random() * 1000)),
|
|
18
22
|
l2BlockHash: L2BlockHash.random(),
|
|
19
23
|
};
|
|
20
24
|
}
|
|
21
25
|
|
|
22
|
-
export async function wrapInBlock<T>(data: T, block: L2Block): Promise<
|
|
26
|
+
export async function wrapInBlock<T>(data: T, block: L2Block): Promise<DataInBlock<T>> {
|
|
23
27
|
return {
|
|
24
28
|
data,
|
|
25
29
|
l2BlockNumber: block.number,
|
|
@@ -30,7 +34,7 @@ export async function wrapInBlock<T>(data: T, block: L2Block): Promise<InBlock<T
|
|
|
30
34
|
export function inBlockSchemaFor<T extends ZodTypeAny>(schema: T) {
|
|
31
35
|
return z.object({
|
|
32
36
|
data: schema,
|
|
33
|
-
l2BlockNumber:
|
|
37
|
+
l2BlockNumber: BlockNumberSchema,
|
|
34
38
|
l2BlockHash: L2BlockHash.schema,
|
|
35
39
|
});
|
|
36
40
|
}
|
package/src/block/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ export * from './l2_block_header.js';
|
|
|
4
4
|
export * from './l2_block_stream/index.js';
|
|
5
5
|
export * from './in_block.js';
|
|
6
6
|
export * from './body.js';
|
|
7
|
-
export * from './
|
|
7
|
+
export * from './block_parameter.js';
|
|
8
8
|
export * from './l2_block_source.js';
|
|
9
9
|
export * from './block_hash.js';
|
|
10
10
|
export * from './published_l2_block.js';
|
package/src/block/l2_block.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type BlockBlobData, encodeBlockBlobData, encodeCheckpointBlobDataFromBlocks } from '@aztec/blob-lib/encoding';
|
|
2
|
-
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { BlockNumber, CheckpointNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
3
3
|
import { Fr } from '@aztec/foundation/fields';
|
|
4
4
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
5
5
|
import { bufferToHex, hexToBuffer } from '@aztec/foundation/string';
|
|
@@ -89,7 +89,7 @@ export class L2Block {
|
|
|
89
89
|
* @returns The L2 block.
|
|
90
90
|
*/
|
|
91
91
|
static async random(
|
|
92
|
-
l2BlockNum:
|
|
92
|
+
l2BlockNum: BlockNumber,
|
|
93
93
|
txsPerBlock = 4,
|
|
94
94
|
numPublicCallsPerTx = 3,
|
|
95
95
|
numPublicLogsPerCall = 1,
|
|
@@ -114,7 +114,7 @@ export class L2Block {
|
|
|
114
114
|
return new L2Block(AppendOnlyTreeSnapshot.empty(), L2BlockHeader.empty(), Body.empty());
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
get number():
|
|
117
|
+
get number(): BlockNumber {
|
|
118
118
|
return this.header.getBlockNumber();
|
|
119
119
|
}
|
|
120
120
|
|
|
@@ -156,7 +156,12 @@ export class L2Block {
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
public toCheckpoint() {
|
|
159
|
-
return new Checkpoint(
|
|
159
|
+
return new Checkpoint(
|
|
160
|
+
this.archive,
|
|
161
|
+
this.getCheckpointHeader(),
|
|
162
|
+
[this.toL2Block()],
|
|
163
|
+
CheckpointNumber.fromBlockNumber(this.number),
|
|
164
|
+
);
|
|
160
165
|
}
|
|
161
166
|
|
|
162
167
|
static fromCheckpoint(checkpoint: Checkpoint) {
|
|
@@ -246,7 +251,7 @@ export class L2Block {
|
|
|
246
251
|
archive: this.archive.root,
|
|
247
252
|
lastArchive: this.header.lastArchive.root,
|
|
248
253
|
blockNumber: this.number,
|
|
249
|
-
slotNumber:
|
|
254
|
+
slotNumber: this.header.getSlot(),
|
|
250
255
|
txCount: this.body.txEffects.length,
|
|
251
256
|
timestamp: this.header.globalVariables.timestamp,
|
|
252
257
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
|
+
import { BlockNumber, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import { compact } from '@aztec/foundation/collection';
|
|
3
3
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
4
|
import { Fr } from '@aztec/foundation/fields';
|
|
@@ -25,7 +25,7 @@ export function makeL2BlockHeader(
|
|
|
25
25
|
overrides?.contentCommitment ?? makeContentCommitment(seed + 0x200, inHash),
|
|
26
26
|
overrides?.state ?? makeStateReference(seed + 0x600),
|
|
27
27
|
makeGlobalVariables((seed += 0x700), {
|
|
28
|
-
...(blockNumber ? { blockNumber } : {}),
|
|
28
|
+
...(blockNumber ? { blockNumber: BlockNumber(blockNumber) } : {}),
|
|
29
29
|
...(slotNumber ? { slotNumber: SlotNumber(slotNumber) } : {}),
|
|
30
30
|
}),
|
|
31
31
|
new Fr(seed + 0x300),
|
|
@@ -77,7 +77,7 @@ function makeGlobalVariables(seed = 1, overrides: Partial<FieldsOf<GlobalVariabl
|
|
|
77
77
|
return GlobalVariables.from({
|
|
78
78
|
chainId: new Fr(seed),
|
|
79
79
|
version: new Fr(seed + 1),
|
|
80
|
-
blockNumber: seed + 2,
|
|
80
|
+
blockNumber: BlockNumber(seed + 2),
|
|
81
81
|
slotNumber: SlotNumber(seed + 3),
|
|
82
82
|
timestamp: BigInt(seed + 4),
|
|
83
83
|
coinbase: EthAddress.fromField(new Fr(seed + 5)),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BlockNumber, BlockNumberSchema, SlotNumber, SlotNumberSchema } from '@aztec/foundation/branded-types';
|
|
1
2
|
import { Fr } from '@aztec/foundation/fields';
|
|
2
3
|
import { schemas } from '@aztec/foundation/schemas';
|
|
3
4
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
@@ -8,19 +9,19 @@ export type L2BlockInfo = {
|
|
|
8
9
|
blockHash?: Fr;
|
|
9
10
|
archive: Fr;
|
|
10
11
|
lastArchive: Fr;
|
|
11
|
-
blockNumber:
|
|
12
|
-
slotNumber:
|
|
12
|
+
blockNumber: BlockNumber;
|
|
13
|
+
slotNumber: SlotNumber;
|
|
13
14
|
txCount: number;
|
|
14
15
|
timestamp: bigint;
|
|
15
16
|
};
|
|
16
17
|
|
|
17
|
-
export function randomBlockInfo(blockNumber?: number): L2BlockInfo {
|
|
18
|
+
export function randomBlockInfo(blockNumber?: BlockNumber | number): L2BlockInfo {
|
|
18
19
|
return {
|
|
19
20
|
blockHash: Fr.random(),
|
|
20
21
|
archive: Fr.random(),
|
|
21
22
|
lastArchive: Fr.random(),
|
|
22
|
-
blockNumber: blockNumber ?? Math.floor(Math.random() * 100000) + 1,
|
|
23
|
-
slotNumber: Math.floor(Math.random() * 100000) + 1,
|
|
23
|
+
blockNumber: BlockNumber(blockNumber ?? Math.floor(Math.random() * 100000) + 1),
|
|
24
|
+
slotNumber: SlotNumber(Math.floor(Math.random() * 100000) + 1),
|
|
24
25
|
txCount: Math.floor(Math.random() * 100),
|
|
25
26
|
timestamp: BigInt(Math.floor(Date.now() / 1000)),
|
|
26
27
|
};
|
|
@@ -30,8 +31,8 @@ export const BlockInfoSchema = z.object({
|
|
|
30
31
|
blockHash: schemas.Fr.optional(),
|
|
31
32
|
archive: schemas.Fr,
|
|
32
33
|
lastArchive: schemas.Fr,
|
|
33
|
-
blockNumber:
|
|
34
|
-
slotNumber:
|
|
34
|
+
blockNumber: BlockNumberSchema,
|
|
35
|
+
slotNumber: SlotNumberSchema,
|
|
35
36
|
txCount: z.number(),
|
|
36
37
|
timestamp: schemas.BigInt,
|
|
37
38
|
});
|
|
@@ -55,8 +56,8 @@ export function deserializeBlockInfo(buffer: Buffer | BufferReader): L2BlockInfo
|
|
|
55
56
|
blockHash: blockHash.equals(Fr.ZERO) ? undefined : blockHash,
|
|
56
57
|
archive: reader.readObject(Fr),
|
|
57
58
|
lastArchive: reader.readObject(Fr),
|
|
58
|
-
blockNumber: reader.readNumber(),
|
|
59
|
-
slotNumber: reader.readNumber(),
|
|
59
|
+
blockNumber: BlockNumber(reader.readNumber()),
|
|
60
|
+
slotNumber: SlotNumber(reader.readNumber()),
|
|
60
61
|
txCount: reader.readNumber(),
|
|
61
62
|
timestamp: reader.readBigInt(),
|
|
62
63
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type BlockBlobData, encodeBlockBlobData } from '@aztec/blob-lib/encoding';
|
|
2
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
3
|
import { Fr } from '@aztec/foundation/fields';
|
|
3
4
|
import { BufferReader, serializeToBuffer } from '@aztec/foundation/serialize';
|
|
4
5
|
|
|
@@ -24,7 +25,7 @@ export class L2BlockNew {
|
|
|
24
25
|
private blockHash: Fr | undefined = undefined,
|
|
25
26
|
) {}
|
|
26
27
|
|
|
27
|
-
get number():
|
|
28
|
+
get number(): BlockNumber {
|
|
28
29
|
return this.header.globalVariables.blockNumber;
|
|
29
30
|
}
|
|
30
31
|
|
|
@@ -102,6 +103,10 @@ export class L2BlockNew {
|
|
|
102
103
|
};
|
|
103
104
|
}
|
|
104
105
|
|
|
106
|
+
static empty() {
|
|
107
|
+
return new L2BlockNew(AppendOnlyTreeSnapshot.empty(), BlockHeader.empty(), Body.empty());
|
|
108
|
+
}
|
|
109
|
+
|
|
105
110
|
/**
|
|
106
111
|
* Creates an L2 block containing random data.
|
|
107
112
|
* @param l2BlockNum - The number of the L2 block.
|
|
@@ -112,7 +117,7 @@ export class L2BlockNew {
|
|
|
112
117
|
* @returns The L2 block.
|
|
113
118
|
*/
|
|
114
119
|
static async random(
|
|
115
|
-
blockNumber:
|
|
120
|
+
blockNumber: BlockNumber,
|
|
116
121
|
{
|
|
117
122
|
txsPerBlock = 1,
|
|
118
123
|
txOptions = {},
|
|
@@ -163,7 +168,7 @@ export class L2BlockNew {
|
|
|
163
168
|
archive: this.archive.root,
|
|
164
169
|
lastArchive: this.header.lastArchive.root,
|
|
165
170
|
blockNumber: this.number,
|
|
166
|
-
slotNumber:
|
|
171
|
+
slotNumber: this.header.getSlot(),
|
|
167
172
|
txCount: this.body.txEffects.length,
|
|
168
173
|
timestamp: this.header.globalVariables.timestamp,
|
|
169
174
|
};
|