Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions analyzer/opcode/opcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func (op *opcode) Analyze(path string, withTrace bool) ([]*analyzer.Issue, error
if err != nil { // non-reachable portion ignored
continue
}
if common.ShouldIgnoreSource(source, op.profile.IgnoredFunctions) {
continue
}
if !withTrace {
source.CallStack = nil
}
Expand Down
4 changes: 4 additions & 0 deletions analyzer/syscall/asm_syscall.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func (a *asmSyscallAnalyser) Analyze(path string, withTrace bool) ([]*analyzer.I
if err != nil { // non-reachable portion ignored
continue
}
if common.ShouldIgnoreSource(source, a.profile.IgnoredFunctions) {
continue
}

if !withTrace {
source.CallStack = nil
}
Expand Down
11 changes: 11 additions & 0 deletions common/stack_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package common
import (
"fmt"
"path/filepath"
"slices"

"github.com/ChainSafe/vm-compat/analyzer"
"github.com/ChainSafe/vm-compat/asmparser"
Expand Down Expand Up @@ -58,3 +59,13 @@ func TraceAsmCaller(
}
return src, nil
}

func ShouldIgnoreSource(callStack *analyzer.CallStack, functions []string) bool {
if callStack != nil {
if slices.Contains(functions, callStack.Function) {
return true
}
return ShouldIgnoreSource(callStack.CallStack, functions)
}
return false
}
3 changes: 3 additions & 0 deletions profile/cannon/cannon-32.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ vm: Cannon
goos: linux
goarch: mips
ignored_functions:
- 'syscall.setrlimit'
- 'runtime.morestack'
- 'runtime.abort'

allowed_opcodes:
- opcode: '0x2'
Expand Down
3 changes: 3 additions & 0 deletions profile/cannon/cannon-64.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ vm: Cannon
goos: linux
goarch: mips64
ignored_functions:
- 'syscall.setrlimit'
- 'runtime.morestack'
- 'runtime.abort'

allowed_opcodes:
- opcode: '0x2'
Expand Down
13 changes: 7 additions & 6 deletions profile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ type OpcodeInstruction struct {

// VMProfile represents the configuration for a specific VM.
type VMProfile struct {
VMName string `yaml:"vm"`
GOOS string `yaml:"goos"`
GOARCH string `yaml:"goarch"`
AllowedOpcodes []OpcodeInstruction `yaml:"allowed_opcodes"`
AllowedSycalls []int `yaml:"allowed_syscalls"`
NOOPSyscalls []int `yaml:"noop_syscalls"`
VMName string `yaml:"vm"`
GOOS string `yaml:"goos"`
GOARCH string `yaml:"goarch"`
AllowedOpcodes []OpcodeInstruction `yaml:"allowed_opcodes"`
AllowedSycalls []int `yaml:"allowed_syscalls"`
NOOPSyscalls []int `yaml:"noop_syscalls"`
IgnoredFunctions []string `yaml:"ignored_functions"`
}

func (p *VMProfile) SetDefaults() {
Expand Down
5 changes: 4 additions & 1 deletion profile/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ A VM profile consists of the following fields:
- `allowed_opcodes`: List of permitted opcodes with optional function values.
- `allowed_syscalls`: List of system calls allowed by the VM.
- `noop_syscalls`: List of system calls treated as no-ops by the VM.
- `ignored_functions`: List of functions or blocks disabled on the VM (e.g., due to multithreading restrictions).
- `ignored_functions`: List of functions or blocks disabled on the VM due to they might never be called in usual scenarios.
Example:
- 'syscall.setrlimit': Only executed in certain condition that doesn't meet with cannon, https://go.dev/src/syscall/rlimit.go
- 'runtime.morestack': Should execute in case of stack overflow, but not in usual case.

## Getting Opcode and Syscall Information
Determining the correct opcodes and syscalls for a VM requires extensive research on the targeted VM
Expand Down
Loading