From a09ac11d2989f3506de436c5094351dd352720d7 Mon Sep 17 00:00:00 2001 From: altafan <18440657+altafan@users.noreply.github.com> Date: Thu, 14 Dec 2023 17:22:09 +0100 Subject: [PATCH 1/2] Add genesis block hash as network param --- network/network.go | 66 ++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/network/network.go b/network/network.go index af94871..7c051bd 100644 --- a/network/network.go +++ b/network/network.go @@ -21,47 +21,51 @@ type Network struct { // Confidential prefix Confidential byte // Bitcoin Asset Hash for the current network - AssetID string + AssetID string + GenesisBlockHash string } // Liquid defines the network parameters for the main Liquid network. var Liquid = Network{ - Name: "liquid", - Bech32: "ex", - Blech32: "lq", - HDPublicKey: [4]byte{0x04, 0x88, 0xb2, 0x1e}, - HDPrivateKey: [4]byte{0x04, 0x88, 0xad, 0xe4}, - PubKeyHash: 57, - ScriptHash: 39, - Wif: 0x80, - Confidential: 12, - AssetID: "6f0279e9ed041c3d710a9f57d0c02928416460c4b722ae3457a11eec381c526d", + Name: "liquid", + Bech32: "ex", + Blech32: "lq", + HDPublicKey: [4]byte{0x04, 0x88, 0xb2, 0x1e}, + HDPrivateKey: [4]byte{0x04, 0x88, 0xad, 0xe4}, + PubKeyHash: 57, + ScriptHash: 39, + Wif: 0x80, + Confidential: 12, + AssetID: "6f0279e9ed041c3d710a9f57d0c02928416460c4b722ae3457a11eec381c526d", + GenesisBlockHash: "1466275836220db2944ca059a3a10ef6fd2ea684b0688d2c379296888a206003", } // Regtest defines the network parameters for the regression regtest network. var Regtest = Network{ - Name: "regtest", - Bech32: "ert", - Blech32: "el", - HDPublicKey: [4]byte{0x04, 0x35, 0x87, 0xcf}, - HDPrivateKey: [4]byte{0x04, 0x35, 0x83, 0x94}, - PubKeyHash: 235, - ScriptHash: 75, - Wif: 0xef, - Confidential: 4, - AssetID: "5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225", + Name: "regtest", + Bech32: "ert", + Blech32: "el", + HDPublicKey: [4]byte{0x04, 0x35, 0x87, 0xcf}, + HDPrivateKey: [4]byte{0x04, 0x35, 0x83, 0x94}, + PubKeyHash: 235, + ScriptHash: 75, + Wif: 0xef, + Confidential: 4, + AssetID: "5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419ca290e0751b225", + GenesisBlockHash: "00902a6b70c2ca83b5d9c815d96a0e2f4202179316970d14ea1847dae5b1ca21", } // Testnet defines the network parameters for the regression testnet network. var Testnet = Network{ - Name: "testnet", - Bech32: "tex", - Blech32: "tlq", - HDPublicKey: [4]byte{0x04, 0x35, 0x87, 0xcf}, - HDPrivateKey: [4]byte{0x04, 0x35, 0x83, 0x94}, - PubKeyHash: 36, - ScriptHash: 19, - Wif: 0xef, - Confidential: 23, - AssetID: "144c654344aa716d6f3abcc1ca90e5641e4e2a7f633bc09fe3baf64585819a49", + Name: "testnet", + Bech32: "tex", + Blech32: "tlq", + HDPublicKey: [4]byte{0x04, 0x35, 0x87, 0xcf}, + HDPrivateKey: [4]byte{0x04, 0x35, 0x83, 0x94}, + PubKeyHash: 36, + ScriptHash: 19, + Wif: 0xef, + Confidential: 23, + AssetID: "144c654344aa716d6f3abcc1ca90e5641e4e2a7f633bc09fe3baf64585819a49", + GenesisBlockHash: "a771da8e52ee6ad581ed1e9a99825e5b3b7992225534eaa2ae23244fe26ab1c1", } From fed2251f6e0202977abb2d7ae44d03c1cf2015ea Mon Sep 17 00:00:00 2001 From: altafan <18440657+altafan@users.noreply.github.com> Date: Thu, 14 Dec 2023 17:25:50 +0100 Subject: [PATCH 2/2] Remove hardcoded genesis block hashes --- psetv2/pset_test.go | 4 ++-- taproot/taproot_e2e_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/psetv2/pset_test.go b/psetv2/pset_test.go index 17a479e..defe85e 100644 --- a/psetv2/pset_test.go +++ b/psetv2/pset_test.go @@ -1438,7 +1438,7 @@ func TestBroadcastBlindedTaprootKeyTx(t *testing.T) { tweakedPrivKey := taproot.TweakTaprootPrivKey(privkey, []byte{}) - genesisBlockhash, _ := chainhash.NewHashFromStr("00902a6b70c2ca83b5d9c815d96a0e2f4202179316970d14ea1847dae5b1ca21") + genesisBlockhash, _ := chainhash.NewHashFromStr(network.Regtest.GenesisBlockHash) unsignedTx, err := ptx.UnsignedTx() require.NoError(t, err) @@ -1587,7 +1587,7 @@ func TestBroadcastBlindedTaprootTapscriptTx(t *testing.T) { }) require.NoError(t, err) - genesisBlockhash, _ := chainhash.NewHashFromStr("00902a6b70c2ca83b5d9c815d96a0e2f4202179316970d14ea1847dae5b1ca21") + genesisBlockhash, _ := chainhash.NewHashFromStr(network.Regtest.GenesisBlockHash) unsignedTx, err := ptx.UnsignedTx() require.NoError(t, err) diff --git a/taproot/taproot_e2e_test.go b/taproot/taproot_e2e_test.go index d6806e1..d4c8447 100644 --- a/taproot/taproot_e2e_test.go +++ b/taproot/taproot_e2e_test.go @@ -134,7 +134,7 @@ func TestKeyPathSpend(t *testing.T) { unsignedTx := p.UnsignedTx // Sign step - genesisBlockhash, _ := chainhash.NewHashFromStr("00902a6b70c2ca83b5d9c815d96a0e2f4202179316970d14ea1847dae5b1ca21") + genesisBlockhash, _ := chainhash.NewHashFromStr(network.Regtest.GenesisBlockHash) sighash := unsignedTx.HashForWitnessV1( 0, @@ -286,7 +286,7 @@ func TestTapscriptSpend(t *testing.T) { unsignedTx := p.UnsignedTx // Sign step - genesisBlockhash, _ := chainhash.NewHashFromStr("00902a6b70c2ca83b5d9c815d96a0e2f4202179316970d14ea1847dae5b1ca21") + genesisBlockhash, _ := chainhash.NewHashFromStr(network.Regtest.GenesisBlockHash) leafProof := tree.LeafMerkleProofs[0] leafHash := leafProof.TapHash()