Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Detailed Error Handling for Invalid Struct Type Usage #278

Merged
merged 4 commits into from
Jul 5, 2024

Conversation

MartinMinkov
Copy link
Contributor

@MartinMinkov MartinMinkov commented Jun 27, 2024

Summary

This PR addresses an issue with the check() method in circuit classes extending Struct.

Changes

  • Add a runtime check for check which checks if we are running on a Struct and throw an error if so

Test Case

import { Struct, Bool, Field } from 'o1js';

class WrappedStruct extends Struct({
  wrappedA: Struct,
}) {}

class WrappedBool extends Struct({
  wrappedB: Bool,
}) {}

class WrappedStructGood extends Struct({
  wrappedA: WrappedBool,
}) {}

let notBool = new Bool(false);
notBool.value = new Field(2n).value; // set to a non-bool

let wrappedBool = new WrappedBool({
  wrappedB: notBool,
});
let wrappedWrappedBool = new WrappedStruct({
  wrappedA: wrappedBool,
});

let wrappedWrappedBoolGood = new WrappedStructGood({
  wrappedA: wrappedBool,
});

WrappedBool.check(wrappedBool); // should throw error correctly from check (invalid Bool)
WrappedStructGood.check(wrappedWrappedBoolGood); // should throw error correctly from check (invalid Bool)
WrappedStruct.check(wrappedWrappedBool); // should error here with thrown error (cannot use Struct here)

…eateDerivers function to prevent incorrect usage and provide correct usage examples
@MartinMinkov MartinMinkov changed the title Add Detailed Error Handling for Invalid Struct/CircuitValue Type Usage Add Detailed Error Handling for Invalid Struct Type Usage Jun 27, 2024
@MartinMinkov MartinMinkov requested a review from Trivo25 June 27, 2024 19:18
@MartinMinkov MartinMinkov marked this pull request as ready for review June 27, 2024 19:18
@MartinMinkov MartinMinkov self-assigned this Jun 28, 2024
@MartinMinkov MartinMinkov requested a review from mitschabaude July 2, 2024 16:18
@MartinMinkov MartinMinkov merged commit df8c87e into main Jul 5, 2024
1 check passed
@MartinMinkov MartinMinkov deleted the feat/inheritence-circuitvalues branch July 5, 2024 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants