diff --git a/state/src/local_data_commitment/local_data_commitment.rs b/state/src/local_data_commitment/local_data_commitment.rs index f111e45f81..7254050bfa 100644 --- a/state/src/local_data_commitment/local_data_commitment.rs +++ b/state/src/local_data_commitment/local_data_commitment.rs @@ -2,7 +2,10 @@ use crate::{verify_record_commitment, LocalDataVerificationError, StateLeafValue use leo_typed::Input as TypedInput; use snarkos_algorithms::commitment_tree::CommitmentMerklePath; -use snarkos_dpc::base_dpc::instantiated::{Components, LocalDataCRH, LocalDataCommitment, RecordCommitment}; +use snarkos_dpc::base_dpc::{ + instantiated::{Components, LocalDataCRH, LocalDataCommitment}, + parameters::SystemParameters, +}; use snarkos_models::{ algorithms::{CommitmentScheme, CRH}, dpc::DPCComponents, @@ -12,14 +15,12 @@ use snarkos_utilities::{bytes::ToBytes, to_bytes, FromBytes}; use std::convert::TryFrom; pub fn verify_local_data_commitment( + system_parameters: &SystemParameters, typed_input: &TypedInput, - record_commitment_params: RecordCommitment, - local_data_commitment_params: LocalDataCommitment, - local_data_crh_params: LocalDataCRH, ) -> Result { // verify record commitment let typed_record = typed_input.get_record(); - let dpc_record_values = verify_record_commitment(typed_record, record_commitment_params)?; + let dpc_record_values = verify_record_commitment(system_parameters, typed_record)?; let record_commitment: Vec = dpc_record_values.commitment; let record_serial_number: Vec = dpc_record_values.serial_number; @@ -47,12 +48,15 @@ pub fn verify_local_data_commitment( // Construct local data commitment leaf let local_data_leaf_randomness = ::Randomness::read(&leaf_randomness[..])?; - let local_data_commitment_leaf = - LocalDataCommitment::commit(&local_data_commitment_params, &input_bytes, &local_data_leaf_randomness)?; + let local_data_commitment_leaf = LocalDataCommitment::commit( + &system_parameters.local_data_commitment, + &input_bytes, + &local_data_leaf_randomness, + )?; // Construct record commitment merkle path let mut local_data_merkle_path = CommitmentMerklePath::::read(&path[..])?; - local_data_merkle_path.parameters = Some(local_data_crh_params); + local_data_merkle_path.parameters = Some(system_parameters.local_data_crh.clone()); // Check record commitment merkle path is valid for the given local data commitment root let local_data_commitment_root = ::Output::read(&root[..])?; diff --git a/state/src/record_commitment/record_commitment.rs b/state/src/record_commitment/record_commitment.rs index 89d671ea71..55493e874f 100644 --- a/state/src/record_commitment/record_commitment.rs +++ b/state/src/record_commitment/record_commitment.rs @@ -1,15 +1,18 @@ use crate::{DPCRecordValues, RecordVerificationError}; use leo_typed::Record as TypedRecord; -use snarkos_dpc::base_dpc::instantiated::RecordCommitment; +use snarkos_dpc::base_dpc::{ + instantiated::{Components, RecordCommitment}, + parameters::SystemParameters, +}; use snarkos_models::algorithms::CommitmentScheme; use snarkos_utilities::{bytes::ToBytes, to_bytes, FromBytes}; use std::convert::TryFrom; pub fn verify_record_commitment( + system_parameters: &SystemParameters, typed_record: &TypedRecord, - record_commitment_params: RecordCommitment, ) -> Result { // generate a dpc record from the typed record let record = DPCRecordValues::try_from(typed_record)?; @@ -30,7 +33,7 @@ pub fn verify_record_commitment( ::Randomness::read(&record.commitment_randomness[..])?; let record_commitment = RecordCommitment::commit( - &record_commitment_params, + &system_parameters.record_commitment, &record_commitment_input, &commitment_randomness, )?; diff --git a/state/tests/test_verify_local_data_commitment.rs b/state/tests/test_verify_local_data_commitment.rs index 43a530cb1d..56b3da4a6c 100644 --- a/state/tests/test_verify_local_data_commitment.rs +++ b/state/tests/test_verify_local_data_commitment.rs @@ -16,7 +16,29 @@ use rand_xorshift::XorShiftRng; use snarkos_models::dpc::DPCScheme; #[test] -fn test_integrate_with_dpc() { +fn test_verify_local_data_commitment_from_file() { + let mut rng = XorShiftRng::seed_from_u64(1231275789u64); + + // Generate parameters for the record commitment scheme + let system_parameters = InstantiatedDPC::generate_system_parameters(&mut rng).unwrap(); + + // Load test record state file from `inputs/test.state` + let file_bytes = include_bytes!("inputs/test_state.state"); + let file_string = String::from_utf8_lossy(file_bytes); + let file = LeoInputParser::parse_file(&file_string).unwrap(); + + let mut program_input = Input::new(); + program_input.parse_state(file).unwrap(); + + // check record state is correct by verifying commitment + let result = verify_local_data_commitment(&system_parameters, &program_input).unwrap(); + + assert!(result); +} + +#[test] +#[ignore] +fn test_generate_values_from_dpc() { use snarkos_testing::storage::*; type L = Ledger; @@ -175,30 +197,3 @@ fn test_integrate_with_dpc() { println!(); println!("////////////////////////////////////////////////////"); } - -#[test] -fn test_verify_local_data_commitment_from_file() { - let mut rng = XorShiftRng::seed_from_u64(1231275789u64); - - // Generate parameters for the record commitment scheme - let system_parameters = InstantiatedDPC::generate_system_parameters(&mut rng).unwrap(); - - // Load test record state file from `inputs/test.state` - let file_bytes = include_bytes!("inputs/test_state.state"); - let file_string = String::from_utf8_lossy(file_bytes); - let file = LeoInputParser::parse_file(&file_string).unwrap(); - - let mut program_input = Input::new(); - program_input.parse_state(file).unwrap(); - - // check record state is correct by verifying commitment - let result = verify_local_data_commitment( - &program_input, - system_parameters.record_commitment, - system_parameters.local_data_commitment, - system_parameters.local_data_crh, - ) - .unwrap(); - - assert!(result); -} diff --git a/state/tests/test_verify_record_commitment.rs b/state/tests/test_verify_record_commitment.rs index 74cbfa708d..e7bde411eb 100644 --- a/state/tests/test_verify_record_commitment.rs +++ b/state/tests/test_verify_record_commitment.rs @@ -25,5 +25,5 @@ fn test_verify_record_from_file() { let typed_record = program_input.get_record(); // check record state is correct by verifying commitment - let _values = verify_record_commitment(typed_record, system_parameters.record_commitment).unwrap(); + let _values = verify_record_commitment(&system_parameters, typed_record).unwrap(); }