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

feat(noir): autogenerate contract interface for calling from external contracts #1487

Merged
merged 16 commits into from
Aug 14, 2023

Conversation

spalladino
Copy link
Collaborator

@spalladino spalladino commented Aug 9, 2023

Builds on @iAmMichaelConnor work to generate a contract interface for simplifying calling function in other contracts. Uses only information present in the ABI. For each function in the target contract, creates a wrapper function that receives the same arguments, serialises them based on the standard ABI encoding format (see here), and uses the call_private_function from the context to call into them.

To handle custom structs, we're re-defining them in the contract interface. Until we get struct type names in the ABI (see noir-lang/noir#2238), we are autogenerating the name as well, based on the function name and param name where they are used. Serialisation is done manually in the code, but we may want to replace it with a Noir intrinsic when available (see noir-lang/noir#2240).

See this file for example output.

Fixes #1237

@socket-security
Copy link

New dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
@types/lodash.capitalize 4.2.7 None +0 3.84 kB types

@iAmMichaelConnor
Copy link
Contributor

Thanks very much for this Santiago! The final code being generated is so clean!
I've added a few questions, here and there.

There are a few example contracts in noir-contracts/ which could make use of contract interfaces, and the cleaner calling syntax. I guess we can open a separate PR to update the 'call' statements of those contracts?

Copy link
Contributor

@iAmMichaelConnor iAmMichaelConnor left a comment

Choose a reason for hiding this comment

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

.

@spalladino
Copy link
Collaborator Author

@iAmMichaelConnor changes ready!

@spalladino spalladino deleted the mc/contract-interfaces branch August 14, 2023 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Auto-generate a ContractInterface struct (in Noir) for a Noir Contract
2 participants