Skip to content

Commit 52d0e60

Browse files
authored
cannon: Support F_GETFD cmd to fcntl (#12050)
* cannon: Support F_GETFD cmd to fcntl. * cannon: Update fuzz test expectations. * cannon: Update MIPS.t.sol * cannon: Introduce a new state version for supporting get_fd. Switches singlethreaded prestate to use .bin.gz instead of json since it now needs to detect the new state version. * cannon: Don't override the cannon version. * Update semver-lock. * cannon: Update tests to detect old versions but only check writing and parsing for the currently supported versions. * cannon: Load old version from cannon docker image * cannon: Improve logging. * cannon: Restore cannon version arg. * Fix contrac semvers. * cannon: Rename singlethreaded-getfd to just singlethreaded-2. We could just go to using the state version number directly, but particularly the difference between singlethreaded and multithreaded feels useful to keep. * cannon: Fix comment. * Update semver again.
1 parent 3aabfe6 commit 52d0e60

File tree

31 files changed

+199
-70
lines changed

31 files changed

+199
-70
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ jobs:
10581058
key: cannon-prestate-{{ checksum "./cannon/bin/cannon" }}-{{ checksum "op-program/bin/op-program-client.elf" }}
10591059
name: Save Cannon prestate to cache
10601060
paths:
1061-
- "op-program/bin/prestate.json"
1061+
- "op-program/bin/prestate.bin.gz"
10621062
- "op-program/bin/meta.json"
10631063
- "op-program/bin/prestate-proof.json"
10641064
- run:
@@ -1079,7 +1079,7 @@ jobs:
10791079
- persist_to_workspace:
10801080
root: .
10811081
paths:
1082-
- "op-program/bin/prestate.json"
1082+
- "op-program/bin/prestate.bin.gz"
10831083
- "op-program/bin/meta.json"
10841084
- "op-program/bin/prestate-proof.json"
10851085

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,16 @@ reproducible-prestate: ## Builds reproducible-prestate binary
134134
.PHONY: reproducible-prestate
135135

136136
# Include any files required for the devnet to build and run.
137-
DEVNET_CANNON_PRESTATE_FILES := op-program/bin/prestate-proof.json op-program/bin/prestate.json op-program/bin/prestate-proof-mt.json op-program/bin/prestate-mt.bin.gz
137+
DEVNET_CANNON_PRESTATE_FILES := op-program/bin/prestate-proof.json op-program/bin/prestate.bin.gz op-program/bin/prestate-proof-mt.json op-program/bin/prestate-mt.bin.gz
138138

139139

140140
$(DEVNET_CANNON_PRESTATE_FILES):
141141
make cannon-prestate
142142
make cannon-prestate-mt
143143

144144
cannon-prestate: op-program cannon ## Generates prestate using cannon and op-program
145-
./cannon/bin/cannon load-elf --type singlethreaded --path op-program/bin/op-program-client.elf --out op-program/bin/prestate.json --meta op-program/bin/meta.json
146-
./cannon/bin/cannon run --proof-at '=0' --stop-at '=1' --input op-program/bin/prestate.json --meta op-program/bin/meta.json --proof-fmt 'op-program/bin/%d.json' --output ""
145+
./cannon/bin/cannon load-elf --type singlethreaded-2 --path op-program/bin/op-program-client.elf --out op-program/bin/prestate.bin.gz --meta op-program/bin/meta.json
146+
./cannon/bin/cannon run --proof-at '=0' --stop-at '=1' --input op-program/bin/prestate.bin.gz --meta op-program/bin/meta.json --proof-fmt 'op-program/bin/%d.json' --output ""
147147
mv op-program/bin/0.json op-program/bin/prestate-proof.json
148148
.PHONY: cannon-prestate
149149

cannon/.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ venv
77
*.log
88
testdata/example/bin
99
contracts/out
10-
state.json
11-
*.json
12-
*.json.gz
1310
*.pprof
1411
*.out
1512
bin

cannon/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ cannon-impl:
1919
env GO111MODULE=on GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build -v $(LDFLAGS) -o ./bin/cannon-impl .
2020

2121
cannon-embeds: cannon-impl
22-
@cp bin/cannon-impl ./multicannon/embeds/cannon-0
22+
@cp bin/cannon-impl ./multicannon/embeds/cannon-2
2323
@cp bin/cannon-impl ./multicannon/embeds/cannon-1
2424

2525
cannon: cannon-embeds

cannon/cmd/load_elf.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func LoadELF(ctx *cli.Context) error {
6969
return err
7070
}
7171
switch ver {
72-
case versions.VersionSingleThreaded:
72+
case versions.VersionSingleThreaded2:
7373
createInitialState = func(f *elf.File) (mipsevm.FPVMState, error) {
7474
return program.LoadELF(f, singlethreaded.CreateInitialState)
7575
}

cannon/cmd/run.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ func Run(ctx *cli.Context) error {
373373
if err != nil {
374374
return fmt.Errorf("failed to load state: %w", err)
375375
}
376+
l.Info("Loaded input state", "version", state.Version)
376377
vm := state.CreateVM(l, po, outLog, errLog, meta)
377378
debugProgram := ctx.Bool(RunDebugFlag.Name)
378379
if debugProgram {

cannon/mipsevm/exec/mips_syscalls.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,15 @@ func HandleSysFcntl(a0, a1 uint32) (v0, v1 uint32) {
286286
// args: a0 = fd, a1 = cmd
287287
v1 = uint32(0)
288288

289-
if a1 == 3 { // F_GETFL: get file descriptor flags
289+
if a1 == 1 { // F_GETFD: get file descriptor flags
290+
switch a0 {
291+
case FdStdin, FdStdout, FdStderr, FdPreimageRead, FdHintRead, FdPreimageWrite, FdHintWrite:
292+
v0 = 0 // No flags set
293+
default:
294+
v0 = 0xFFffFFff
295+
v1 = MipsEBADF
296+
}
297+
} else if a1 == 3 { // F_GETFL: get file status flags
290298
switch a0 {
291299
case FdStdin, FdPreimageRead, FdHintRead:
292300
v0 = 0 // O_RDONLY

cannon/mipsevm/multithreaded/state.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ func CreateInitialState(pc, heapStart uint32) *State {
9797
}
9898

9999
func (s *State) CreateVM(logger log.Logger, po mipsevm.PreimageOracle, stdOut, stdErr io.Writer, meta mipsevm.Metadata) mipsevm.FPVM {
100-
logger.Info("Using cannon multithreaded VM")
101100
return NewInstrumentedState(s, po, stdOut, stdErr, logger, meta)
102101
}
103102

cannon/mipsevm/singlethreaded/state.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ func CreateInitialState(pc, heapStart uint32) *State {
6969
}
7070

7171
func (s *State) CreateVM(logger log.Logger, po mipsevm.PreimageOracle, stdOut, stdErr io.Writer, meta mipsevm.Metadata) mipsevm.FPVM {
72-
logger.Info("Using cannon VM")
7372
return NewInstrumentedState(s, po, stdOut, stdErr, meta)
7473
}
7574

cannon/mipsevm/tests/fuzz_evm_common_test.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,17 @@ func FuzzStateSyscallFcntl(f *testing.F) {
150150
expected.Step += 1
151151
expected.PC = state.GetCpu().NextPC
152152
expected.NextPC = state.GetCpu().NextPC + 4
153-
if cmd == 3 {
153+
if cmd == 1 {
154+
switch fd {
155+
case exec.FdStdin, exec.FdStdout, exec.FdStderr,
156+
exec.FdPreimageRead, exec.FdHintRead, exec.FdPreimageWrite, exec.FdHintWrite:
157+
expected.Registers[2] = 0
158+
expected.Registers[7] = 0
159+
default:
160+
expected.Registers[2] = 0xFF_FF_FF_FF
161+
expected.Registers[7] = exec.MipsEBADF
162+
}
163+
} else if cmd == 3 {
154164
switch fd {
155165
case exec.FdStdin, exec.FdPreimageRead, exec.FdHintRead:
156166
expected.Registers[2] = 0

0 commit comments

Comments
 (0)