diff --git a/client/asset/eth/eth.go b/client/asset/eth/eth.go index 1d1b9d8cc3..d5521ae817 100644 --- a/client/asset/eth/eth.go +++ b/client/asset/eth/eth.go @@ -686,6 +686,9 @@ func (eth *ExchangeWallet) Redeem(form *asset.RedeemForm) ([]dex.Bytes, asset.Co for _, redemption := range form.Redemptions { var secretHash [32]byte copy(secretHash[:], redemption.Spends.SecretHash) + if secretHash != sha256.Sum256(redemption.Secret) { + return fail(fmt.Errorf("Redeem: secretHash %x != sha256(%x)", secretHash, redemption.Secret)) + } swapData, err := eth.node.swap(eth.ctx, secretHash, form.AssetVersion) if err != nil { return nil, nil, 0, fmt.Errorf("Redeem: error finding swap state: %w", err) diff --git a/client/asset/eth/eth_test.go b/client/asset/eth/eth_test.go index da55344f24..0cd1bf22ff 100644 --- a/client/asset/eth/eth_test.go +++ b/client/asset/eth/eth_test.go @@ -115,21 +115,7 @@ func (n *testNode) initiate(ctx context.Context, contracts []*asset.Contract, ma if n.initErr != nil { return nil, n.initErr } - // baseTx := &types.DynamicFeeTx{ - // Nonce: n.nonce, - // GasFeeCap: maxFeeRate, - // GasTipCap: MinGasTipCap, - // Gas: dexeth.InitGas(len(contracts)), - // Value: opts.Value, - // Data: []byte{}, - // } tx = types.NewTx(&types.DynamicFeeTx{}) - // n.nonce++ - // n.lastInitiation = initTx{ - // initiations: initiations, - // hash: tx.Hash(), - // opts: opts, - // } n.nonce++ return types.NewTx(&types.DynamicFeeTx{ Nonce: n.nonce, @@ -140,22 +126,7 @@ func (n *testNode) redeem(ctx context.Context, redemptions []*asset.Redemption, if n.redeemErr != nil { return nil, n.redeemErr } - /*baseTx := &types.DynamicFeeTx{ - Nonce: n.nonce, - GasFeeCap: opts.GasFeeCap, - GasTipCap: opts.GasTipCap, - Gas: opts.GasLimit, - Value: opts.Value, - Data: []byte{}, - }*/ - //tx := types.NewTx(baseTx) n.nonce++ - // n.lastRedemption = redeemTx{ - // redemptions: redemptions, - // hash: tx.Hash(), - // opts: opts, - // tx: tx, - // } return types.NewTx(&types.DynamicFeeTx{ Nonce: n.nonce, }), nil @@ -1273,11 +1244,30 @@ func TestRedeem(t *testing.T) { AssetVersion: 0, }, }, + { + name: "hash of secret != secretHash", + expectError: true, + form: asset.RedeemForm{ + Redemptions: []*asset.Redemption{ + { + Spends: &asset.AuditInfo{ + SecretHash: secretHashes[1][:], + Coin: &coin{ + id: encode.RandomBytes(32), + }, + }, + Secret: secrets[0][:], + }, + }, + FeeSuggestion: 100, + AssetVersion: 0, + }, + }, { name: "empty redemptions slice error", expectError: true, form: asset.RedeemForm{ - Redemptions: []*asset.Redemption{}, + Redemptions: []*asset.Redemption{}, FeeSuggestion: 100, AssetVersion: 0, },