From e374443006d757d93330b7d5263bc90b20032faa Mon Sep 17 00:00:00 2001 From: wissyLeeei <wissyLeeei@gmail.com> Date: Thu, 12 Sep 2024 05:32:45 +0300 Subject: [PATCH] Fix the error usage in cannon (#11368) --- cannon/cmd/run.go | 3 ++- cannon/mipsevm/program/patch.go | 3 ++- cannon/mipsevm/testutil/mips.go | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cannon/cmd/run.go b/cannon/cmd/run.go index 2fe67fc3e44c..49c248f6f9d2 100644 --- a/cannon/cmd/run.go +++ b/cannon/cmd/run.go @@ -2,6 +2,7 @@ package cmd import ( "context" + "errors" "fmt" "os" "os/exec" @@ -375,7 +376,7 @@ func Run(ctx *cli.Context) error { debugProgram := ctx.Bool(RunDebugFlag.Name) if debugProgram { if metaPath := ctx.Path(RunMetaFlag.Name); metaPath == "" { - return fmt.Errorf("cannot enable debug mode without a metadata file") + return errors.New("cannot enable debug mode without a metadata file") } if err := vm.InitDebug(); err != nil { return fmt.Errorf("failed to initialize debug mode: %w", err) diff --git a/cannon/mipsevm/program/patch.go b/cannon/mipsevm/program/patch.go index 46b75a69ff1c..0380d3bfcc87 100644 --- a/cannon/mipsevm/program/patch.go +++ b/cannon/mipsevm/program/patch.go @@ -4,6 +4,7 @@ import ( "bytes" "debug/elf" "encoding/binary" + "errors" "fmt" "github.com/ethereum-optimism/optimism/cannon/mipsevm" @@ -57,7 +58,7 @@ func PatchStack(st mipsevm.FPVMState) error { sp := uint32(0x7f_ff_d0_00) // allocate 1 page for the initial stack data, and 16KB = 4 pages for the stack to grow if err := st.GetMemory().SetMemoryRange(sp-4*memory.PageSize, bytes.NewReader(make([]byte, 5*memory.PageSize))); err != nil { - return fmt.Errorf("failed to allocate page for stack content") + return errors.New("failed to allocate page for stack content") } st.GetRegistersRef()[29] = sp diff --git a/cannon/mipsevm/testutil/mips.go b/cannon/mipsevm/testutil/mips.go index f596e0e4de7b..ac9d8b2b3092 100644 --- a/cannon/mipsevm/testutil/mips.go +++ b/cannon/mipsevm/testutil/mips.go @@ -123,7 +123,7 @@ func EncodePreimageOracleInput(t *testing.T, wit *mipsevm.StepWitness, localCont return input, nil case preimage.PrecompileKeyType: if localOracle == nil { - return nil, fmt.Errorf("local oracle is required for precompile preimages") + return nil, errors.New("local oracle is required for precompile preimages") } preimage := localOracle.GetPreimage(preimage.Keccak256Key(wit.PreimageKey).PreimageKey()) precompile := common.BytesToAddress(preimage[:20])