diff --git a/CHANGELOG.md b/CHANGELOG.md index 144f77cac..386946e42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Unreleased](https://github.com/o1-labs/o1js/compare/b04520d...HEAD) +### Fixed + +- Witness generation error in `Gadgets.arrayGet()` when accessing out-of-bounds indices https://github.com/o1-labs/o1js/pull/1886 + ## [2.0.0](https://github.com/o1-labs/o1js/compare/7e9394...b04520d) ### Breaking Changes diff --git a/src/lib/provable/gadgets/basic.ts b/src/lib/provable/gadgets/basic.ts index aaf893591..235472780 100644 --- a/src/lib/provable/gadgets/basic.ts +++ b/src/lib/provable/gadgets/basic.ts @@ -85,7 +85,7 @@ function arrayGet(array: Field[], index: Field) { let i = toVar(index); // witness result - let a = existsOne(() => array[Number(i.toBigInt())].toBigInt() ?? 0n); + 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]