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

New-generation Marlin with SonicKZG10 as PC #317

Merged
merged 26 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8d86165
progress 7/28
weikengchen Jul 29, 2021
a5a8f61
adjust the changes
weikengchen Jul 29, 2021
324ae91
progress
weikengchen Jul 29, 2021
9637a04
some progress
weikengchen Jul 30, 2021
21f1169
some progress
weikengchen Jul 30, 2021
8683f6b
Merge remote-tracking branch 'origin/testnet2' into feat/new-marlin
weikengchen Jul 30, 2021
5c6392d
Merge branch 'feat/new-marlin' of https://github.com/AleoHQ/snarkVM i…
weikengchen Jul 30, 2021
ecc156f
progress
weikengchen Jul 31, 2021
9f93fe3
progress
weikengchen Aug 1, 2021
b80ba39
progress
weikengchen Aug 2, 2021
48f3a1c
progress; fix the missing marlin-testnet1 tomorrow
weikengchen Aug 2, 2021
e17cda1
Merge remote-tracking branch 'origin/testnet2' into feat/new-marlin
weikengchen Aug 2, 2021
0ce5802
Merge branch 'feat/new-marlin' of https://github.com/AleoHQ/snarkVM i…
weikengchen Aug 2, 2021
d29b00a
end-to-end test
weikengchen Aug 2, 2021
311748d
constraint gadgets
weikengchen Aug 2, 2021
eea4f71
adjust the parameters
weikengchen Aug 2, 2021
d057c50
fmt
weikengchen Aug 2, 2021
96892b3
fix ledger
weikengchen Aug 2, 2021
0245b60
fix ledger
weikengchen Aug 2, 2021
59a2506
eprintln
weikengchen Aug 2, 2021
1437ae3
clippy
weikengchen Aug 2, 2021
bf57c4f
apply the review comments
weikengchen Aug 2, 2021
5c94e7a
Merge branch 'testnet2' into feat/new-marlin
weikengchen Aug 4, 2021
1437e37
fix the merge conflict
weikengchen Aug 4, 2021
af1b719
Merge branch 'testnet2' into feat/new-marlin
weikengchen Aug 6, 2021
5129552
Resamples all parameters
Aug 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .integration/tests/dpc_testnet1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fn dpc_testnet1_integration_test() {
previous_block_hash: BlockHeaderHash([0u8; 32]),
merkle_root_hash: MerkleRootHash([0u8; 32]),
pedersen_merkle_root_hash: PedersenMerkleRootHash([0u8; 32]),
proof: ProofOfSuccinctWork([0u8; 972]),
proof: ProofOfSuccinctWork::default(),
time: 0,
difficulty_target: 0xFFFF_FFFF_FFFF_FFFF_u64,
nonce: 0,
Expand Down Expand Up @@ -187,7 +187,7 @@ fn dpc_testnet1_integration_test() {
difficulty_target: previous_block.header.difficulty_target,
nonce: 0,
pedersen_merkle_root_hash: PedersenMerkleRootHash([0u8; 32]),
proof: ProofOfSuccinctWork([0u8; 972]),
proof: ProofOfSuccinctWork::default(),
};

assert!(Testnet1DPC::verify_transactions(&dpc, &transactions.0, &ledger));
Expand Down Expand Up @@ -282,7 +282,7 @@ fn test_testnet1_dpc_execute_constraints() {
difficulty_target: 0xFFFF_FFFF_FFFF_FFFF_u64,
nonce: 0,
pedersen_merkle_root_hash: PedersenMerkleRootHash([0u8; 32]),
proof: ProofOfSuccinctWork([0u8; 972]),
proof: ProofOfSuccinctWork::default(),
},
transactions: Transactions::new(),
};
Expand Down
8 changes: 4 additions & 4 deletions .integration/tests/dpc_testnet2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn dpc_testnet2_integration_test() {
previous_block_hash: BlockHeaderHash([0u8; 32]),
merkle_root_hash: MerkleRootHash([0u8; 32]),
pedersen_merkle_root_hash: PedersenMerkleRootHash([0u8; 32]),
proof: ProofOfSuccinctWork([0u8; 972]),
proof: ProofOfSuccinctWork::default(),
time: 0,
difficulty_target: 0xFFFF_FFFF_FFFF_FFFF_u64,
nonce: 0,
Expand Down Expand Up @@ -188,7 +188,7 @@ fn dpc_testnet2_integration_test() {
difficulty_target: previous_block.header.difficulty_target,
nonce: 0,
pedersen_merkle_root_hash: PedersenMerkleRootHash([0u8; 32]),
proof: ProofOfSuccinctWork([0u8; 972]),
proof: ProofOfSuccinctWork::default(),
};

assert!(dpc.verify_transactions(&transactions.0, &ledger));
Expand Down Expand Up @@ -284,7 +284,7 @@ fn test_testnet2_dpc_execute_constraints() {
difficulty_target: 0xFFFF_FFFF_FFFF_FFFF_u64,
nonce: 0,
pedersen_merkle_root_hash: PedersenMerkleRootHash([0u8; 32]),
proof: ProofOfSuccinctWork([0u8; 972]),
proof: ProofOfSuccinctWork::default(),
},
transactions: Transactions::new(),
};
Expand Down Expand Up @@ -529,7 +529,7 @@ fn test_testnet2_dpc_execute_constraints() {
println!("=========================================================");
let num_constraints = outer_circuit_cs.num_constraints();
println!("Outer circuit num constraints: {:?}", num_constraints);
assert_eq!(878967, num_constraints);
assert_eq!(787899, num_constraints);
println!("=========================================================");
}

