Skip to content

Commit

Permalink
better error msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Oct 24, 2024
1 parent 696538c commit 8fd78ed
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
10 changes: 8 additions & 2 deletions yarn-project/foundation/src/collection/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@ import { type Tuple } from '../serialize/types.js';
* @param arr - Array with elements to pad.
* @param elem - Element to use for padding.
* @param length - Target length.
* @param errorMsg - Error message to throw if target length exceeds the input array length.
* @returns A new padded array.
*/
export function padArrayEnd<T, N extends number>(arr: T[], elem: T, length: N): Tuple<T, N> {
export function padArrayEnd<T, N extends number>(
arr: T[],
elem: T,
length: N,
errorMsg = 'Array size exceeds target length',
): Tuple<T, N> {
if (arr.length > length) {
throw new Error(`Array size exceeds target length`);
throw new Error(errorMsg);
}
// Since typescript cannot always deduce that something is a tuple, we cast
return [...arr, ...Array(length - arr.length).fill(elem)] as Tuple<T, N>;
Expand Down
35 changes: 31 additions & 4 deletions yarn-project/simulator/src/public/enqueued_call_simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,48 +283,75 @@ export class EnqueuedCallSimulator {
callContext: result.executionRequest.callContext,
proverAddress: AztecAddress.ZERO,
argsHash: computeVarArgsHash(result.executionRequest.args),
noteHashes: padArrayEnd(result.noteHashes, NoteHash.empty(), MAX_NOTE_HASHES_PER_CALL),
nullifiers: padArrayEnd(result.nullifiers, Nullifier.empty(), MAX_NULLIFIERS_PER_CALL),
l2ToL1Msgs: padArrayEnd(result.l2ToL1Messages, L2ToL1Message.empty(), MAX_L2_TO_L1_MSGS_PER_CALL),
noteHashes: padArrayEnd(
result.noteHashes,
NoteHash.empty(),
MAX_NOTE_HASHES_PER_CALL,
`Too many note hashes. Got ${result.noteHashes.length} with max being ${MAX_NOTE_HASHES_PER_CALL}`,
),
nullifiers: padArrayEnd(
result.nullifiers,
Nullifier.empty(),
MAX_NULLIFIERS_PER_CALL,
`Too many nullifiers. Got ${result.nullifiers.length} with max being ${MAX_NULLIFIERS_PER_CALL}`,
),
l2ToL1Msgs: padArrayEnd(
result.l2ToL1Messages,
L2ToL1Message.empty(),
MAX_L2_TO_L1_MSGS_PER_CALL,
`Too many L2 to L1 messages. Got ${result.l2ToL1Messages.length} with max being ${MAX_L2_TO_L1_MSGS_PER_CALL}`,
),
startSideEffectCounter: result.startSideEffectCounter,
endSideEffectCounter: result.endSideEffectCounter,
returnsHash: computeVarArgsHash(result.returnValues),
noteHashReadRequests: padArrayEnd(
result.noteHashReadRequests,
TreeLeafReadRequest.empty(),
MAX_NOTE_HASH_READ_REQUESTS_PER_CALL,
`Too many note hash read requests. Got ${result.noteHashReadRequests.length} with max being ${MAX_NOTE_HASH_READ_REQUESTS_PER_CALL}`,
),
nullifierReadRequests: padArrayEnd(
result.nullifierReadRequests,
ReadRequest.empty(),
MAX_NULLIFIER_READ_REQUESTS_PER_CALL,
`Too many nullifier read requests. Got ${result.nullifierReadRequests.length} with max being ${MAX_NULLIFIER_READ_REQUESTS_PER_CALL}`,
),
nullifierNonExistentReadRequests: padArrayEnd(
result.nullifierNonExistentReadRequests,
ReadRequest.empty(),
MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL,
`Too many nullifier non-existent read requests. Got ${result.nullifierNonExistentReadRequests.length} with max being ${MAX_NULLIFIER_NON_EXISTENT_READ_REQUESTS_PER_CALL}`,
),
l1ToL2MsgReadRequests: padArrayEnd(
result.l1ToL2MsgReadRequests,
TreeLeafReadRequest.empty(),
MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL,
`Too many L1 to L2 message read requests. Got ${result.l1ToL2MsgReadRequests.length} with max being ${MAX_L1_TO_L2_MSG_READ_REQUESTS_PER_CALL}`,
),
contractStorageReads: padArrayEnd(
result.contractStorageReads,
ContractStorageRead.empty(),
MAX_PUBLIC_DATA_READS_PER_CALL,
`Too many public data reads. Got ${result.contractStorageReads.length} with max being ${MAX_PUBLIC_DATA_READS_PER_CALL}`,
),
contractStorageUpdateRequests: padArrayEnd(
result.contractStorageUpdateRequests,
ContractStorageUpdateRequest.empty(),
MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL,
`Too many public data update requests. Got ${result.contractStorageUpdateRequests.length} with max being ${MAX_PUBLIC_DATA_UPDATE_REQUESTS_PER_CALL}`,
),
publicCallRequests: padArrayEnd(
result.publicCallRequests,
PublicInnerCallRequest.empty(),
MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL,
`Too many public call requests. Got ${result.publicCallRequests.length} with max being ${MAX_PUBLIC_CALL_STACK_LENGTH_PER_CALL}`,
),
unencryptedLogsHashes: padArrayEnd(
result.unencryptedLogsHashes,
LogHash.empty(),
MAX_UNENCRYPTED_LOGS_PER_CALL,
`Too many unencrypted logs. Got ${result.unencryptedLogsHashes.length} with max being ${MAX_UNENCRYPTED_LOGS_PER_CALL}`,
),
unencryptedLogsHashes: padArrayEnd(result.unencryptedLogsHashes, LogHash.empty(), MAX_UNENCRYPTED_LOGS_PER_CALL),
historicalHeader: this.historicalHeader,
globalVariables: this.globalVariables,
startGasLeft: Gas.from(result.startGasLeft),
Expand Down

0 comments on commit 8fd78ed

Please sign in to comment.