Commit f15821af authored by Adrian Sutton's avatar Adrian Sutton Committed by GitHub

op-program: Delegate oracle precompile override gas calculations to the original precompile (#9721)

* op-program: Generic precompile oracle

The generic precompile oracle replaces the point evaluation precompile
oracle. The new oracle can be used to retrieve the return data and
status of any precompile, including bn256Pairing and ecrecover.

* op-challenger: Use generic precompile oracle

Replace the KZG point evaluation oracle with a generic precompile oracle

* op-program: Simplify required gas logic.
Use FromHex instead of Hex2Bytes

* op-program: Set beacon URL when capturing and verifying sepolia chain data

* op-program: Actually use the beacon URL

* op-program: Use default l1-rpckind if not set rather than overriding to debug_geth

* Use freshly generated sepolia test data

* Use sepolia compatibility data

* Fix spelling

* update PreimageOracle.sol snapshot

* op-program: Delegate oracle precompile override gas calculations to the original precompile

Ensures that any future gas schedule changes for precompiles are automatically picked up and reduces the amount of duplicated code.

* op-geth: Update to latest optimism branch commit

---------
Co-authored-by: default avatarinphi <mlaw2501@gmail.com>
Co-authored-by: default avatarrefcell <abigger87@gmail.com>
parent 20407c5a
......@@ -217,7 +217,7 @@ require (
rsc.io/tmplfunc v0.0.3 // indirect
)
replace github.com/ethereum/go-ethereum v1.13.8 => github.com/ethereum-optimism/op-geth v1.101308.2-rc.2
replace github.com/ethereum/go-ethereum v1.13.8 => github.com/ethereum-optimism/op-geth v1.101308.3-0.20240305151625-7c19ab73a4b3
// replace github.com/ethereum-optimism/superchain-registry/superchain => ../superchain-registry/superchain
......
......@@ -170,8 +170,8 @@ github.com/elastic/gosigar v0.14.2 h1:Dg80n8cr90OZ7x+bAax/QjoW/XqTI11RmA79ZwIm9/
github.com/elastic/gosigar v0.14.2/go.mod h1:iXRIGg2tLnu7LBdpqzyQfGDEidKCfWcCMS0WKyPWoMs=
github.com/ethereum-optimism/go-ethereum-hdwallet v0.1.3 h1:RWHKLhCrQThMfch+QJ1Z8veEq5ZO3DfIhZ7xgRP9WTc=
github.com/ethereum-optimism/go-ethereum-hdwallet v0.1.3/go.mod h1:QziizLAiF0KqyLdNJYD7O5cpDlaFMNZzlxYNcWsJUxs=
github.com/ethereum-optimism/op-geth v1.101308.2-rc.2 h1:Tjm2n7/actyINbRIbqeDS+SyWAcIl+pRfOHODwW7lpQ=
github.com/ethereum-optimism/op-geth v1.101308.2-rc.2/go.mod h1:RPqVhnX00rJNys/YRDK4Wl4PvS6dgFrLqhsopIZOhEw=
github.com/ethereum-optimism/op-geth v1.101308.3-0.20240305151625-7c19ab73a4b3 h1:jFLkp8h3cA8w80tCuuAJAS7L4dTT1yD1vYCqeIljGz0=
github.com/ethereum-optimism/op-geth v1.101308.3-0.20240305151625-7c19ab73a4b3/go.mod h1:RPqVhnX00rJNys/YRDK4Wl4PvS6dgFrLqhsopIZOhEw=
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240222155908-ab073f6aa74f h1:L2ub0d0iW2Nqwh1r9WxMqebgZf7rU+wHuVCv21uAGx8=
github.com/ethereum-optimism/superchain-registry/superchain v0.0.0-20240222155908-ab073f6aa74f/go.mod h1:7xh2awFQqsiZxFrHKTgEd+InVfDRrkKVUIuK8SAFHp0=
github.com/ethereum/c-kzg-4844 v0.4.0 h1:3MS1s4JtA868KpJxroZoepdV0ZKBp3u/O5HcZ7R3nlY=
......
......@@ -50,15 +50,15 @@ type PrecompileOracle interface {
}
func CreatePrecompileOverrides(precompileOracle PrecompileOracle) vm.PrecompileOverrides {
return func(rules params.Rules, address common.Address) (vm.PrecompiledContract, bool) {
return func(rules params.Rules, orig vm.PrecompiledContract, address common.Address) (vm.PrecompiledContract, bool) {
// NOTE: Ignoring chain rules for now. We assume that precompile behavior won't change for the foreseeable future
switch address {
case ecrecoverPrecompileAddress:
return &ecrecoverOracle{Oracle: precompileOracle}, true
return &ecrecoverOracle{Orig: orig, Oracle: precompileOracle}, true
case bn256PairingPrecompileAddress:
return &bn256PairingOracle{Oracle: precompileOracle, rules: rules}, true
return &bn256PairingOracle{Orig: orig, Oracle: precompileOracle}, true
case kzgPointEvaluationPrecompileAddress:
return &kzgPointEvaluationOracle{Oracle: precompileOracle}, true
return &kzgPointEvaluationOracle{Orig: orig, Oracle: precompileOracle}, true
default:
return nil, false
}
......@@ -66,11 +66,12 @@ func CreatePrecompileOverrides(precompileOracle PrecompileOracle) vm.PrecompileO
}
type ecrecoverOracle struct {
Orig vm.PrecompiledContract
Oracle PrecompileOracle
}
func (c *ecrecoverOracle) RequiredGas(input []byte) uint64 {
return params.EcrecoverGas
return c.Orig.RequiredGas(input)
}
func (c *ecrecoverOracle) Run(input []byte) ([]byte, error) {
......@@ -117,18 +118,12 @@ func allZero(b []byte) bool {
}
type bn256PairingOracle struct {
rules params.Rules
Orig vm.PrecompiledContract
Oracle PrecompileOracle
}
func (b *bn256PairingOracle) RequiredGas(input []byte) uint64 {
// Required gas changed in Istanbul. Note that IsIstanbul is true for Istanbul and all forks after it
// TODO(client-pod#628): Investigate delegating this to the original precompile implementation to avoid reimplementing.
if b.rules.IsIstanbul {
return params.Bn256PairingBaseGasIstanbul + uint64(len(input)/192)*params.Bn256PairingPerPointGasIstanbul
} else {
return params.Bn256PairingBaseGasByzantium + uint64(len(input)/192)*params.Bn256PairingPerPointGasByzantium
}
return b.Orig.RequiredGas(input)
}
var (
......@@ -162,12 +157,13 @@ func (b *bn256PairingOracle) Run(input []byte) ([]byte, error) {
// kzgPointEvaluationOracle implements the EIP-4844 point evaluation precompile,
// using the preimage-oracle to perform the evaluation.
type kzgPointEvaluationOracle struct {
Orig vm.PrecompiledContract
Oracle PrecompileOracle
}
// RequiredGas estimates the gas required for running the point evaluation precompile.
func (b *kzgPointEvaluationOracle) RequiredGas(_ []byte) uint64 {
return params.BlobTxPointEvaluationPrecompileGas
func (b *kzgPointEvaluationOracle) RequiredGas(input []byte) uint64 {
return b.Orig.RequiredGas(input)
}
const (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment