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

Expose some types and gadgets #1860

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

mitschabaude
Copy link
Contributor

@mitschabaude mitschabaude commented Oct 10, 2024

Several additions that were handy when implementing dynamic-length SHA2 and general-purpose array types in zksecurity/mina-attestations#25

  • Exposes a few utility types like InferValue, From, TupleN
  • Exposes a few gadgets like arrayGet() and UInt32 to/from bytes
  • make the Packed class much better typed

CI run here: zksecurity#2

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some unused imports and an unused method purged here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exposing the uint32 / bytes converters that we already use internally for sha2

Comment on lines -242 to +237
function sha256Compression(H: UInt32[], W: UInt32[]) {
function sha256Compression([...H]: UInt32[], W: UInt32[]) {
Copy link
Contributor Author

@mitschabaude mitschabaude Oct 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fixes a bug, the compression function mutated its input, which bit me because in dynamic sha2 you don't necessarily want to use the output

Comment on lines +174 to +179
function mapValue<
A extends ProvableHashable<any>,
V extends InferValue<A>,
W,
T extends InferProvable<A>
>(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

method to take one provable and modify its "value" type

Comment on lines +22 to +24

// expore base class so that we can detect Bytes with `instanceof`
Bytes.Base = InternalBytes;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should always expose base classes somewhere for type factories, so that users can detect what class they have using instanceof.
putting base classes on .Base of the factory function seems like a nice, non-intrusive pattern to me.

@mitschabaude mitschabaude marked this pull request as ready for review October 11, 2024 15:15
@mitschabaude
Copy link
Contributor Author

@Trivo25 or @ymekuria this is ready for review

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.

1 participant