Skip to content

Commit e86cc35

Browse files
authored
op-program: Enable interop fault proofs mode in action test (#13677)
* op-program: Enable interop fault proofs mode in action test * op-program: Use the right chain output. Won't handle the padding yet, but we have tests covering that we'll need to do further work to address later anyway. * op-program: Tweak name and fix exec mode.
1 parent 7719c5a commit e86cc35

File tree

9 files changed

+51
-37
lines changed

9 files changed

+51
-37
lines changed

op-e2e/actions/interop/interop_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,15 @@ func TestInteropFaultProofs(gt *testing.T) {
297297
agreedClaim: start.Marshal(),
298298
disputedClaim: start.Marshal(),
299299
expectValid: false,
300+
skip: true,
300301
},
301302
{
302303
name: "ClaimDirectToNextTimestamp",
303304
startTimestamp: startTimestamp,
304305
agreedClaim: start.Marshal(),
305306
disputedClaim: end.Marshal(),
306307
expectValid: false,
308+
skip: true,
307309
},
308310
{
309311
name: "FirstChainOptimisticBlock",
@@ -361,6 +363,7 @@ func TestInteropFaultProofs(gt *testing.T) {
361363
actors.ChainA.L2Genesis,
362364
chain1End.BlockRef.Number,
363365
checkResult,
366+
fpHelpers.WithInteropEnabled(),
364367
)
365368
})
366369
}

op-e2e/actions/proofs/helpers/env.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ func WithL2BlockNumber(num uint64) FixtureInputParam {
157157
}
158158
}
159159

160+
func WithInteropEnabled() FixtureInputParam {
161+
return func(f *FixtureInputs) {
162+
f.InteropEnabled = true
163+
}
164+
}
165+
160166
func (env *L2FaultProofEnv) RunFaultProofProgram(t helpers.Testing, l2ClaimBlockNum uint64, checkResult CheckResult, fixtureInputParams ...FixtureInputParam) {
161167
RunFaultProofProgram(t, env.log, env.Miner, env.Sequencer.L2Verifier, env.Engine, env.Sd.L2Cfg, l2ClaimBlockNum, checkResult, fixtureInputParams...)
162168
}
@@ -195,24 +201,18 @@ func NewBatcherCfg(params ...BatcherCfgParam) *helpers.BatcherCfg {
195201
return dfault
196202
}
197203

198-
type OpProgramCfgParam func(p *config.Config)
199-
200204
func NewOpProgramCfg(
201205
t helpers.Testing,
202206
rollupCfg *rollup.Config,
203207
l2Genesis *params.ChainConfig,
204208
fi *FixtureInputs,
205-
params ...OpProgramCfgParam,
206209
) *config.Config {
207210
dfault := config.NewConfig(rollupCfg, l2Genesis, fi.L1Head, fi.L2Head, fi.L2OutputRoot, fi.L2Claim, fi.L2BlockNumber)
208211

209212
if dumpFixtures {
210213
dfault.DataDir = t.TempDir()
211214
dfault.DataFormat = hostTypes.DataFormatPebble
212215
}
213-
214-
for _, apply := range params {
215-
apply(dfault)
216-
}
216+
dfault.InteropEnabled = fi.InteropEnabled
217217
return dfault
218218
}

op-e2e/actions/proofs/helpers/fixture.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ type TestFixture struct {
3838
}
3939

4040
type FixtureInputs struct {
41-
L2BlockNumber uint64 `toml:"l2-block-number"`
42-
L2Claim common.Hash `toml:"l2-claim"`
43-
L2Head common.Hash `toml:"l2-head"`
44-
L2OutputRoot common.Hash `toml:"l2-output-root"`
45-
L2ChainID uint64 `toml:"l2-chain-id"`
46-
L1Head common.Hash `toml:"l1-head"`
41+
L2BlockNumber uint64 `toml:"l2-block-number"`
42+
L2Claim common.Hash `toml:"l2-claim"`
43+
L2Head common.Hash `toml:"l2-head"`
44+
L2OutputRoot common.Hash `toml:"l2-output-root"`
45+
L2ChainID uint64 `toml:"l2-chain-id"`
46+
L1Head common.Hash `toml:"l1-head"`
47+
InteropEnabled bool `toml:"use-interop"`
4748
}
4849

4950
// Dumps a `fp-tests` test fixture to disk if the `OP_E2E_FPP_FIXTURE_DIR` environment variable is set.

