lnwire: all hashes within the protocol are now 32-bytes
We now enforce that the site of all revocation pre-images+hashes (used for HTLC’s) are now 32-bytes. Additionally, all payment pre-images are now required to be 32-bytes not he wire. There also exists a Script level enforcement of the payment pre-image size at a lower level. This commit serves to unify the sizes of all hashes/pre-images across the codebase.
This commit is contained in:
parent
fd02c1c1aa
commit
bba9b665ef
@ -46,7 +46,7 @@ type FundingRequest struct {
|
||||
// 2: channel responder
|
||||
FeePayer uint8
|
||||
|
||||
RevocationHash [20]byte
|
||||
RevocationHash [32]byte
|
||||
Pubkey *btcec.PublicKey
|
||||
DeliveryPkScript PkScript // *MUST* be either P2PKH or P2SH
|
||||
ChangePkScript PkScript // *MUST* be either P2PKH or P2SH
|
||||
|
@ -9,8 +9,6 @@ import (
|
||||
)
|
||||
|
||||
func TestFundingRequestEncodeDecode(t *testing.T) {
|
||||
copy(revocationHash[:], revocationHashBytes)
|
||||
|
||||
// funding request
|
||||
fr := &FundingRequest{
|
||||
ReservationID: uint64(12345678),
|
||||
@ -23,7 +21,7 @@ func TestFundingRequestEncodeDecode(t *testing.T) {
|
||||
FeePayer: uint8(0),
|
||||
PaymentAmount: btcutil.Amount(1234567),
|
||||
MinDepth: uint32(6),
|
||||
RevocationHash: revocationHash,
|
||||
RevocationHash: revHash,
|
||||
Pubkey: pubKey,
|
||||
DeliveryPkScript: deliveryPkScript,
|
||||
ChangePkScript: changePkScript,
|
||||
|
@ -30,7 +30,7 @@ type FundingResponse struct {
|
||||
// 2: channel responder
|
||||
FeePayer uint8
|
||||
|
||||
RevocationHash [20]byte
|
||||
RevocationHash [32]byte
|
||||
Pubkey *btcec.PublicKey
|
||||
CommitSig *btcec.Signature // Requester's Commitment
|
||||
DeliveryPkScript PkScript // *MUST* be either P2PKH or P2SH
|
||||
|
@ -21,7 +21,7 @@ func TestFundingResponseEncodeDecode(t *testing.T) {
|
||||
MinDepth: uint32(6),
|
||||
LockTime: uint32(4320), // 30 block-days
|
||||
FeePayer: uint8(1),
|
||||
RevocationHash: revocationHash,
|
||||
RevocationHash: revHash,
|
||||
Pubkey: pubKey,
|
||||
CommitSig: commitSig,
|
||||
DeliveryPkScript: deliveryPkScript,
|
||||
|
@ -45,7 +45,7 @@ type HTLCAddRequest struct {
|
||||
// number of pre-images for each of the listed hashes. For regular HTLC's
|
||||
// this slice only has one hash. However, for "multi-sig" HTLC's, the
|
||||
// length of this slice should be N.
|
||||
RedemptionHashes [][20]byte
|
||||
RedemptionHashes [][32]byte
|
||||
|
||||
// OnionBlob is the raw serialized mix header used to route an HTLC in
|
||||
// a privacy-preserving manner. The mix header is defined currently to
|
||||
@ -78,7 +78,7 @@ func (c *HTLCAddRequest) Decode(r io.Reader, pver uint32) error {
|
||||
// Expiry(4)
|
||||
// Amount(4)
|
||||
// ContractType(1)
|
||||
// RedemptionHashes (numOfHashes * 20 + numOfHashes)
|
||||
// RedemptionHashes (numOfHashes * 32 + numOfHashes)
|
||||
// OnionBlog
|
||||
err := readElements(r,
|
||||
&c.ChannelPoint,
|
||||
|
@ -7,8 +7,8 @@ import (
|
||||
)
|
||||
|
||||
func TestHTLCAddRequestEncodeDecode(t *testing.T) {
|
||||
redemptionHashes := make([][20]byte, 1)
|
||||
copy(redemptionHashes[0][:], bytes.Repeat([]byte{0x09}, 20))
|
||||
redemptionHashes := make([][32]byte, 1)
|
||||
redemptionHashes[0] = revHash
|
||||
|
||||
// First create a new HTLCAR message.
|
||||
addReq := &HTLCAddRequest{
|
||||
|
@ -21,17 +21,18 @@ type HTLCSettleRequest struct {
|
||||
|
||||
// HTLCKey denotes the exact HTLC stage within the receiving node's
|
||||
// commitment transaction to be removed.
|
||||
// TODO(roasbeef): rename to LogIndex
|
||||
HTLCKey HTLCKey
|
||||
|
||||
// RedemptionProofs are the R-value preimages required to fully settle
|
||||
// an HTLC. The number of preimages in the slice will depend on the
|
||||
// specific ContractType of the referenced HTLC.
|
||||
RedemptionProofs [][20]byte
|
||||
RedemptionProofs [][32]byte
|
||||
}
|
||||
|
||||
// NewHTLCSettleRequest returns a new empty HTLCSettleRequest.
|
||||
func NewHTLCSettleRequest(chanPoint *wire.OutPoint, key HTLCKey,
|
||||
redemptionProofs [][20]byte) *HTLCSettleRequest {
|
||||
redemptionProofs [][32]byte) *HTLCSettleRequest {
|
||||
|
||||
return &HTLCSettleRequest{
|
||||
ChannelPoint: chanPoint,
|
||||
@ -51,7 +52,7 @@ var _ Message = (*HTLCSettleRequest)(nil)
|
||||
func (c *HTLCSettleRequest) Decode(r io.Reader, pver uint32) error {
|
||||
// ChannelPoint(8)
|
||||
// HTLCKey(8)
|
||||
// RedemptionProofs(N*20)
|
||||
// RedemptionProofs(N*32)
|
||||
err := readElements(r,
|
||||
&c.ChannelPoint,
|
||||
&c.HTLCKey,
|
||||
@ -94,8 +95,8 @@ func (c *HTLCSettleRequest) Command() uint32 {
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *HTLCSettleRequest) MaxPayloadLength(uint32) uint32 {
|
||||
// 36 + 8 + (21 * 15)
|
||||
return 359
|
||||
// 36 + 8 + (32 * 15)
|
||||
return 524
|
||||
}
|
||||
|
||||
// Validate performs any necessary sanity checks to ensure all fields present
|
||||
|
@ -7,8 +7,8 @@ import (
|
||||
)
|
||||
|
||||
func TestHTLCSettleRequestEncodeDecode(t *testing.T) {
|
||||
redemptionProofs := make([][20]byte, 1)
|
||||
copy(redemptionProofs[0][:], bytes.Repeat([]byte{0x09}, 20))
|
||||
redemptionProofs := make([][32]byte, 1)
|
||||
redemptionProofs[0] = revHash
|
||||
|
||||
// First create a new HTLCSR message.
|
||||
settleReq := NewHTLCSettleRequest(outpoint1, HTLCKey(23), redemptionProofs)
|
||||
|
@ -169,7 +169,7 @@ func writeElement(w io.Writer, element interface{}) error {
|
||||
if _, err := w.Write(e[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
case [][20]byte:
|
||||
case [][32]byte:
|
||||
// First write out the number of elements in the slice.
|
||||
sliceSize := len(e)
|
||||
if err := writeElement(w, uint16(sliceSize)); err != nil {
|
||||
@ -182,7 +182,7 @@ func writeElement(w io.Writer, element interface{}) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
case [20]byte:
|
||||
case [32]byte:
|
||||
// TODO(roasbeef): should be factor out to caller logic...
|
||||
if _, err := w.Write(e[:]); err != nil {
|
||||
return err
|
||||
@ -408,7 +408,7 @@ func readElement(r io.Reader, element interface{}) error {
|
||||
return err
|
||||
}
|
||||
*e = sig
|
||||
case *[][20]byte:
|
||||
case *[][32]byte:
|
||||
// How many to read
|
||||
var sliceSize uint16
|
||||
err = readElement(r, &sliceSize)
|
||||
@ -416,10 +416,10 @@ func readElement(r io.Reader, element interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
data := make([][20]byte, 0, sliceSize)
|
||||
data := make([][32]byte, 0, sliceSize)
|
||||
// Append the actual
|
||||
for i := uint16(0); i < sliceSize; i++ {
|
||||
var element [20]byte
|
||||
var element [32]byte
|
||||
err = readElement(r, &element)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -427,7 +427,7 @@ func readElement(r io.Reader, element interface{}) error {
|
||||
data = append(data, element)
|
||||
}
|
||||
*e = data
|
||||
case *[20]byte:
|
||||
case *[32]byte:
|
||||
if _, err = io.ReadFull(r, e[:]); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -15,6 +15,13 @@ import (
|
||||
// Common variables and functions for the message tests
|
||||
|
||||
var (
|
||||
revHash = [32]byte{
|
||||
0xb7, 0x94, 0x38, 0x5f, 0x2d, 0x1e, 0xf7, 0xab,
|
||||
0x4d, 0x92, 0x73, 0xd1, 0x90, 0x63, 0x81, 0xb4,
|
||||
0x4f, 0x2f, 0x6f, 0x25, 0x88, 0xa3, 0xef, 0xb9,
|
||||
0x6a, 0x49, 0x18, 0x83, 0x31, 0x98, 0x47, 0x53,
|
||||
}
|
||||
|
||||
// For debugging, writes to /dev/shm/
|
||||
// Maybe in the future do it if you do "go test -v"
|
||||
WRITE_FILE = false
|
||||
|
Loading…
Reference in New Issue
Block a user