Skip to content

Commit

Permalink
handle out of bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
mitschabaude committed Oct 11, 2024
1 parent ecc4b03 commit ee52796
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lib/provable/gadgets/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit ee52796

Please sign in to comment.