From 7e273039dec6850e1e4ecfa4912c6e9dc62cb2a2 Mon Sep 17 00:00:00 2001 From: Piotr Dyraga Date: Mon, 21 Oct 2019 11:53:18 +0200 Subject: [PATCH] Workaround for go-ethereum problem with gas estimation When estimating gas price in `go-ethereum` ABI, `tx.gasprice` is not passed to the function doing the estimation. This leads to incorrect gas estimates when code execution path depends on `tx.gasprice`. This was fixed today in https://github.com/ethereum/go-ethereum/pull/20189 We need to make a workaround in the contract code before this fix will be released. --- .../solidity/contracts/KeepRandomBeaconOperator.sol | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/contracts/solidity/contracts/KeepRandomBeaconOperator.sol b/contracts/solidity/contracts/KeepRandomBeaconOperator.sol index 6b33730459..9ed394e3a0 100644 --- a/contracts/solidity/contracts/KeepRandomBeaconOperator.sol +++ b/contracts/solidity/contracts/KeepRandomBeaconOperator.sol @@ -471,7 +471,14 @@ contract KeepRandomBeaconOperator { * be returned to the DKG fee pool of the service contract which triggered the DKG. */ function reimburseDkgSubmitter() internal { - uint256 gasPrice = tx.gasprice < priceFeedEstimate ? tx.gasprice : priceFeedEstimate; + uint256 gasPrice = priceFeedEstimate; + // We need to check if tx.gasprice is non-zero as a workaround to a bug + // in go-ethereum: + // https://github.com/ethereum/go-ethereum/pull/20189 + if (tx.gasprice > 0 && tx.gasprice < priceFeedEstimate) { + gasPrice = tx.gasprice; + } + uint256 reimbursementFee = dkgGasEstimate.mul(gasPrice); address payable magpie = stakingContract.magpieOf(msg.sender);