diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 7f56c3eee..cd68df138 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -55,6 +55,9 @@ import ( const ( defaultGasPrice = 50 * params.Shannon + + //Hex-encoded 64 byte array of "17" values + maxPrivateIntrinsicDataHex = "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111" ) // PublicEthereumAPI provides an API to access Ethereum related information. @@ -771,6 +774,33 @@ func (s *PublicBlockChainAPI) EstimateGas(ctx context.Context, args CallArgs) (h return 0, fmt.Errorf("gas required exceeds allowance or always failing transaction") } } + + //QUORUM + + //We don't know if this is going to be a private or public transaction + //It is possible to have a data field that has a lower intrinsic value than the PTM hash + //so this checks that if we were to place a PTM hash (with all non-zero values) here then the transaction would + //still run + //This makes the return value a potential over-estimate of gas, rather than the exact cost to run right now + + //if the transaction has a value then it cannot be private, so we can skip this check + if args.Value.ToInt().Cmp(big.NewInt(0)) == 0 { + + isHomestead := s.b.ChainConfig().IsHomestead(new(big.Int).SetInt64(int64(rpc.PendingBlockNumber))) + intrinsicGasPublic, _ := core.IntrinsicGas(args.Data, args.To == nil, isHomestead) + intrinsicGasPrivate, _ := core.IntrinsicGas(common.Hex2Bytes(maxPrivateIntrinsicDataHex), args.To == nil, isHomestead) + + if intrinsicGasPrivate > intrinsicGasPublic { + if math.MaxUint64 - hi < intrinsicGasPrivate - intrinsicGasPublic { + return 0, fmt.Errorf("private intrinsic gas addition exceeds allowance") + } + return hexutil.Uint64(hi + (intrinsicGasPrivate - intrinsicGasPublic)), nil + } + + } + + //END QUORUM + return hexutil.Uint64(hi), nil }