Skip to content

Commit 536a067

Browse files
AztecBotvezenovmTomAFrench
committed
feat: Sync from noir (AztecProtocol/aztec-packages#5794)
Automated pull of development from the [noir](https://github.com/noir-lang/noir) programming language, a dependency of Aztec. BEGIN_COMMIT_OVERRIDE chore: fix alerts on rust msrv (#4817) chore(ci): fix alerts on msrv issues (#4816) chore: run clippy (#4810) chore: optimize poseidon2 implementation (#4807) fix: catch panics from EC point creation (e.g. the point is at infinity) (#4790) feat: Sync from aztec-packages (#4792) feat: lalrpop lexer prototype (#4656) feat(nargo): Handle call stacks for multiple Acir calls (#4711) fix: proper field inversion for bigints (#4802) feat: add `NARGO_FOREIGN_CALL_TIMEOUT` environment variable (#4780) chore(debugger): Docs (#4145) feat: narrow ABI encoding errors down to target problem argument/field (#4798) chore: Rename 'global' to 'function' in the monomorphization pass (#4774) chore: Add Hir -> Ast conversion (#4788) fix: Fix panic when returning a zeroed unit value (#4797) END_COMMIT_OVERRIDE --------- Co-authored-by: vezenovm <[email protected]> Co-authored-by: Tom French <[email protected]>
2 parents b25ca49 + 3d39823 commit 536a067

13 files changed

Lines changed: 610 additions & 990 deletions

File tree

.aztec-sync-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
274f7d935230ce21d062644f6ec5f7cd0f58ae62
1+
84c930a912ca9ed0d9c0ce2436309a4e9a840bcb

.github/workflows/test-rust-workspace-msrv.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ jobs:
112112
# We treat any cancelled, skipped or failing jobs as a failure for the workflow as a whole.
113113
FAIL: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped') }}
114114

115+
- name: Checkout
116+
if: ${{ failure() }}
117+
uses: actions/checkout@v4
118+
115119
# Raise an issue if the tests failed
116120
- name: Alert on failed publish
117121
uses: JasonEtco/create-an-issue@v2
@@ -122,4 +126,4 @@ jobs:
122126
WORKFLOW_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
123127
with:
124128
update_existing: true
125-
filename: .github/JS_PUBLISH_FAILED.md
129+
filename: .github/ACVM_NOT_PUBLISHABLE.md

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ examples/**/target/
44
examples/9
55
node_modules
66
pkg/
7+
.idea
78

89
# Yarn
910
.pnp.*

Cargo.lock

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

acvm-repo/bn254_blackbox_solver/Cargo.toml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ repository.workspace = true
1616
acir.workspace = true
1717
acvm_blackbox_solver.workspace = true
1818
thiserror.workspace = true
19-
num-traits.workspace = true
2019
cfg-if = "1.0.0"
20+
hex.workspace = true
21+
lazy_static = "1.4"
2122

2223
# BN254 fixed base scalar multiplication solver
2324
grumpkin = { version = "0.1.0", package = "noir_grumpkin", features = ["std"] }
@@ -38,6 +39,18 @@ js-sys.workspace = true
3839
getrandom.workspace = true
3940
wasmer = "4.2.6"
4041

42+
[dev-dependencies]
43+
criterion = "0.5.0"
44+
pprof = { version = "0.12", features = [
45+
"flamegraph",
46+
"frame-pointer",
47+
"criterion",
48+
] }
49+
50+
[[bench]]
51+
name = "criterion"
52+
harness = false
53+
4154
[features]
4255
default = ["bn254"]
4356
bn254 = ["acir/bn254"]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use criterion::{criterion_group, criterion_main, Criterion};
2+
use std::{hint::black_box, time::Duration};
3+
4+
use acir::FieldElement;
5+
use bn254_blackbox_solver::poseidon2_permutation;
6+
7+
use pprof::criterion::{Output, PProfProfiler};
8+
9+
fn bench_poseidon2(c: &mut Criterion) {
10+
let inputs = [FieldElement::zero(); 4];
11+
12+
c.bench_function("poseidon2", |b| b.iter(|| poseidon2_permutation(black_box(&inputs), 4)));
13+
}
14+
15+
criterion_group!(
16+
name = benches;
17+
config = Criterion::default().sample_size(40).measurement_time(Duration::from_secs(20)).with_profiler(PProfProfiler::new(100, Output::Flamegraph(None)));
18+
targets = bench_poseidon2
19+
);
20+
21+
criterion_main!(benches);

acvm-repo/bn254_blackbox_solver/src/fixed_base_scalar_mul.rs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,29 @@ pub fn fixed_base_scalar_mul(
4747
}
4848
}
4949

50+
fn create_point(x: FieldElement, y: FieldElement) -> Result<grumpkin::SWAffine, String> {
51+
let point = grumpkin::SWAffine::new_unchecked(x.into_repr(), y.into_repr());
52+
if !point.is_on_curve() {
53+
return Err(format!("Point ({}, {}) is not on curve", x.to_hex(), y.to_hex()));
54+
};
55+
if !point.is_in_correct_subgroup_assuming_on_curve() {
56+
return Err(format!("Point ({}, {}) is not in correct subgroup", x.to_hex(), y.to_hex()));
57+
};
58+
Ok(point)
59+
}
60+
5061
pub fn embedded_curve_add(
5162
input1_x: FieldElement,
5263
input1_y: FieldElement,
5364
input2_x: FieldElement,
5465
input2_y: FieldElement,
5566
) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> {
56-
let mut point1 = grumpkin::SWAffine::new(input1_x.into_repr(), input1_y.into_repr());
57-
let point2 = grumpkin::SWAffine::new(input2_x.into_repr(), input2_y.into_repr());
58-
let res = point1 + point2;
59-
point1 = res.into();
60-
if let Some((res_x, res_y)) = point1.xy() {
67+
let point1 = create_point(input1_x, input1_y)
68+
.map_err(|e| BlackBoxResolutionError::Failed(BlackBoxFunc::EmbeddedCurveAdd, e))?;
69+
let point2 = create_point(input2_x, input2_y)
70+
.map_err(|e| BlackBoxResolutionError::Failed(BlackBoxFunc::EmbeddedCurveAdd, e))?;
71+
let res = grumpkin::SWAffine::from(point1 + point2);
72+
if let Some((res_x, res_y)) = res.xy() {
6173
Ok((FieldElement::from_repr(*res_x), FieldElement::from_repr(*res_y)))
6274
} else {
6375
Err(BlackBoxResolutionError::Failed(
@@ -72,6 +84,7 @@ mod grumpkin_fixed_base_scalar_mul {
7284
use ark_ff::BigInteger;
7385

7486
use super::*;
87+
7588
#[test]
7689
fn smoke_test() -> Result<(), BlackBoxResolutionError> {
7790
let input = FieldElement::one();
@@ -84,6 +97,7 @@ mod grumpkin_fixed_base_scalar_mul {
8497
assert_eq!(y, res.1.to_hex());
8598
Ok(())
8699
}
100+
87101
#[test]
88102
fn low_high_smoke_test() -> Result<(), BlackBoxResolutionError> {
89103
let low = FieldElement::one();
@@ -103,9 +117,9 @@ mod grumpkin_fixed_base_scalar_mul {
103117
let max_limb = FieldElement::from(u128::MAX);
104118
let invalid_limb = max_limb + FieldElement::one();
105119

106-
let expected_error = Err(BlackBoxResolutionError::Failed(
120+
let expected_error = Err(BlackBoxResolutionError::Failed(
107121
BlackBoxFunc::FixedBaseScalarMul,
108-
"Limb 0000000000000000000000000000000100000000000000000000000000000000 is not less than 2^128".into()
122+
"Limb 0000000000000000000000000000000100000000000000000000000000000000 is not less than 2^128".into(),
109123
));
110124

111125
let res = fixed_base_scalar_mul(&invalid_limb, &FieldElement::zero());
@@ -128,7 +142,23 @@ mod grumpkin_fixed_base_scalar_mul {
128142
res,
129143
Err(BlackBoxResolutionError::Failed(
130144
BlackBoxFunc::FixedBaseScalarMul,
131-
"30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47 is not a valid grumpkin scalar".into()
145+
"30644e72e131a029b85045b68181585d97816a916871ca8d3c208c16d87cfd47 is not a valid grumpkin scalar".into(),
146+
))
147+
);
148+
}
149+
150+
#[test]
151+
fn rejects_addition_of_points_not_in_curve() {
152+
let x = FieldElement::from(1u128);
153+
let y = FieldElement::from(2u128);
154+
155+
let res = embedded_curve_add(x, y, x, y);
156+
157+
assert_eq!(
158+
res,
159+
Err(BlackBoxResolutionError::Failed(
160+
BlackBoxFunc::EmbeddedCurveAdd,
161+
"Point (0000000000000000000000000000000000000000000000000000000000000001, 0000000000000000000000000000000000000000000000000000000000000002) is not on curve".into(),
132162
))
133163
);
134164
}

acvm-repo/bn254_blackbox_solver/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mod poseidon2;
1010
mod wasm;
1111

1212
pub use fixed_base_scalar_mul::{embedded_curve_add, fixed_base_scalar_mul};
13-
use poseidon2::Poseidon2;
13+
pub use poseidon2::poseidon2_permutation;
1414
use wasm::Barretenberg;
1515

1616
use self::wasm::{Pedersen, SchnorrSig};
@@ -112,7 +112,6 @@ impl BlackBoxFunctionSolver for Bn254BlackBoxSolver {
112112
inputs: &[FieldElement],
113113
len: u32,
114114
) -> Result<Vec<FieldElement>, BlackBoxResolutionError> {
115-
let poseidon = Poseidon2::new();
116-
poseidon.permutation(inputs, len)
115+
poseidon2_permutation(inputs, len)
117116
}
118117
}

0 commit comments

Comments
 (0)