diff --git a/CHANGELOG.md b/CHANGELOG.md index 52e6dc9e8..e41c7fca1 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 diff --git a/src/bindings b/src/bindings index 1e2957723..cbdbff3d9 160000 --- a/src/bindings +++ b/src/bindings @@ -1 +1 @@ -Subproject commit 1e29577237e331a1e0040398cc929ff295fd3383 +Subproject commit cbdbff3d9c317aa1131667cd56f2a8a374640436 diff --git a/src/lib/provable/test/struct.unit-test.ts b/src/lib/provable/test/struct.unit-test.ts index 5554aafc8..8aaef12fe 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! 🎉'); diff --git a/src/lib/provable/types/struct.ts b/src/lib/provable/types/struct.ts index 60e9d23c3..96d962d4e 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