Skip to content

Commit a6b8553

Browse files
authored
cannon: Add go 1.25 tests (#18279)
* cannon: Add go 1.25 tests * cannon: Use go 1.25.4 for tests. Simplify and actually run the keccak tests.
1 parent 1181311 commit a6b8553

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+6300
-4
lines changed

cannon/mipsevm/multithreaded/instrumented_test.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/ethereum/go-ethereum/log"
1515
"github.com/stretchr/testify/require"
16+
"golang.org/x/crypto/sha3"
1617

1718
"github.com/ethereum-optimism/optimism/cannon/mipsevm"
1819
"github.com/ethereum-optimism/optimism/cannon/mipsevm/memory"
@@ -69,8 +70,36 @@ func TestInstrumentedState_Claim(t *testing.T) {
6970
})
7071
}
7172

73+
func TestInstrumentedState_Keccak(t *testing.T) {
74+
runTestAcrossVms(t, "Keccak", func(t *testing.T, vmFactory VMFactory[*State], goTarget testutil.GoTarget) {
75+
state, meta := testutil.LoadELFProgram(t, testutil.ProgramPath("keccak", goTarget), CreateInitialState)
76+
77+
var stdOutBuf, stdErrBuf bytes.Buffer
78+
us := vmFactory(state, nil, io.MultiWriter(&stdOutBuf, os.Stdout), io.MultiWriter(&stdErrBuf, os.Stderr), testutil.CreateLogger(), meta)
79+
80+
for i := 0; i < 2000_000; i++ {
81+
if us.GetState().GetExited() {
82+
break
83+
}
84+
_, err := us.Step(false)
85+
require.NoError(t, err)
86+
}
87+
88+
require.True(t, state.GetExited(), "must complete program")
89+
require.Equal(t, uint8(0), state.GetExitCode(), "exit with 0")
90+
91+
var result []byte
92+
keccakState := sha3.NewLegacyKeccak256()
93+
keccakState.Write([]byte{1, 2, 3})
94+
result = keccakState.Sum(result)
95+
expectedStdOut := fmt.Sprintf("keccak program. result=%x\n", result)
96+
require.Equal(t, expectedStdOut, stdOutBuf.String(), "stdout")
97+
require.Equal(t, "", stdErrBuf.String(), "stderr")
98+
})
99+
}
100+
72101
func TestInstrumentedState_Random(t *testing.T) {
73-
state, meta := testutil.LoadELFProgram(t, testutil.ProgramPath("random", testutil.Go1_24), CreateInitialState)
102+
state, meta := testutil.LoadELFProgram(t, testutil.ProgramPath("random", testutil.Go1_25), CreateInitialState)
74103

75104
var stdOutBuf, stdErrBuf bytes.Buffer
76105
us := latestVm(state, nil, io.MultiWriter(&stdOutBuf, os.Stdout), io.MultiWriter(&stdErrBuf, os.Stderr), testutil.CreateLogger(), meta)
@@ -420,6 +449,7 @@ func runTestsAcrossVms[T any](t *testing.T, testNamer TestNamer[T], testCases []
420449
variations := []VMVariations{
421450
{name: "Go 1.23 VM", goTarget: testutil.Go1_23, features: mipsevm.FeatureToggles{}},
422451
{name: "Go 1.24 VM", goTarget: testutil.Go1_24, features: allFeaturesEnabled()},
452+
{name: "Go 1.25 VM", goTarget: testutil.Go1_25, features: allFeaturesEnabled()},
423453
}
424454

425455
for _, testCase := range testCases {

cannon/mipsevm/tests/evm_common_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ func TestEVM_RandomProgram(t *testing.T) {
992992
validator := testutil.NewEvmValidator(t, v.StateHashFn, v.Contracts)
993993

994994
var stdOutBuf, stdErrBuf bytes.Buffer
995-
elfFile := testutil.ProgramPath("random", testutil.Go1_24)
995+
elfFile := testutil.ProgramPath("random", testutil.Go1_25)
996996
goVm := v.ElfVMFactory(t, elfFile, nil, io.MultiWriter(&stdOutBuf, os.Stdout), io.MultiWriter(&stdErrBuf, os.Stderr), testutil.CreateLogger())
997997
state := goVm.GetState()
998998

cannon/mipsevm/tests/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func GetMipsVersionTestCases(t require.TestingT) []VersionedVMTestCase {
9191
goTarget := testutil.Go1_23
9292
features := versions.FeaturesForVersion(version)
9393
if features.SupportWorkingSysGetRandom {
94-
goTarget = testutil.Go1_24
94+
goTarget = testutil.Go1_25
9595
}
9696
cases = append(cases, GetMultiThreadedTestCase(t, version, goTarget))
9797
}

cannon/mipsevm/testutil/elf.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type GoTarget string
1515
const (
1616
Go1_23 GoTarget = "go-1-23"
1717
Go1_24 GoTarget = "go-1-24"
18+
Go1_25 GoTarget = "go-1-25"
1819
)
1920

2021
func LoadELFProgram[T mipsevm.FPVMState](t require.TestingT, name string, initState program.CreateInitialFPVMState[T]) (T, *program.Metadata) {

cannon/testdata/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,15 @@ go1-24:
88
make -C ./go-1-24 elf
99
.PHONY: go1-24
1010

11+
go1-25:
12+
make -C ./go-1-25 elf
13+
.PHONY: go1-25
14+
1115
.PHONY: elf
12-
elf: go1-23 go1-24
16+
elf: go1-23 go1-24 go1-25
1317

1418
.PHONY: clean
1519
clean:
1620
make -C ./go-1-23 clean
1721
make -C ./go-1-24 clean
22+
make -C ./go-1-25 clean
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module keccak
2+
3+
go 1.23.0
4+
5+
toolchain go1.23.8
6+
7+
require golang.org/x/crypto v0.35.0
8+
9+
require golang.org/x/sys v0.30.0 // indirect
10+
11+
replace github.com/ethereum-optimism/optimism v0.0.0 => ./../../../..
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs=
2+
golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ=
3+
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
4+
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
6+
"golang.org/x/crypto/sha3"
7+
)
8+
9+
func main() {
10+
var result []byte
11+
state := sha3.NewLegacyKeccak256()
12+
state.Write([]byte{1, 2, 3})
13+
result = state.Sum(result)
14+
15+
fmt.Printf("keccak program. result=%x\n", result)
16+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module keccak
2+
3+
go 1.24
4+
5+
toolchain go1.24.2
6+
7+
require golang.org/x/crypto v0.35.0
8+
9+
require golang.org/x/sys v0.30.0 // indirect
10+
11+
replace github.com/ethereum-optimism/optimism v0.0.0 => ./../../../..
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs=
2+
golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ=
3+
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
4+
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=

0 commit comments

Comments
 (0)