Skip to content

Commit

Permalink
Fix extract atomic swap data pushes (kaspanet#2203)
Browse files Browse the repository at this point in the history
* Remove unnecessary drop from ExtractAtomicSwapDataPushes

* fixed atomicswap 

fixed ExtractAtomicSwapDataPushes to extract the correct RefundBlake2b

* Fix message converters

* Fix locktime data size in ExtractAtomicSwapDataPushes

---------

Co-authored-by: pieroforfora <[email protected]>
  • Loading branch information
2 people authored and KashProtocol committed Dec 17, 2023
1 parent 75def80 commit af24f3b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions app/appmessage/domainconverters.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func RPCTransactionToDomainTransaction(rpcTransaction *RPCTransaction) (*externa
Outputs: outputs,
LockTime: rpcTransaction.LockTime,
SubnetworkID: *subnetworkID,
Gas: rpcTransaction.LockTime,
Gas: rpcTransaction.Gas,
Payload: payload,
}, nil
}
Expand Down Expand Up @@ -287,7 +287,7 @@ func DomainTransactionToRPCTransaction(transaction *externalapi.DomainTransactio
Outputs: outputs,
LockTime: transaction.LockTime,
SubnetworkID: subnetworkID,
Gas: transaction.LockTime,
Gas: transaction.Gas,
Payload: payload,
}
}
Expand Down
21 changes: 10 additions & 11 deletions domain/consensus/utils/txscript/standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ func ExtractAtomicSwapDataPushes(version uint16, scriptPubKey []byte) (*AtomicSw
return nil, err
}

if len(pops) != 20 {
if len(pops) != 19 {
return nil, nil
}
isAtomicSwap := pops[0].opcode.value == OpIf &&
Expand All @@ -403,23 +403,22 @@ func ExtractAtomicSwapDataPushes(version uint16, scriptPubKey []byte) (*AtomicSw
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 == OpBlake2b &&
pops[16].opcode.value == OpData32 &&
pops[17].opcode.value == OpEndIf &&
pops[18].opcode.value == OpEqualVerify &&
pops[19].opcode.value == OpCheckSig
pops[13].opcode.value == OpDup &&
pops[14].opcode.value == OpBlake2b &&
pops[15].opcode.value == OpData32 &&
pops[16].opcode.value == OpEndIf &&
pops[17].opcode.value == OpEqualVerify &&
pops[18].opcode.value == OpCheckSig
if !isAtomicSwap {
return nil, nil
}

pushes := new(AtomicSwapDataPushes)
copy(pushes.SecretHash[:], pops[5].data)
copy(pushes.RecipientBlake2b[:], pops[9].data)
copy(pushes.RefundBlake2b[:], pops[16].data)
copy(pushes.RefundBlake2b[:], pops[15].data)
if pops[2].data != nil {
locktime, err := makeScriptNum(pops[2].data, 5)
locktime, err := makeScriptNum(pops[2].data, 8)
if err != nil {
return nil, nil
}
Expand All @@ -430,7 +429,7 @@ func ExtractAtomicSwapDataPushes(version uint16, scriptPubKey []byte) (*AtomicSw
return nil, nil
}
if pops[11].data != nil {
locktime, err := makeScriptNum(pops[11].data, 5)
locktime, err := makeScriptNum(pops[11].data, 8)
if err != nil {
return nil, nil
}
Expand Down

0 comments on commit af24f3b

Please sign in to comment.