diff --git a/bitcoin/src/blockdata/constants.rs b/bitcoin/src/blockdata/constants.rs index eb0534c855..3eeec57e69 100644 --- a/bitcoin/src/blockdata/constants.rs +++ b/bitcoin/src/blockdata/constants.rs @@ -57,13 +57,43 @@ pub const MAX_SCRIPTNUM_VALUE: u32 = 0x80000000; // 2^31 /// Number of blocks needed for an output from a coinbase transaction to be spendable. pub const COINBASE_MATURITY: u32 = 100; +// This is the 65 byte (uncompressed) pubkey used as the one-and-only output of the genesis transaction. +// +// ref: https://blockstream.info/tx/4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b?expand +// Note output script includes a leading 0x41 and trailing 0xac (added below using the `script::Builder`). +#[rustfmt::skip] +const GENESIS_OUTPUT_PK: [u8; 65] = [ + 0x04, + 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, 0x48, 0x27, + 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, 0xb7, 0x10, + 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, 0x09, 0xa6, + 0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, 0xde, 0xb6, + 0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, 0x38, 0xc4, + 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, 0x12, 0xde, + 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, 0x57, + 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, 0x5f +]; + +#[rustfmt::skip] +const TESTNET4_GENESIS_OUTPUT_PK: [u8; 33] = [0x00; 33]; + /// The maximum value allowed in an output (useful for sanity checking, /// since keeping everything below this value should prevent overflows /// if you are doing anything remotely sane with monetary values). pub const MAX_MONEY: u64 = 21_000_000 * COIN_VALUE; /// Constructs and returns the coinbase (and only) transaction of the Bitcoin genesis block. -fn bitcoin_genesis_tx() -> Transaction { +fn bitcoin_genesis_tx(network: Network) -> Transaction { + if network == Network::Testnet { + return bitcoin_testnet4_genesis_tx(); + } else { + return bitcoin_default_genesis_tx(); + } + +} + +/// Constructs and returns the coinbase (and only) transaction of the Bitcoin genesis block. +fn bitcoin_default_genesis_tx() -> Transaction { // Base let mut ret = Transaction { version: 1, @@ -99,9 +129,44 @@ fn bitcoin_genesis_tx() -> Transaction { ret } + +/// Constructs and returns the coinbase (and only) transaction of the Bitcoin genesis block. +fn bitcoin_testnet4_genesis_tx() -> Transaction { + // Base + let mut ret = Transaction { + version: 1, + lock_time: absolute::LockTime::ZERO, + input: vec![], + output: vec![], + }; + + // Inputs + let in_script = script::Builder::new() + .push_int(486604799) + .push_int_non_minimal(4) + .push_slice(b"03/May/2024 000000000000000000001ebd58c244970b3aa9d783bb001011fbe8ea8e98e00e") + .into_script(); + let out_script = script::Builder::new().push_slice(TESTNET4_GENESIS_OUTPUT_PK).push_opcode(OP_CHECKSIG).into_script(); + ret.input.push(TxIn { + previous_output: OutPoint::null(), + script_sig: in_script, + sequence: Sequence::MAX, + witness: Witness::default(), + }); + + // Outputs + ret.output.push(TxOut { + value: 50 * COIN_VALUE, + script_pubkey: out_script + }); + + // end + ret +} + /// Constructs and returns the genesis block. pub fn genesis_block(network: Network) -> Block { - let txdata = vec![bitcoin_genesis_tx()]; + let txdata = vec![bitcoin_genesis_tx(network)]; let hash: sha256d::Hash = txdata[0].txid().into(); let merkle_root = hash.into(); match network { @@ -124,9 +189,9 @@ pub fn genesis_block(network: Network) -> Block { version: block::Version::ONE, prev_blockhash: Hash::all_zeros(), merkle_root, - time: 1296688602, + time: 1714777860, bits: CompactTarget::from_consensus(0x1d00ffff), - nonce: 414098458 + nonce: 393743547 }, txdata, } @@ -171,7 +236,7 @@ impl ChainHash { /// `ChainHash` for mainnet bitcoin. pub const BITCOIN: Self = Self([111, 226, 140, 10, 182, 241, 179, 114, 193, 166, 162, 70, 174, 99, 247, 79, 147, 30, 131, 101, 225, 90, 8, 156, 104, 214, 25, 0, 0, 0, 0, 0]); /// `ChainHash` for testnet bitcoin. - pub const TESTNET: Self = Self([67, 73, 127, 215, 248, 38, 149, 113, 8, 244, 163, 15, 217, 206, 195, 174, 186, 121, 151, 32, 132, 233, 14, 173, 1, 234, 51, 9, 0, 0, 0, 0]); + pub const TESTNET: Self = Self([67, 240, 139, 218, 176, 80, 227, 91, 86, 124, 134, 75, 145, 244, 127, 80, 174, 114, 90, 226, 222, 83, 188, 251, 186, 242, 132, 218, 0, 0, 0, 0]); /// `ChainHash` for signet bitcoin. pub const SIGNET: Self = Self([246, 30, 238, 59, 99, 163, 128, 164, 119, 160, 99, 175, 50, 178, 187, 201, 124, 159, 249, 240, 31, 44, 66, 37, 233, 115, 152, 129, 8, 0, 0, 0]); /// `ChainHash` for regtest bitcoin. @@ -197,7 +262,7 @@ mod test { #[test] fn bitcoin_genesis_first_transaction() { - let gen = bitcoin_genesis_tx(); + let gen = bitcoin_genesis_tx(Network::Bitcoin); assert_eq!(gen.version, 1); assert_eq!(gen.input.len(), 1); @@ -235,11 +300,11 @@ mod test { let gen = genesis_block(Network::Testnet); assert_eq!(gen.header.version, block::Version::ONE); assert_eq!(gen.header.prev_blockhash, Hash::all_zeros()); - assert_eq!(gen.header.merkle_root.to_string(), "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b"); - assert_eq!(gen.header.time, 1296688602); + assert_eq!(gen.header.merkle_root.to_string(), "7aa0a7ae1e223414cb807e40cd57e667b718e42aaf9306db9102fe28912b7b4e"); + assert_eq!(gen.header.time, 1714777860); assert_eq!(gen.header.bits, CompactTarget::from_consensus(0x1d00ffff)); - assert_eq!(gen.header.nonce, 414098458); - assert_eq!(gen.header.block_hash().to_string(), "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"); + assert_eq!(gen.header.nonce, 393743547); + assert_eq!(gen.header.block_hash().to_string(), "00000000da84f2bafbbc53dee25a72ae507ff4914b867c565be350b0da8bf043"); } #[test] diff --git a/bitcoin/src/blockdata/script/push_bytes.rs b/bitcoin/src/blockdata/script/push_bytes.rs index 3f14363090..eb6c767010 100644 --- a/bitcoin/src/blockdata/script/push_bytes.rs +++ b/bitcoin/src/blockdata/script/push_bytes.rs @@ -185,7 +185,7 @@ mod primitive { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, - 71, 72, 73, + 71, 72, 73, 74, 75, 76 } /// Owned, growable counterpart to `PushBytes`. diff --git a/bitcoin/src/consensus/params.rs b/bitcoin/src/consensus/params.rs index dc4909d4c0..adb40212b3 100644 --- a/bitcoin/src/consensus/params.rs +++ b/bitcoin/src/consensus/params.rs @@ -69,10 +69,10 @@ impl Params { }, Network::Testnet => Params { network: Network::Testnet, - bip16_time: 1333238400, // Apr 1 2012 - bip34_height: 21111, // 0000000023b3a96d3484e5abb3755c413e7d41500f8e2a5c3f0dd01299cd8ef8 - bip65_height: 581885, // 00000000007f6655f22f98e72ed80d8b06dc761d5da09df0fa1dc4be4f861eb6 - bip66_height: 330776, // 000000002104c8c45e99a8853285a3b592602a3ccde2b832481da85e9e4ba182 + bip16_time: 1333238400, // Apr 1 2012 + bip34_height: 1, + bip65_height: 1, + bip66_height: 1, rule_change_activation_threshold: 1512, // 75% miner_confirmation_window: 2016, pow_limit: Work::TESTNET_MIN, diff --git a/bitcoin/src/network/constants.rs b/bitcoin/src/network/constants.rs index 9ef85ee713..3d48033273 100644 --- a/bitcoin/src/network/constants.rs +++ b/bitcoin/src/network/constants.rs @@ -69,7 +69,7 @@ pub const PROTOCOL_VERSION: u32 = 70001; pub enum Network { /// Mainnet Bitcoin. Bitcoin, - /// Bitcoin's testnet network. + /// Bitcoin's testnet4 network. Testnet, /// Bitcoin's signet network. Signet, @@ -250,8 +250,8 @@ pub struct Magic([u8; 4]); impl Magic { /// Bitcoin mainnet network magic bytes. pub const BITCOIN: Self = Self([0xF9, 0xBE, 0xB4, 0xD9]); - /// Bitcoin testnet network magic bytes. - pub const TESTNET: Self = Self([0x0B, 0x11, 0x09, 0x07]); + /// Bitcoin testnet4 network magic bytes. + pub const TESTNET: Self = Self([0x1c, 0x16, 0x3f, 0x28]); /// Bitcoin signet network magic bytes. pub const SIGNET: Self = Self([0x0A, 0x03, 0xCF, 0x40]); /// Bitcoin regtest network magic bytes. @@ -554,12 +554,12 @@ mod tests { #[test] fn serialize_test() { assert_eq!(serialize(&Network::Bitcoin.magic()), &[0xf9, 0xbe, 0xb4, 0xd9]); - assert_eq!(serialize(&Network::Testnet.magic()), &[0x0b, 0x11, 0x09, 0x07]); + assert_eq!(serialize(&Network::Testnet.magic()), &[0x1c, 0x16, 0x3f, 0x28]); assert_eq!(serialize(&Network::Signet.magic()), &[0x0a, 0x03, 0xcf, 0x40]); assert_eq!(serialize(&Network::Regtest.magic()), &[0xfa, 0xbf, 0xb5, 0xda]); assert_eq!(deserialize(&[0xf9, 0xbe, 0xb4, 0xd9]).ok(), Some(Network::Bitcoin.magic())); - assert_eq!(deserialize(&[0x0b, 0x11, 0x09, 0x07]).ok(), Some(Network::Testnet.magic())); + assert_eq!(deserialize(&[0x1c, 0x16, 0x3f, 0x28]).ok(), Some(Network::Testnet.magic())); assert_eq!(deserialize(&[0x0a, 0x03, 0xcf, 0x40]).ok(), Some(Network::Signet.magic())); assert_eq!(deserialize(&[0xfa, 0xbf, 0xb5, 0xda]).ok(), Some(Network::Regtest.magic())); } @@ -645,7 +645,7 @@ mod tests { fn magic_from_str() { let known_network_magic_strs = [ ("f9beb4d9", Network::Bitcoin), - ("0b110907", Network::Testnet), + ("1c163f28", Network::Testnet), ("fabfb5da", Network::Regtest), ("0a03cf40", Network::Signet), ];