mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-09 14:48:08 -05:00
[consensus] lottery with headstart, for zero-stake participation
This commit is contained in:
@@ -20,6 +20,7 @@ contract "Lead" {
|
||||
Base mu_y,
|
||||
Base sigma1,
|
||||
Base sigma2,
|
||||
Base headstart,
|
||||
}
|
||||
|
||||
circuit "Lead" {
|
||||
@@ -83,10 +84,11 @@ circuit "Lead" {
|
||||
term2_1 = base_mul(sigma2, value);
|
||||
term2 = base_mul(term2_1, value);
|
||||
target = base_add(term1, term2);
|
||||
shifted_target = base_add(target, headstart);
|
||||
#lottery
|
||||
#constrain public value sigma1
|
||||
constrain_instance(sigma1);
|
||||
# constrain public value sigma2
|
||||
constrain_instance(sigma2);
|
||||
less_than_loose(y, target);
|
||||
less_than_loose(y, shifted_target);
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ lazy_static! {
|
||||
pub static ref MAX_DER: Float10 = Float10::try_from("0.1").unwrap();
|
||||
pub static ref MIN_DER: Float10 = Float10::try_from("-0.1").unwrap();
|
||||
pub static ref MAX_F: Float10 = Float10::try_from("0.99").unwrap();
|
||||
pub static ref MIN_F: Float10 = Float10::try_from("0.05").unwrap();
|
||||
pub static ref MIN_F: Float10 = Float10::try_from("0.01").unwrap();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -30,9 +30,9 @@ use halo2_proofs::{arithmetic::Field, circuit::Value};
|
||||
use log::info;
|
||||
use rand::rngs::OsRng;
|
||||
|
||||
use super::constants::EPOCH_LENGTH;
|
||||
use super::constants::{EPOCH_LENGTH};
|
||||
use crate::{
|
||||
consensus::{constants, TransferStx, TxRcpt},
|
||||
consensus::{constants, TransferStx, TxRcpt, Float10, utils::fbig2base},
|
||||
zk::{
|
||||
proof::{Proof, ProvingKey},
|
||||
vm::ZkCircuit,
|
||||
@@ -213,6 +213,7 @@ impl LeadCoin {
|
||||
// rho
|
||||
let rho_msg = [seed, rho_mu];
|
||||
let rho = poseidon_hash(rho_msg);
|
||||
let headstart = Self::headstart();
|
||||
let public_inputs = vec![
|
||||
pk,
|
||||
*c1_cm_coord.x(),
|
||||
@@ -228,6 +229,7 @@ impl LeadCoin {
|
||||
rho,
|
||||
sigma1,
|
||||
sigma2,
|
||||
headstart,
|
||||
];
|
||||
public_inputs
|
||||
}
|
||||
@@ -282,6 +284,12 @@ impl LeadCoin {
|
||||
}
|
||||
*/
|
||||
|
||||
pub fn headstart() -> pallas::Base {
|
||||
let headstart = constants::MIN_F.clone() * Float10::try_from(constants::P.clone()).unwrap();
|
||||
let headstart_base = fbig2base(headstart);
|
||||
headstart_base
|
||||
}
|
||||
|
||||
pub fn is_leader(
|
||||
&self,
|
||||
sigma1: pallas::Base,
|
||||
@@ -298,7 +306,8 @@ impl LeadCoin {
|
||||
|
||||
let value = pallas::Base::from(self.value);
|
||||
|
||||
let target = sigma1 * value + sigma2 * value * value;
|
||||
let headstart = Self::headstart();
|
||||
let target = sigma1 * value + sigma2 * value * value + headstart;
|
||||
|
||||
let y_t_str = format!("{:?},{:?}\n", y, target);
|
||||
let f =
|
||||
|
||||
Reference in New Issue
Block a user