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
14 changes: 10 additions & 4 deletions client/asset/eth/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -5865,19 +5865,25 @@ func (eth *baseWallet) SignCoinMessage(_ asset.Coin, msg dex.Bytes) (pubkeys, si

// AuditContract retrieves information about a swap contract on the
// blockchain. This would be used to verify the counter-party's contract
// during a swap. coinID is expected to be the transaction id, and must
// be the same as the hash of serializedTx. contract is expected to be
// (contractVersion|secretHash) where the secretHash uniquely keys the swap.
// during a swap. coinID is expected to be the transaction id. contract
// is expected to be (contractVersion|secretHash) where the secretHash
// uniquely keys the swap.
func (w *assetWallet) AuditContract(coinID, contract, serializedTx dex.Bytes, rebroadcast bool) (*asset.AuditInfo, error) {
tx := new(types.Transaction)
err := tx.UnmarshalBinary(serializedTx)
if err != nil {
return nil, fmt.Errorf("AuditContract: failed to unmarshal transaction: %w", err)
}

// The deserialized tx hash may not match coinID if the RPC provider
// returned the transaction without signature data. This is acceptable
// because the contract state is validated against the locator from the
// contract data, not the tx hash. Use the coinID as the canonical hash.
txHash := tx.Hash()
if !bytes.Equal(coinID, txHash[:]) {
return nil, fmt.Errorf("AuditContract: coin id != txHash - coin id: %x, txHash: %s", coinID, tx.Hash())
w.log.Warnf("AuditContract: coinID %x differs from deserialized txHash %s (unsigned tx from RPC?). Proceeding with contract validation.",
[]byte(coinID), txHash)
copy(txHash[:], coinID)
}

version, locator, err := dexeth.DecodeContractData(contract)
Expand Down
5 changes: 3 additions & 2 deletions client/asset/eth/eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4725,8 +4725,9 @@ func testAuditContract(t *testing.T, assetID uint32) {
Value: dexeth.GweiToWei(1),
},
},
differentHash: true,
wantErr: true,
differentHash: true,
wantRecipient: testAddressA.Hex(),
wantExpiration: now,
},
{
name: "contract is invalid versioned bytes",
Expand Down
Loading