|
@@ -31,6 +31,7 @@ use darkfi_sdk::{
|
|
|
pasta::{group::ff::PrimeField, pallas},
|
|
pasta::{group::ff::PrimeField, pallas},
|
|
|
};
|
|
};
|
|
|
use darkfi_serial::{deserialize, serialize, Decodable, Encodable, WriteExt};
|
|
use darkfi_serial::{deserialize, serialize, Decodable, Encodable, WriteExt};
|
|
|
|
|
+use halo2_proofs::arithmetic::Field;
|
|
|
use log::{debug, error, info, warn};
|
|
use log::{debug, error, info, warn};
|
|
|
use rand::rngs::OsRng;
|
|
use rand::rngs::OsRng;
|
|
|
use serde_json::json;
|
|
use serde_json::json;
|
|
@@ -264,8 +265,7 @@ impl ValidatorState {
|
|
|
coin_index: usize,
|
|
coin_index: usize,
|
|
|
sigma1: pallas::Base,
|
|
sigma1: pallas::Base,
|
|
|
sigma2: pallas::Base,
|
|
sigma2: pallas::Base,
|
|
|
- derived_blind: pallas::Scalar,
|
|
|
|
|
- ) -> Result<Option<(BlockProposal, LeadCoin)>> {
|
|
|
|
|
|
|
+ ) -> Result<Option<(BlockProposal, LeadCoin, pallas::Scalar)>> {
|
|
|
let eta = self.consensus.get_eta();
|
|
let eta = self.consensus.get_eta();
|
|
|
// Check if node can produce proposals
|
|
// Check if node can produce proposals
|
|
|
if !self.consensus.proposing {
|
|
if !self.consensus.proposing {
|
|
@@ -291,6 +291,9 @@ impl ValidatorState {
|
|
|
(checkpoint.proposal.hash, checkpoint.coins[coin_index])
|
|
(checkpoint.proposal.hash, checkpoint.coins[coin_index])
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+ // Generate derived coin blind
|
|
|
|
|
+ let derived_blind = pallas::Scalar::random(&mut OsRng);
|
|
|
|
|
+
|
|
|
// Generating leader proof
|
|
// Generating leader proof
|
|
|
let (proof, public_inputs) = coin.create_lead_proof(
|
|
let (proof, public_inputs) = coin.create_lead_proof(
|
|
|
sigma1,
|
|
sigma1,
|
|
@@ -324,7 +327,7 @@ impl ValidatorState {
|
|
|
*self.consensus.leaders_history.last().unwrap(),
|
|
*self.consensus.leaders_history.last().unwrap(),
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- Ok(Some((BlockProposal::new(header, unproposed_txs, lead_info), coin)))
|
|
|
|
|
|
|
+ Ok(Some((BlockProposal::new(header, unproposed_txs, lead_info), coin, derived_blind)))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/// Retrieve all unconfirmed transactions not proposed in previous blocks
|
|
/// Retrieve all unconfirmed transactions not proposed in previous blocks
|
|
@@ -365,8 +368,7 @@ impl ValidatorState {
|
|
|
pub async fn receive_proposal(
|
|
pub async fn receive_proposal(
|
|
|
&mut self,
|
|
&mut self,
|
|
|
proposal: &BlockProposal,
|
|
proposal: &BlockProposal,
|
|
|
- coin: Option<(usize, LeadCoin)>,
|
|
|
|
|
- derived_blind: pallas::Scalar,
|
|
|
|
|
|
|
+ coin: Option<(usize, LeadCoin, pallas::Scalar)>,
|
|
|
) -> Result<bool> {
|
|
) -> Result<bool> {
|
|
|
let current = self.consensus.current_slot();
|
|
let current = self.consensus.current_slot();
|
|
|
// Node hasn't started participating
|
|
// Node hasn't started participating
|
|
@@ -554,7 +556,7 @@ impl ValidatorState {
|
|
|
// TODO: [PLACEHOLDER] Add rewards validation
|
|
// TODO: [PLACEHOLDER] Add rewards validation
|
|
|
|
|
|
|
|
// If proposal came fromself, we derive new coin
|
|
// If proposal came fromself, we derive new coin
|
|
|
- if let Some((idx, c)) = coin {
|
|
|
|
|
|
|
+ if let Some((idx, c, derived_blind)) = coin {
|
|
|
state_checkpoint.coins[idx] =
|
|
state_checkpoint.coins[idx] =
|
|
|
c.derive_coin(&mut state_checkpoint.coins_tree, derived_blind);
|
|
c.derive_coin(&mut state_checkpoint.coins_tree, derived_blind);
|
|
|
}
|
|
}
|