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: acir_formal_proofs #6947

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

jewelofchaos9
Copy link

Description

The ACIR formal verification. Combines a test generator in the Noir repository with a formal verifier in Barretenberg to mathematically prove the correctness of ACIR instructions using SMT solving. Verifies range of operations including 127-bit arithmetic (addition, subtraction, multiplication), 126-bit division, bitwise operations (though currently limited to 32-bit for AND/OR/XOR), shift operations, field operations (ADD, MUL, DIV), and comparison operations

Additional Context

aztec-packages PR

Documentation*

Check one:

  • No documentation needed.
  • Documentation included in this PR.
  • [For Experimental Features] Documentation to be submitted in a separate PR.

PR Checklist*

  • I have tested the changes locally.
  • I have formatted the changes with Prettier and/or cargo fmt on default settings.

Copy link
Contributor

github-actions bot commented Jan 6, 2025

Thank you for your contribution to the Noir language.

Please do not force push to this branch after the Noir team have started review of this PR. Doing so will only delay us merging your PR as we will need to start the review process from scratch.

Thanks for your understanding.

@jewelofchaos9 jewelofchaos9 changed the title init for acir_formal_proofs feat: acir_formal_proofs Jan 6, 2025
@@ -28,7 +28,7 @@ impl<T> Id<T> {
///
/// This is private so that we can guarantee ids created from this function
/// point to valid T values in their external maps.
fn new(index: u32) -> Self {
pub(crate) fn new(index: u32) -> Self {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why?

Copy link
Author

Choose a reason for hiding this comment

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

Why?

It was changed in #6807 from pub(crate) to private. I can not use test_new instead, because of #[cfg(test)] attribute. I need Id for function building.

Copy link
Collaborator

@Rumata888 Rumata888 left a comment

Choose a reason for hiding this comment

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

Please change how you import dependencies (Cargo.toml) and remove .gitignore


/// Creates an SSA function for truncate operations
fn truncate_function(variable_type: Type) -> Ssa {
// truncate v0: field 10, 20?..
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why the question mark?

Copy link
Author

@jewelofchaos9 jewelofchaos9 Jan 6, 2025

Choose a reason for hiding this comment

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

Why the question mark?

I wasn't sure what the third argument (max_bit_size) of the Truncate opcode does. Fixed.

Comment on lines +26 to +38
pub struct InstructionArtifacts {
/// Name of the instruction
pub instruction_name: String,

/// SSA representation formatted as "acir(inline) {...}"
pub formatted_ssa: String,

/// JSON serialized SSA
pub serialized_ssa: String,

/// Gzipped bytes of ACIR program
pub serialized_acir: Vec<u8>,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks quite specific to the use case you have. Could it live in the new crate you created?

Copy link
Author

Choose a reason for hiding this comment

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

This looks quite specific to the use case you have. Could it live in the new crate you created?

No, InstructionArtifacts needs to stay in noirc_evaluator since its implementation uses internal methods and structs of this crate. I don't know how to move this struct to the new crate without breaking the current architecture, if I understand you correctly

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, I see even FunctionBuilder is only pub(crate). Maybe there is a case for making that public, as a more general purpose SSA related utility, than making InstructionArtifacts part of the public interface, given its limited scope. I could be wrong, just seeing different serialised SSA formats in it seems overly specific to how you are generating the inputs for the verification, not something anyone else will use.

Copy link
Author

Choose a reason for hiding this comment

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

I can try to move the entire ssa_verification crate into the noirc_evaluator crate -- this way we wouldn't need to expose anything. However, I'm not sure if this is the right approach since ssa_verification is very specific.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, I don’t think that’s the right approach either. Maybe @TomAFrench can weigh in on how important it is to keep things private to the crate?

Comment on lines +26 to +27
FLAGS:
-d, --dir <PATH> Output directory for test artifacts [default: ../../../../../barretenberg/cpp/src/barretenberg/acir_formal_proofs/artifacts/]"
Copy link
Contributor

Choose a reason for hiding this comment

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

I think clap creates these on its own.

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.

3 participants