Skip to content

feat: acir_formal_proofs#6947

Closed
defkit wants to merge 4 commits intonoir-lang:masterfrom
defkit:master
Closed

feat: acir_formal_proofs#6947
defkit wants to merge 4 commits intonoir-lang:masterfrom
defkit:master

Conversation

@defkit
Copy link
Copy Markdown
Contributor

@defkit defkit commented Jan 6, 2025

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.

@github-actions
Copy link
Copy Markdown
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.

@defkit defkit changed the title init for acir_formal_proofs feat: acir_formal_proofs Jan 6, 2025
/// 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
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why?

Copy link
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

@defkit defkit 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
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
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
Copy Markdown
Contributor 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
Copy Markdown
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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@aakoshh after looking this over, I wonder if it would be better to expose the SSA parser we use in tests and not FunctionBuilder 🤔 To me it looks like it makes more sense as a public (debugging etc) interface

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree with exposing the parser, it's much easier to get started with if we have an SSA to start off from. I suppose the benefit of the FunctionBuilder is compile time warnings about any breaking change, but the parser is pretty good at pointing out what's wrong with a snippet.

@defkit defkit requested review from Rumata888 and aakoshh January 6, 2025 17:18
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
Copy Markdown
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.

@defkit defkit mentioned this pull request Apr 21, 2025
5 tasks
@defkit defkit marked this pull request as draft April 21, 2025 10:49
@defkit defkit closed this May 22, 2025
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.

4 participants