aboutsummaryrefslogtreecommitdiffstats
path: root/core/vm/contracts.go
diff options
context:
space:
mode:
Diffstat (limited to 'core/vm/contracts.go')
-rw-r--r--core/vm/contracts.go39
1 files changed, 18 insertions, 21 deletions
diff --git a/core/vm/contracts.go b/core/vm/contracts.go
index 593b6ca55..9645d268f 100644
--- a/core/vm/contracts.go
+++ b/core/vm/contracts.go
@@ -17,6 +17,8 @@
package vm
import (
+ "math/big"
+
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/logger"
@@ -28,8 +30,8 @@ import (
// requires a deterministic gas count based on the input size of the Run method of the
// contract.
type PrecompiledContract interface {
- RequiredGas(inputSize int) uint64 // RequiredPrice calculates the contract gas use
- Run(input []byte) []byte // Run runs the precompiled contract
+ RequiredGas(inputSize int) *big.Int // RequiredPrice calculates the contract gas use
+ Run(input []byte) []byte // Run runs the precompiled contract
}
// Precompiled contains the default set of ethereum contracts
@@ -55,7 +57,7 @@ func RunPrecompiledContract(p PrecompiledContract, input []byte, contract *Contr
// ECRECOVER implemented as a native contract
type ecrecover struct{}
-func (c *ecrecover) RequiredGas(inputSize int) uint64 {
+func (c *ecrecover) RequiredGas(inputSize int) *big.Int {
return params.EcrecoverGas
}
@@ -90,12 +92,10 @@ func (c *ecrecover) Run(in []byte) []byte {
// SHA256 implemented as a native contract
type sha256 struct{}
-// RequiredGas returns the gas required to execute the pre-compiled contract.
-//
-// This method does not require any overflow checking as the input size gas costs
-// required for anything significant is so high it's impossible to pay for.
-func (c *sha256) RequiredGas(inputSize int) uint64 {
- return uint64(inputSize+31)/32*params.Sha256WordGas + params.Sha256Gas
+func (c *sha256) RequiredGas(inputSize int) *big.Int {
+ n := big.NewInt(int64(inputSize+31) / 32)
+ n.Mul(n, params.Sha256WordGas)
+ return n.Add(n, params.Sha256Gas)
}
func (c *sha256) Run(in []byte) []byte {
return crypto.Sha256(in)
@@ -104,12 +104,10 @@ func (c *sha256) Run(in []byte) []byte {
// RIPMED160 implemented as a native contract
type ripemd160 struct{}
-// RequiredGas returns the gas required to execute the pre-compiled contract.
-//
-// This method does not require any overflow checking as the input size gas costs
-// required for anything significant is so high it's impossible to pay for.
-func (c *ripemd160) RequiredGas(inputSize int) uint64 {
- return uint64(inputSize+31)/32*params.Ripemd160WordGas + params.Ripemd160Gas
+func (c *ripemd160) RequiredGas(inputSize int) *big.Int {
+ n := big.NewInt(int64(inputSize+31) / 32)
+ n.Mul(n, params.Ripemd160WordGas)
+ return n.Add(n, params.Ripemd160Gas)
}
func (c *ripemd160) Run(in []byte) []byte {
return common.LeftPadBytes(crypto.Ripemd160(in), 32)
@@ -118,12 +116,11 @@ func (c *ripemd160) Run(in []byte) []byte {
// data copy implemented as a native contract
type dataCopy struct{}
-// RequiredGas returns the gas required to execute the pre-compiled contract.
-//
-// This method does not require any overflow checking as the input size gas costs
-// required for anything significant is so high it's impossible to pay for.
-func (c *dataCopy) RequiredGas(inputSize int) uint64 {
- return uint64(inputSize+31)/32*params.IdentityWordGas + params.IdentityGas
+func (c *dataCopy) RequiredGas(inputSize int) *big.Int {
+ n := big.NewInt(int64(inputSize+31) / 32)
+ n.Mul(n, params.IdentityWordGas)
+
+ return n.Add(n, params.IdentityGas)
}
func (c *dataCopy) Run(in []byte) []byte {
return in