Skip to content

continued support for noir -> r1cs#1

Merged
recmo merged 21 commits into
mainfrom
noir-r1cs-compiler
Mar 31, 2025
Merged

continued support for noir -> r1cs#1
recmo merged 21 commits into
mainfrom
noir-r1cs-compiler

Conversation

@dolores-park
Copy link
Copy Markdown
Collaborator

  • add r1cs optimization, 1 poseidon row count reduced from 644->428

Comment thread noir-r1cs/src/compiler.rs
let term = expr.mul_terms[0];
a = vec![(FieldElement::one(), self.map_witness(term.1))];
b = vec![(FieldElement::one(), self.map_witness(term.2))];
}
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.

There is a more general result: The last mul term never needs an intermediate constraint (even if there are multiple mul-terms).

@dolores-park
Copy link
Copy Markdown
Collaborator Author

dolores-park commented Mar 5, 2025

fixed witness generation

@dolores-park
Copy link
Copy Markdown
Collaborator Author

dolores-park commented Mar 17, 2025

@recmo think this is a good place to merge into main, would love to get feedback / approval from you
for the updates:

  • fixed & optimized the -> r1cs process
  • added witness population from .gz witness files
  • added bunch of IO functions

to test,
run commands like
cargo run --bin noir-r1cs -- noir /Users/ende.shen/pork/ProveKit/noir-r1cs/noir-examples/basic-3/target/basic.json /Users/ende.shen/pork/ProveKit/noir-r1cs/noir-examples/basic-3/target/basic.gz
after that,
there should be a r1cs.json file generated,
and that file can be copied into ssh://git@github.com/reilabs/ProveKit.git, and proven with their prover/src/main.rs

On a separate note,
I've found the std impl of sha256, in the history of noir-lang repo,
https://github.com/noir-lang/noir/blob/e895feb4e7b25530a22668bca597dfc78be92584/noir_stdlib/src/hash/sha256.nr
In all its history, it always had

#[foreign(sha256_compression)]
pub fn sha256_compression(_input: [u32; 16], _state: [u32; 8]) -> [u32; 8] {}

as a blackbox function anyways, so will try to
rip the r1cs constraints from circom / gnark

@dolores-park
Copy link
Copy Markdown
Collaborator Author

dolores-park commented Mar 17, 2025

Added some scripts from @RyanCao7 , to run use

cd noir-r1cs
bash scripts/run_all.sh

see the outputs at scripts/all_outputs.txt

@dolores-park
Copy link
Copy Markdown
Collaborator Author

dolores-park commented Mar 26, 2025

To have a full end to end run,
try picking a noir program
say cd noir-r1cs/noir-examples/poseidon-rounds
provide the correct Prover.toml file under that dir (inputs to noir programs)
and run
nargo execute
to generate
.json file -- represent the circuit represented in ACIR
and .gz file -- represent the witness

after having the noir intermediate representations, compile file at noir-r1cs/src/main.rs
and run
target/debug/noir-r1cs /path-to/*.json /path-to/*.gz
the two args are path to .json file and path to .gz file

after that, there should be a r1cs.json at this ProveKit, this is the ABC matrices that representing the r1cs

==========================================================================================
(For these below, also checkout https://github.com/reilabs/gnark-whir/blob/main/README.md)

copy that to the repo at
https://github.com/reilabs/ProveKit.git
as prover/r1cs.json
and run
rustup run beta cargo run --bin prover -- --input_file_path prover/r1cs.json
to get the two files
prover/params and prover/proof

checkout the repo at
https://github.com/reilabs/gnark-whir
cd into the repo, and run
go run .
note that it assumes
https://github.com/reilabs/gnark-whir and https://github.com/reilabs/ProveKit.git live side by side, and the two files prover/params and prover/proof live in https://github.com/reilabs/ProveKit.git.

==========================================================================================

@recmo
Copy link
Copy Markdown
Contributor

recmo commented Mar 31, 2025

For above instructions to work it is important that the noirc version matches the noirc_artifacts crate.

noirup -C 03b58fa2

dcbuild3r pushed a commit that referenced this pull request May 16, 2026
dcbuild3r pushed a commit that referenced this pull request May 16, 2026
continued support for noir -> r1cs
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