Skip to content

Commit

Permalink
feat: add a not before proof (#5560)
Browse files Browse the repository at this point in the history
Description
---
Added a `not before proof` to the genesis block. The data to be added is
just a simple Vec<u8>, which can represent anything, but must be limited
in size.

_**Note:** This is to implement what some members of the Tari community
have been discussing. The `not before proof` or how it is implemented is
not my idea; I merely executed it. That being said, I had some fun with
choosing the examples._

Motivation and Context
---
The basic idea behind adding a `not before proof` to the genesis block
is to provide some level of authenticity. If we would, for example,
insert a digitized headline of the _New York Times_ just before mainnet
launches, it will provide a timestamped reference to a widely recognized
and verifiable event and prove that the blockchain has not been in
existence before that time.

How Has This Been Tested?
---
Genesis block sanity test

What process can a PR reviewer use to test or verify this change?
---
Review changes

<!-- Checklist -->
<!-- 1. Is the title of your PR in the form that would make nice release
notes? The title, excluding the conventional commit
tag, will be included exactly as is in the CHANGELOG, so please think
about it carefully. -->


Breaking Changes
---

- [x] None
- [ ] Requires data directory on base node to be deleted
- [ ] Requires hard fork
- [ ] Other - Please specify

<!-- Does this include a breaking change? If so, include this line as a
footer -->
<!-- BREAKING CHANGE: Description what the user should do, e.g. delete a
database, resync the chain -->

Co-authored-by: SW van Heerden <[email protected]>
  • Loading branch information
hansieodendaal and SWvheerden authored Jun 30, 2023
1 parent f7f749c commit 11f42fb
Showing 1 changed file with 62 additions and 6 deletions.
68 changes: 62 additions & 6 deletions base_layer/core/src/blocks/genesis_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ use chrono::{DateTime, FixedOffset};
use tari_common::configuration::Network;
use tari_common_types::types::{FixedHash, PrivateKey};
use tari_crypto::tari_utilities::hex::*;
use tari_utilities::ByteArray;

use crate::{
blocks::{block::Block, BlockHeader, BlockHeaderAccumulatedData, ChainBlock},
proof_of_work::{Difficulty, PowAlgorithm, ProofOfWork},
transactions::{aggregated_body::AggregateBody, transaction_components::TransactionOutput},
};

// This can be adjusted as required, but must be limited
const NOT_BEFORE_PROOF_BYTES_SIZE: usize = u16::MAX as usize;

/// Returns the genesis block for the selected network.
pub fn get_genesis_block(network: Network) -> ChainBlock {
use Network::{Esmeralda, Igor, LocalNet, MainNet, NextNet, StageNet};
Expand Down Expand Up @@ -132,7 +136,18 @@ pub fn get_stagenet_genesis_block() -> ChainBlock {
fn get_stagenet_genesis_block_raw() -> Block {
// Set genesis timestamp
let genesis_timestamp = DateTime::parse_from_rfc2822("15 Jun 2023 14:00:00 +0200").expect("parse may not fail");
get_raw_block(&genesis_timestamp)
let not_before_proof = b"i am the stagenet genesis block, watch out, here i come \
\
The New York Times , 2000/01/01 \
\
Lorem Ipsum \
\
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore \
magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo \
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla \
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id \
est laborum.";
get_raw_block(&genesis_timestamp, &not_before_proof.to_vec())
}

pub fn get_nextnet_genesis_block() -> ChainBlock {
Expand Down Expand Up @@ -170,7 +185,19 @@ pub fn get_nextnet_genesis_block() -> ChainBlock {
fn get_nextnet_genesis_block_raw() -> Block {
// Set genesis timestamp
let genesis_timestamp = DateTime::parse_from_rfc2822("15 Jun 2023 14:00:00 +0200").expect("parse may not fail");
get_raw_block(&genesis_timestamp)
// Let us add a "not before" proof to the genesis block
let not_before_proof = b"nextnet has a blast, its prowess echoed in every gust \
\
The New York Times , 2000/01/01 \
\
Lorem Ipsum \
\
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore \
magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo \
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla \
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id \
est laborum.";
get_raw_block(&genesis_timestamp, &not_before_proof.to_vec())
}

pub fn get_mainnet_genesis_block() -> ChainBlock {
Expand Down Expand Up @@ -216,7 +243,19 @@ pub fn get_igor_genesis_block() -> ChainBlock {
fn get_igor_genesis_block_raw() -> Block {
// Set genesis timestamp
let genesis_timestamp = DateTime::parse_from_rfc2822("15 Jun 2023 14:00:00 +0200").expect("parse may not fail");
get_raw_block(&genesis_timestamp)
// Let us add a "not before" proof to the genesis block
let not_before_proof = b"but igor is the best, it is whispered in the wind \
\
The New York Times , 2000/01/01 \
\
Lorem Ipsum \
\
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore \
magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo \
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla \
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id \
est laborum.";
get_raw_block(&genesis_timestamp, &not_before_proof.to_vec())
}

pub fn get_esmeralda_genesis_block() -> ChainBlock {
Expand Down Expand Up @@ -258,12 +297,29 @@ pub fn get_esmeralda_genesis_block() -> ChainBlock {
fn get_esmeralda_genesis_block_raw() -> Block {
// Set genesis timestamp
let genesis_timestamp = DateTime::parse_from_rfc2822("15 Jun 2023 14:00:00 +0200").expect("parse may not fail");
get_raw_block(&genesis_timestamp)
// Let us add a "not before" proof to the genesis block
let not_before_proof =
b"as I sip my drink, thoughts of esmeralda consume my mind, like a refreshing nourishing draught \
\
The New York Times , 2000/01/01 \
\
Lorem Ipsum \
\
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore \
magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo \
consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla \
pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id \
est laborum.";
get_raw_block(&genesis_timestamp, &not_before_proof.to_vec())
}

fn get_raw_block(genesis_timestamp: &DateTime<FixedOffset>) -> Block {
fn get_raw_block(genesis_timestamp: &DateTime<FixedOffset>, not_before_proof: &[u8]) -> Block {
// Note: Use 'print_new_genesis_block_values' in core/tests/helpers/block_builders.rs to generate the required
// fields below

let mut not_before_proof = not_before_proof.to_vec();
not_before_proof.truncate(NOT_BEFORE_PROOF_BYTES_SIZE);

#[allow(clippy::cast_sign_loss)]
let timestamp = genesis_timestamp.timestamp() as u64;
Block {
Expand All @@ -290,7 +346,7 @@ fn get_raw_block(genesis_timestamp: &DateTime<FixedOffset>) -> Block {
nonce: 0,
pow: ProofOfWork {
pow_algo: PowAlgorithm::Sha3x,
pow_data: vec![],
pow_data: not_before_proof,
},
},
body: AggregateBody::new(vec![], vec![], vec![]),
Expand Down

0 comments on commit 11f42fb

Please sign in to comment.