mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
Merge pull request #9 from sei-protocol/precompile-gas
add precompile interface with dynamically-calculated gas
This commit is contained in:
commit
6ff4c5e1d8
1 changed files with 7 additions and 0 deletions
|
|
@ -42,6 +42,10 @@ type PrecompiledContract interface {
|
|||
Run(evm *EVM, sender common.Address, input []byte) ([]byte, error) // Run runs the precompiled contract
|
||||
}
|
||||
|
||||
type DynamicGasPrecompiledContract interface {
|
||||
RunAndCalculateGas(evm *EVM, sender common.Address, input []byte, suppliedGas uint64) (ret []byte, remainingGas uint64, err error) // Run runs the precompiled contract and calculate gas dynamically
|
||||
}
|
||||
|
||||
// PrecompiledContractsHomestead contains the default set of pre-compiled Ethereum
|
||||
// contracts used in the Frontier and Homestead releases.
|
||||
var PrecompiledContractsHomestead = map[common.Address]PrecompiledContract{
|
||||
|
|
@ -169,6 +173,9 @@ func ActivePrecompiles(rules params.Rules) []common.Address {
|
|||
// - the _remaining_ gas,
|
||||
// - any error that occurred
|
||||
func RunPrecompiledContract(p PrecompiledContract, evm *EVM, sender common.Address, input []byte, suppliedGas uint64) (ret []byte, remainingGas uint64, err error) {
|
||||
if dp, ok := p.(DynamicGasPrecompiledContract); ok {
|
||||
return dp.RunAndCalculateGas(evm, sender, input, suppliedGas)
|
||||
}
|
||||
gasCost := p.RequiredGas(input)
|
||||
if suppliedGas < gasCost {
|
||||
return nil, 0, ErrOutOfGas
|
||||
|
|
|
|||
Loading…
Reference in a new issue