Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth: remove isRedeemable contract method, disable estimateRedeemGas #2111

Merged
merged 4 commits into from
Feb 8, 2023
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
7 changes: 0 additions & 7 deletions client/asset/eth/contractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ type contractor interface {
estimateInitGas(ctx context.Context, n int) (uint64, error)
estimateRedeemGas(ctx context.Context, secrets [][32]byte) (uint64, error)
estimateRefundGas(ctx context.Context, secretHash [32]byte) (uint64, error)
isRedeemable(secretHash, secret [32]byte) (bool, error)
// value checks the incoming or outgoing contract value. This is just the
// one of redeem, refund, or initiate values. It is not an error if the
// transaction does not pay to the contract, and the values returned in that
Expand Down Expand Up @@ -70,7 +69,6 @@ type contractV0 interface {
Redeem(opts *bind.TransactOpts, redemptions []swapv0.ETHSwapRedemption) (*types.Transaction, error)
Swap(opts *bind.CallOpts, secretHash [32]byte) (swapv0.ETHSwapSwap, error)
Refund(opts *bind.TransactOpts, secretHash [32]byte) (*types.Transaction, error)
IsRedeemable(opts *bind.CallOpts, secretHash [32]byte, secret [32]byte) (bool, error)
IsRefundable(opts *bind.CallOpts, secretHash [32]byte) (bool, error)
}

Expand Down Expand Up @@ -200,11 +198,6 @@ func (c *contractorV0) refund(txOpts *bind.TransactOpts, secretHash [32]byte) (t
return c.contractV0.Refund(txOpts, secretHash)
}

// isRedeemable exposes the isRedeemable method of the swap contract.
func (c *contractorV0) isRedeemable(secretHash, secret [32]byte) (bool, error) {
return c.contractV0.IsRedeemable(&bind.CallOpts{From: c.acctAddr}, secretHash, secret)
}

// isRefundable exposes the isRefundable method of the swap contract.
func (c *contractorV0) isRefundable(secretHash [32]byte) (bool, error) {
return c.contractV0.IsRefundable(&bind.CallOpts{From: c.acctAddr}, secretHash)
Expand Down
4 changes: 0 additions & 4 deletions client/asset/eth/contractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ func (c *tContractV0) Refund(opts *bind.TransactOpts, secretHash [32]byte) (*typ
return nil, nil
}

func (c *tContractV0) IsRedeemable(opts *bind.CallOpts, secretHash [32]byte, secret [32]byte) (bool, error) {
return false, nil
}

func (c tContractV0) IsRefundable(opts *bind.CallOpts, secretHash [32]byte) (bool, error) {
return false, nil
}
Expand Down
33 changes: 24 additions & 9 deletions client/asset/eth/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -1898,11 +1898,14 @@ func (w *assetWallet) Redeem(form *asset.RedeemForm, feeWallet *assetWallet, non

gasLimit, gasFeeCap := g.Redeem*n, form.FeeSuggestion
originalFundsReserved := gasLimit * gasFeeCap
gasEst, err := w.estimateRedeemGas(w.ctx, secrets, contractVer)
if err != nil {

/* We could get a gas estimate via RPC, but this will reveal the secret key
before submitting the redeem transaction. This is not OK for maker.
Disable for now.

if gasEst, err := w.estimateRedeemGas(w.ctx, secrets, contractVer); err != nil {
return fail(fmt.Errorf("error getting redemption estimate: %w", err))
}
if gasEst > gasLimit {
} else if gasEst > gasLimit {
// This is sticky. We only reserved so much for redemption, so accepting
// a gas limit higher than anticipated could potentially mess us up. On
// the other hand, we don't want to simply reject the redemption.
Expand All @@ -1920,6 +1923,7 @@ func (w *assetWallet) Redeem(form *asset.RedeemForm, feeWallet *assetWallet, non
w.log.Warnf("live gas estimate %d exceeded expected max value %d. using higher limit %d for redemption", gasEst, gasLimit, candidateLimit)
gasLimit = candidateLimit
}
*/

// If the base fee is higher than the FeeSuggestion we attempt to increase
// the gasFeeCap to 2*baseFee. If we don't have enough funds, we use the
Expand Down Expand Up @@ -3714,6 +3718,10 @@ func (w *assetWallet) estimateInitGas(ctx context.Context, numSwaps int, contrac
}

// estimateRedeemGas checks the amount of gas that is used for the redemption.
// Only used with testing and development tools like the
// nodeclient_harness_test.go suite (GetGasEstimates, testRedeemGas, etc.).
// Never use this with a public RPC provider, especially as maker, since it
// reveals the secret keys.
func (w *assetWallet) estimateRedeemGas(ctx context.Context, secrets [][32]byte, contractVer uint32) (gas uint64, err error) {
return gas, w.withContractor(contractVer, func(c contractor) error {
gas, err = c.estimateRedeemGas(ctx, secrets)
Expand Down Expand Up @@ -3863,12 +3871,19 @@ func (w *assetWallet) refund(secretHash [32]byte, maxFeeRate uint64, contractVer
})
}

// isRedeemable checks if the swap identified by secretHash is redeemable using secret.
// isRedeemable checks if the swap identified by secretHash is redeemable using
// secret. This must NOT be a contractor call.
func (w *assetWallet) isRedeemable(secretHash [32]byte, secret [32]byte, contractVer uint32) (redeemable bool, err error) {
return redeemable, w.withContractor(contractVer, func(c contractor) error {
redeemable, err = c.isRedeemable(secretHash, secret)
return err
})
swap, err := w.swap(w.ctx, secretHash, contractVer)
if err != nil {
return false, err
}

if swap.State != dexeth.SSInitiated {
return false, nil
}

return w.ValidateSecret(secret[:], secretHash[:]), nil
}

func (w *assetWallet) isRefundable(secretHash [32]byte, contractVer uint32) (refundable bool, err error) {
Expand Down
Loading