op-program/client/interop/interop.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ type taskExecutor interface {
3333
l2Oracle l2.Oracle) (tasks.DerivationResult, error)
3434
}
3535

36-
func RunInteropProgram(logger log.Logger, bootInfo *boot.BootInfo, l1PreimageOracle l1.Oracle, l2PreimageOracle l2.Oracle, validate bool) error {
37-
return runInteropProgram(logger, bootInfo, l1PreimageOracle, l2PreimageOracle, validate, &interopTaskExecutor{})
36+
func RunInteropProgram(logger log.Logger, bootInfo *boot.BootInfo, l1PreimageOracle l1.Oracle, l2PreimageOracle l2.Oracle, validateClaim bool) error {
37+
return runInteropProgram(logger, bootInfo, l1PreimageOracle, l2PreimageOracle, validateClaim, &interopTaskExecutor{})
3838
}
3939

40-
func runInteropProgram(logger log.Logger, bootInfo *boot.BootInfo, l1PreimageOracle l1.Oracle, l2PreimageOracle l2.Oracle, validate bool, tasks taskExecutor) error {
40+
func runInteropProgram(logger log.Logger, bootInfo *boot.BootInfo, l1PreimageOracle l1.Oracle, l2PreimageOracle l2.Oracle, validateClaim bool, tasks taskExecutor) error {
4141
logger.Info("Interop Program Bootstrapped", "bootInfo", bootInfo)
4242

4343
// For the first step in a timestamp, we would get a SuperRoot as the agreed claim - TransitionStateByRoot will
@@ -64,7 +64,7 @@ func runInteropProgram(logger log.Logger, bootInfo *boot.BootInfo, l1PreimageOra
6464
bootInfo.RollupConfig,
6565
bootInfo.L2ChainConfig,
6666
bootInfo.L1Head,
67-
superRoot.Chains[0].Output,
67+
superRoot.Chains[transitionState.Step].Output,
6868
claimedBlockNumber,
6969
l1PreimageOracle,
7070
l2PreimageOracle,
@@ -88,7 +88,7 @@ func runInteropProgram(logger log.Logger, bootInfo *boot.BootInfo, l1PreimageOra
8888
if err != nil {
8989
return err
9090
}
91-
if !validate {
91+
if !validateClaim {
9292
return nil
9393
}
9494
return claim.ValidateClaim(logger, derivationResult.SafeHead, eth.Bytes32(bootInfo.L2Claim), eth.Bytes32(expected))

op-program/client/l2/cache.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ func NewCachingOracle(oracle Oracle) *CachingOracle {
2828
nodeLRU, _ := simplelru.NewLRU[common.Hash, []byte](nodeCacheSize, nil)
2929
codeLRU, _ := simplelru.NewLRU[common.Hash, []byte](codeCacheSize, nil)
3030
outputLRU, _ := simplelru.NewLRU[common.Hash, eth.Output](codeCacheSize, nil)
31+
transitionStates, _ := simplelru.NewLRU[common.Hash, *interopTypes.TransitionState](codeCacheSize, nil)
3132
return &CachingOracle{
32-
oracle: oracle,
33-
blocks: blockLRU,
34-
nodes: nodeLRU,
35-
codes: codeLRU,
36-
outputs: outputLRU,
33+
oracle: oracle,
34+
blocks: blockLRU,
35+
nodes: nodeLRU,
36+
codes: codeLRU,
37+
outputs: outputLRU,
38+
transitionStates: transitionStates,
3739
}
3840
}
3941

op-program/client/program.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@ import (
1414
"github.com/ethereum/go-ethereum/log"
1515
)
1616

17-
type RunProgramFlag bool
18-
19-
const (
20-
RunProgramFlagSkipValidation RunProgramFlag = false
21-
RunProgramFlagValidate RunProgramFlag = true
22-
)
17+
type Config struct {
18+
SkipValidation bool
19+
InteropEnabled bool
20+
}
2321

2422
// Main executes the client program in a detached context and exits the current process.
2523
// The client runtime environment must be preset before calling this function.
2624
func Main(logger log.Logger) {
2725
log.Info("Starting fault proof program client")
2826
preimageOracle := preimage.ClientPreimageChannel()
2927
preimageHinter := preimage.ClientHinterChannel()
30-
if err := RunProgram(logger, preimageOracle, preimageHinter, RunProgramFlagValidate); errors.Is(err, claim.ErrClaimNotValid) {
28+
config := Config{
29+
InteropEnabled: os.Getenv("OP_PROGRAM_CLIENT_USE_INTEROP") == "true",
30+
}
31+
if err := RunProgram(logger, preimageOracle, preimageHinter, config); errors.Is(err, claim.ErrClaimNotValid) {
3132
log.Error("Claim is invalid", "err", err)
3233
os.Exit(1)
3334
} else if err != nil {
@@ -40,15 +41,15 @@ func Main(logger log.Logger) {
4041
}
4142

4243
// RunProgram executes the Program, while attached to an IO based pre-image oracle, to be served by a host.
43-
func RunProgram(logger log.Logger, preimageOracle io.ReadWriter, preimageHinter io.ReadWriter, flags RunProgramFlag) error {
44+
func RunProgram(logger log.Logger, preimageOracle io.ReadWriter, preimageHinter io.ReadWriter, cfg Config) error {
4445
pClient := preimage.NewOracleClient(preimageOracle)
4546
hClient := preimage.NewHintWriter(preimageHinter)
4647
l1PreimageOracle := l1.NewCachingOracle(l1.NewPreimageOracle(pClient, hClient))
4748
l2PreimageOracle := l2.NewCachingOracle(l2.NewPreimageOracle(pClient, hClient))
4849

4950
bootInfo := boot.NewBootstrapClient(pClient).BootInfo()
50-
if os.Getenv("OP_PROGRAM_USE_INTEROP") == "true" {
51-
return interop.RunInteropProgram(logger, bootInfo, l1PreimageOracle, l2PreimageOracle, flags == RunProgramFlagValidate)
51+
if cfg.InteropEnabled {
52+
return interop.RunInteropProgram(logger, bootInfo, l1PreimageOracle, l2PreimageOracle, !cfg.SkipValidation)
5253
}
5354
return RunPreInteropProgram(logger, bootInfo, l1PreimageOracle, l2PreimageOracle)
5455
}

op-program/host/common/common.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ func FaultProofProgram(ctx context.Context, logger log.Logger, cfg *config.Confi
9999
cmd.ExtraFiles[cl.PClientWFd-3] = pClientRW.Writer()
100100
cmd.Stdout = os.Stdout // for debugging
101101
cmd.Stderr = os.Stderr // for debugging
102+
if cfg.InteropEnabled {
103+
cmd.Env = append(os.Environ(), "OP_PROGRAM_CLIENT_USE_INTEROP=true")
104+
}
102105

103106
err := cmd.Start()
104107
if err != nil {
@@ -110,11 +113,12 @@ func FaultProofProgram(ctx context.Context, logger log.Logger, cfg *config.Confi
110113
logger.Debug("Client program completed successfully")
111114
return nil
112115
} else {
113-
runFlag := cl.RunProgramFlagValidate
116+
var clientCfg cl.Config
114117
if programConfig.skipValidation {
115-
runFlag = cl.RunProgramFlagSkipValidation
118+
clientCfg.SkipValidation = true
116119
}
117-
return cl.RunProgram(logger, pClientRW, hClientRW, runFlag)
120+
clientCfg.InteropEnabled = cfg.InteropEnabled
121+
return cl.RunProgram(logger, pClientRW, hClientRW, clientCfg)
118122
}
119123
}
120124

op-program/host/config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ type Config struct {
7777
// ServerMode indicates that the program should run in pre-image server mode and wait for requests.
7878
// No client program is run.
7979
ServerMode bool
80+
81+
// InteropEnabled enables interop fault proof rules when running the client in-process
82+
InteropEnabled bool
8083
}
8184

8285
func (c *Config) Check() error {

op-program/host/host.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func Main(logger log.Logger, cfg *config.Config) error {
6060
return nil
6161
}
6262

63-
// FaultProofProgram is the programmatic entry-point for the fault proof program
63+
// FaultProofProgramWithDefaultPrefecher is the programmatic entry-point for the fault proof program
6464
func FaultProofProgramWithDefaultPrefecher(ctx context.Context, logger log.Logger, cfg *config.Config, opts ...hostcommon.ProgramOpt) error {
6565
var newopts []hostcommon.ProgramOpt
6666
newopts = append(newopts, hostcommon.WithPrefetcher(makeDefaultPrefetcher))

0 commit comments

Comments
 (0)