Просмотр исходного кода

contract/consensus: removed coin blind for hashes

aggstam 3 лет назад
Родитель
Сommit
b7b26c77b6

+ 0 - 3
src/contract/consensus/proof/consensus_burn_v1.zk

@@ -11,8 +11,6 @@ witness "ConsensusBurn_V1" {
 	Base epoch,
 	# Unique serial number corresponding to this coin
 	Base serial,
-	# Random blinding factor for coin
-	Base coin_blind,
 	# Random blinding factor for value commitment
 	Scalar value_blind,
 	# Secret key used to derive nullifier and coins' public key
@@ -46,7 +44,6 @@ circuit "ConsensusBurn_V1" {
 		value,
 		epoch,
 		serial,
-		coin_blind,
 	);
 
 	# Merkle root

+ 0 - 3
src/contract/consensus/proof/consensus_mint_v1.zk

@@ -14,8 +14,6 @@ witness "ConsensusMint_V1" {
 	Base epoch,
 	# Unique serial number corresponding to this coin
 	Base serial,
-	# Random blinding factor for coin
-	Base coin_blind,
 	# Random blinding factor for the value commitment
 	Scalar value_blind,
 }
@@ -31,7 +29,6 @@ circuit "ConsensusMint_V1" {
 		value,
 		epoch,
 		serial,
-		coin_blind,
 	);
 	constrain_instance(C);
 

+ 0 - 6
src/contract/consensus/proof/consensus_proposal_v1.zk

@@ -17,16 +17,12 @@ witness "ConsensusProposal_V1" {
 	Base reward,
 	# Random blinding factor for the value commitment
 	Scalar input_value_blind,
-	# Random blinding factor for coin
-	Base input_coin_blind,
 	# Leaf position of the coin in the Merkle tree of coins
 	Uint32 leaf_pos,
 	# Merkle path to the coin
 	MerklePath path,
 	# Random blinding factor for the value commitment of the new coin
 	Scalar output_value_blind,
-	# Random blinding factor for new coin
-	Base output_coin_blind,
 	# Election seed y
 	Base mu_y,
 	# Election seed rho
@@ -73,7 +69,6 @@ circuit "ConsensusProposal_V1" {
 		input_value,
 		epoch,
 		input_serial,
-		input_coin_blind,
 	);
 
 	# Merkle inclusion proof
@@ -124,7 +119,6 @@ circuit "ConsensusProposal_V1" {
 		output_value,
 		ZERO,
 		output_serial,
-		output_coin_blind,
 	);
 	constrain_instance(output_coin);
 

+ 2 - 19
src/contract/consensus/src/client/common.rs

@@ -41,7 +41,6 @@ pub struct ConsensusMintOutputInfo {
     pub public_key: PublicKey,
     pub value_blind: pallas::Scalar,
     pub serial: pallas::Base,
-    pub coin_blind: pallas::Base,
 }
 
 pub struct ConsensusBurnInputInfo {
@@ -79,14 +78,7 @@ pub fn create_consensus_mint_proof(
     let value_commit = pedersen_commitment_u64(output.value, output.value_blind);
     let (pub_x, pub_y) = output.public_key.xy();
 
-    let coin = Coin::from(poseidon_hash([
-        pub_x,
-        pub_y,
-        value_pallas,
-        epoch_pallas,
-        output.serial,
-        output.coin_blind,
-    ]));
+    let coin = Coin::from(poseidon_hash([pub_x, pub_y, value_pallas, epoch_pallas, output.serial]));
 
     let public_inputs = ConsensusMintRevealed { epoch: output.epoch, coin, value_commit };
 
@@ -96,7 +88,6 @@ pub fn create_consensus_mint_proof(
         Witness::Base(Value::known(value_pallas)),
         Witness::Base(Value::known(epoch_pallas)),
         Witness::Base(Value::known(output.serial)),
-        Witness::Base(Value::known(output.coin_blind)),
         Witness::Scalar(Value::known(output.value_blind)),
     ];
 
@@ -147,14 +138,7 @@ pub fn create_consensus_burn_proof(
     let public_key = PublicKey::from_secret(input.secret);
     let (pub_x, pub_y) = public_key.xy();
 
-    let coin = poseidon_hash([
-        pub_x,
-        pub_y,
-        value_pallas,
-        epoch_pallas,
-        input.note.serial,
-        input.note.coin_blind,
-    ]);
+    let coin = poseidon_hash([pub_x, pub_y, value_pallas, epoch_pallas, input.note.serial]);
 
     let merkle_root = {
         let position: u64 = input.leaf_position.into();
@@ -182,7 +166,6 @@ pub fn create_consensus_burn_proof(
         Witness::Base(Value::known(value_pallas)),
         Witness::Base(Value::known(epoch_pallas)),
         Witness::Base(Value::known(input.note.serial)),
-        Witness::Base(Value::known(input.note.coin_blind)),
         Witness::Scalar(Value::known(input.value_blind)),
         Witness::Base(Value::known(input.secret.inner())),
         Witness::Uint32(Value::known(u64::from(input.leaf_position).try_into().unwrap())),

+ 0 - 3
src/contract/consensus/src/client/genesis_stake_v1.rs

@@ -74,7 +74,6 @@ impl ConsensusGenesisStakeCallBuilder {
         // We just create the pedersen commitment blinds here. We simply
         // enforce that the clear input and the anon output have the same
         // commitments.
-        let coin_blind = pallas::Base::random(&mut OsRng);
         let value_blind = pallas::Scalar::random(&mut OsRng);
         let token_blind = pallas::Scalar::random(&mut OsRng);
         let reward_blind = pallas::Scalar::random(&mut OsRng);
@@ -98,7 +97,6 @@ impl ConsensusGenesisStakeCallBuilder {
             public_key: self.recipient,
             value_blind,
             serial,
-            coin_blind,
         };
 
         info!("Creating genesis stake mint proof for output");
@@ -110,7 +108,6 @@ impl ConsensusGenesisStakeCallBuilder {
             serial,
             value: output.value,
             epoch,
-            coin_blind,
             value_blind,
             reward: 0,
             reward_blind,

+ 0 - 7
src/contract/consensus/src/client/proposal_v1.rs

@@ -143,7 +143,6 @@ impl ConsensusProposalCallBuilder {
         };
 
         debug!("Building Consensus::ProposalV1 anonymous output");
-        let output_coin_blind = pallas::Base::random(&mut OsRng);
         let output_reward_blind = pallas::Scalar::random(&mut OsRng);
         let output_value_blind = input.value_blind + output_reward_blind;
 
@@ -161,7 +160,6 @@ impl ConsensusProposalCallBuilder {
             public_key: output_keypair.public,
             value_blind: output_value_blind,
             serial: output_serial,
-            coin_blind: output_coin_blind,
         };
 
         info!("Building Consensus::ProposalV1 VRF proof");
@@ -194,7 +192,6 @@ impl ConsensusProposalCallBuilder {
             serial: output.serial,
             value: output.value,
             epoch: output.epoch,
-            coin_blind: output.coin_blind,
             value_blind: output.value_blind,
             reward: REWARD,
             reward_blind: output_reward_blind,
@@ -269,7 +266,6 @@ fn create_proposal_proof(
         pallas::Base::from(input.note.value),
         pallas::Base::from(input.note.epoch),
         input.note.serial,
-        input.note.coin_blind,
     ]);
 
     let merkle_root = {
@@ -294,7 +290,6 @@ fn create_proposal_proof(
         pallas::Base::from(output.value),
         pallas::Base::from(output.epoch),
         output.serial,
-        output.coin_blind,
     ]));
 
     // Create the ZK proof
@@ -324,11 +319,9 @@ fn create_proposal_proof(
         Witness::Base(Value::known(pallas::Base::from(input.note.epoch))),
         Witness::Base(Value::known(pallas::Base::from(REWARD))),
         Witness::Scalar(Value::known(input.value_blind)),
-        Witness::Base(Value::known(input.note.coin_blind)),
         Witness::Uint32(Value::known(u64::from(input.leaf_position).try_into().unwrap())),
         Witness::MerklePath(Value::known(input.merkle_path.clone().try_into().unwrap())),
         Witness::Scalar(Value::known(output.value_blind)),
-        Witness::Base(Value::known(output.coin_blind)),
         Witness::Base(Value::known(public_inputs.mu_y)),
         Witness::Base(Value::known(public_inputs.mu_rho)),
         Witness::Base(Value::known(public_inputs.sigma1)),

+ 0 - 3
src/contract/consensus/src/client/stake_v1.rs

@@ -66,7 +66,6 @@ impl ConsensusStakeCallBuilder {
 
         debug!("Building anonymous output");
         let serial = pallas::Base::random(&mut OsRng);
-        let coin_blind = pallas::Base::random(&mut OsRng);
         let public_key = PublicKey::from_secret(self.coin.secret);
 
         let output = ConsensusMintOutputInfo {
@@ -75,7 +74,6 @@ impl ConsensusStakeCallBuilder {
             public_key,
             value_blind: self.value_blind,
             serial,
-            coin_blind,
         };
         debug!("Finished building output");
 
@@ -88,7 +86,6 @@ impl ConsensusStakeCallBuilder {
             serial,
             value: output.value,
             epoch: self.epoch,
-            coin_blind,
             value_blind: self.value_blind,
             reward: 0,
             reward_blind: self.value_blind,

+ 0 - 3
src/contract/consensus/src/client/unstake_request_v1.rs

@@ -95,7 +95,6 @@ impl ConsensusUnstakeRequestCallBuilder {
         let output_keypair = Keypair::new(SecretKey::from(output_secret_key));
         let output_serial =
             poseidon_hash([SERIAL_PREFIX, self.owncoin.secret.inner(), self.owncoin.note.serial]);
-        let output_coin_blind = pallas::Base::random(&mut OsRng);
 
         // We create a new random keypair for the output
         //let output_keypair = Keypair::random(&mut OsRng);
@@ -106,7 +105,6 @@ impl ConsensusUnstakeRequestCallBuilder {
             public_key: output_keypair.public,
             value_blind: input.value_blind,
             serial: output_serial,
-            coin_blind: output_coin_blind,
         };
 
         info!("Building Consensus::UnstakeRequestV1 Burn ZK proof");
@@ -130,7 +128,6 @@ impl ConsensusUnstakeRequestCallBuilder {
             serial: output_serial,
             value: output.value,
             epoch: output.epoch,
-            coin_blind: output_coin_blind,
             value_blind: input.value_blind,
             reward: 0,
             reward_blind: pallas::Scalar::ZERO,

+ 1 - 1
src/contract/consensus/src/entrypoint/stake_v1.rs

@@ -116,7 +116,7 @@ pub(crate) fn consensus_stake_process_instruction_v1(
     // validate this state transition.
     let consensus_coins_db = db_lookup(cid, CONSENSUS_CONTRACT_STAKED_COINS_TREE)?;
     let consensus_unstaked_coins_db = db_lookup(cid, CONSENSUS_CONTRACT_UNSTAKED_COINS_TREE)?;
-    let money_nullifiers_db = db_lookup(*MONEY_CONTRACT_ID, MONEY_CONTRACT_NULLIFIERS_TREE)?;
+    let _money_nullifiers_db = db_lookup(*MONEY_CONTRACT_ID, MONEY_CONTRACT_NULLIFIERS_TREE)?;
     let money_coin_roots_db = db_lookup(*MONEY_CONTRACT_ID, MONEY_CONTRACT_COIN_ROOTS_TREE)?;
 
     // ===================================

+ 1 - 3
src/contract/money/src/client/mod.rs

@@ -144,8 +144,6 @@ pub struct ConsensusNote {
     pub value: u64,
     /// Epoch the coin was minted
     pub epoch: u64,
-    /// Blinding factor for the coin bulla
-    pub coin_blind: pallas::Base,
     /// Blinding factor for the value pedersen commitment
     pub value_blind: pallas::Scalar,
     /// Value of the reward
@@ -162,7 +160,7 @@ impl From<ConsensusNote> for MoneyNote {
             token_id: *DARK_TOKEN_ID,
             spend_hook: pallas::Base::ZERO,
             user_data: pallas::Base::ZERO,
-            coin_blind: consensus_note.coin_blind,
+            coin_blind: pallas::Base::ZERO,
             value_blind: consensus_note.value_blind,
             token_blind: pallas::Scalar::ZERO,
             memo: vec![],

+ 1 - 1
src/contract/money/src/entrypoint/unstake_v1.rs

@@ -88,7 +88,7 @@ pub(crate) fn money_unstake_process_instruction_v1(
     // Access the necessary databases where there is information to
     // validate this state transition.
     let money_coins_db = db_lookup(cid, MONEY_CONTRACT_COINS_TREE)?;
-    let consensus_nullifiers_db =
+    let _consensus_nullifiers_db =
         db_lookup(*CONSENSUS_CONTRACT_ID, CONSENSUS_CONTRACT_NULLIFIERS_TREE)?;
     let consensus_unstaked_coin_roots_db =
         db_lookup(*CONSENSUS_CONTRACT_ID, CONSENSUS_CONTRACT_UNSTAKED_COIN_ROOTS_TREE)?;

+ 1 - 1
src/contract/test-harness/src/vks.rs

@@ -48,7 +48,7 @@ use darkfi_serial::{deserialize, serialize};
 use log::debug;
 
 /// Update this if any circuits are changed
-const VKS_HASH: &str = "f731fc9e7922583be551236328814c6e3a0fb6ee5cf7f4516c4c2be1ac5333b5";
+const VKS_HASH: &str = "4c9b94adf8aba19add503d76d154e2bdc5c49cfd19ab1f1f0c0c058862cadf67";
 
 fn vks_path() -> Result<PathBuf> {
     let output = Command::new("git").arg("rev-parse").arg("--show-toplevel").output()?.stdout;