bluealloy / revm

Rust implementation of the Ethereum Virtual Machine.
https://bluealloy.github.io/revm/
MIT License
1.59k stars 518 forks source link

chore: switch gas check order in blake2 precompile #1718

Closed pcy190 closed 2 weeks ago

pcy190 commented 2 weeks ago

Go-ethereum always check gas before checking the detailed flag in [1]:

func RunPrecompiledContract(p PrecompiledContract, input []byte, suppliedGas uint64, logger *tracing.Hooks) (ret []byte, remainingGas uint64, err error) {
    gasCost := p.RequiredGas(input)
    if suppliedGas < gasCost {
        return nil, 0, ErrOutOfGas
    }
    if logger != nil && logger.OnGasChange != nil {
        logger.OnGasChange(suppliedGas, suppliedGas-gasCost, tracing.GasChangeCallPrecompiledContract)
    }
    suppliedGas -= gasCost
    output, err := p.Run(input)
    return output, suppliedGas, err
}

[1]https://github.com/ethereum/go-ethereum/blob/941ae33d7e0b36afc2f8551884f555d963de7c6b/core/vm/contracts.go#L190-L206

Therefore, when the final flag is invalid (neither 1 nor 0) in blake2 precompile, and the gas limit is below the minimum requirement, the behavior differs between revm and go-ethereum.