From 0a30b295d0fd116b4c7cbdba850de986a28964c9 Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 24 Oct 2024 18:19:58 +0200 Subject: [PATCH 1/2] don't fail on out of bounds index --- src/lib/provable/gadgets/basic.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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] From 4123a24355227164bc8ab80344571e19d60ce27a Mon Sep 17 00:00:00 2001 From: Gregor Date: Thu, 24 Oct 2024 20:46:34 +0200 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) 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