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

WIP: contract/consensus/client/proposal: verify coin value is less than slot target before creating proof

aggstam 3 лет назад
Родитель
Сommit
7f9bed8e50
2 измененных файлов с 14 добавлено и 0 удалено
  1. 11 0
      src/contract/consensus/src/client/proposal_v1.rs
  2. 3 0
      src/error.rs

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

@@ -19,6 +19,7 @@
 //! This API is crufty. Please rework it into something nice to read and nice to use.
 
 use darkfi::{
+    error::Error::CoinIsNotSlotProducer,
     zk::{halo2::Value, Proof, ProvingKey, Witness, ZkCircuit},
     zkas::ZkBinary,
     Result,
@@ -250,6 +251,16 @@ fn create_proposal_proof(
     let mu_rho = poseidon_hash([MU_RHO_PREFIX, eta, pallas::Base::from(slot.id)]);
     let rho = poseidon_hash([seed, mu_rho]);
 
+    // Verify coin is the slot block producer
+    let value_pallas = pallas::Base::from(input.note.value);
+    let shifted_target =
+        slot.sigma1 * value_pallas + slot.sigma2 * value_pallas * value_pallas + HEADSTART;
+    // TODO: this check is true, while the proof can be created and is valid, when it shouldn't
+    if y >= shifted_target {
+        info!("1) What");
+        //return Err(CoinIsNotSlotProducer)
+    }
+
     // Derive the input's nullifier
     let nullifier = Nullifier::from(poseidon_hash([input.secret.inner(), input.note.serial]));
 

+ 3 - 0
src/error.rs

@@ -236,6 +236,9 @@ pub enum Error {
     #[error("Public inputs are invalid")]
     InvalidPublicInputsError,
 
+    #[error("Coin is not the slot block producer")]
+    CoinIsNotSlotProducer,
+
     #[error("Error during leader proof verification")]
     LeaderProofVerification,