From f611f2c4195b3e54fad40165ad4974c22e4be16f Mon Sep 17 00:00:00 2001 From: Martin Minkov Date: Thu, 27 Jun 2024 12:17:18 -0700 Subject: [PATCH 1/4] chore(bindings): update subproject commit hash to cbdbff3d9c317aa1131667cd56f2a8a374640436 --- src/bindings | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings b/src/bindings index 1e29577237..cbdbff3d9c 160000 --- a/src/bindings +++ b/src/bindings @@ -1 +1 @@ -Subproject commit 1e29577237e331a1e0040398cc929ff295fd3383 +Subproject commit cbdbff3d9c317aa1131667cd56f2a8a374640436 From 3527fb8f4fc15869315ca5b7ce73f0c720f33d23 Mon Sep 17 00:00:00 2001 From: Martin Minkov Date: Thu, 27 Jun 2024 14:39:58 -0700 Subject: [PATCH 2/4] docs(struct.ts): add note about potential issues when directly using `Struct` as a type, and how to avoid them Co-authored-by: Gregor Mitscha-Baude --- src/lib/provable/types/struct.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/provable/types/struct.ts b/src/lib/provable/types/struct.ts index 60e9d23c30..96d962d4e6 100644 --- a/src/lib/provable/types/struct.ts +++ b/src/lib/provable/types/struct.ts @@ -129,6 +129,8 @@ type AnyConstructor = Constructor; * Again, it's important to note that this doesn't enable you to prove anything about the `fullName` string. * From the circuit point of view, it simply doesn't exist! * + * @note Ensure you do not use or extend `Struct` as a type directly. Instead, always call it as a function to construct a type. `Struct` is not a valid provable type itself, types created with `Struct(...)` are. + * * @param type Object specifying the layout of the `Struct` * @param options Advanced option which allows you to force a certain order of object keys * @returns Class which you can extend From b4401afaffbe3451fb475057253e6cf24f37f2f7 Mon Sep 17 00:00:00 2001 From: Martin Minkov Date: Thu, 27 Jun 2024 14:42:18 -0700 Subject: [PATCH 3/4] docs(CHANGELOG.md): update Unreleased section with fix details for static `check()` method in Struct classes to improve documentation --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52e6dc9e83..e41c7fca13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Fixed - Fix reversed order of account updates when using `TokenContract.approveAccountUpdates()` https://github.com/o1-labs/o1js/pull/1722 +- Fixed the static `check()` method in Struct classes to properly handle inheritance, preventing issues with under-constrained circuits. Added error handling to avoid using Struct directly as a field type. https://github.com/o1-labs/o1js/pull/1707 ## [1.4.0](https://github.com/o1-labs/o1js/compare/40c597775...ed198f305) - 2024-06-25 From e2cfaea42c93a5a7a1c8d59a70f17905ffab8938 Mon Sep 17 00:00:00 2001 From: Martin Minkov Date: Tue, 2 Jul 2024 09:16:43 -0700 Subject: [PATCH 4/4] feat(struct.unit-test.ts): add test case for invalid struct property to ensure struct validation works as expected --- src/lib/provable/test/struct.unit-test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/lib/provable/test/struct.unit-test.ts b/src/lib/provable/test/struct.unit-test.ts index 5554aafc81..8aaef12fe8 100644 --- a/src/lib/provable/test/struct.unit-test.ts +++ b/src/lib/provable/test/struct.unit-test.ts @@ -265,4 +265,16 @@ await tx.prove(); // assert that prover got the target string expect(gotTargetString).toEqual(true); +// Having `Struct` as a property is not allowed +class InvalidStruct extends Struct({ + inner: Struct, +}) {} + +expect(() => { + let invalidStruct = new InvalidStruct({ + inner: MyStruct.empty(), + }); + InvalidStruct.check(invalidStruct); +}).toThrow(); + console.log('provable types work as expected! 🎉');