2018-03-05 22:33:44 +03:00
|
|
|
// Copyright 2018 The Grin Developers
|
2016-10-22 21:35:48 +03:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2016-10-21 03:06:12 +03:00
|
|
|
//! Definition of the genesis block. Placeholder for now.
|
|
|
|
|
2018-12-14 05:56:45 +03:00
|
|
|
// required for genesis replacement
|
|
|
|
//! #![allow(unused_imports)]
|
|
|
|
|
2018-08-10 17:00:18 +03:00
|
|
|
use chrono::prelude::{TimeZone, Utc};
|
2016-10-21 03:06:12 +03:00
|
|
|
|
2018-12-08 02:59:40 +03:00
|
|
|
use crate::core;
|
|
|
|
use crate::global;
|
|
|
|
use crate::pow::{Difficulty, Proof, ProofOfWork};
|
2018-12-14 05:56:45 +03:00
|
|
|
use crate::util;
|
|
|
|
use crate::util::secp::constants::SINGLE_BULLET_PROOF_SIZE;
|
2018-12-14 03:46:41 +03:00
|
|
|
use crate::util::secp::pedersen::{Commitment, RangeProof};
|
2018-12-15 01:13:05 +03:00
|
|
|
use crate::util::secp::Signature;
|
2016-10-21 03:06:12 +03:00
|
|
|
|
2018-12-13 04:54:25 +03:00
|
|
|
use crate::core::hash::Hash;
|
|
|
|
use crate::keychain::BlindingFactor;
|
|
|
|
|
2017-11-16 00:49:15 +03:00
|
|
|
/// Genesis block definition for development networks. The proof of work size
|
|
|
|
/// is small enough to mine it on the fly, so it does not contain its own
|
|
|
|
/// proof of work solution. Can also be easily mutated for different tests.
|
|
|
|
pub fn genesis_dev() -> core::Block {
|
2018-08-16 00:14:48 +03:00
|
|
|
core::Block::with_header(core::BlockHeader {
|
|
|
|
height: 0,
|
2018-11-01 12:51:32 +03:00
|
|
|
// previous: core::hash::Hash([0xff; 32]),
|
2018-08-16 00:14:48 +03:00
|
|
|
timestamp: Utc.ymd(1997, 8, 4).and_hms(0, 0, 0),
|
2018-09-19 01:12:57 +03:00
|
|
|
pow: ProofOfWork {
|
2018-09-11 01:36:57 +03:00
|
|
|
nonce: global::get_genesis_nonce(),
|
|
|
|
..Default::default()
|
|
|
|
},
|
2018-08-16 00:14:48 +03:00
|
|
|
..Default::default()
|
|
|
|
})
|
2017-11-16 00:49:15 +03:00
|
|
|
}
|
|
|
|
|
2018-12-19 01:03:55 +03:00
|
|
|
/// Placeholder for floonet genesis block, will definitely change before
|
|
|
|
/// release
|
|
|
|
pub fn genesis_floo() -> core::Block {
|
|
|
|
let gen = core::Block::with_header(core::BlockHeader {
|
2018-10-10 12:09:44 +03:00
|
|
|
height: 0,
|
2018-12-29 01:46:21 +03:00
|
|
|
timestamp: Utc.ymd(2018, 12, 28).and_hms(20, 48, 4),
|
2018-12-21 00:04:57 +03:00
|
|
|
prev_root: Hash::from_hex(
|
2018-12-29 01:46:21 +03:00
|
|
|
"00000000000000000017ff4903ef366c8f62e3151ba74e41b8332a126542f538",
|
2018-12-21 00:04:57 +03:00
|
|
|
)
|
|
|
|
.unwrap(),
|
|
|
|
output_root: Hash::from_hex(
|
2018-12-29 01:46:21 +03:00
|
|
|
"73b5e0a05ea9e1e4e33b8f1c723bc5c10d17f07042c2af7644f4dbb61f4bc556",
|
2018-12-21 00:04:57 +03:00
|
|
|
)
|
|
|
|
.unwrap(),
|
|
|
|
range_proof_root: Hash::from_hex(
|
2018-12-29 01:46:21 +03:00
|
|
|
"667a3ba22f237a875f67c9933037c8564097fa57a3e75be507916de28fc0da26",
|
2018-12-21 00:04:57 +03:00
|
|
|
)
|
|
|
|
.unwrap(),
|
|
|
|
kernel_root: Hash::from_hex(
|
2018-12-29 01:46:21 +03:00
|
|
|
"cfdddfe2d938d0026f8b1304442655bbdddde175ff45ddf44cb03bcb0071a72d",
|
2018-12-21 00:04:57 +03:00
|
|
|
)
|
|
|
|
.unwrap(),
|
|
|
|
total_kernel_offset: BlindingFactor::from_hex(
|
|
|
|
"0000000000000000000000000000000000000000000000000000000000000000",
|
|
|
|
)
|
|
|
|
.unwrap(),
|
2018-12-19 01:03:55 +03:00
|
|
|
output_mmr_size: 1,
|
|
|
|
kernel_mmr_size: 1,
|
2018-10-10 12:09:44 +03:00
|
|
|
pow: ProofOfWork {
|
2018-12-29 01:46:21 +03:00
|
|
|
total_difficulty: Difficulty::from_num(10_u64.pow(5)),
|
2018-12-19 01:03:55 +03:00
|
|
|
secondary_scaling: 1856,
|
2018-12-29 01:46:21 +03:00
|
|
|
nonce: 23,
|
2018-11-25 01:50:50 +03:00
|
|
|
proof: Proof {
|
2018-12-21 00:04:57 +03:00
|
|
|
nonces: vec![
|
2018-12-29 01:46:21 +03:00
|
|
|
16994232, 22975978, 32664019, 44016212, 50238216, 57272481, 85779161,
|
|
|
|
124272202, 125203242, 133907662, 140522149, 145870823, 147481297, 164952795,
|
|
|
|
177186722, 183382201, 197418356, 211393794, 239282197, 239323031, 250757611,
|
|
|
|
281414565, 305112109, 308151499, 357235186, 374041407, 389924708, 390768911,
|
|
|
|
401322239, 401886855, 406986280, 416797005, 418935317, 429007407, 439527429,
|
|
|
|
484809502, 486257104, 495589543, 495892390, 525019296, 529899691, 531685572,
|
2018-12-21 00:04:57 +03:00
|
|
|
],
|
2018-11-25 01:50:50 +03:00
|
|
|
edge_bits: 29,
|
|
|
|
},
|
2018-10-10 12:09:44 +03:00
|
|
|
},
|
|
|
|
..Default::default()
|
2018-12-19 01:03:55 +03:00
|
|
|
});
|
|
|
|
let kernel = core::TxKernel {
|
2019-01-08 19:07:38 +03:00
|
|
|
features: core::KernelFeatures::Coinbase,
|
2018-12-19 01:03:55 +03:00
|
|
|
fee: 0,
|
|
|
|
lock_height: 0,
|
2018-12-21 00:04:57 +03:00
|
|
|
excess: Commitment::from_vec(
|
|
|
|
util::from_hex(
|
2018-12-29 01:46:21 +03:00
|
|
|
"08df2f1d996cee37715d9ac0a0f3b13aae508d1101945acb8044954aee30960be9".to_string(),
|
2018-12-21 00:04:57 +03:00
|
|
|
)
|
|
|
|
.unwrap(),
|
|
|
|
),
|
|
|
|
excess_sig: Signature::from_raw_data(&[
|
2018-12-29 01:46:21 +03:00
|
|
|
25, 176, 52, 246, 172, 1, 12, 220, 247, 111, 73, 101, 13, 16, 157, 130, 110, 196, 123,
|
|
|
|
217, 246, 137, 45, 110, 106, 186, 0, 151, 255, 193, 233, 178, 103, 26, 210, 215, 200,
|
|
|
|
89, 146, 188, 9, 161, 28, 212, 227, 143, 82, 54, 5, 223, 16, 65, 237, 132, 196, 241,
|
|
|
|
39, 76, 133, 45, 252, 131, 88, 0,
|
2018-12-21 00:04:57 +03:00
|
|
|
])
|
|
|
|
.unwrap(),
|
2018-12-19 01:03:55 +03:00
|
|
|
};
|
|
|
|
let output = core::Output {
|
2019-01-08 19:07:38 +03:00
|
|
|
features: core::OutputFeatures::Coinbase,
|
2018-12-21 00:04:57 +03:00
|
|
|
commit: Commitment::from_vec(
|
|
|
|
util::from_hex(
|
2018-12-29 01:46:21 +03:00
|
|
|
"08c12007af16d1ee55fffe92cef808c77e318dae70c3bc70cb6361f49d517f1b68".to_string(),
|
2018-12-21 00:04:57 +03:00
|
|
|
)
|
|
|
|
.unwrap(),
|
|
|
|
),
|
2018-12-19 01:03:55 +03:00
|
|
|
proof: RangeProof {
|
|
|
|
plen: SINGLE_BULLET_PROOF_SIZE,
|
2018-12-21 00:04:57 +03:00
|
|
|
proof: [
|
2018-12-29 01:46:21 +03:00
|
|
|
159, 156, 202, 179, 128, 169, 14, 227, 176, 79, 118, 180, 62, 164, 2, 234, 123, 30,
|
|
|
|
77, 126, 232, 124, 42, 186, 239, 208, 21, 217, 228, 246, 148, 74, 100, 25, 247,
|
|
|
|
251, 82, 100, 37, 16, 146, 122, 164, 5, 2, 165, 212, 192, 221, 167, 199, 8, 231,
|
|
|
|
149, 158, 216, 194, 200, 62, 15, 53, 200, 188, 207, 0, 79, 211, 88, 194, 211, 54,
|
|
|
|
1, 206, 53, 72, 118, 155, 184, 233, 166, 245, 224, 16, 254, 209, 235, 153, 85, 53,
|
|
|
|
145, 33, 186, 218, 118, 144, 35, 189, 241, 63, 229, 52, 237, 231, 39, 176, 202, 93,
|
|
|
|
247, 85, 131, 16, 193, 247, 180, 33, 138, 255, 102, 190, 213, 129, 174, 182, 167,
|
|
|
|
3, 126, 184, 221, 99, 114, 238, 219, 157, 125, 230, 179, 160, 89, 202, 230, 16, 91,
|
|
|
|
199, 57, 158, 225, 142, 125, 12, 211, 164, 78, 9, 4, 155, 106, 157, 41, 233, 188,
|
|
|
|
237, 205, 184, 53, 0, 190, 24, 215, 42, 44, 184, 120, 58, 196, 198, 190, 114, 50,
|
|
|
|
98, 240, 15, 213, 77, 163, 24, 3, 212, 125, 93, 175, 169, 249, 24, 27, 191, 113,
|
|
|
|
89, 59, 169, 40, 87, 250, 144, 159, 118, 171, 232, 92, 217, 5, 179, 152, 249, 247,
|
|
|
|
71, 239, 26, 180, 82, 177, 226, 132, 185, 3, 33, 162, 120, 98, 87, 109, 57, 100,
|
|
|
|
202, 162, 57, 230, 44, 31, 63, 213, 30, 222, 241, 78, 162, 118, 120, 70, 196, 128,
|
|
|
|
72, 223, 110, 5, 17, 151, 97, 214, 43, 57, 157, 1, 59, 87, 96, 17, 159, 174, 144,
|
|
|
|
217, 159, 87, 36, 113, 41, 155, 186, 252, 162, 46, 22, 80, 133, 3, 113, 248, 11,
|
|
|
|
118, 144, 155, 188, 77, 166, 40, 119, 107, 15, 233, 47, 47, 101, 77, 167, 141, 235,
|
|
|
|
148, 34, 218, 164, 168, 71, 20, 239, 71, 24, 12, 109, 146, 232, 243, 65, 31, 72,
|
|
|
|
186, 131, 190, 43, 227, 157, 41, 49, 126, 136, 51, 41, 50, 213, 37, 186, 223, 87,
|
|
|
|
248, 34, 43, 132, 34, 0, 143, 75, 79, 43, 74, 183, 26, 2, 168, 53, 203, 208, 159,
|
|
|
|
69, 107, 124, 33, 68, 113, 206, 127, 216, 158, 15, 52, 206, 1, 101, 109, 199, 13,
|
|
|
|
131, 122, 29, 131, 133, 125, 219, 70, 69, 144, 133, 68, 233, 67, 203, 132, 160,
|
|
|
|
143, 101, 84, 110, 15, 175, 111, 124, 24, 185, 222, 154, 238, 77, 241, 105, 8, 224,
|
|
|
|
230, 43, 178, 49, 95, 137, 33, 227, 118, 207, 239, 56, 21, 51, 220, 22, 48, 162,
|
|
|
|
22, 118, 229, 215, 248, 112, 198, 126, 180, 27, 161, 237, 56, 2, 220, 129, 126, 11,
|
|
|
|
104, 8, 133, 190, 162, 204, 3, 63, 249, 173, 210, 152, 252, 143, 157, 79, 228, 232,
|
|
|
|
230, 72, 164, 131, 183, 151, 230, 219, 186, 21, 34, 154, 219, 215, 231, 179, 47,
|
|
|
|
217, 44, 115, 203, 157, 35, 195, 113, 235, 194, 102, 96, 205, 24, 221, 213, 147,
|
|
|
|
120, 178, 221, 153, 146, 44, 172, 131, 77, 21, 61, 15, 5, 6, 205, 164, 203, 76,
|
|
|
|
228, 29, 126, 136, 88, 230, 210, 62, 164, 103, 125, 55, 231, 129, 89, 61, 222, 50,
|
|
|
|
71, 71, 75, 230, 70, 80, 85, 193, 136, 183, 222, 146, 46, 235, 0, 222, 118, 32, 70,
|
|
|
|
85, 39, 92, 233, 211, 169, 159, 207, 145, 13, 206, 125, 3, 45, 51, 64, 167, 179,
|
|
|
|
133, 83, 57, 190, 51, 239, 211, 74, 116, 75, 71, 248, 249, 184, 13, 31, 129, 107,
|
|
|
|
104, 179, 76, 194, 186, 4, 13, 122, 167, 254, 126, 153, 50, 8, 1, 200, 203, 213,
|
|
|
|
230, 217, 97, 105, 50, 208, 126, 180, 113, 81, 152, 238, 123, 157, 232, 19, 164,
|
|
|
|
159, 164, 89, 75, 33, 70, 140, 204, 158, 236, 10, 226, 102, 14, 88, 134, 82, 131,
|
|
|
|
36, 195, 127, 158, 81, 252, 223, 165, 11, 52, 105, 245, 245, 228, 235, 168, 175,
|
|
|
|
52, 175, 76, 157, 120, 208, 99, 135, 210, 81, 114, 230, 181,
|
2018-12-21 00:04:57 +03:00
|
|
|
],
|
2018-12-19 01:03:55 +03:00
|
|
|
},
|
|
|
|
};
|
|
|
|
gen.with_reward(output, kernel)
|
2018-10-10 12:09:44 +03:00
|
|
|
}
|
2018-12-14 05:56:45 +03:00
|
|
|
|
2017-11-16 00:49:15 +03:00
|
|
|
/// Placeholder for mainnet genesis block, will definitely change before
|
|
|
|
/// release so no use trying to pre-mine it.
|
|
|
|
pub fn genesis_main() -> core::Block {
|
2018-12-14 03:46:41 +03:00
|
|
|
let gen = core::Block::with_header(core::BlockHeader {
|
2018-08-16 00:14:48 +03:00
|
|
|
height: 0,
|
2018-12-13 04:54:25 +03:00
|
|
|
timestamp: Utc.ymd(2019, 1, 15).and_hms(12, 0, 0), // REPLACE
|
2018-12-14 03:46:41 +03:00
|
|
|
prev_root: Hash::default(), // REPLACE
|
|
|
|
output_root: Hash::default(), // REPLACE
|
|
|
|
range_proof_root: Hash::default(), // REPLACE
|
|
|
|
kernel_root: Hash::default(), // REPLACE
|
|
|
|
total_kernel_offset: BlindingFactor::zero(), // REPLACE
|
2018-12-11 04:07:17 +03:00
|
|
|
output_mmr_size: 1,
|
|
|
|
kernel_mmr_size: 1,
|
2018-09-19 01:12:57 +03:00
|
|
|
pow: ProofOfWork {
|
2018-12-11 04:07:17 +03:00
|
|
|
total_difficulty: Difficulty::from_num(10_u64.pow(8)),
|
|
|
|
secondary_scaling: 1856,
|
2018-12-13 04:54:25 +03:00
|
|
|
nonce: 1, // REPLACE
|
2018-12-11 04:07:17 +03:00
|
|
|
proof: Proof {
|
2018-12-13 04:54:25 +03:00
|
|
|
nonces: vec![0; 42], // REPLACE
|
2018-12-11 04:07:17 +03:00
|
|
|
edge_bits: 29,
|
|
|
|
},
|
2018-09-11 01:36:57 +03:00
|
|
|
},
|
2018-08-16 00:14:48 +03:00
|
|
|
..Default::default()
|
2018-12-14 03:46:41 +03:00
|
|
|
});
|
|
|
|
let kernel = core::TxKernel {
|
2019-01-08 19:07:38 +03:00
|
|
|
features: core::KernelFeatures::Coinbase,
|
2018-12-14 03:46:41 +03:00
|
|
|
fee: 0,
|
|
|
|
lock_height: 0,
|
|
|
|
excess: Commitment::from_vec(vec![]), // REPLACE
|
|
|
|
excess_sig: Signature::from_raw_data(&[0; 64]).unwrap(), //REPLACE
|
|
|
|
};
|
|
|
|
let output = core::Output {
|
2019-01-08 19:07:38 +03:00
|
|
|
features: core::OutputFeatures::Coinbase,
|
2018-12-14 03:46:41 +03:00
|
|
|
commit: Commitment::from_vec(vec![]), // REPLACE
|
2018-12-14 05:56:45 +03:00
|
|
|
proof: RangeProof {
|
|
|
|
plen: SINGLE_BULLET_PROOF_SIZE,
|
|
|
|
proof: [0; SINGLE_BULLET_PROOF_SIZE], // REPLACE
|
2018-12-15 01:13:05 +03:00
|
|
|
},
|
2018-12-14 03:46:41 +03:00
|
|
|
};
|
|
|
|
gen.with_reward(output, kernel)
|
2016-10-21 03:06:12 +03:00
|
|
|
}
|
2018-12-13 04:54:25 +03:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use super::*;
|
2018-12-15 01:35:59 +03:00
|
|
|
use crate::core::hash::Hashed;
|
2018-12-21 00:04:57 +03:00
|
|
|
use crate::ser;
|
2018-12-13 04:54:25 +03:00
|
|
|
|
2018-12-19 01:03:55 +03:00
|
|
|
#[test]
|
|
|
|
fn floonet_genesis_hash() {
|
|
|
|
let gen_hash = genesis_floo().hash();
|
|
|
|
println!("floonet genesis hash: {}", gen_hash.to_hex());
|
|
|
|
let gen_bin = ser::ser_vec(&genesis_floo()).unwrap();
|
|
|
|
println!("floonet genesis full hash: {}\n", gen_bin.hash().to_hex());
|
2018-12-21 00:07:53 +03:00
|
|
|
assert_eq!(
|
|
|
|
gen_hash.to_hex(),
|
2018-12-29 01:46:21 +03:00
|
|
|
"edc758c1370d43e1d733f70f58cf187c3be8242830429b1676b89fd91ccf2dab"
|
2018-12-21 00:07:53 +03:00
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
gen_bin.hash().to_hex(),
|
2018-12-29 01:46:21 +03:00
|
|
|
"91c638fc019a54e6652bd6bb3d9c5e0c17e889cef34a5c28528e7eb61a884dc4"
|
2018-12-21 00:07:53 +03:00
|
|
|
);
|
2018-12-19 01:03:55 +03:00
|
|
|
}
|
|
|
|
|
2018-12-15 01:12:54 +03:00
|
|
|
// TODO hardcode the hashes once genesis is set
|
2018-12-13 04:54:25 +03:00
|
|
|
#[test]
|
|
|
|
fn mainnet_genesis_hash() {
|
|
|
|
let gen_hash = genesis_main().hash();
|
|
|
|
println!("mainnet genesis hash: {}", gen_hash.to_hex());
|
2018-12-15 01:35:59 +03:00
|
|
|
let gen_bin = ser::ser_vec(&genesis_main()).unwrap();
|
2018-12-15 01:12:54 +03:00
|
|
|
println!("mainnet genesis full hash: {}\n", gen_bin.hash().to_hex());
|
2018-12-13 04:54:25 +03:00
|
|
|
//assert_eq!(gene_hash.to_hex, "");
|
|
|
|
}
|
|
|
|
}
|