From 7f9bed8e5072f231613a53dcab25f9b9ea580ef2 Mon Sep 17 00:00:00 2001 From: aggstam Date: Fri, 14 Jul 2023 14:01:20 +0300 Subject: [PATCH] WIP: contract/consensus/client/proposal: verify coin value is less than slot target before creating proof --- src/contract/consensus/src/client/proposal_v1.rs | 11 +++++++++++ src/error.rs | 3 +++ 2 files changed, 14 insertions(+) diff --git a/src/contract/consensus/src/client/proposal_v1.rs b/src/contract/consensus/src/client/proposal_v1.rs index 3333580cb..0fdac0969 100644 --- a/src/contract/consensus/src/client/proposal_v1.rs +++ b/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])); diff --git a/src/error.rs b/src/error.rs index 10e1a89ea..9bbdc34e4 100644 --- a/src/error.rs +++ b/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,