constants.rs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2022 Dyne.org foundation
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. use lazy_static::lazy_static;
  19. use crate::{consensus::Float10, util::time::Timestamp};
  20. lazy_static! {
  21. /// Genesis hash for the mainnet chain
  22. pub static ref MAINNET_GENESIS_HASH_BYTES: blake3::Hash = blake3::hash(b"darkfi_mainnet");
  23. /// Genesis timestamp for the mainnet chain
  24. pub static ref MAINNET_GENESIS_TIMESTAMP: Timestamp = Timestamp(1650887115);
  25. /// Genesis hash for the testnet chain
  26. pub static ref TESTNET_GENESIS_HASH_BYTES: blake3::Hash = blake3::hash(b"darkfi_testnet");
  27. /// Genesis timestamp for the testnet chain
  28. pub static ref TESTNET_GENESIS_TIMESTAMP: Timestamp = Timestamp(1650887115);
  29. // Commonly used Float10
  30. pub static ref FLOAT10_ZERO: Float10 = Float10::from_str_native("0").unwrap().with_precision(RADIX_BITS).value();
  31. pub static ref FLOAT10_ONE: Float10 = Float10::from_str_native("1").unwrap().with_precision(RADIX_BITS).value();
  32. pub static ref FLOAT10_TWO: Float10 = Float10::from_str_native("2").unwrap().with_precision(RADIX_BITS).value();
  33. pub static ref FLOAT10_THREE: Float10 = Float10::from_str_native("3").unwrap().with_precision(RADIX_BITS).value();
  34. pub static ref FLOAT10_NINE: Float10 = Float10::from_str_native("9").unwrap().with_precision(RADIX_BITS).value();
  35. pub static ref FLOAT10_TEN: Float10 = Float10::from_str_native("10").unwrap().with_precision(RADIX_BITS).value();
  36. // Consensus parameters
  37. pub static ref TI: Float10 = FLOAT10_ONE.clone() / FLOAT10_TEN.clone();
  38. pub static ref TD: Float10 = FLOAT10_ONE.clone() / FLOAT10_TEN.clone();
  39. }
  40. /// Block version number
  41. pub const BLOCK_VERSION: u8 = 1;
  42. /// Block magic bytes
  43. pub const BLOCK_MAGIC_BYTES: [u8; 4] = [0x11, 0x6d, 0x75, 0x1f];
  44. /// Block info magic bytes
  45. pub const BLOCK_INFO_MAGIC_BYTES: [u8; 4] = [0x90, 0x44, 0xf1, 0xf6];
  46. /// Number of slots in one epoch
  47. pub const EPOCH_LENGTH: usize = 10;
  48. /// Slot time in seconds
  49. pub const SLOT_TIME: u64 = 20;
  50. /// Block leader reward
  51. pub const REWARD: u64 = 420;
  52. /// Leader proofs k for zk proof rows (rows=2^k)
  53. pub const LEADER_PROOF_K: u32 = 13;
  54. // TODO: Describe these constants
  55. pub const RADIX_BITS: usize = 76;
  56. pub const P: &str = "28948022309329048855892746252171976963363056481941560715954676764349967630337";
  57. pub const LOTTERY_HEAD_START: u64 = 1;
  58. pub const PRF_NULLIFIER_PREFIX: u64 = 0;
  59. pub const PI_NULLIFIER_INDEX: usize = 7;
  60. pub const PI_COMMITMENT_X_INDEX: usize = 1;
  61. pub const PI_COMMITMENT_Y_INDEX: usize = 2;
  62. pub const PI_MU_Y_INDEX: usize = 8;
  63. pub const PI_MU_RHO_INDEX: usize = 10;