Expand Down
4 changes: 2 additions & 2 deletions algorithms/src/fft/polynomial/dense.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ impl<F: Field> DensePolynomial<F> {
return self.coeffs[0];
}
let mut powers_of_point = vec![F::one()];
let mut cur = point;
let mut cur = point.clone();
for _ in 0..self.degree() {
powers_of_point.push(cur);
cur *= &point;
cur *= point;
}
assert_eq!(powers_of_point.len(), self.coeffs.len());
let zero = F::zero();
Expand Down
2 changes: 1 addition & 1 deletion algorithms/src/traits/snark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ pub trait SNARK {
type PreparedVerifyingKey: Clone;
type Proof: Clone + Debug + ToBytes + FromBytes + Send + Sync;
type ProvingKey: Clone + ToBytes + FromBytes + Send + Sync;
type VerifierInput: ?Sized;

// We can specify their defaults to `()` when `associated_type_defaults` feature becomes stable in Rust
type UniversalSetupConfig: Clone;
type UniversalSetupParameters: FromBytes + ToBytes + Clone;

type VerifierInput: ?Sized;
type VerifyingKey: Clone
+ Send
+ Sync
Expand Down
4 changes: 2 additions & 2 deletions dpc/src/parameters/testnet1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl Parameters for Testnet1Parameters {
type ProgramIDCRHGadget = PoseidonCryptoHashGadget<Self::OuterScalarField, 4, false>;
type ProgramIDTreeDigest = <Self::ProgramIDCRH as CRH>::Output;
type ProgramIDTreeParameters = ProgramIDMerkleTreeParameters;

type RecordCommitmentScheme = BHPCompressedCommitment<EdwardsBls12, 48, 50>;
type RecordCommitmentGadget = BHPCompressedCommitmentGadget<EdwardsBls12, Self::InnerScalarField, EdwardsBls12Gadget, 48, 50>;
type RecordCommitment = <Self::RecordCommitmentScheme as CommitmentScheme>::Output;
Expand All @@ -166,7 +166,7 @@ impl Parameters for Testnet1Parameters {
type RecordSerialNumberTreeCRH = BHPCompressedCRH<EdwardsBls12, 8, 32>;
type RecordSerialNumberTreeDigest = <Self::RecordSerialNumberTreeCRH as CRH>::Output;
type RecordSerialNumberTreeParameters = SerialNumberMerkleTreeParameters;

type SerialNumberNonceCRH = BHPCompressedCRH<EdwardsBls12, 32, 63>;
type SerialNumberNonceCRHGadget = BHPCompressedCRHGadget<EdwardsBls12, Self::InnerScalarField, EdwardsBls12Gadget, 32, 63>;

Expand Down
31 changes: 10 additions & 21 deletions dpc/src/parameters/testnet2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ use snarkvm_marlin::{
PoseidonSponge,
};
use snarkvm_parameters::{testnet2::*, Parameter};
use snarkvm_polycommit::marlin_pc::{marlin_kzg10::MarlinKZG10Gadget, MarlinKZG10};
use snarkvm_polycommit::sonic_pc::{sonic_kzg10::SonicKZG10Gadget, SonicKZG10};
use snarkvm_utilities::FromBytes;

use once_cell::sync::OnceCell;
Expand Down Expand Up @@ -124,16 +124,16 @@ impl Parameters for Testnet2Parameters {
type ProgramSNARK = MarlinSNARK<
Self::InnerScalarField,
Self::OuterScalarField,
MarlinKZG10<Self::InnerCurve>,
SonicKZG10<Self::InnerCurve>,
FiatShamirAlgebraicSpongeRng<Self::InnerScalarField, Self::OuterScalarField, PoseidonSponge<Self::OuterScalarField>>,
MarlinTestnet2Mode,
ProgramPublicVariables<Self>,
>;
type ProgramSNARKGadget = MarlinVerificationGadget<
Self::InnerScalarField,
Self::OuterScalarField,
MarlinKZG10<Self::InnerCurve>,
MarlinKZG10Gadget<Self::InnerCurve, Self::OuterCurve, PairingGadget>,
SonicKZG10<Self::InnerCurve>,
SonicKZG10Gadget<Self::InnerCurve, Self::OuterCurve, PairingGadget>,
>;

type AccountCommitmentScheme = BHPCompressedCommitment<EdwardsBls12, 33, 48>;
Expand Down Expand Up @@ -173,7 +173,7 @@ impl Parameters for Testnet2Parameters {
type ProgramIDCRHGadget = PoseidonCryptoHashGadget<Self::OuterScalarField, 4, false>;
type ProgramIDTreeDigest = <Self::ProgramIDCRH as CRH>::Output;
type ProgramIDTreeParameters = ProgramIDMerkleTreeParameters;

type RecordCommitmentScheme = BHPCompressedCommitment<EdwardsBls12, 48, 50>;
type RecordCommitmentGadget = BHPCompressedCommitmentGadget<EdwardsBls12, Self::InnerScalarField, EdwardsBls12Gadget, 48, 50>;
type RecordCommitment = <Self::RecordCommitmentScheme as CommitmentScheme>::Output;
Expand All @@ -186,10 +186,10 @@ impl Parameters for Testnet2Parameters {
type RecordSerialNumberTreeCRH = BHPCompressedCRH<EdwardsBls12, 8, 32>;
type RecordSerialNumberTreeDigest = <Self::RecordSerialNumberTreeCRH as CRH>::Output;
type RecordSerialNumberTreeParameters = SerialNumberMerkleTreeParameters;

type SerialNumberNonceCRH = BHPCompressedCRH<EdwardsBls12, 32, 63>;
type SerialNumberNonceCRHGadget = BHPCompressedCRHGadget<EdwardsBls12, Self::InnerScalarField, EdwardsBls12Gadget, 32, 63>;

dpc_setup!{account_commitment_scheme, ACCOUNT_COMMITMENT_SCHEME, AccountCommitmentScheme, ACCOUNT_COMMITMENT_INPUT} // TODO (howardwu): Rename to "AleoAccountCommitmentScheme0".
dpc_setup!{account_encryption_scheme, ACCOUNT_ENCRYPTION_SCHEME, AccountEncryptionScheme, ACCOUNT_ENCRYPTION_AND_SIGNATURE_INPUT}
dpc_setup!{account_signature_scheme, ACCOUNT_SIGNATURE_SCHEME, AccountSignatureScheme, ACCOUNT_ENCRYPTION_AND_SIGNATURE_INPUT}
Expand All @@ -210,7 +210,7 @@ impl Parameters for Testnet2Parameters {
.hash_field_elements(&Self::inner_circuit_verifying_key().to_field_elements().expect("Failed to convert inner circuit verifying key to elements"))
.expect("Failed to hash inner circuit verifying key elements"))
}

dpc_snark_setup_with_mode!{Testnet2Parameters, inner_circuit_proving_key, INNER_CIRCUIT_PROVING_KEY, InnerSNARK, ProvingKey, InnerSNARKPKParameters, "inner circuit proving key"}
dpc_snark_setup!{Testnet2Parameters, inner_circuit_verifying_key, INNER_CIRCUIT_VERIFYING_KEY, InnerSNARK, VerifyingKey, InnerSNARKVKParameters, "inner circuit verifying key"}

Expand All @@ -219,12 +219,12 @@ impl Parameters for Testnet2Parameters {

dpc_snark_setup_with_mode!{Testnet2Parameters, outer_circuit_proving_key, OUTER_CIRCUIT_PROVING_KEY, OuterSNARK, ProvingKey, OuterSNARKPKParameters, "outer circuit proving key"}
dpc_snark_setup!{Testnet2Parameters, outer_circuit_verifying_key, OUTER_CIRCUIT_VERIFYING_KEY, OuterSNARK, VerifyingKey, OuterSNARKVKParameters, "outer circuit verifying key"}

fn program_id_tree_parameters() -> &'static Self::ProgramIDTreeParameters {
static PROGRAM_ID_TREE_PARAMETERS: OnceCell<<Testnet2Parameters as Parameters>::ProgramIDTreeParameters> = OnceCell::new();
PROGRAM_ID_TREE_PARAMETERS.get_or_init(|| Self::ProgramIDTreeParameters::from(Self::program_id_crh().clone()))
}

fn record_commitment_tree_parameters() -> &'static Self::RecordCommitmentTreeParameters {
static RECORD_COMMITMENT_TREE_PARAMETERS: OnceCell<<Testnet2Parameters as Parameters>::RecordCommitmentTreeParameters> = OnceCell::new();
RECORD_COMMITMENT_TREE_PARAMETERS.get_or_init(|| Self::RecordCommitmentTreeParameters::from(Self::record_commitment_tree_crh().clone()))
Expand All @@ -244,14 +244,3 @@ impl Parameters for Testnet2Parameters {
Rc::new(RefCell::new(SRS::<_, _>::Universal(universal_srs)))
}
}

// This is currently unused.
//
// use snarkvm_marlin::{FiatShamirAlgebraicSpongeRngVar, PoseidonSpongeVar};
//
// pub type FSG = FiatShamirAlgebraicSpongeRngVar<
// Self::InnerScalarField,
// Self::OuterScalarField,
// PoseidonSponge<Self::OuterScalarField>,
// PoseidonSpongeVar<Self::OuterScalarField>,
// >;
Loading