Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions internal/handshake/spv.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,12 @@ func (p *Proof) UnmarshalJSON(data []byte) error {
return nil
}

func (p *Proof) hashInternal(prefix []byte, prefixSize uint16, left []byte, right []byte) []byte {
func (p *Proof) hashInternal(
prefix []byte,
prefixSize uint16,
left []byte,
right []byte,
) []byte {
h, _ := blake2b.New256(nil)
if len(prefix) == 0 {
h.Write(ProofInternal)
Expand Down Expand Up @@ -261,7 +266,12 @@ func (p *Proof) hashValue(key []byte, value []byte) []byte {
return p.hashLeaf(key, tmpSum)
}

func (p *Proof) has(prefix []byte, prefixSize uint16, key []byte, depth uint16) bool {
func (p *Proof) has(
prefix []byte,
prefixSize uint16,
key []byte,
depth uint16,
) bool {
tmpLen := min(
prefixSize,
uint16(256-depth),
Expand Down Expand Up @@ -337,7 +347,10 @@ func (p *Proof) Verify(
}
depth -= 1
if hasBit(key, int(depth)) {
copy(next, p.hashInternal(item.Prefix, item.PrefixSize, item.Node, next))
copy(
next,
p.hashInternal(item.Prefix, item.PrefixSize, item.Node, next),
)
} else {
copy(next, p.hashInternal(item.Prefix, item.PrefixSize, next, item.Node))
}
Expand Down
24 changes: 18 additions & 6 deletions internal/handshake/spv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ func TestVerifySpvProof(t *testing.T) {
}{
// Domain "name"
{
root: decodeHex("5174d1e0d32c4a31b79c71f4e9e26904a813ec19a76087758f71e99f9f90e393"),
key: decodeHex("859cbd19b98e068fe07e440cb69f824d74fc8d5715f272d6dccf464fe0aa6c71"),
root: decodeHex(
"5174d1e0d32c4a31b79c71f4e9e26904a813ec19a76087758f71e99f9f90e393",
),
key: decodeHex(
"859cbd19b98e068fe07e440cb69f824d74fc8d5715f272d6dccf464fe0aa6c71",
),
proofJson: `
{
"type": "TYPE_SHORT",
Expand Down Expand Up @@ -123,8 +127,12 @@ func TestVerifySpvProof(t *testing.T) {
},
// Domain "trees"
{
root: decodeHex("5174d1e0d32c4a31b79c71f4e9e26904a813ec19a76087758f71e99f9f90e393"),
key: decodeHex("92ec68524dbcc44bc3ff4847ed45e3a86789009d862499ce558c793498413cec"),
root: decodeHex(
"5174d1e0d32c4a31b79c71f4e9e26904a813ec19a76087758f71e99f9f90e393",
),
key: decodeHex(
"92ec68524dbcc44bc3ff4847ed45e3a86789009d862499ce558c793498413cec",
),
proofJson: `
{
"type": "TYPE_EXISTS",
Expand Down Expand Up @@ -244,8 +252,12 @@ func TestVerifySpvProof(t *testing.T) {
},
// Domain "blinklabs"
{
root: decodeHex("5174d1e0d32c4a31b79c71f4e9e26904a813ec19a76087758f71e99f9f90e393"),
key: decodeHex("66d0eae73152781048a2d83dd103a6dc155d162e72fba88d055f32d99580cef8"),
root: decodeHex(
"5174d1e0d32c4a31b79c71f4e9e26904a813ec19a76087758f71e99f9f90e393",
),
key: decodeHex(
"66d0eae73152781048a2d83dd103a6dc155d162e72fba88d055f32d99580cef8",
),
proofJson: `
{
"type": "TYPE_EXISTS",
Expand Down
4 changes: 3 additions & 1 deletion internal/handshake/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ import (

func TestTransactionHash(t *testing.T) {
// From TX 1881afbe757f9d433144edf49e29c7f6bbfdbc1941d06792dc5ee13020d63570 on mainnet
testTxBytes := decodeHex("00000000010000000000000000000000000000000000000000000000000000000000000000ffffffff3b2cf8140134369b3b00000000001498c8297a67eb81ec36253828b5621a601ba2328a0000a62204000306566961425443087c524fd539e1eab8080000000000000000")
testTxBytes := decodeHex(
"00000000010000000000000000000000000000000000000000000000000000000000000000ffffffff3b2cf8140134369b3b00000000001498c8297a67eb81ec36253828b5621a601ba2328a0000a62204000306566961425443087c524fd539e1eab8080000000000000000",
)
expectedHash := "1881afbe757f9d433144edf49e29c7f6bbfdbc1941d06792dc5ee13020d63570"
expectedWitnessHash := "d36b1e9861dd504629b053d14d9801b295667a4c7002c9d2836be502bfdb3b3a"
br := bytes.NewReader(testTxBytes)
Expand Down
Loading