From ee527961c427d43ea709fce9a0fc3b56c0db3d72 Mon Sep 17 00:00:00 2001 From: Gregor Date: Fri, 11 Oct 2024 17:05:32 +0200 Subject: [PATCH] handle out of bounds --- src/lib/provable/gadgets/basic.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/provable/gadgets/basic.ts b/src/lib/provable/gadgets/basic.ts index efc91e66e7..aaf8935917 100644 --- a/src/lib/provable/gadgets/basic.ts +++ b/src/lib/provable/gadgets/basic.ts @@ -79,13 +79,13 @@ function assertMul( function arrayGet(array: Field[], index: Field) { // if index is constant, we can return the value directly if (index.isConstant()) { - return array[Number(index.toBigInt())]; + return array[Number(index.toBigInt())] ?? createField(0n); } let i = toVar(index); // witness result - let a = existsOne(() => array[Number(i.toBigInt())].toBigInt()); + let a = existsOne(() => array[Number(i.toBigInt())].toBigInt() ?? 0n); // we prove a === array[j] + z[j]*(i - j) for some z[j], for all j. // setting j = i, this implies a === array[i]