Use BLAKE2B instead of HASH160, and get rid of any usage of RIPEMD160 and SHA1 (#1618)

* Use BLAKE2B instead of HASH160, and get rid of any usage of RIPEMD160

* Change genesis coinbase payload script to OP_FALSE

* Fix tests after conflict

* Remove duplicate tests

* Change file name

* Change atomic swap to use proper hash size
This commit is contained in:
Ori Newman 2021-03-18 10:20:12 +02:00 committed by GitHub
parent 7d69b66c7c
commit d0511c1636
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 339 additions and 464 deletions

View File

@ -476,7 +476,7 @@ func TestGetPruningPointUTXOs(t *testing.T) {
Sequence: constants.MaxTxInSequenceNum,
}
outputs := make([]*externalapi.DomainTransactionOutput, 1125)
outputs := make([]*externalapi.DomainTransactionOutput, 900)
for i := 0; i < len(outputs); i++ {
outputs[i] = &externalapi.DomainTransactionOutput{
ScriptPublicKey: scriptPublicKey,
@ -619,7 +619,7 @@ func BenchmarkGetPruningPointUTXOs(b *testing.B) {
SignatureScript: signatureScript,
Sequence: constants.MaxTxInSequenceNum,
}
outputs := make([]*externalapi.DomainTransactionOutput, 1125)
outputs := make([]*externalapi.DomainTransactionOutput, 900)
for i := 0; i < len(outputs); i++ {
outputs[i] = &externalapi.DomainTransactionOutput{
ScriptPublicKey: scriptPublicKey,

View File

@ -38,12 +38,12 @@ func TestBlockWindow(t *testing.T) {
{
parents: []string{"C", "D"},
id: "E",
expectedWindow: []string{"D", "C", "B"},
expectedWindow: []string{"C", "D", "B"},
},
{
parents: []string{"C", "D"},
id: "F",
expectedWindow: []string{"D", "C", "B"},
expectedWindow: []string{"C", "D", "B"},
},
{
parents: []string{"A"},
@ -58,37 +58,37 @@ func TestBlockWindow(t *testing.T) {
{
parents: []string{"H", "F"},
id: "I",
expectedWindow: []string{"F", "D", "C", "H", "G", "B"},
expectedWindow: []string{"F", "C", "H", "D", "G", "B"},
},
{
parents: []string{"I"},
id: "J",
expectedWindow: []string{"I", "F", "D", "C", "H", "G", "B"},
expectedWindow: []string{"I", "F", "C", "H", "D", "G", "B"},
},
{
parents: []string{"J"},
id: "K",
expectedWindow: []string{"J", "I", "F", "D", "C", "H", "G", "B"},
expectedWindow: []string{"J", "I", "F", "C", "H", "D", "G", "B"},
},
{
parents: []string{"K"},
id: "L",
expectedWindow: []string{"K", "J", "I", "F", "D", "C", "H", "G", "B"},
expectedWindow: []string{"K", "J", "I", "F", "C", "H", "D", "G", "B"},
},
{
parents: []string{"L"},
id: "M",
expectedWindow: []string{"L", "K", "J", "I", "F", "D", "C", "H", "G", "B"},
expectedWindow: []string{"L", "K", "J", "I", "F", "C", "H", "D", "G", "B"},
},
{
parents: []string{"M"},
id: "N",
expectedWindow: []string{"M", "L", "K", "J", "I", "F", "D", "C", "H", "G"},
expectedWindow: []string{"M", "L", "K", "J", "I", "F", "C", "H", "D", "G"},
},
{
parents: []string{"N"},
id: "O",
expectedWindow: []string{"N", "M", "L", "K", "J", "I", "F", "D", "C", "H"},
expectedWindow: []string{"N", "M", "L", "K", "J", "I", "F", "C", "H", "D"},
},
},
dagconfig.TestnetParams.Name: {
@ -110,12 +110,12 @@ func TestBlockWindow(t *testing.T) {
{
parents: []string{"C", "D"},
id: "E",
expectedWindow: []string{"C", "D", "B"},
expectedWindow: []string{"D", "C", "B"},
},
{
parents: []string{"C", "D"},
id: "F",
expectedWindow: []string{"C", "D", "B"},
expectedWindow: []string{"D", "C", "B"},
},
{
parents: []string{"A"},
@ -130,37 +130,37 @@ func TestBlockWindow(t *testing.T) {
{
parents: []string{"H", "F"},
id: "I",
expectedWindow: []string{"F", "H", "C", "D", "B", "G"},
expectedWindow: []string{"F", "D", "H", "C", "B", "G"},
},
{
parents: []string{"I"},
id: "J",
expectedWindow: []string{"I", "F", "H", "C", "D", "B", "G"},
expectedWindow: []string{"I", "F", "D", "H", "C", "B", "G"},
},
{
parents: []string{"J"},
id: "K",
expectedWindow: []string{"J", "I", "F", "H", "C", "D", "B", "G"},
expectedWindow: []string{"J", "I", "F", "D", "H", "C", "B", "G"},
},
{
parents: []string{"K"},
id: "L",
expectedWindow: []string{"K", "J", "I", "F", "H", "C", "D", "B", "G"},
expectedWindow: []string{"K", "J", "I", "F", "D", "H", "C", "B", "G"},
},
{
parents: []string{"L"},
id: "M",
expectedWindow: []string{"L", "K", "J", "I", "F", "H", "C", "D", "B", "G"},
expectedWindow: []string{"L", "K", "J", "I", "F", "D", "H", "C", "B", "G"},
},
{
parents: []string{"M"},
id: "N",
expectedWindow: []string{"M", "L", "K", "J", "I", "F", "H", "C", "D", "B"},
expectedWindow: []string{"M", "L", "K", "J", "I", "F", "D", "H", "C", "B"},
},
{
parents: []string{"N"},
id: "O",
expectedWindow: []string{"N", "M", "L", "K", "J", "I", "F", "H", "C", "D"},
expectedWindow: []string{"N", "M", "L", "K", "J", "I", "F", "D", "H", "C"},
},
},
dagconfig.DevnetParams.Name: {
@ -274,32 +274,32 @@ func TestBlockWindow(t *testing.T) {
{
parents: []string{"H", "F"},
id: "I",
expectedWindow: []string{"F", "H", "D", "C", "B", "G"},
expectedWindow: []string{"F", "H", "D", "C", "G", "B"},
},
{
parents: []string{"I"},
id: "J",
expectedWindow: []string{"I", "F", "H", "D", "C", "B", "G"},
expectedWindow: []string{"I", "F", "H", "D", "C", "G", "B"},
},
{
parents: []string{"J"},
id: "K",
expectedWindow: []string{"J", "I", "F", "H", "D", "C", "B", "G"},
expectedWindow: []string{"J", "I", "F", "H", "D", "C", "G", "B"},
},
{
parents: []string{"K"},
id: "L",
expectedWindow: []string{"K", "J", "I", "F", "H", "D", "C", "B", "G"},
expectedWindow: []string{"K", "J", "I", "F", "H", "D", "C", "G", "B"},
},
{
parents: []string{"L"},
id: "M",
expectedWindow: []string{"L", "K", "J", "I", "F", "H", "D", "C", "B", "G"},
expectedWindow: []string{"L", "K", "J", "I", "F", "H", "D", "C", "G", "B"},
},
{
parents: []string{"M"},
id: "N",
expectedWindow: []string{"M", "L", "K", "J", "I", "F", "H", "D", "C", "B"},
expectedWindow: []string{"M", "L", "K", "J", "I", "F", "H", "D", "C", "G"},
},
{
parents: []string{"N"},

View File

@ -33,10 +33,10 @@ func TestPruning(t *testing.T) {
dagconfig.SimnetParams.Name: "1582",
},
"dag-for-test-pruning.json": {
dagconfig.MainnetParams.Name: "503",
dagconfig.MainnetParams.Name: "502",
dagconfig.TestnetParams.Name: "503",
dagconfig.DevnetParams.Name: "503",
dagconfig.SimnetParams.Name: "502",
dagconfig.SimnetParams.Name: "503",
},
}

View File

@ -116,6 +116,16 @@ func TestValidateTransactionInContextAndPopulateMassAndFee(t *testing.T) {
SubnetworkID: subnetworks.SubnetworkIDRegistry,
Gas: 0,
LockTime: 0}
for i, input := range validTx.Inputs {
signatureScript, err := txscript.SignatureScript(&validTx, i, consensushashing.SigHashAll, privateKey,
&consensushashing.SighashReusedValues{})
if err != nil {
t.Fatalf("Failed to create a sigScript: %v", err)
}
input.SignatureScript = signatureScript
}
txWithImmatureCoinbase := externalapi.DomainTransaction{
Version: constants.MaxTransactionVersion,
Inputs: []*externalapi.DomainTransactionInput{&txInput},
@ -145,16 +155,6 @@ func TestValidateTransactionInContextAndPopulateMassAndFee(t *testing.T) {
Gas: 0,
LockTime: 0}
for i, input := range validTx.Inputs {
signatureScript, err := txscript.SignatureScript(&validTx, i, consensushashing.SigHashAll, privateKey,
&consensushashing.SighashReusedValues{})
if err != nil {
t.Fatalf("Failed to create a sigScript: %v", err)
}
input.SignatureScript = signatureScript
}
povBlockHash := externalapi.NewDomainHashFromByteArray(&[32]byte{0x01})
tc.DAABlocksStore().StageDAAScore(povBlockHash, params.BlockCoinbaseMaturity+txInput.UTXOEntry.BlockDAAScore())
tc.DAABlocksStore().StageDAAScore(povBlockHash, 10)
@ -226,7 +226,7 @@ func TestValidateTransactionInContextAndPopulateMassAndFee(t *testing.T) {
if test.isValid {
if err != nil {
t.Fatalf("Unexpected error on TestValidateTransactionInContextAndPopulateMassAndFee"+
" on test %v: %v", test.name, err)
" on test '%v': %v", test.name, err)
}
} else {
if err == nil || !errors.Is(err, test.expectedError) {

View File

@ -108,86 +108,86 @@ func TestCalculateSignatureHash(t *testing.T) {
// sigHashAll
{name: "native-all-0", tx: nativeTx, hashType: all, inputIndex: 0,
expectedSignatureHash: "92889a2e79e692e485ca306cd322c2c1eaa7d9fb86a67d7e7a74df0c713e7018"},
expectedSignatureHash: "c899a5ea7414f0bbfd77e50674f46da34ce8722b928d4362a4b4b727c69c6499"},
{name: "native-all-0-modify-input-1", tx: nativeTx, hashType: all, inputIndex: 0,
modificationFunction: modifyInput(1), // should change the hash
expectedSignatureHash: "6054721ae186b9b61ad315c2e8971160d37b875dbcff3b9e829651dbced4f4bc"},
expectedSignatureHash: "faf3b9db2e07b1c14b2df02002d3e40f1e430f177ac5cd3354c84dad8fbe72ce"},
{name: "native-all-0-modify-output-1", tx: nativeTx, hashType: all, inputIndex: 0,
modificationFunction: modifyOutput(1), // should change the hash
expectedSignatureHash: "9894a9b4a89de26313aa110e5bd4276c47e362db210d5de398f970a5a54e9913"},
expectedSignatureHash: "3a557c5b873aab72dcb81649642e1d7a63b75dcdcc74e19d340964a9e0eac76c"},
{name: "native-all-0-modify-sequence-1", tx: nativeTx, hashType: all, inputIndex: 0,
modificationFunction: modifySequence(1), // should change the hash
expectedSignatureHash: "68784e57413bc8a101c66b8aa00955285ad213196e279c7cbe629e0bf6286dfa"},
expectedSignatureHash: "2dd5fe8f9fa4bf551ea2f080a26e07b2462083e12d3b2ed01cb9369a61920665"},
{name: "native-all-anyonecanpay-0", tx: nativeTx, hashType: allAnyoneCanPay, inputIndex: 0,
expectedSignatureHash: "41c6e5720a6e7099fdac5a1128ac287d1ecb61aa2fcbce7ebd8086d57cd58b77"},
expectedSignatureHash: "19fe2e0db681017f318fda705a39bbbad9c1085514cfbcff6fac01e1725f758b"},
{name: "native-all-anyonecanpay-0-modify-input-0", tx: nativeTx, hashType: allAnyoneCanPay, inputIndex: 0,
modificationFunction: modifyInput(0), // should change the hash
expectedSignatureHash: "73b72f972890556a6189067689da0d857ac9158146ec237319170eb2c0a3c404"},
expectedSignatureHash: "5b21d492560a1c794595f769b3ae3c151775b9cfc4029d17c53f1856e1005da4"},
{name: "native-all-anyonecanpay-0-modify-input-1", tx: nativeTx, hashType: allAnyoneCanPay, inputIndex: 0,
modificationFunction: modifyInput(1), // shouldn't change the hash
expectedSignatureHash: "41c6e5720a6e7099fdac5a1128ac287d1ecb61aa2fcbce7ebd8086d57cd58b77"},
expectedSignatureHash: "19fe2e0db681017f318fda705a39bbbad9c1085514cfbcff6fac01e1725f758b"},
{name: "native-all-anyonecanpay-0-modify-sequence", tx: nativeTx, hashType: allAnyoneCanPay, inputIndex: 0,
modificationFunction: modifySequence(1), // shouldn't change the hash
expectedSignatureHash: "41c6e5720a6e7099fdac5a1128ac287d1ecb61aa2fcbce7ebd8086d57cd58b77"},
expectedSignatureHash: "19fe2e0db681017f318fda705a39bbbad9c1085514cfbcff6fac01e1725f758b"},
// sigHashNone
{name: "native-none-0", tx: nativeTx, hashType: none, inputIndex: 0,
expectedSignatureHash: "dfe67982cfccf245e29b94be260a9df08ffbfb88d3e91f814602549b0159cbfb"},
expectedSignatureHash: "fafabaabf6349fee4e18626b4eff015472f2317576a8f4bf7b0eea1df6f3e32b"},
{name: "native-none-0-modify-output-1", tx: nativeTx, hashType: none, inputIndex: 0,
modificationFunction: modifyOutput(1), // shouldn't change the hash
expectedSignatureHash: "dfe67982cfccf245e29b94be260a9df08ffbfb88d3e91f814602549b0159cbfb"},
expectedSignatureHash: "fafabaabf6349fee4e18626b4eff015472f2317576a8f4bf7b0eea1df6f3e32b"},
{name: "native-none-0-modify-sequence-0", tx: nativeTx, hashType: none, inputIndex: 0,
modificationFunction: modifySequence(0), // should change the hash
expectedSignatureHash: "fd61e1c6750d23e5db6b026b0ea9cd4fe314d980280cb529cd1a37680a0fa8f0"},
expectedSignatureHash: "daee0700e0ed4ab9f50de24d83e0bfce62999474ec8ceeb537ea35980662b601"},
{name: "native-none-0-modify-sequence-1", tx: nativeTx, hashType: none, inputIndex: 0,
modificationFunction: modifySequence(1), // shouldn't change the hash
expectedSignatureHash: "dfe67982cfccf245e29b94be260a9df08ffbfb88d3e91f814602549b0159cbfb"},
expectedSignatureHash: "fafabaabf6349fee4e18626b4eff015472f2317576a8f4bf7b0eea1df6f3e32b"},
{name: "native-none-anyonecanpay-0", tx: nativeTx, hashType: noneAnyoneCanPay, inputIndex: 0,
expectedSignatureHash: "b8554c61787a17765b08d10149372681c983d2bf089052ddfc6f777217706eeb"},
expectedSignatureHash: "4e5c2d895f9711dc89c19d49ba478e9c8f4be0d82c9bd6b60d0361eb9b5296bc"},
{name: "native-none-anyonecanpay-0-modify-amount-spent", tx: nativeTx, hashType: noneAnyoneCanPay, inputIndex: 0,
modificationFunction: modifyAmountSpent(0), // should change the hash
expectedSignatureHash: "d7f2ee72e63e19da3e6dbb88a49152e8d17d6807fb12315fe144701fd2dc17c3"},
expectedSignatureHash: "9ce2f75eafc85b8e19133942c3143d14b61f2e7cc479fbc6d2fca026e50897f1"},
{name: "native-none-anyonecanpay-0-modify-script-public-key", tx: nativeTx, hashType: noneAnyoneCanPay, inputIndex: 0,
modificationFunction: modifyScriptPublicKey(0), // should change the hash
expectedSignatureHash: "d919065f5b09d2e9dfc4bca7434f902d7a313f798d306075fffb8ebbc2e4e052"},
expectedSignatureHash: "c6c364190520fe6c0419c2f45e25bf084356333b03ac7aaec28251126398bda3"},
// sigHashSingle
{name: "native-single-0", tx: nativeTx, hashType: single, inputIndex: 0,
expectedSignatureHash: "d630a0b36ef564b1de69fa5a36c33dd4faa243dac7d390d7ca4af15c9704eb0d"},
expectedSignatureHash: "6ff01d5d7cd82e24bc9ca0edec8bd6931ffb5aa1d303f07ca05dc89757343a92"},
{name: "native-single-0-modify-output-0", tx: nativeTx, hashType: single, inputIndex: 0,
modificationFunction: modifyOutput(0), // should change the hash
expectedSignatureHash: "4c4aabc567542bf13f49c214d5322a7ea5f7d3c9786f9fada20ab197ae999ea7"},
expectedSignatureHash: "d62af956aea369365bacc7e7f1aac106836994f1648311e82dd38da822c8771e"},
{name: "native-single-0-modify-output-1", tx: nativeTx, hashType: single, inputIndex: 0,
modificationFunction: modifyOutput(1), // shouldn't change the hash
expectedSignatureHash: "d630a0b36ef564b1de69fa5a36c33dd4faa243dac7d390d7ca4af15c9704eb0d"},
expectedSignatureHash: "6ff01d5d7cd82e24bc9ca0edec8bd6931ffb5aa1d303f07ca05dc89757343a92"},
{name: "native-single-0-modify-sequence-0", tx: nativeTx, hashType: single, inputIndex: 0,
modificationFunction: modifySequence(0), // should change the hash
expectedSignatureHash: "0b6b2e51a1e7b8eb7d231e19aef9280b624d81e863af71d098e43be273311819"},
expectedSignatureHash: "46692229d45bf2ceacb18960faba29753e325c0ade26ecf94495b91daacb828d"},
{name: "native-single-0-modify-sequence-1", tx: nativeTx, hashType: single, inputIndex: 0,
modificationFunction: modifySequence(1), // shouldn't change the hash
expectedSignatureHash: "d630a0b36ef564b1de69fa5a36c33dd4faa243dac7d390d7ca4af15c9704eb0d"},
expectedSignatureHash: "6ff01d5d7cd82e24bc9ca0edec8bd6931ffb5aa1d303f07ca05dc89757343a92"},
{name: "native-single-2-no-corresponding-output", tx: nativeTx, hashType: single, inputIndex: 2,
expectedSignatureHash: "feeb7519d34aa26f3ed8b5d9adda9a6d615b1fba1d34bb8521e68e9c98a1e5c5"},
expectedSignatureHash: "d3cc385082a7f272ec2c8aae7f3a96ab2f49a4a4e1ed44d61af34058a7721281"},
{name: "native-single-2-no-corresponding-output-modify-output-1", tx: nativeTx, hashType: single, inputIndex: 2,
modificationFunction: modifyOutput(1), // shouldn't change the hash
expectedSignatureHash: "feeb7519d34aa26f3ed8b5d9adda9a6d615b1fba1d34bb8521e68e9c98a1e5c5"},
expectedSignatureHash: "d3cc385082a7f272ec2c8aae7f3a96ab2f49a4a4e1ed44d61af34058a7721281"},
{name: "native-single-anyonecanpay-0", tx: nativeTx, hashType: singleAnyoneCanPay, inputIndex: 0,
expectedSignatureHash: "65d10f4bf89837b4b4715e5303939baba232e0bf8717f74f4105ef41dd46ee14"},
expectedSignatureHash: "408fcfd8ceca135c0f54569ccf8ac727e1aa6b5a15f87ccca765f1d5808aa4ea"},
{name: "native-single-anyonecanpay-2-no-corresponding-output", tx: nativeTx, hashType: singleAnyoneCanPay, inputIndex: 2,
expectedSignatureHash: "b565addaad79a99c0c86f5ad55931c460c6f854b3db37cc7a2f3c024789c499c"},
expectedSignatureHash: "685fac0d0b9dd3c5556f266714c4f7f93475d49fa12befb18e8297bc062aeaba"},
// subnetwork transaction
{name: "subnetwork-all-0", tx: subnetworkTx, hashType: all, inputIndex: 0,
expectedSignatureHash: "12f317cc543f200f42cf57e6ff398ffb4edabe90e3f574a29224a03dc57646c7"},
expectedSignatureHash: "0e8b1433b761a220a61c0dc1f0fda909d49cef120d98d9f87344fef52dac0d8b"},
{name: "subnetwork-all-modify-payload", tx: subnetworkTx, hashType: all, inputIndex: 0,
modificationFunction: modifyPayload, // should change the hash
expectedSignatureHash: "f38e75bb5f3c956936b616fd9d3b695e725c51f3e314520b6bad59125c4ecd00"},
expectedSignatureHash: "087315acb9193eaa14929dbe3d0ace80238aebe13eab3bf8db6c0a0d7ddb782e"},
{name: "subnetwork-all-modify-gas", tx: subnetworkTx, hashType: all, inputIndex: 0,
modificationFunction: modifyGas, // should change the hash
expectedSignatureHash: "a78ab950e51a9be1976d85ce98fa29accf195a9ab9eb1076bc7012fb76f98ba7"},
expectedSignatureHash: "07a90408ef45864ae8354b07a74cf826a4621391425ba417470a6e680af4ce70"},
{name: "subnetwork-all-subnetwork-id", tx: subnetworkTx, hashType: all, inputIndex: 0,
modificationFunction: modifySubnetworkID, // should change the hash
expectedSignatureHash: "65d6642bb9b5eb4a86289b33e7618de1006e996b6d6ff45a8b29ed5370cc889a"},
expectedSignatureHash: "4ca44c2e35729ae5efe831a77027f1a58a41dbdd853459c26cbfe7d6c88783fb"},
}
for _, test := range tests {
@ -214,7 +214,7 @@ func generateTxs() (nativeTx, subnetworkTx *externalapi.DomainTransaction, err e
genesisCoinbase := dagconfig.SimnetParams.GenesisBlock.Transactions[0]
genesisCoinbaseTransactionID := consensushashing.TransactionID(genesisCoinbase)
address1Str := "kaspasim:qzpj2cfa9m40w9m2cmr8pvfuqpp32mzzwsuw6ukhfd"
address1Str := "kaspasim:qzpj2cfa9m40w9m2cmr8pvfuqpp32mzzwsuw6ukhfduqpp32mzzws59e8fapc"
address1, err := util.DecodeAddress(address1Str, util.Bech32PrefixKaspaSim)
if err != nil {
return nil, nil, fmt.Errorf("error decoding address1: %+v", err)
@ -224,7 +224,7 @@ func generateTxs() (nativeTx, subnetworkTx *externalapi.DomainTransaction, err e
return nil, nil, fmt.Errorf("error generating script: %+v", err)
}
address2Str := "kaspasim:qr7w7nqsdnc3zddm6u8s9fex4ysk95hm3v30q353ym"
address2Str := "kaspasim:qr7w7nqsdnc3zddm6u8s9fex4ysk95hm3v30q353ymuqpp32mzzws59e8fapc"
address2, err := util.DecodeAddress(address2Str, util.Bech32PrefixKaspaSim)
if err != nil {
return nil, nil, fmt.Errorf("error decoding address2: %+v", err)

View File

@ -273,7 +273,7 @@
],
[
"'' 1",
"IF SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ENDIF 0x14 0x68ca4fec736264c13b859bac43d5173df6871682 EQUAL",
"IF SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ENDIF 0x20 0x2c49a55fe0ca3e7a005420c19a527865df8f17e468d234f562ef238d4236a632 EQUAL",
"",
"OK"
],
@ -304,7 +304,7 @@
],
[
"'' 0",
"NOTIF SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ELSE ELSE SHA1 ENDIF 0x14 0x68ca4fec736264c13b859bac43d5173df6871682 EQUAL",
"NOTIF SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ELSE ELSE SHA256 ENDIF 0x20 0x2c49a55fe0ca3e7a005420c19a527865df8f17e468d234f562ef238d4236a632 EQUAL",
"",
"OK"
],
@ -1139,37 +1139,19 @@
],
[
"''",
"RIPEMD160 0x14 0x9c1185a5c5e9fc54612808977ee8f548b2258d31 EQUAL",
"SHA256 0x20 0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 EQUAL",
"",
"OK"
],
[
"'a'",
"RIPEMD160 0x14 0x0bdc9d2d256b3ee9daae347be6f4dc835a467ffe EQUAL",
"SHA256 0x20 0xca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb EQUAL",
"",
"OK"
],
[
"'abcdefghijklmnopqrstuvwxyz'",
"RIPEMD160 0x14 0xf71c27109c692c1b56bbdceb5b9d2865b3708dbc EQUAL",
"",
"OK"
],
[
"''",
"SHA1 0x14 0xda39a3ee5e6b4b0d3255bfef95601890afd80709 EQUAL",
"",
"OK"
],
[
"'a'",
"SHA1 0x14 0x86f7e437faa5a7fce15d1ddcb9eaeaea377667b8 EQUAL",
"",
"OK"
],
[
"'abcdefghijklmnopqrstuvwxyz'",
"SHA1 0x14 0x32d10c7b8cf96570ca04ce37f2a19d84240d3a89 EQUAL",
"SHA256 0x20 0x71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73 EQUAL",
"",
"OK"
],
@ -1193,44 +1175,44 @@
],
[
"''",
"DUP HASH160 SWAP SHA256 RIPEMD160 EQUAL",
"",
"OK"
],
[
"''",
"NOP HASH160 0x14 0xb472a266d0bd89c13706a4132ccfb16f7c3b9fcb EQUAL",
"SHA256 0x20 0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 EQUAL",
"",
"OK"
],
[
"'a'",
"HASH160 NOP 0x14 0x994355199e516ff76c4fa4aab39337b9d84cf12b EQUAL",
"SHA256 0x20 0xca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb EQUAL",
"",
"OK"
],
[
"'abcdefghijklmnopqrstuvwxyz'",
"NOP HASH160 0x14 0xc286a1af0947f58d1ad787385b1c2c4a976f9e71 EQUAL",
"SHA256 0x20 0x71c480df93d6ae2f1efad1447c66c9525e316218cf51fc8d9ed832f2daf18b73 EQUAL",
"",
"OK"
],
[
"''",
"NOP BLAKE2B 0x20 0x0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8 EQUAL",
"",
"OK"
],
[
"'a'",
"BLAKE2B NOP 0x20 0x8928aae63c84d87ea098564d1e03ad813f107add474e56aedd286349c0c03ea4 EQUAL",
"",
"OK"
],
[
"'abcdefghijklmnopqrstuvwxyz'",
"NOP BLAKE2B 0x20 0x117ad6b940f5e8292c007d9c7e7350cd33cf85b5887e8da71c7957830f536e7c EQUAL",
"",
"OK",
"The NOP is added so the script won't be interpreted as P2SH"
],
[
"''",
"BLAKE2B 0x20 0x0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8 EQUAL",
"",
"OK"
],
[
"'a'",
"BLAKE2B 0x20 0x8928aae63c84d87ea098564d1e03ad813f107add474e56aedd286349c0c03ea4 EQUAL",
"",
"OK"
],
[
"'abcdefghijklmnopqrstuvwxyz'",
"BLAKE2B 0x20 0x117ad6b940f5e8292c007d9c7e7350cd33cf85b5887e8da71c7957830f536e7c EQUAL",
"NOP BLAKE2B 0x20 0x8928aae63c84d87ea098564d1e03ad813f107add474e56aedd286349c0c03ea4 EQUAL",
"",
"OK"
],
@ -2193,30 +2175,12 @@
"",
"OK"
],
[
"0",
"RIPEMD160",
"",
"OK"
],
[
"0",
"SHA1",
"",
"OK"
],
[
"0",
"SHA256",
"",
"OK"
],
[
"0",
"HASH160",
"",
"OK"
],
[
"0",
"BLAKE2B",
@ -2592,7 +2556,7 @@
],
[
"0x01 1",
"HASH160 0x14 0xda1745e9b549bd0bfa1a569971c77eba30cd5a4b EQUAL",
"BLAKE2B 0x20 0xce57216285125006ec18197bd8184221cefa559bb0798410d99a5bba5b07cd1d EQUAL",
"",
"OK",
"Very basic P2SH"
@ -3873,7 +3837,7 @@
],
[
"1 0x01 0xbb",
"HASH160 0x14 0x6b598ec091379f3d1a7f0532738e86accc36dc9f EQUAL",
"BLAKE2B 0x20 0x4324d0dc945c746e3be93be15b636ec1684108806912a479e8a34b2858be114a EQUAL",
"DISCOURAGE_UPGRADABLE_NOPS",
"DISCOURAGE_UPGRADABLE_NOPS",
"Discouraged NOP10 in redeemScript"
@ -4296,13 +4260,7 @@
],
[
"",
"RIPEMD160",
"",
"INVALID_STACK_OPERATION"
],
[
"",
"SHA1",
"SHA256",
"",
"INVALID_STACK_OPERATION"
],
@ -4314,7 +4272,13 @@
],
[
"",
"HASH160",
"SHA256",
"",
"INVALID_STACK_OPERATION"
],
[
"",
"BLAKE2B",
"",
"INVALID_STACK_OPERATION"
],
@ -4771,18 +4735,6 @@
"",
"INVALID_STACK_OPERATION"
],
[
"",
"RIPEMD160 1",
"",
"INVALID_STACK_OPERATION"
],
[
"",
"SHA1 1",
"",
"INVALID_STACK_OPERATION"
],
[
"",
"SHA256 1",
@ -4791,7 +4743,7 @@
],
[
"",
"HASH160 1",
"BLAKE2B 1",
"",
"INVALID_STACK_OPERATION"
],
@ -4890,27 +4842,27 @@
],
[
"NOP 0x01 1",
"HASH160 0x14 0xda1745e9b549bd0bfa1a569971c77eba30cd5a4b EQUAL",
"BLAKE2B 0x20 0xda1745e9b549bd0bfa1a569971c77eba30cd5a4b EQUAL",
"",
"SIG_PUSHONLY",
"Tests for Script.IsPushOnly()"
],
[
"NOP1 0x01 1",
"HASH160 0x14 0xda1745e9b549bd0bfa1a569971c77eba30cd5a4b EQUAL",
"BLAKE2B 0x20 0xda1745e9b549bd0bfa1a569971c77eba30cd5a4b EQUAL",
"",
"SIG_PUSHONLY"
],
[
"0 0x01 0x50",
"HASH160 0x14 0xece424a6bb6ddf4db592c0faed60685047a361b1 EQUAL",
"BLAKE2B 0x20 0xece424a6bb6ddf4db592c0faed60685047a361b1 EQUAL",
"",
"BAD_OPCODE",
"OP_RESERVED in P2SH should fail"
],
[
"0 0x01",
"VER HASH160 0x14 0x0f4d7845db968f2a81b530b6f3c1d6246d4c7e01 EQUAL",
"VER BLAKE2B 0x20 0x0f4d7845db968f2a81b530b6f3c1d6246d4c7e01 EQUAL",
"",
"BAD_OPCODE",
"OP_VER in P2SH should fail"

View File

@ -22,7 +22,7 @@ func ExamplePayToAddrScript() {
// which is useful to ensure the accuracy of the address and determine
// the address type. It is also required for the upcoming call to
// PayToAddrScript.
addressStr := "kaspa:qqfgqp8l9l90zwetj84k2jcac2m8falvvyy8xjtnhd"
addressStr := "kaspa:qqfgqp8l9l90zwetj84k2jcac2m8falvvyy8xjtnhdac2m8falvvyvc9fuvqt"
address, err := util.DecodeAddress(addressStr, util.Bech32PrefixKaspa)
if err != nil {
fmt.Println(err)
@ -45,15 +45,15 @@ func ExamplePayToAddrScript() {
fmt.Println("Script Disassembly:", disasm)
// Output:
// Script Hex: 76a914128004ff2fcaf13b2b91eb654b1dc2b674f7ec6188ac
// Script Disassembly: OP_DUP OP_HASH160 128004ff2fcaf13b2b91eb654b1dc2b674f7ec61 OP_EQUALVERIFY OP_CHECKSIG
// Script Hex: 76aa20128004ff2fcaf13b2b91eb654b1dc2b674f7ec6108734973bb7b856ce9efd8c288ac
// Script Disassembly: OP_DUP OP_BLAKE2B 128004ff2fcaf13b2b91eb654b1dc2b674f7ec6108734973bb7b856ce9efd8c2 OP_EQUALVERIFY OP_CHECKSIG
}
// This example demonstrates extracting information from a standard public key
// script.
func ExampleExtractScriptPubKeyAddress() {
// Start with a standard pay-to-pubkey-hash script.
scriptHex := "76a914128004ff2fcaf13b2b91eb654b1dc2b674f7ec6188ac"
scriptHex := "76aa20128004ff2fcaf13b2b91eb65128004ff2fcaf13b2b91eb654b1dc2b674f7ec6188ac"
script, err := hex.DecodeString(scriptHex)
if err != nil {
fmt.Println(err)
@ -75,5 +75,5 @@ func ExampleExtractScriptPubKeyAddress() {
// Output:
// Script Class: pubkeyhash
// Address: kaspa:qqfgqp8l9l90zwetj84k2jcac2m8falvvyy8xjtnhd
// Address: kaspa:qqfgqp8l9l90zwetj84k2y5qqnljljh38v4er6m9fvwu9dn57lkxztu8quj75
}

View File

@ -6,7 +6,6 @@ package txscript
import (
"bytes"
"crypto/sha1"
"crypto/sha256"
"encoding/binary"
"fmt"
@ -19,7 +18,6 @@ import (
"github.com/kaspanet/kaspad/domain/consensus/utils/constants"
"github.com/kaspanet/go-secp256k1"
"golang.org/x/crypto/ripemd160"
)
// An opcode defines the information related to a txscript opcode. opfunc, if
@ -203,10 +201,10 @@ const (
OpMin = 0xa3 // 163
OpMax = 0xa4 // 164
OpWithin = 0xa5 // 165
OpRipeMD160 = 0xa6 // 166
OpSHA1 = 0xa7 // 167
OpUnknown166 = 0xa6 // 166
OpUnknown167 = 0xa7 // 167
OpSHA256 = 0xa8 // 168
OpHash160 = 0xa9 // 169
OpUnknown169 = 0xa9 // 169
OpBlake2b = 0xaa // 170
OpUnknown171 = 0xab // 171
OpCheckSig = 0xac // 172
@ -487,10 +485,7 @@ var opcodeArray = [256]opcode{
OpWithin: {OpWithin, "OP_WITHIN", 1, opcodeWithin},
// Crypto opcodes.
OpRipeMD160: {OpRipeMD160, "OP_RIPEMD160", 1, opcodeRipemd160},
OpSHA1: {OpSHA1, "OP_SHA1", 1, opcodeSha1},
OpSHA256: {OpSHA256, "OP_SHA256", 1, opcodeSha256},
OpHash160: {OpHash160, "OP_HASH160", 1, opcodeHash160},
OpBlake2b: {OpBlake2b, "OP_BLAKE2B", 1, opcodeBlake2b},
OpCheckSig: {OpCheckSig, "OP_CHECKSIG", 1, opcodeCheckSig},
OpCheckSigVerify: {OpCheckSigVerify, "OP_CHECKSIGVERIFY", 1, opcodeCheckSigVerify},
@ -510,6 +505,9 @@ var opcodeArray = [256]opcode{
OpNop10: {OpNop10, "OP_NOP10", 1, opcodeNop},
// Undefined opcodes.
OpUnknown166: {OpUnknown166, "OP_UNKNOWN166", 1, opcodeInvalid},
OpUnknown167: {OpUnknown167, "OP_UNKNOWN167", 1, opcodeInvalid},
OpUnknown169: {OpUnknown169, "OP_UNKNOWN169", 1, opcodeInvalid},
OpUnknown171: {OpUnknown171, "OP_UNKNOWN171", 1, opcodeInvalid},
OpUnknown188: {OpUnknown188, "OP_UNKNOWN188", 1, opcodeInvalid},
OpUnknown189: {OpUnknown189, "OP_UNKNOWN189", 1, opcodeInvalid},
@ -1905,35 +1903,6 @@ func calcHash(buf []byte, hasher hash.Hash) []byte {
return hasher.Sum(nil)
}
// opcodeRipemd160 treats the top item of the data stack as raw bytes and
// replaces it with ripemd160(data).
//
// Stack transformation: [... x1] -> [... ripemd160(x1)]
func opcodeRipemd160(op *parsedOpcode, vm *Engine) error {
buf, err := vm.dstack.PopByteArray()
if err != nil {
return err
}
vm.dstack.PushByteArray(calcHash(buf, ripemd160.New()))
return nil
}
// opcodeSha1 treats the top item of the data stack as raw bytes and replaces it
// with sha1(data).
//
// Stack transformation: [... x1] -> [... sha1(x1)]
func opcodeSha1(op *parsedOpcode, vm *Engine) error {
buf, err := vm.dstack.PopByteArray()
if err != nil {
return err
}
hash := sha1.Sum(buf)
vm.dstack.PushByteArray(hash[:])
return nil
}
// opcodeSha256 treats the top item of the data stack as raw bytes and replaces
// it with sha256(data).
//
@ -1949,21 +1918,6 @@ func opcodeSha256(op *parsedOpcode, vm *Engine) error {
return nil
}
// opcodeHash160 treats the top item of the data stack as raw bytes and replaces
// it with ripemd160(sha256(data)).
//
// Stack transformation: [... x1] -> [... ripemd160(sha256(x1))]
func opcodeHash160(op *parsedOpcode, vm *Engine) error {
buf, err := vm.dstack.PopByteArray()
if err != nil {
return err
}
hash := sha256.Sum256(buf)
vm.dstack.PushByteArray(calcHash(hash[:], ripemd160.New()))
return nil
}
// opcodeBlake2b treats the top item of the data stack as raw bytes and replaces
// it with blake2b(data).
//

View File

@ -71,8 +71,8 @@ func TestOpcodeDisasm(t *testing.T) {
0x9f: "OP_LESSTHAN", 0xa0: "OP_GREATERTHAN",
0xa1: "OP_LESSTHANOREQUAL", 0xa2: "OP_GREATERTHANOREQUAL",
0xa3: "OP_MIN", 0xa4: "OP_MAX", 0xa5: "OP_WITHIN",
0xa6: "OP_RIPEMD160", 0xa7: "OP_SHA1", 0xa8: "OP_SHA256",
0xa9: "OP_HASH160", 0xaa: "OP_BLAKE2B",
0xa8: "OP_SHA256",
0xaa: "OP_BLAKE2B",
0xac: "OP_CHECKSIG", 0xad: "OP_CHECKSIGVERIFY",
0xae: "OP_CHECKMULTISIG", 0xaf: "OP_CHECKMULTISIGVERIFY",
0xb0: "OP_CHECKLOCKTIMEVERIFY", 0xb1: "OP_CHECKSEQUENCEVERIFY",
@ -186,7 +186,8 @@ func TestOpcodeDisasm(t *testing.T) {
}
func isOpUnknown(opcodeVal int) bool {
return opcodeVal >= 0xba && opcodeVal <= 0xf9 || opcodeVal == 0xfc || opcodeVal == 0xab
return opcodeVal >= 0xba && opcodeVal <= 0xf9 || opcodeVal == 0xfc || opcodeVal == 0xab ||
opcodeVal == 0xa6 || opcodeVal == 0xa7 || opcodeVal == 0xa9
}
func isNumberedNop(opcodeVal int) bool {

View File

@ -33,8 +33,8 @@ func isSmallInt(op *opcode) bool {
// transaction, false otherwise.
func isScriptHash(pops []parsedOpcode) bool {
return len(pops) == 3 &&
pops[0].opcode.value == OpHash160 &&
pops[1].opcode.value == OpData20 &&
pops[0].opcode.value == OpBlake2b &&
pops[1].opcode.value == OpData32 &&
pops[2].opcode.value == OpEqual
}

View File

@ -3299,38 +3299,6 @@ func TestUnparsingInvalidOpcodes(t *testing.T) {
},
expectedErr: scriptError(ErrInternal, ""),
},
{
name: "OP_RIPEMD160",
pop: &parsedOpcode{
opcode: &opcodeArray[OpRipeMD160],
data: nil,
},
expectedErr: nil,
},
{
name: "OP_RIPEMD160 long",
pop: &parsedOpcode{
opcode: &opcodeArray[OpRipeMD160],
data: make([]byte, 1),
},
expectedErr: scriptError(ErrInternal, ""),
},
{
name: "OP_SHA1",
pop: &parsedOpcode{
opcode: &opcodeArray[OpSHA1],
data: nil,
},
expectedErr: nil,
},
{
name: "OP_SHA1 long",
pop: &parsedOpcode{
opcode: &opcodeArray[OpSHA1],
data: make([]byte, 1),
},
expectedErr: scriptError(ErrInternal, ""),
},
{
name: "OP_SHA256",
pop: &parsedOpcode{
@ -3347,22 +3315,6 @@ func TestUnparsingInvalidOpcodes(t *testing.T) {
},
expectedErr: scriptError(ErrInternal, ""),
},
{
name: "OP_HASH160",
pop: &parsedOpcode{
opcode: &opcodeArray[OpHash160],
data: nil,
},
expectedErr: nil,
},
{
name: "OP_HASH160 long",
pop: &parsedOpcode{
opcode: &opcodeArray[OpHash160],
data: make([]byte, 1),
},
expectedErr: scriptError(ErrInternal, ""),
},
{
name: "OP_BLAKE2B",
pop: &parsedOpcode{
@ -3686,7 +3638,7 @@ func TestPushedData(t *testing.T) {
true,
},
{
"DUP HASH160 '17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem' EQUALVERIFY CHECKSIG",
"DUP BLAKE2B '17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem' EQUALVERIFY CHECKSIG",
[][]byte{
// 17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem
{
@ -3828,7 +3780,7 @@ func TestGetPreciseSigOps(t *testing.T) {
// The signature in the p2sh script is nonsensical for the tests since
// this script will never be executed. What matters is that it matches
// the right pattern.
scriptOnly := mustParseShortForm("HASH160 DATA_20 0x433ec2ac1ffa1b7b7d0"+
scriptOnly := mustParseShortForm("BLAKE2B DATA_32 0x433ec2ac1ffa1b7b7d0"+
"27f564529c57197f9ae88 EQUAL", 0)
scriptPubKey := &externalapi.ScriptPublicKey{scriptOnly, 0}
for _, test := range tests {

View File

@ -31,9 +31,9 @@ func TestScriptBuilderAddOp(t *testing.T) {
expected: []byte{Op1, Op2},
},
{
name: "push OP_HASH160 OP_EQUAL",
opcodes: []byte{OpHash160, OpEqual},
expected: []byte{OpHash160, OpEqual},
name: "push OP_BLAKE2B OP_EQUAL",
opcodes: []byte{OpBlake2b, OpEqual},
expected: []byte{OpBlake2b, OpEqual},
},
}

View File

@ -214,7 +214,7 @@ func TestSignTxOutput(t *testing.T) {
}
address, err := util.NewAddressPubKeyHash(
util.Hash160(serializedPubKey[:]), util.Bech32PrefixKaspaTest)
util.HashBlake2b(serializedPubKey[:]), util.Bech32PrefixKaspaTest)
if err != nil {
t.Errorf("failed to make address for %s: %v",
msg, err)
@ -265,7 +265,7 @@ func TestSignTxOutput(t *testing.T) {
}
address, err := util.NewAddressPubKeyHash(
util.Hash160(serializedPubKey[:]), util.Bech32PrefixKaspaTest)
util.HashBlake2b(serializedPubKey[:]), util.Bech32PrefixKaspaTest)
if err != nil {
t.Errorf("failed to make address for %s: %v",
msg, err)
@ -343,7 +343,7 @@ func TestSignTxOutput(t *testing.T) {
}
address, err := util.NewAddressPubKeyHash(
util.Hash160(serializedPubKey[:]), util.Bech32PrefixKaspaTest)
util.HashBlake2b(serializedPubKey[:]), util.Bech32PrefixKaspaTest)
if err != nil {
t.Errorf("failed to make address for %s: %v",
msg, err)
@ -408,7 +408,7 @@ func TestSignTxOutput(t *testing.T) {
}
address, err := util.NewAddressPubKeyHash(
util.Hash160(serializedPubKey[:]), util.Bech32PrefixKaspaTest)
util.HashBlake2b(serializedPubKey[:]), util.Bech32PrefixKaspaTest)
if err != nil {
t.Errorf("failed to make address for %s: %v",
msg, err)
@ -491,7 +491,7 @@ func generateKeys() (keyPair *secp256k1.SchnorrKeyPair, scriptPublicKey *externa
return nil, nil, nil, errors.Errorf("failed to serialize a pubkey for %s: %s", pubKey, err)
}
address, err := util.NewAddressPubKeyHash(
util.Hash160(serializedPubKey[:]), util.Bech32PrefixKaspaTest)
util.HashBlake2b(serializedPubKey[:]), util.Bech32PrefixKaspaTest)
if err != nil {
return nil, nil, nil, errors.Errorf("failed to make address for %s: %s", serializedPubKey, err)
}
@ -534,9 +534,15 @@ var (
oldCompressedScriptPubKey = &externalapi.ScriptPublicKey{[]byte{0x76, 0xa9, 0x14, 0x27, 0x4d, 0x9f, 0x7f,
0x61, 0x7e, 0x7c, 0x7a, 0x1c, 0x1f, 0xb2, 0x75, 0x79, 0x10,
0x43, 0x65, 0x68, 0x27, 0x9d, 0x86, 0x88, 0xac}, 0}
p2pkhScriptPubKey = &externalapi.ScriptPublicKey{[]byte{0x76, 0xa9, 0x14, 0x7e, 0x01, 0x76, 0xb6,
0x72, 0x08, 0xc0, 0x08, 0x98, 0x85, 0x97, 0x00, 0x4e, 0x1a, 0x8d,
0x60, 0x89, 0xfe, 0x42, 0x6f, 0x88, 0xac}, 0}
p2pkhScriptPubKey = &externalapi.ScriptPublicKey{[]byte{0x76, 0xaa, 0x20,
0x51, 0x9c, 0x25, 0xca, 0x95, 0xa0, 0xd8, 0xcd,
0xf5, 0xb8, 0x3f, 0x96, 0xa1, 0x5e, 0x8c, 0x1a,
0xae, 0x33, 0xeb, 0x50, 0xc8, 0x66, 0xc9, 0xd0,
0xa5, 0xce, 0x3e, 0x5f, 0x6b, 0x3b, 0x38, 0x8d,
0x88, 0xac}, 0}
shortScriptPubKey = &externalapi.ScriptPublicKey{[]byte{0x76, 0xa9, 0x14, 0xd1, 0x7c, 0xb5,
0xeb, 0xa4, 0x02, 0xcb, 0x68, 0xe0, 0x69, 0x56, 0xbf, 0x32,
0x53, 0x90, 0x0e, 0x0a, 0x88, 0xac}, 0}
)
// Pretend output amounts.

View File

@ -48,8 +48,8 @@ func (t ScriptClass) String() string {
func isPubkeyHash(pops []parsedOpcode) bool {
return len(pops) == 5 &&
pops[0].opcode.value == OpDup &&
pops[1].opcode.value == OpHash160 &&
pops[2].opcode.value == OpData20 &&
pops[1].opcode.value == OpBlake2b &&
pops[2].opcode.value == OpData32 &&
pops[3].opcode.value == OpEqualVerify &&
pops[4].opcode.value == OpCheckSig
@ -173,7 +173,7 @@ func CalcScriptInfo(sigScript, scriptPubKey []byte, isP2SH bool) (*ScriptInfo, e
// output to a 20-byte pubkey hash. It is expected that the input is a valid
// hash.
func payToPubKeyHashScript(pubKeyHash []byte) ([]byte, error) {
return NewScriptBuilder().AddOp(OpDup).AddOp(OpHash160).
return NewScriptBuilder().AddOp(OpDup).AddOp(OpBlake2b).
AddData(pubKeyHash).AddOp(OpEqualVerify).AddOp(OpCheckSig).
Script()
}
@ -181,7 +181,7 @@ func payToPubKeyHashScript(pubKeyHash []byte) ([]byte, error) {
// payToScriptHashScript creates a new script to pay a transaction output to a
// script hash. It is expected that the input is a valid hash.
func payToScriptHashScript(scriptHash []byte) ([]byte, error) {
return NewScriptBuilder().AddOp(OpHash160).AddData(scriptHash).
return NewScriptBuilder().AddOp(OpBlake2b).AddData(scriptHash).
AddOp(OpEqual).Script()
}
@ -220,9 +220,9 @@ func PayToAddrScript(addr util.Address) (*externalapi.ScriptPublicKey, error) {
// PayToScriptHashScript takes a script and returns an equivalent pay-to-script-hash script
func PayToScriptHashScript(redeemScript []byte) ([]byte, error) {
redeemScriptHash := util.Hash160(redeemScript)
redeemScriptHash := util.HashBlake2b(redeemScript)
script, err := NewScriptBuilder().
AddOp(OpHash160).AddData(redeemScriptHash).
AddOp(OpBlake2b).AddData(redeemScriptHash).
AddOp(OpEqual).Script()
if err != nil {
return nil, err
@ -278,7 +278,7 @@ func ExtractScriptPubKeyAddress(scriptPubKey *externalapi.ScriptPublicKey, dagPa
switch scriptClass {
case PubKeyHashTy:
// A pay-to-pubkey-hash script is of the form:
// OP_DUP OP_HASH160 <hash> OP_EQUALVERIFY OP_CHECKSIG
// OP_DUP OP_BLAKE2B <hash> OP_EQUALVERIFY OP_CHECKSIG
// Therefore the pubkey hash is the 3rd item on the stack.
// If the pubkey hash is invalid for some reason, return a nil address.
addr, err := util.NewAddressPubKeyHash(pops[2].data,
@ -290,7 +290,7 @@ func ExtractScriptPubKeyAddress(scriptPubKey *externalapi.ScriptPublicKey, dagPa
case ScriptHashTy:
// A pay-to-script-hash script is of the form:
// OP_HASH160 <scripthash> OP_EQUAL
// OP_BLAKE2B <scripthash> OP_EQUAL
// Therefore the script hash is the 2nd item on the stack.
// If the script hash ss invalid for some reason, return a nil address.
addr, err := util.NewAddressScriptHashFromHash(pops[1].data,
@ -311,8 +311,8 @@ func ExtractScriptPubKeyAddress(scriptPubKey *externalapi.ScriptPublicKey, dagPa
// AtomicSwapDataPushes houses the data pushes found in atomic swap contracts.
type AtomicSwapDataPushes struct {
RecipientHash160 [20]byte
RefundHash160 [20]byte
RecipientBlake2b [32]byte
RefundBlake2b [32]byte
SecretHash [32]byte
SecretSize int64
LockTime uint64
@ -346,15 +346,15 @@ func ExtractAtomicSwapDataPushes(version uint16, scriptPubKey []byte) (*AtomicSw
pops[5].opcode.value == OpData32 &&
pops[6].opcode.value == OpEqualVerify &&
pops[7].opcode.value == OpDup &&
pops[8].opcode.value == OpHash160 &&
pops[9].opcode.value == OpData20 &&
pops[8].opcode.value == OpBlake2b &&
pops[9].opcode.value == OpData32 &&
pops[10].opcode.value == OpElse &&
canonicalPush(pops[11]) &&
pops[12].opcode.value == OpCheckLockTimeVerify &&
pops[13].opcode.value == OpDrop &&
pops[14].opcode.value == OpDup &&
pops[15].opcode.value == OpHash160 &&
pops[16].opcode.value == OpData20 &&
pops[15].opcode.value == OpBlake2b &&
pops[16].opcode.value == OpData32 &&
pops[17].opcode.value == OpEndIf &&
pops[18].opcode.value == OpEqualVerify &&
pops[19].opcode.value == OpCheckSig
@ -364,8 +364,8 @@ func ExtractAtomicSwapDataPushes(version uint16, scriptPubKey []byte) (*AtomicSw
pushes := new(AtomicSwapDataPushes)
copy(pushes.SecretHash[:], pops[5].data)
copy(pushes.RecipientHash160[:], pops[9].data)
copy(pushes.RefundHash160[:], pops[16].data)
copy(pushes.RecipientBlake2b[:], pops[9].data)
copy(pushes.RefundBlake2b[:], pops[16].data)
if pops[2].data != nil {
locktime, err := makeScriptNum(pops[2].data, 5)
if err != nil {

View File

@ -69,23 +69,23 @@ func TestExtractScriptPubKeyAddrs(t *testing.T) {
{
name: "standard p2pkh",
script: &externalapi.ScriptPublicKey{
Script: hexToBytes("76a914ad06dd6ddee55cbca9a9e3713bd" +
"7587509a3056488ac"),
Script: hexToBytes("76aa20ad06dd6ddee55cbca9a9e3713bd" +
"7587509a30564ad06dd6ddee55cbca9a9e37188ac"),
Version: 0,
},
addr: newAddressPubKeyHash(hexToBytes("ad06dd6ddee5" +
"5cbca9a9e3713bd7587509a30564")),
"5cbca9a9e3713bd7587509a30564ad06dd6ddee55cbca9a9e371")),
class: PubKeyHashTy,
},
{
name: "standard p2sh",
script: &externalapi.ScriptPublicKey{
Script: hexToBytes("a91463bcc565f9e68ee0189dd5cc67f1b" +
"0e5f02f45cb87"),
Script: hexToBytes("aa2063bcc565f9e68ee0189dd5cc67f1b" +
"0e5f02f45cbad06dd6ddee55cbca9a9e37187"),
Version: 0,
},
addr: newAddressScriptHash(hexToBytes("63bcc565f9e6" +
"8ee0189dd5cc67f1b0e5f02f45cb")),
"8ee0189dd5cc67f1b0e5f02f45cbad06dd6ddee55cbca9a9e371")),
class: ScriptHashTy,
},
@ -198,8 +198,8 @@ func TestCalcScriptInfo(t *testing.T) {
name: "scriptPubKey doesn't parse",
sigScript: "1 81 DATA_8 2DUP EQUAL NOT VERIFY ABS " +
"SWAP ABS EQUAL",
scriptPubKey: "HASH160 DATA_20 0xfe441065b6532231de2fac56" +
"3152205ec4f59c",
scriptPubKey: "BLAKE2B DATA_32 0xfe441065b6532231de2fac56" +
"3152205ec4f59cfe441065b6532231de2fac56",
isP2SH: true,
scriptInfoErr: scriptError(ErrMalformedPush, ""),
},
@ -208,19 +208,19 @@ func TestCalcScriptInfo(t *testing.T) {
// Truncated version of p2sh script below.
sigScript: "1 81 DATA_8 2DUP EQUAL NOT VERIFY ABS " +
"SWAP ABS",
scriptPubKey: "HASH160 DATA_20 0xfe441065b6532231de2fac56" +
"3152205ec4f59c74 EQUAL",
scriptPubKey: "BLAKE2B DATA_32 0xfe441065b6532231de2fac56" +
"3152205ec4f59c74fe441065b6532231de2fac56 EQUAL",
isP2SH: true,
scriptInfoErr: scriptError(ErrMalformedPush, ""),
},
{
// Invented scripts, the hashes do not match
name: "p2sh standard script",
sigScript: "1 81 DATA_25 DUP HASH160 DATA_20 0x010203" +
"0405060708090a0b0c0d0e0f1011121314 EQUALVERIFY " +
sigScript: "1 81 DATA_37 DUP BLAKE2B DATA_32 0x010203" +
"0405060708090a0b0c0d0e0f1011121314fe441065b6532231de2fac56 EQUALVERIFY " +
"CHECKSIG",
scriptPubKey: "HASH160 DATA_20 0xfe441065b6532231de2fac56" +
"3152205ec4f59c74 EQUAL",
scriptPubKey: "BLAKE2B DATA_32 0xfe441065b6532231de2fac56" +
"3152205ec4f59c74fe441065b6532231de2fac56 EQUAL",
isP2SH: true,
scriptInfo: ScriptInfo{
ScriptPubKeyClass: ScriptHashTy,
@ -233,8 +233,8 @@ func TestCalcScriptInfo(t *testing.T) {
name: "p2sh nonstandard script",
sigScript: "1 81 DATA_8 2DUP EQUAL NOT VERIFY ABS " +
"SWAP ABS EQUAL",
scriptPubKey: "HASH160 DATA_20 0xfe441065b6532231de2fac56" +
"3152205ec4f59c74 EQUAL",
scriptPubKey: "BLAKE2B DATA_32 0xfe441065b6532231de2fac56" +
"3152205ec4f59c74fe441065b6532231de2fac56 EQUAL",
isP2SH: true,
scriptInfo: ScriptInfo{
ScriptPubKeyClass: ScriptHashTy,
@ -303,17 +303,14 @@ func (b *bogusAddress) Prefix() util.Bech32Prefix {
func TestPayToAddrScript(t *testing.T) {
t.Parallel()
// 1MirQ9bwyQcGVJPwKUgapu5ouK2E2Ey4gX
p2pkhMain, err := util.NewAddressPubKeyHash(hexToBytes("e34cce70c86"+
"373273efcc54ce7d2a491bb4a0e84"), util.Bech32PrefixKaspa)
"373273efcc54ce7d2a491bb4a0e84e34cce70c86373273efcc54c"), util.Bech32PrefixKaspa)
if err != nil {
t.Fatalf("Unable to create public key hash address: %v", err)
}
// Taken from transaction:
// b0539a45de13b3e0403909b8bd1a555b8cbe45fd4e3f3fda76f3a5f52835c29d
p2shMain, err := util.NewAddressScriptHashFromHash(hexToBytes("e8c300"+
"c87986efa84c37c0519929019ef86eb5b4"), util.Bech32PrefixKaspa)
"c87986efa84c37c0519929019ef86eb5b4e34cce70c86373273efcc54c"), util.Bech32PrefixKaspa)
if err != nil {
t.Fatalf("Unable to create script hash address: %v", err)
}
@ -331,16 +328,16 @@ func TestPayToAddrScript(t *testing.T) {
// pay-to-pubkey-hash address on mainnet
{
p2pkhMain,
"DUP HASH160 DATA_20 0xe34cce70c86373273efcc54ce7d2a4" +
"91bb4a0e8488 CHECKSIG",
"DUP BLAKE2B DATA_32 0xe34cce70c86373273efcc54ce7d2a4" +
"91bb4a0e84e34cce70c86373273efcc54c EQUALVERIFY CHECKSIG",
0,
nil,
},
// pay-to-script-hash address on mainnet
{
p2shMain,
"HASH160 DATA_20 0xe8c300c87986efa84c37c0519929019ef8" +
"6eb5b4 EQUAL",
"BLAKE2B DATA_32 0xe8c300c87986efa84c37c0519929019ef8" +
"6eb5b4e34cce70c86373273efcc54c EQUAL",
0,
nil,
},
@ -401,10 +398,9 @@ var scriptClassTests = []struct {
"0bfa9b8b64f9d4c03f999b8643f656b412a3 CHECKSIG",
class: NonStandardTy,
},
// tx 599e47a8114fe098103663029548811d2651991b62397e057f0c863c2bc9f9ea
{
name: "Pay PubkeyHash",
script: "DUP HASH160 DATA_20 0x660d4ef3a743e3e696ad990364e555" +
script: "DUP BLAKE2B DATA_32 0x660d4ef3a743e3e696ad990364e55543e3e696ad990364e555e555" +
"c271ad504b EQUALVERIFY CHECKSIG",
class: PubKeyHashTy,
},
@ -415,10 +411,9 @@ var scriptClassTests = []struct {
"5329a00357b3a7886211ab414d55a 1 CHECKMULTISIG",
class: NonStandardTy,
},
// tx e5779b9e78f9650debc2893fd9636d827b26b4ddfa6a8172fe8708c924f5c39d
{
name: "P2SH",
script: "HASH160 DATA_20 0x433ec2ac1ffa1b7b7d027f564529c57197f" +
script: "BLAKE2B DATA_32 0x433ec2ac1ffa1b7b7d027f564529c57197fa1b7b7d027f564529c57197f" +
"9ae88 EQUAL",
class: ScriptHashTy,
},

View File

@ -16,10 +16,8 @@ var genesisTxOuts = []*externalapi.DomainTransactionOutput{}
var genesisTxPayload = []byte{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Blue score
0x00, 0x00, //script version
0x17, // Varint
0xa9, 0x14, 0xda, 0x17, 0x45, 0xe9, 0xb5, 0x49, // OP-TRUE p2sh
0xbd, 0x0b, 0xfa, 0x1a, 0x56, 0x99, 0x71, 0xc7,
0x7e, 0xba, 0x30, 0xcd, 0x5a, 0x4b, 0x87,
0x01, // Varint
0x00, // OP-FALSE
}
// genesisCoinbaseTx is the coinbase transaction for the genesis blocks for
@ -30,19 +28,19 @@ var genesisCoinbaseTx = transactionhelper.NewSubnetworkTransaction(0, []*externa
// genesisHash is the hash of the first block in the block DAG for the main
// network (genesis block).
var genesisHash = externalapi.NewDomainHashFromByteArray(&[externalapi.DomainHashSize]byte{
0xf2, 0xfa, 0x21, 0x85, 0xbd, 0x7c, 0x01, 0x22,
0x23, 0xf7, 0x58, 0x8e, 0xe9, 0xb4, 0x01, 0xf3,
0xfe, 0xf9, 0xb9, 0x70, 0xff, 0xec, 0xdd, 0x19,
0xc1, 0xdd, 0x6d, 0x8d, 0x8b, 0x93, 0x65, 0xc9,
0x8b, 0xde, 0x80, 0xec, 0x12, 0x9a, 0x30, 0x3a,
0xd5, 0x4a, 0x17, 0x13, 0xdf, 0x46, 0x16, 0x8d,
0xdd, 0xca, 0x9f, 0x59, 0xc4, 0x4a, 0x37, 0x6a,
0xc3, 0xc9, 0xc2, 0x90, 0xe9, 0x63, 0x23, 0x26,
})
// genesisMerkleRoot is the hash of the first transaction in the genesis block
// for the main network.
var genesisMerkleRoot = externalapi.NewDomainHashFromByteArray(&[externalapi.DomainHashSize]byte{
0xca, 0x21, 0x52, 0xc9, 0x86, 0x99, 0x26, 0xf5,
0x66, 0x23, 0xb9, 0xbf, 0x22, 0x01, 0x83, 0x2e,
0x7f, 0xf4, 0xda, 0xfb, 0x6f, 0x9d, 0x69, 0x94,
0xcf, 0x48, 0x8b, 0x8a, 0x16, 0x8b, 0x33, 0x37,
0xc5, 0x04, 0xfd, 0x49, 0x6a, 0xa5, 0x3f, 0x44,
0x51, 0x2c, 0x5a, 0x73, 0x9c, 0x28, 0xd5, 0x30,
0xfa, 0x54, 0xbb, 0x8e, 0x88, 0x82, 0xbb, 0x9a,
0xdb, 0xd6, 0x7f, 0x09, 0xd0, 0x2c, 0x6c, 0x47,
})
// genesisBlock defines the genesis block of the block DAG which serves as the
@ -54,9 +52,9 @@ var genesisBlock = externalapi.DomainBlock{
genesisMerkleRoot,
&externalapi.DomainHash{},
&externalapi.DomainHash{},
0x17772f4a238,
0x177a5f1dd32,
0x207fffff,
0x5,
0x4,
),
Transactions: []*externalapi.DomainTransaction{genesisCoinbaseTx},
}
@ -66,10 +64,8 @@ var devnetGenesisTxOuts = []*externalapi.DomainTransactionOutput{}
var devnetGenesisTxPayload = []byte{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Blue score
0x00, 0x00, // Script version
0x17, // Varint
0xa9, 0x14, 0xda, 0x17, 0x45, 0xe9, 0xb5, 0x49, // OP-TRUE p2sh
0xbd, 0x0b, 0xfa, 0x1a, 0x56, 0x99, 0x71, 0xc7,
0x7e, 0xba, 0x30, 0xcd, 0x5a, 0x4b, 0x87,
0x01, // Varint
0x00, // OP-FALSE
0x6b, 0x61, 0x73, 0x70, 0x61, 0x2d, 0x64, 0x65, 0x76, 0x6e, 0x65, 0x74, // kaspa-devnet
}
@ -82,19 +78,19 @@ var devnetGenesisCoinbaseTx = transactionhelper.NewSubnetworkTransaction(0,
// devGenesisHash is the hash of the first block in the block DAG for the development
// network (genesis block).
var devnetGenesisHash = externalapi.NewDomainHashFromByteArray(&[externalapi.DomainHashSize]byte{
0xac, 0x97, 0xf4, 0x05, 0x65, 0x60, 0x1c, 0x89,
0x93, 0x86, 0x86, 0x9d, 0xa8, 0x25, 0x75, 0xd0,
0x73, 0x18, 0x3f, 0xfc, 0x7d, 0x48, 0xc4, 0x51,
0x6e, 0x86, 0x23, 0x0c, 0x29, 0x8b, 0x83, 0x4c,
0x9b, 0x61, 0x0c, 0x49, 0x01, 0xb7, 0x44, 0x25,
0x21, 0x6d, 0x75, 0x7b, 0x7b, 0xf2, 0x82, 0x07,
0xb6, 0x4b, 0xa2, 0xf9, 0xe7, 0xeb, 0x77, 0x7c,
0xb3, 0x66, 0x96, 0x4b, 0xad, 0xfe, 0x44, 0xa4,
})
// devnetGenesisMerkleRoot is the hash of the first transaction in the genesis block
// for the devopment network.
var devnetGenesisMerkleRoot = externalapi.NewDomainHashFromByteArray(&[externalapi.DomainHashSize]byte{
0x07, 0xf1, 0x02, 0xe1, 0xca, 0xdc, 0x1c, 0xac,
0xb3, 0xc1, 0x5e, 0x3e, 0x41, 0x1b, 0x55, 0x78,
0x71, 0xab, 0xed, 0xc6, 0xaf, 0xe0, 0xbe, 0x40,
0x7e, 0xe0, 0x7e, 0x31, 0x8a, 0xf7, 0x23, 0xa4,
0xfc, 0x35, 0x93, 0x85, 0x4d, 0x0a, 0x24, 0xe3,
0xc4, 0x52, 0xdd, 0x4d, 0xe5, 0xf1, 0x4d, 0xf1,
0x5e, 0xff, 0xcd, 0x40, 0x81, 0x63, 0x53, 0x4e,
0xec, 0x86, 0x62, 0x99, 0x91, 0x28, 0x45, 0xa4,
})
// devnetGenesisBlock defines the genesis block of the block DAG which serves as the
@ -108,7 +104,7 @@ var devnetGenesisBlock = externalapi.DomainBlock{
&externalapi.DomainHash{},
0x11e9db49828,
0x1e7fffff,
0x5a8d,
0x16ff1,
),
Transactions: []*externalapi.DomainTransaction{devnetGenesisCoinbaseTx},
}
@ -118,10 +114,8 @@ var simnetGenesisTxOuts = []*externalapi.DomainTransactionOutput{}
var simnetGenesisTxPayload = []byte{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Blue score
0x00, 0x00, // Script version
0x17, // Varint
0xa9, 0x14, 0xda, 0x17, 0x45, 0xe9, 0xb5, 0x49, // OP-TRUE p2sh
0xbd, 0x0b, 0xfa, 0x1a, 0x56, 0x99, 0x71, 0xc7,
0x7e, 0xba, 0x30, 0xcd, 0x5a, 0x4b, 0x87,
0x01, // Varint
0x00, // OP-FALSE
0x6b, 0x61, 0x73, 0x70, 0x61, 0x2d, 0x73, 0x69, 0x6d, 0x6e, 0x65, 0x74, // kaspa-simnet
}
@ -133,19 +127,19 @@ var simnetGenesisCoinbaseTx = transactionhelper.NewSubnetworkTransaction(0,
// simnetGenesisHash is the hash of the first block in the block DAG for
// the simnet (genesis block).
var simnetGenesisHash = externalapi.NewDomainHashFromByteArray(&[externalapi.DomainHashSize]byte{
0xde, 0x29, 0x53, 0xb7, 0xa3, 0xac, 0x9c, 0xc1,
0xf6, 0xca, 0xa7, 0xc8, 0x25, 0x12, 0x80, 0xf7,
0xb1, 0xe4, 0x42, 0xbc, 0x58, 0x89, 0x3f, 0x36,
0xd9, 0x70, 0x6b, 0xbd, 0xae, 0x8b, 0xae, 0xc4,
0x74, 0xad, 0xf5, 0x43, 0x5d, 0x87, 0x42, 0xa7,
0x37, 0xa7, 0x70, 0x8d, 0xaf, 0xea, 0x46, 0xe7,
0x11, 0xcc, 0x31, 0x47, 0x96, 0xb4, 0xd0, 0x1c,
0x2c, 0x75, 0x6c, 0x8a, 0xc1, 0x7f, 0x44, 0x00,
})
// simnetGenesisMerkleRoot is the hash of the first transaction in the genesis block
// for the devopment network.
var simnetGenesisMerkleRoot = externalapi.NewDomainHashFromByteArray(&[externalapi.DomainHashSize]byte{
0xb7, 0xcd, 0xe4, 0x96, 0x5b, 0xbc, 0x6b, 0x5c,
0xca, 0x40, 0x0a, 0x8f, 0x13, 0xf8, 0x15, 0x1b,
0x0e, 0xd2, 0xdc, 0x2c, 0x6e, 0x8c, 0x25, 0x7a,
0x89, 0x6a, 0x69, 0xcd, 0x58, 0x7a, 0x30, 0xd0,
0x28, 0x5d, 0x64, 0x1f, 0x27, 0xdd, 0x7e, 0x56,
0x46, 0x75, 0xeb, 0xe5, 0x05, 0x58, 0x5b, 0x7a,
0xd4, 0x0c, 0x65, 0x07, 0xb8, 0x66, 0x0e, 0xd8,
0x17, 0xfc, 0xc7, 0x53, 0x77, 0x48, 0xd2, 0x3a,
})
// simnetGenesisBlock defines the genesis block of the block DAG which serves as the
@ -157,9 +151,9 @@ var simnetGenesisBlock = externalapi.DomainBlock{
simnetGenesisMerkleRoot,
&externalapi.DomainHash{},
&externalapi.DomainHash{},
0x17772f7a1f8,
0x177a5f1ddbf,
0x207fffff,
0x5,
0x1,
),
Transactions: []*externalapi.DomainTransaction{simnetGenesisCoinbaseTx},
}
@ -182,10 +176,10 @@ var testnetGenesisCoinbaseTx = transactionhelper.NewSubnetworkTransaction(0,
// testnetGenesisHash is the hash of the first block in the block DAG for the test
// network (genesis block).
var testnetGenesisHash = externalapi.NewDomainHashFromByteArray(&[externalapi.DomainHashSize]byte{
0x30, 0x66, 0xaa, 0x51, 0xc0, 0x1f, 0x8a, 0x8d,
0x6e, 0x09, 0x65, 0x7e, 0x24, 0x3b, 0x9e, 0xb0,
0x0d, 0x89, 0xa7, 0x21, 0x64, 0x67, 0xbd, 0x4d,
0x76, 0x74, 0x67, 0xe4, 0xdf, 0x16, 0x9a, 0x93,
0x79, 0x21, 0x07, 0xaf, 0xad, 0x07, 0xca, 0xd5,
0xfc, 0x66, 0xd3, 0x84, 0x36, 0x54, 0x83, 0x3f,
0x93, 0x9a, 0x6d, 0x29, 0x57, 0xb4, 0x0c, 0x76,
0x71, 0x09, 0x3a, 0xf1, 0xea, 0xaa, 0x70, 0x81,
})
// testnetGenesisMerkleRoot is the hash of the first transaction in the genesis block
@ -206,9 +200,9 @@ var testnetGenesisBlock = externalapi.DomainBlock{
testnetGenesisMerkleRoot,
&externalapi.DomainHash{},
&externalapi.DomainHash{},
0x17772f4a25e,
0x177a5f1ddbf,
0x1e7fffff,
0x11447,
0x2bf,
),
Transactions: []*externalapi.DomainTransaction{testnetGenesisCoinbaseTx},
}

View File

@ -178,7 +178,7 @@ func TestCheckTransactionStandard(t *testing.T) {
SignatureScript: dummySigScript,
Sequence: constants.MaxTxInSequenceNum,
}
addrHash := [20]byte{0x01}
addrHash := [32]byte{0x01}
addr, err := util.NewAddressPubKeyHash(addrHash[:], util.Bech32PrefixKaspaTest)
if err != nil {
t.Fatalf("NewAddressPubKeyHash: unexpected error: %v", err)

View File

@ -18,14 +18,14 @@ const (
rpcAddress2 = "127.0.0.1:12346"
rpcAddress3 = "127.0.0.1:12347"
miningAddress1 = "kaspasim:qzpj2cfa9m40w9m2cmr8pvfuqpp32mzzwsuw6ukhfd"
miningAddress1PrivateKey = "be9e9884f03e687166479e22d21b064db7903d69b5a46878aae66521c01a6094"
miningAddress1 = "kaspasim:qr79e37hxdgkn4xjjmfxvqvayc5gsmsql2660d08u9ej9vnc8lzcywr265u64"
miningAddress1PrivateKey = "0ec5d7308f65717f3f0c3e4d962d73056c1c255a16593b3989589281b51ad5bc"
miningAddress2 = "kaspasim:qr7w7nqsdnc3zddm6u8s9fex4ysk95hm3v30q353ym"
miningAddress2PrivateKey = "98bd8d8e1f7078abefd017839f83edd0e3c8226ed4989e4d7a8bceb5935de193"
miningAddress2 = "kaspasim:qpvr825ypd2fzq779yl83zvte2r4wlgxwra625rgthk9jj96d4cxgsegwryhg"
miningAddress2PrivateKey = "2a2e99d4a5c3e6d4add69e7baf66b9c7a2f17e74fad86cbd36a3a6815cecc10e"
miningAddress3 = "kaspasim:qz7n8gfak3j2wt9vywy5ljhs3v3xu7lgmutfjqaay5"
miningAddress3PrivateKey = "eb0af684f2cdbb4ed2d85fbfe0b7f40654a7777fb2c47f142ffb5543b594d1e4"
miningAddress3 = "kaspasim:qpvr825ypd2fzq779yl83zvte2r4wlgxwra625rgthk9jj96d4cxgsegwryhg"
miningAddress3PrivateKey = "2a2e99d4a5c3e6d4add69e7baf66b9c7a2f17e74fad86cbd36a3a6815cecc10e"
defaultTimeout = 10 * time.Second
)

View File

@ -6,9 +6,9 @@ package util
import (
"github.com/pkg/errors"
"golang.org/x/crypto/blake2b"
"github.com/kaspanet/kaspad/util/bech32"
"golang.org/x/crypto/ripemd160"
)
var (
@ -79,11 +79,11 @@ func (prefix Bech32Prefix) String() string {
}
// encodeAddress returns a human-readable payment address given a network prefix
// and a ripemd160 hash which encodes the kaspa network and address type. It is used
// and a blake2b hash which encodes the kaspa network and address type. It is used
// in both pay-to-pubkey-hash (P2PKH) and pay-to-script-hash (P2SH) address
// encoding.
func encodeAddress(prefix Bech32Prefix, hash160 []byte, version byte) string {
return bech32.Encode(prefix.String(), hash160[:ripemd160.Size], version)
func encodeAddress(prefix Bech32Prefix, hash256 []byte, version byte) string {
return bech32.Encode(prefix.String(), hash256[:blake2b.Size256], version)
}
// Address is an interface type for any type of destination a transaction
@ -141,7 +141,7 @@ func DecodeAddress(addr string, expectedPrefix Bech32Prefix) (Address, error) {
// Switch on decoded length to determine the type.
switch len(decoded) {
case ripemd160.Size: // P2PKH or P2SH
case blake2b.Size256: // P2PKH or P2SH
switch version {
case pubKeyHashAddrID:
return newAddressPubKeyHash(prefix, decoded)
@ -159,12 +159,12 @@ func DecodeAddress(addr string, expectedPrefix Bech32Prefix) (Address, error) {
// transaction.
type AddressPubKeyHash struct {
prefix Bech32Prefix
hash [ripemd160.Size]byte
hash [blake2b.Size256]byte
}
// NewAddressPubKeyHashFromPublicKey returns a new AddressPubKeyHash from given public key
func NewAddressPubKeyHashFromPublicKey(publicKey []byte, prefix Bech32Prefix) (*AddressPubKeyHash, error) {
pkHash := Hash160(publicKey)
pkHash := HashBlake2b(publicKey)
return newAddressPubKeyHash(prefix, pkHash)
}
@ -177,12 +177,12 @@ func NewAddressPubKeyHash(pkHash []byte, prefix Bech32Prefix) (*AddressPubKeyHas
// newAddressPubKeyHash is the internal API to create a pubkey hash address
// with a known leading identifier byte for a network, rather than looking
// it up through its parameters. This is useful when creating a new address
// structure from a string encoding where the identifer byte is already
// structure from a string encoding where the identifier byte is already
// known.
func newAddressPubKeyHash(prefix Bech32Prefix, pkHash []byte) (*AddressPubKeyHash, error) {
// Check for a valid pubkey hash length.
if len(pkHash) != ripemd160.Size {
return nil, errors.New("pkHash must be 20 bytes")
if len(pkHash) != blake2b.Size256 {
return nil, errors.Errorf("pkHash must be %d bytes", blake2b.Size256)
}
addr := &AddressPubKeyHash{prefix: prefix}
@ -220,10 +220,10 @@ func (a *AddressPubKeyHash) String() string {
return a.EncodeAddress()
}
// Hash160 returns the underlying array of the pubkey hash. This can be useful
// HashBlake2b returns the underlying array of the pubkey hash. This can be useful
// when an array is more appropiate than a slice (for example, when used as map
// keys).
func (a *AddressPubKeyHash) Hash160() *[ripemd160.Size]byte {
func (a *AddressPubKeyHash) HashBlake2b() *[blake2b.Size256]byte {
return &a.hash
}
@ -231,12 +231,12 @@ func (a *AddressPubKeyHash) Hash160() *[ripemd160.Size]byte {
// transaction.
type AddressScriptHash struct {
prefix Bech32Prefix
hash [ripemd160.Size]byte
hash [blake2b.Size256]byte
}
// NewAddressScriptHash returns a new AddressScriptHash.
func NewAddressScriptHash(serializedScript []byte, prefix Bech32Prefix) (*AddressScriptHash, error) {
scriptHash := Hash160(serializedScript)
scriptHash := HashBlake2b(serializedScript)
return newAddressScriptHashFromHash(prefix, scriptHash)
}
@ -253,8 +253,8 @@ func NewAddressScriptHashFromHash(scriptHash []byte, prefix Bech32Prefix) (*Addr
// known.
func newAddressScriptHashFromHash(prefix Bech32Prefix, scriptHash []byte) (*AddressScriptHash, error) {
// Check for a valid script hash length.
if len(scriptHash) != ripemd160.Size {
return nil, errors.New("scriptHash must be 20 bytes")
if len(scriptHash) != blake2b.Size256 {
return nil, errors.Errorf("scriptHash must be %d bytes", blake2b.Size256)
}
addr := &AddressScriptHash{prefix: prefix}
@ -292,9 +292,9 @@ func (a *AddressScriptHash) String() string {
return a.EncodeAddress()
}
// Hash160 returns the underlying array of the script hash. This can be useful
// HashBlake2b returns the underlying array of the script hash. This can be useful
// when an array is more appropiate than a slice (for example, when used as map
// keys).
func (a *AddressScriptHash) Hash160() *[ripemd160.Size]byte {
func (a *AddressScriptHash) HashBlake2b() *[blake2b.Size256]byte {
return &a.hash
}

View File

@ -7,12 +7,12 @@ package util_test
import (
"bytes"
"fmt"
"golang.org/x/crypto/blake2b"
"reflect"
"strings"
"testing"
"github.com/kaspanet/kaspad/util"
"golang.org/x/crypto/ripemd160"
)
func TestAddresses(t *testing.T) {
@ -29,18 +29,23 @@ func TestAddresses(t *testing.T) {
// Positive P2PKH tests.
{
name: "mainnet p2pkh",
addr: "kaspa:qr35ennsep3hxfe7lnz5ee7j5jgmkjswsslwxj42ta",
encoded: "kaspa:qr35ennsep3hxfe7lnz5ee7j5jgmkjswsslwxj42ta",
addr: "kaspa:qr35ennsep3hxfe7lnz5ee7j5jgmkjswsn35ennsep3hxfe7ln35cdv0dy335",
encoded: "kaspa:qr35ennsep3hxfe7lnz5ee7j5jgmkjswsn35ennsep3hxfe7ln35cdv0dy335",
valid: true,
result: util.TstAddressPubKeyHash(
util.Bech32PrefixKaspa,
[ripemd160.Size]byte{
[blake2b.Size256]byte{
0xe3, 0x4c, 0xce, 0x70, 0xc8, 0x63, 0x73, 0x27, 0x3e, 0xfc,
0xc5, 0x4c, 0xe7, 0xd2, 0xa4, 0x91, 0xbb, 0x4a, 0x0e, 0x84}),
0xc5, 0x4c, 0xe7, 0xd2, 0xa4, 0x91, 0xbb, 0x4a, 0x0e, 0x84,
0xe3, 0x4c, 0xce, 0x70, 0xc8, 0x63, 0x73, 0x27, 0x3e, 0xfc,
0xe3, 0x4c,
}),
f: func() (util.Address, error) {
pkHash := []byte{
0xe3, 0x4c, 0xce, 0x70, 0xc8, 0x63, 0x73, 0x27, 0x3e, 0xfc,
0xc5, 0x4c, 0xe7, 0xd2, 0xa4, 0x91, 0xbb, 0x4a, 0x0e, 0x84}
0xc5, 0x4c, 0xe7, 0xd2, 0xa4, 0x91, 0xbb, 0x4a, 0x0e, 0x84,
0xe3, 0x4c, 0xce, 0x70, 0xc8, 0x63, 0x73, 0x27, 0x3e, 0xfc,
0xe3, 0x4c}
return util.NewAddressPubKeyHash(pkHash, util.Bech32PrefixKaspa)
},
passedPrefix: util.Bech32PrefixUnknown,
@ -48,18 +53,24 @@ func TestAddresses(t *testing.T) {
},
{
name: "mainnet p2pkh 2",
addr: "kaspa:qq80qvqs0lfxuzmt7sz3909ze6camq9d4g0emmlzty",
encoded: "kaspa:qq80qvqs0lfxuzmt7sz3909ze6camq9d4g0emmlzty",
addr: "kaspa:qq80qvqs0lfxuzmt7sz3909ze6camq9d4t35ennsep3hxfe7ln35cvfqgz3z8",
encoded: "kaspa:qq80qvqs0lfxuzmt7sz3909ze6camq9d4t35ennsep3hxfe7ln35cvfqgz3z8",
valid: true,
result: util.TstAddressPubKeyHash(
util.Bech32PrefixKaspa,
[ripemd160.Size]byte{
[blake2b.Size256]byte{
0x0e, 0xf0, 0x30, 0x10, 0x7f, 0xd2, 0x6e, 0x0b, 0x6b, 0xf4,
0x05, 0x12, 0xbc, 0xa2, 0xce, 0xb1, 0xdd, 0x80, 0xad, 0xaa}),
0x05, 0x12, 0xbc, 0xa2, 0xce, 0xb1, 0xdd, 0x80, 0xad, 0xaa,
0xe3, 0x4c, 0xce, 0x70, 0xc8, 0x63, 0x73, 0x27, 0x3e, 0xfc,
0xe3, 0x4c,
}),
f: func() (util.Address, error) {
pkHash := []byte{
0x0e, 0xf0, 0x30, 0x10, 0x7f, 0xd2, 0x6e, 0x0b, 0x6b, 0xf4,
0x05, 0x12, 0xbc, 0xa2, 0xce, 0xb1, 0xdd, 0x80, 0xad, 0xaa}
0x05, 0x12, 0xbc, 0xa2, 0xce, 0xb1, 0xdd, 0x80, 0xad, 0xaa,
0xe3, 0x4c, 0xce, 0x70, 0xc8, 0x63, 0x73, 0x27, 0x3e, 0xfc,
0xe3, 0x4c,
}
return util.NewAddressPubKeyHash(pkHash, util.Bech32PrefixKaspa)
},
passedPrefix: util.Bech32PrefixKaspa,
@ -67,18 +78,24 @@ func TestAddresses(t *testing.T) {
},
{
name: "testnet p2pkh",
addr: "kaspatest:qputx94qseratdmjs0j395mq8u03er0x3u2xu3wvh9",
encoded: "kaspatest:qputx94qseratdmjs0j395mq8u03er0x3u2xu3wvh9",
addr: "kaspatest:qputx94qseratdmjs0j395mq8u03er0x3l35ennsep3hxfe7ln35ckquw528z",
encoded: "kaspatest:qputx94qseratdmjs0j395mq8u03er0x3l35ennsep3hxfe7ln35ckquw528z",
valid: true,
result: util.TstAddressPubKeyHash(
util.Bech32PrefixKaspaTest,
[ripemd160.Size]byte{
[blake2b.Size256]byte{
0x78, 0xb3, 0x16, 0xa0, 0x86, 0x47, 0xd5, 0xb7, 0x72, 0x83,
0xe5, 0x12, 0xd3, 0x60, 0x3f, 0x1f, 0x1c, 0x8d, 0xe6, 0x8f}),
0xe5, 0x12, 0xd3, 0x60, 0x3f, 0x1f, 0x1c, 0x8d, 0xe6, 0x8f,
0xe3, 0x4c, 0xce, 0x70, 0xc8, 0x63, 0x73, 0x27, 0x3e, 0xfc,
0xe3, 0x4c,
}),
f: func() (util.Address, error) {
pkHash := []byte{
0x78, 0xb3, 0x16, 0xa0, 0x86, 0x47, 0xd5, 0xb7, 0x72, 0x83,
0xe5, 0x12, 0xd3, 0x60, 0x3f, 0x1f, 0x1c, 0x8d, 0xe6, 0x8f}
0xe5, 0x12, 0xd3, 0x60, 0x3f, 0x1f, 0x1c, 0x8d, 0xe6, 0x8f,
0xe3, 0x4c, 0xce, 0x70, 0xc8, 0x63, 0x73, 0x27, 0x3e, 0xfc,
0xe3, 0x4c,
}
return util.NewAddressPubKeyHash(pkHash, util.Bech32PrefixKaspaTest)
},
passedPrefix: util.Bech32PrefixKaspaTest,
@ -110,18 +127,18 @@ func TestAddresses(t *testing.T) {
// Positive P2SH tests.
{
// Taken from transactions:
// output: 3c9018e8d5615c306d72397f8f5eef44308c98fb576a88e030c25456b4f3a7ac
// input: 837dea37ddc8b1e3ce646f1a656e79bbd8cc7f558ac56a169626d649ebe2a3ba
name: "mainnet p2sh",
addr: "kaspa:pruptvpkmxamee0f72sq40gm70wfr624zqxqrguzm2",
encoded: "kaspa:pruptvpkmxamee0f72sq40gm70wfr624zqxqrguzm2",
addr: "kaspa:prq20q4qd9ulr044cauyy9wtpeupqpjv67pn2vyc6acly7xqkrjdzmh8rj9f4",
encoded: "kaspa:prq20q4qd9ulr044cauyy9wtpeupqpjv67pn2vyc6acly7xqkrjdzmh8rj9f4",
valid: true,
result: util.TstAddressScriptHash(
util.Bech32PrefixKaspa,
[ripemd160.Size]byte{
0xf8, 0x15, 0xb0, 0x36, 0xd9, 0xbb, 0xbc, 0xe5, 0xe9, 0xf2,
0xa0, 0x0a, 0xbd, 0x1b, 0xf3, 0xdc, 0x91, 0xe9, 0x55, 0x10}),
[blake2b.Size256]byte{
0xc0, 0xa7, 0x82, 0xa0, 0x69, 0x79, 0xf1, 0xbe,
0xb5, 0xc7, 0x78, 0x42, 0x15, 0xcb, 0x0e, 0x78,
0x10, 0x06, 0x4c, 0xd7, 0x83, 0x35, 0x30, 0x98,
0xd7, 0x71, 0xf2, 0x78, 0xc0, 0xb0, 0xe4, 0xd1,
}),
f: func() (util.Address, error) {
script := []byte{
0x52, 0x41, 0x04, 0x91, 0xbb, 0xa2, 0x51, 0x09, 0x12, 0xa5,
@ -155,18 +172,24 @@ func TestAddresses(t *testing.T) {
// output: b0539a45de13b3e0403909b8bd1a555b8cbe45fd4e3f3fda76f3a5f52835c29d
// input: (not yet redeemed at time test was written)
name: "mainnet p2sh 2",
addr: "kaspa:pr5vxqxg0xrwl2zvxlq9rxffqx00sm44ksnw9jhzqr",
encoded: "kaspa:pr5vxqxg0xrwl2zvxlq9rxffqx00sm44ksnw9jhzqr",
addr: "kaspa:pr5vxqxg0xrwl2zvxlq9rxffqx00sm44ksqqqqqqqqqqqqqqqqqqq33flv3je",
encoded: "kaspa:pr5vxqxg0xrwl2zvxlq9rxffqx00sm44ksqqqqqqqqqqqqqqqqqqq33flv3je",
valid: true,
result: util.TstAddressScriptHash(
util.Bech32PrefixKaspa,
[ripemd160.Size]byte{
[blake2b.Size256]byte{
0xe8, 0xc3, 0x00, 0xc8, 0x79, 0x86, 0xef, 0xa8, 0x4c, 0x37,
0xc0, 0x51, 0x99, 0x29, 0x01, 0x9e, 0xf8, 0x6e, 0xb5, 0xb4}),
0xc0, 0x51, 0x99, 0x29, 0x01, 0x9e, 0xf8, 0x6e, 0xb5, 0xb4,
0xe8, 0xc3, 0x00, 0xc8, 0x79, 0x86, 0xef, 0xa8, 0x4c, 0x37,
0xe8, 0xc3,
}),
f: func() (util.Address, error) {
hash := []byte{
0xe8, 0xc3, 0x00, 0xc8, 0x79, 0x86, 0xef, 0xa8, 0x4c, 0x37,
0xc0, 0x51, 0x99, 0x29, 0x01, 0x9e, 0xf8, 0x6e, 0xb5, 0xb4}
0xc0, 0x51, 0x99, 0x29, 0x01, 0x9e, 0xf8, 0x6e, 0xb5, 0xb4,
0xe8, 0xc3, 0x00, 0xc8, 0x79, 0x86, 0xef, 0xa8, 0x4c, 0x37,
0xe8, 0xc3,
}
return util.NewAddressScriptHashFromHash(hash, util.Bech32PrefixKaspa)
},
passedPrefix: util.Bech32PrefixKaspa,
@ -174,18 +197,24 @@ func TestAddresses(t *testing.T) {
},
{
name: "testnet p2sh",
addr: "kaspatest:przhjdpv93xfygpqtckdc2zkzuzqeyj2pgg3hlfnac",
encoded: "kaspatest:przhjdpv93xfygpqtckdc2zkzuzqeyj2pgg3hlfnac",
addr: "kaspatest:przhjdpv93xfygpqtckdc2zkzuzqeyj2pgqqqqqqqqqqqqqqqqqqqyjpt4duk",
encoded: "kaspatest:przhjdpv93xfygpqtckdc2zkzuzqeyj2pgqqqqqqqqqqqqqqqqqqqyjpt4duk",
valid: true,
result: util.TstAddressScriptHash(
util.Bech32PrefixKaspaTest,
[ripemd160.Size]byte{
[blake2b.Size256]byte{
0xc5, 0x79, 0x34, 0x2c, 0x2c, 0x4c, 0x92, 0x20, 0x20, 0x5e,
0x2c, 0xdc, 0x28, 0x56, 0x17, 0x04, 0x0c, 0x92, 0x4a, 0x0a}),
0x2c, 0xdc, 0x28, 0x56, 0x17, 0x04, 0x0c, 0x92, 0x4a, 0x0a,
0xe8, 0xc3, 0x00, 0xc8, 0x79, 0x86, 0xef, 0xa8, 0x4c, 0x37,
0xe8, 0xc3,
}),
f: func() (util.Address, error) {
hash := []byte{
0xc5, 0x79, 0x34, 0x2c, 0x2c, 0x4c, 0x92, 0x20, 0x20, 0x5e,
0x2c, 0xdc, 0x28, 0x56, 0x17, 0x04, 0x0c, 0x92, 0x4a, 0x0a}
0x2c, 0xdc, 0x28, 0x56, 0x17, 0x04, 0x0c, 0x92, 0x4a, 0x0a,
0xe8, 0xc3, 0x00, 0xc8, 0x79, 0x86, 0xef, 0xa8, 0x4c, 0x37,
0xe8, 0xc3,
}
return util.NewAddressScriptHashFromHash(hash, util.Bech32PrefixKaspaTest)
},
passedPrefix: util.Bech32PrefixKaspaTest,
@ -248,7 +277,7 @@ func TestAddresses(t *testing.T) {
saddr = util.TstAddressSAddr(encoded)
}
// Check script address, as well as the Hash160 method for P2PKH and
// Check script address, as well as the HashBlake2b method for P2PKH and
// P2SH addresses.
if !bytes.Equal(saddr, decoded.ScriptAddress()) {
t.Errorf("%v: script addresses do not match:\n%x != \n%x",
@ -257,14 +286,14 @@ func TestAddresses(t *testing.T) {
}
switch a := decoded.(type) {
case *util.AddressPubKeyHash:
if h := a.Hash160()[:]; !bytes.Equal(saddr, h) {
if h := a.HashBlake2b()[:]; !bytes.Equal(saddr, h) {
t.Errorf("%v: hashes do not match:\n%x != \n%x",
test.name, saddr, h)
return
}
case *util.AddressScriptHash:
if h := a.Hash160()[:]; !bytes.Equal(saddr, h) {
if h := a.HashBlake2b()[:]; !bytes.Equal(saddr, h) {
t.Errorf("%v: hashes do not match:\n%x != \n%x",
test.name, saddr, h)
return
@ -321,7 +350,7 @@ func TestDecodeAddressErrorConditions(t *testing.T) {
"decoded address's prefix could not be parsed",
},
{
"kaspasim:raskzctpv9skzctpv9skzctpv9skzctpvy37ct7zaf",
"kaspasim:raskzctpv9skzctpv9skzctpv9skzctpvy37ct7zafpv9skzctpvymmnd3gh8",
util.Bech32PrefixKaspaSim,
"unknown address type",
},

15
util/blake2b.go Normal file
View File

@ -0,0 +1,15 @@
// Copyright (c) 2013-2017 The btcsuite developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package util
import (
"golang.org/x/crypto/blake2b"
)
// HashBlake2b calculates the hash blake2b(b).
func HashBlake2b(buf []byte) []byte {
hashedBuf := blake2b.Sum256(buf)
return hashedBuf[:]
}

View File

@ -1,23 +0,0 @@
// Copyright (c) 2013-2017 The btcsuite developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package util
import (
"crypto/sha256"
"hash"
"golang.org/x/crypto/ripemd160"
)
// Calculate the hash of hasher over buf.
func calcHash(buf []byte, hasher hash.Hash) []byte {
hasher.Write(buf)
return hasher.Sum(nil)
}
// Hash160 calculates the hash ripemd160(sha256(b)).
func Hash160(buf []byte) []byte {
return calcHash(calcHash(buf, sha256.New()), ripemd160.New())
}

View File

@ -13,7 +13,7 @@ package util
import (
"github.com/kaspanet/kaspad/util/bech32"
"golang.org/x/crypto/ripemd160"
"golang.org/x/crypto/blake2b"
)
// TstAppDataDir makes the internal appDir function available to the test
@ -22,7 +22,7 @@ func TstAppDataDir(goos, appName string, roaming bool) string {
return appDir(goos, appName, roaming)
}
func TstAddressPubKeyHash(prefix Bech32Prefix, hash [ripemd160.Size]byte) *AddressPubKeyHash {
func TstAddressPubKeyHash(prefix Bech32Prefix, hash [blake2b.Size256]byte) *AddressPubKeyHash {
return &AddressPubKeyHash{
prefix: prefix,
hash: hash,
@ -31,7 +31,7 @@ func TstAddressPubKeyHash(prefix Bech32Prefix, hash [ripemd160.Size]byte) *Addre
// TstAddressScriptHash makes an AddressScriptHash, setting the
// unexported fields with the parameters hash and netID.
func TstAddressScriptHash(prefix Bech32Prefix, hash [ripemd160.Size]byte) *AddressScriptHash {
func TstAddressScriptHash(prefix Bech32Prefix, hash [blake2b.Size256]byte) *AddressScriptHash {
return &AddressScriptHash{
prefix: prefix,
@ -43,5 +43,5 @@ func TstAddressScriptHash(prefix Bech32Prefix, hash [ripemd160.Size]byte) *Addre
// P2PKH and P2SH kaspa addresses.
func TstAddressSAddr(addr string) []byte {
_, decoded, _, _ := bech32.Decode(addr)
return decoded[:ripemd160.Size]
return decoded[:blake2b.Size256]
}