Skip to content

Commit

Permalink
Merge pull request #1707 from o1-labs/feat/inheritence-circuitvalues
Browse files Browse the repository at this point in the history
Add Detailed Error Handling for Invalid Struct Type Usage
  • Loading branch information
MartinMinkov committed Jul 5, 2024
2 parents 9549719 + e2cfaea commit 4559af8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/bindings
12 changes: 12 additions & 0 deletions src/lib/provable/test/struct.unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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! 🎉');
2 changes: 2 additions & 0 deletions src/lib/provable/types/struct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ type AnyConstructor = Constructor<any>;
* 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
Expand Down

0 comments on commit 4559af8

Please sign in to comment.