Skip to content

Commit 3fcf93c

Browse files
committed
eth: Warn instead of fail on audit txHash mismatch.
Some RPC providers return unsigned transaction data, causing the deserialized tx hash to differ from the on-chain tx hash (coinID). The contract state is validated against the locator from the contract data, not the tx hash, so the mismatch is not a security concern.
1 parent 8812f99 commit 3fcf93c

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

client/asset/eth/eth.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5865,19 +5865,25 @@ func (eth *baseWallet) SignCoinMessage(_ asset.Coin, msg dex.Bytes) (pubkeys, si
58655865

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

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

58835889
version, locator, err := dexeth.DecodeContractData(contract)

0 commit comments

Comments
 (0)