Skip to content

Commit

Permalink
Remove customized heights for gen_abar_to_ar and gen_abar_to_bar (#261)
Browse files Browse the repository at this point in the history
* the system does not prefer customized height

* fmt

* edit

* fix

* update

* update

* fmt

* minor

* wasm
  • Loading branch information
weikengchen authored Apr 22, 2023
1 parent 3f70ffb commit 32e6ed6
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 46 deletions.
25 changes: 24 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ env:

jobs:
style:
name: Check Style
name: Check style
runs-on: ubuntu-latest
strategy:
fail-fast: true
Expand All @@ -22,6 +22,29 @@ jobs:
- name: fmt
run: cargo fmt --all -- --check

check-benches:
name: Check benchmarks
runs-on: ubuntu-latest
env:
RUSTFLAGS: -Dwarnings
CARGO_TERM_COLOR: always
strategy:
fail-fast: true
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-benches-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Check
run: |
cargo bench --no-run
test-accumulators:
name: Test (accumulators/)
runs-on: ubuntu-latest
Expand Down
6 changes: 3 additions & 3 deletions api/benches/anon_xfr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use noah::{
AnonAssetRecord, MTLeafInfo, MTNode, MTPath, OpenAnonAssetRecord,
OpenAnonAssetRecordBuilder,
},
FEE_TYPE, TREE_DEPTH,
FEE_TYPE,
},
keys::KeyPair,
xfr::{
Expand Down Expand Up @@ -164,7 +164,7 @@ fn abar_to_abar(
fn abar_to_ar(c: &mut Criterion) {
let mut prng = test_rng();
let address_format = SECP256K1;
let params = ProverParams::gen_abar_to_ar(TREE_DEPTH, address_format).unwrap();
let params = ProverParams::gen_abar_to_ar(address_format).unwrap();
let verify_params = VerifierParams::get_abar_to_ar(address_format).unwrap();

let sender = KeyPair::sample(&mut prng, address_format);
Expand Down Expand Up @@ -226,7 +226,7 @@ fn abar_to_ar(c: &mut Criterion) {
fn abar_to_bar(c: &mut Criterion) {
let mut prng = test_rng();
let address_format = SECP256K1;
let params = ProverParams::gen_abar_to_bar(TREE_DEPTH, address_format).unwrap();
let params = ProverParams::gen_abar_to_bar(address_format).unwrap();
let verify_params = VerifierParams::get_abar_to_bar(address_format).unwrap();

let sender = KeyPair::sample(&mut prng, address_format);
Expand Down
38 changes: 12 additions & 26 deletions api/src/parameters/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,7 @@ impl ProverParams {
}

/// Obtain the parameters for anonymous to confidential.
pub fn gen_abar_to_bar(
tree_depth: usize,
address_format: AddressFormat,
) -> Result<ProverParams> {
pub fn gen_abar_to_bar(address_format: AddressFormat) -> Result<ProverParams> {
let label = match address_format {
SECP256K1 => String::from("abar_to_bar_secp256k1"),
ED25519 => String::from("abar_to_bar_ed25519"),
Expand Down Expand Up @@ -287,7 +284,7 @@ impl ProverParams {
uid: 0,
amount: 0,
asset_type: bls_zero,
path: MTPath::new(vec![node.clone(); tree_depth]),
path: MTPath::new(vec![node.clone(); TREE_DEPTH]),
blind: bls_zero,
};

Expand Down Expand Up @@ -320,13 +317,9 @@ impl ProverParams {
let pcs = load_srs_params(cs_size)?;
let lagrange_pcs = load_lagrange_params(cs_size);

let verifier_params = if tree_depth == TREE_DEPTH {
match VerifierParams::load_abar_to_bar(address_format).ok() {
Some(v) => Some(v.verifier_params),
None => None,
}
} else {
None
let verifier_params = match VerifierParams::load_abar_to_bar(address_format).ok() {
Some(v) => Some(v.verifier_params),
None => None,
};

let prover_params =
Expand Down Expand Up @@ -389,10 +382,7 @@ impl ProverParams {
}

/// Obtain the parameters for anonymous to transparent.
pub fn gen_abar_to_ar(
tree_depth: usize,
address_format: AddressFormat,
) -> Result<ProverParams> {
pub fn gen_abar_to_ar(address_format: AddressFormat) -> Result<ProverParams> {
let label = match address_format {
SECP256K1 => String::from("abar_to_ar_secp256k1"),
ED25519 => String::from("abar_to_ar_ed25519"),
Expand All @@ -418,7 +408,7 @@ impl ProverParams {
uid: 0,
amount: 0,
asset_type: bls_zero,
path: MTPath::new(vec![node.clone(); tree_depth]),
path: MTPath::new(vec![node.clone(); TREE_DEPTH]),
blind: bls_zero,
};
let (_, nullifier_trace) = nullify(
Expand Down Expand Up @@ -446,13 +436,9 @@ impl ProverParams {
let pcs = load_srs_params(cs_size)?;
let lagrange_pcs = load_lagrange_params(cs_size);

let verifier_params = if tree_depth == TREE_DEPTH {
match VerifierParams::load_abar_to_ar(address_format).ok() {
Some(v) => Some(v.verifier_params),
None => None,
}
} else {
None
let verifier_params = match VerifierParams::load_abar_to_ar(address_format).ok() {
Some(v) => Some(v.verifier_params),
None => None,
};

let prover_params =
Expand Down Expand Up @@ -549,7 +535,7 @@ impl VerifierParams {
match Self::load_abar_to_bar(address_format) {
Ok(vk) => Ok(vk),
_ => {
let prover_params = ProverParams::gen_abar_to_bar(TREE_DEPTH, address_format)?;
let prover_params = ProverParams::gen_abar_to_bar(address_format)?;
Ok(VerifierParams::from(prover_params))
}
}
Expand Down Expand Up @@ -646,7 +632,7 @@ impl VerifierParams {
match Self::load_abar_to_ar(address_format) {
Ok(vk) => Ok(vk),
_ => {
let prover_params = ProverParams::gen_abar_to_ar(TREE_DEPTH, address_format)?;
let prover_params = ProverParams::gen_abar_to_ar(address_format)?;
Ok(VerifierParams::from(prover_params))
}
}
Expand Down
8 changes: 4 additions & 4 deletions api/src/parameters/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ fn gen_transfer_vk(directory: PathBuf, address_format: AddressFormat) {
fn gen_abar_to_bar_vk(path: PathBuf) {
println!("Generating the verifying key for ABAR TO BAR for secp256k1 ...");
let mut new_path = path.clone();
let user_params = ProverParams::gen_abar_to_bar(TREE_DEPTH, SECP256K1).unwrap();
let user_params = ProverParams::gen_abar_to_bar(SECP256K1).unwrap();
let node_params = VerifierParams::from(user_params);
println!(
"the size of the constraint system for ABAR TO BAR for secp256k1: {}",
Expand All @@ -213,7 +213,7 @@ fn gen_abar_to_bar_vk(path: PathBuf) {

println!("Generating the verifying key for ABAR TO BAR for ed25519 ...");
let mut new_path = path.clone();
let user_params = ProverParams::gen_abar_to_bar(TREE_DEPTH, ED25519).unwrap();
let user_params = ProverParams::gen_abar_to_bar(ED25519).unwrap();
let node_params = VerifierParams::from(user_params);
println!(
"the size of the constraint system for ABAR TO BAR for ed25519: {}",
Expand Down Expand Up @@ -273,7 +273,7 @@ fn gen_ar_to_abar_vk(mut path: PathBuf) {
fn gen_abar_to_ar_vk(path: PathBuf) {
println!("Generating the verifying key for ABAR TO AR for secp256k1 ...");
let mut new_path = path.clone();
let user_params = ProverParams::gen_abar_to_ar(TREE_DEPTH, SECP256K1).unwrap();
let user_params = ProverParams::gen_abar_to_ar(SECP256K1).unwrap();
let node_params = VerifierParams::from(user_params);
println!(
"the size of the constraint system for ABAR TO AR for secp256k1: {}",
Expand All @@ -290,7 +290,7 @@ fn gen_abar_to_ar_vk(path: PathBuf) {

println!("Generating the verifying key for ABAR TO AR for ed25519 ...");
let mut new_path = path.clone();
let user_params = ProverParams::gen_abar_to_ar(TREE_DEPTH, ED25519).unwrap();
let user_params = ProverParams::gen_abar_to_ar(ED25519).unwrap();
let node_params = VerifierParams::from(user_params);
println!(
"the size of the constraint system for ABAR TO AR for ed25519: {}",
Expand Down
6 changes: 3 additions & 3 deletions smoke-tests/src/tests/smoke_axfr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ mod smoke_axfr {
AnonAssetRecord, MTLeafInfo, MTNode, MTPath, OpenAnonAssetRecord,
OpenAnonAssetRecordBuilder,
},
FEE_TYPE, TREE_DEPTH,
FEE_TYPE,
},
keys::{KeyPair, KeyType, PublicKey},
xfr::{
Expand Down Expand Up @@ -249,7 +249,7 @@ mod smoke_axfr {
SecretKey::Secp256k1(_) => SECP256K1,
};

let params = ProverParams::gen_abar_to_ar(TREE_DEPTH, address_format).unwrap();
let params = ProverParams::gen_abar_to_ar(address_format).unwrap();
let verify_params = VerifierParams::get_abar_to_ar(address_format).unwrap();

let fdb = MemoryDB::new();
Expand Down Expand Up @@ -362,7 +362,7 @@ mod smoke_axfr {
SecretKey::Secp256k1(_) => SECP256K1,
};

let params = ProverParams::gen_abar_to_bar(TREE_DEPTH, address_format).unwrap();
let params = ProverParams::gen_abar_to_bar(address_format).unwrap();
let verify_params = VerifierParams::get_abar_to_bar(address_format).unwrap();

let fdb = MemoryDB::new();
Expand Down
6 changes: 3 additions & 3 deletions smoke-tests/src/tests/smoke_axfr_compatibility.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ mod smoke_axfr_compatibility {
AnonAssetRecord, AxfrOwnerMemo, MTLeafInfo, MTNode, MTPath, OpenAnonAssetRecord,
OpenAnonAssetRecordBuilder,
},
FEE_TYPE, TREE_DEPTH,
FEE_TYPE,
},
keys::KeyPair,
xfr::{
Expand Down Expand Up @@ -309,7 +309,7 @@ mod smoke_axfr_compatibility {
};

let mut prng = test_rng();
let params = ProverParams::gen_abar_to_ar(TREE_DEPTH, address_format).unwrap();
let params = ProverParams::gen_abar_to_ar(address_format).unwrap();
let verify_params = VerifierParams::get_abar_to_ar(address_format).unwrap();
let receiver = if prng.gen() {
KeyPair::sample(&mut prng, SECP256K1)
Expand Down Expand Up @@ -456,7 +456,7 @@ mod smoke_axfr_compatibility {
SecretKey::Secp256k1(_) => SECP256K1,
};

let params = ProverParams::gen_abar_to_bar(TREE_DEPTH, address_format).unwrap();
let params = ProverParams::gen_abar_to_bar(address_format).unwrap();
let verify_params = VerifierParams::get_abar_to_bar(address_format).unwrap();
let receiver = if prng.gen() {
KeyPair::sample(&mut prng, SECP256K1)
Expand Down
5 changes: 2 additions & 3 deletions smoke-tests/src/tests/smoke_axfr_secp256k1_address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ mod smoke_axfr_secp256k1_address {
AnonAssetRecord, MTLeafInfo, MTNode, MTPath, OpenAnonAssetRecord,
OpenAnonAssetRecordBuilder,
},
TREE_DEPTH,
},
keys::{KeyPair, PublicKey},
xfr::{
Expand Down Expand Up @@ -177,7 +176,7 @@ mod smoke_axfr_secp256k1_address {
#[test]
fn abar_to_address() {
let mut prng = test_rng();
let params = ProverParams::gen_abar_to_ar(TREE_DEPTH, SECP256K1).unwrap();
let params = ProverParams::gen_abar_to_ar(SECP256K1).unwrap();
let verify_params = VerifierParams::get_abar_to_ar(SECP256K1).unwrap();

let sender = KeyPair::sample(&mut prng, SECP256K1);
Expand Down Expand Up @@ -225,7 +224,7 @@ mod smoke_axfr_secp256k1_address {
#[test]
fn abar_to_secp256k1() {
let mut prng = test_rng();
let params = ProverParams::gen_abar_to_bar(TREE_DEPTH, SECP256K1).unwrap();
let params = ProverParams::gen_abar_to_bar(SECP256K1).unwrap();
let verify_params = VerifierParams::get_abar_to_bar(SECP256K1).unwrap();

let sender = KeyPair::sample(&mut prng, SECP256K1);
Expand Down
6 changes: 3 additions & 3 deletions smoke-tests/src/tests/smoke_axfr_wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod smoke_axfr_wasm {
AnonAssetRecord, MTLeafInfo, MTNode, MTPath, OpenAnonAssetRecord,
OpenAnonAssetRecordBuilder,
},
FEE_TYPE, TREE_DEPTH,
FEE_TYPE,
},
keys::{KeyPair, PublicKey},
xfr::{
Expand Down Expand Up @@ -189,7 +189,7 @@ mod smoke_axfr_wasm {
fn abar_to_ar(sender: KeyPair, receiver: KeyPair) {
let seed: [u8; 32] = [0u8; 32];
let mut prng = ChaChaRng::from_seed(seed);
let params = ProverParams::gen_abar_to_ar(TREE_DEPTH, SECP256K1).unwrap();
let params = ProverParams::gen_abar_to_ar(SECP256K1).unwrap();
let verify_params = VerifierParams::get_abar_to_ar(SECP256K1).unwrap();

let mut mt = EphemeralMerkleTree::new().unwrap();
Expand Down Expand Up @@ -237,7 +237,7 @@ mod smoke_axfr_wasm {
fn abar_to_bar(sender: KeyPair, receiver: KeyPair) {
let seed: [u8; 32] = [0u8; 32];
let mut prng = ChaChaRng::from_seed(seed);
let params = ProverParams::gen_abar_to_bar(TREE_DEPTH, SECP256K1).unwrap();
let params = ProverParams::gen_abar_to_bar(SECP256K1).unwrap();
let verify_params = VerifierParams::get_abar_to_bar(SECP256K1).unwrap();

let mut mt = EphemeralMerkleTree::new().unwrap();
Expand Down

0 comments on commit 32e6ed6

Please sign in to comment.