rename sbf to sbpf
This commit is contained in:
parent
4770d3aca0
commit
34c3a854a3
|
@ -1,4 +1,4 @@
|
|||
package sbf
|
||||
package sbpf
|
||||
|
||||
import "fmt"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package sbf
|
||||
package sbpf
|
||||
|
||||
import (
|
||||
"fmt"
|
|
@ -5,7 +5,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
|
||||
"go.firedancer.io/radiance/pkg/sbf"
|
||||
"go.firedancer.io/radiance/pkg/sbpf"
|
||||
)
|
||||
|
||||
// The following ELF loading rules seem mostly arbitrary.
|
||||
|
@ -90,9 +90,9 @@ func (l *Loader) checkSectionAddrs(sh *elf.Section64) error {
|
|||
}
|
||||
|
||||
// Ensure section within VM program range
|
||||
vaddr := clampAddUint64(sbf.VaddrProgram, sh.Addr)
|
||||
vaddr := clampAddUint64(sbpf.VaddrProgram, sh.Addr)
|
||||
vaddrEnd := vaddr + sh.Size
|
||||
if vaddrEnd < vaddr || vaddrEnd > sbf.VaddrStack {
|
||||
if vaddrEnd < vaddr || vaddrEnd > sbpf.VaddrStack {
|
||||
return fmt.Errorf("section virtual address out-of-bounds")
|
||||
}
|
||||
|
|
@ -9,7 +9,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
|
||||
"go.firedancer.io/radiance/pkg/sbf"
|
||||
"go.firedancer.io/radiance/pkg/sbpf"
|
||||
)
|
||||
|
||||
// TODO Fuzz
|
||||
|
@ -81,7 +81,7 @@ func NewLoaderFromBytes(buf []byte) (*Loader, error) {
|
|||
//
|
||||
// This loader differs from rbpf in a few ways:
|
||||
// We don't support spec bugs, we relocate after loading.
|
||||
func (l *Loader) Load() (*sbf.Program, error) {
|
||||
func (l *Loader) Load() (*sbpf.Program, error) {
|
||||
if err := l.parse(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -94,11 +94,11 @@ func (l *Loader) Load() (*sbf.Program, error) {
|
|||
return l.getProgram(), nil
|
||||
}
|
||||
|
||||
func (l *Loader) getProgram() *sbf.Program {
|
||||
return &sbf.Program{
|
||||
func (l *Loader) getProgram() *sbpf.Program {
|
||||
return &sbpf.Program{
|
||||
RO: l.program,
|
||||
Text: l.text,
|
||||
TextVA: sbf.VaddrProgram + l.textRange.min,
|
||||
TextVA: sbpf.VaddrProgram + l.textRange.min,
|
||||
Entrypoint: l.entrypoint,
|
||||
Funcs: l.funcs,
|
||||
}
|
|
@ -11,7 +11,7 @@ import (
|
|||
)
|
||||
|
||||
func TestLoader_Noop(t *testing.T) {
|
||||
soNoop := fixtures.Load(t, "sbf", "noop.so")
|
||||
soNoop := fixtures.Load(t, "sbpf", "noop.so")
|
||||
|
||||
loader, err := NewLoaderFromBytes(soNoop)
|
||||
require.NoError(t, err)
|
||||
|
@ -201,7 +201,7 @@ func isZeroBytes(b []byte) bool {
|
|||
}
|
||||
|
||||
func TestVerifier(t *testing.T) {
|
||||
loader, err := NewLoaderFromBytes(fixtures.Load(t, "sbf", "noop.so"))
|
||||
loader, err := NewLoaderFromBytes(fixtures.Load(t, "sbpf", "noop.so"))
|
||||
require.NoError(t, err)
|
||||
|
||||
program, err := loader.Load()
|
|
@ -5,7 +5,7 @@ import (
|
|||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
"go.firedancer.io/radiance/pkg/sbf"
|
||||
"go.firedancer.io/radiance/pkg/sbpf"
|
||||
)
|
||||
|
||||
// relocate applies ELF relocations (for syscalls and position-independent code).
|
||||
|
@ -25,13 +25,13 @@ func (l *Loader) relocate() error {
|
|||
|
||||
func (l *Loader) fixupRelativeCalls() error {
|
||||
// TODO does invariant text.size%8 == 0 hold?
|
||||
insCount := l.textRange.len() / sbf.SlotSize
|
||||
insCount := l.textRange.len() / sbpf.SlotSize
|
||||
buf := l.getRange(l.textRange)
|
||||
for i := uint64(0); i < insCount; i++ {
|
||||
off := i * sbf.SlotSize
|
||||
slot := sbf.GetSlot(buf[off : off+sbf.SlotSize])
|
||||
off := i * sbpf.SlotSize
|
||||
slot := sbpf.GetSlot(buf[off : off+sbpf.SlotSize])
|
||||
|
||||
isCall := slot.Op() == sbf.OpCall && slot.Imm() != -1
|
||||
isCall := slot.Op() == sbpf.OpCall && slot.Imm() != -1
|
||||
if !isCall {
|
||||
continue
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ func (l *Loader) fixupRelativeCalls() error {
|
|||
}
|
||||
|
||||
func (l *Loader) registerFunc(target uint64) (uint32, error) {
|
||||
hash := sbf.PCHash(target)
|
||||
hash := sbpf.PCHash(target)
|
||||
// TODO check for collision with syscalls
|
||||
//if _, ok := l.funcs[hash]; ok {
|
||||
// return 0, fmt.Errorf("symbol hash collision for func at=%d hash=%#08x", target, hash)
|
||||
|
@ -95,8 +95,8 @@ func (l *Loader) applyReloc(reloc *elf.Rel64) error {
|
|||
relAddr := binary.LittleEndian.Uint32(l.program[rOff+4 : rOff+8])
|
||||
addr := clampAddUint64(sym.Value, uint64(relAddr))
|
||||
|
||||
if addr < sbf.VaddrProgram {
|
||||
addr += sbf.VaddrProgram
|
||||
if addr < sbpf.VaddrProgram {
|
||||
addr += sbpf.VaddrProgram
|
||||
}
|
||||
|
||||
// Write to imm field of two slots
|
||||
|
@ -111,8 +111,8 @@ func (l *Loader) applyReloc(reloc *elf.Rel64) error {
|
|||
if addr == 0 {
|
||||
return fmt.Errorf("invalid R_BPF_64_RELATIVE")
|
||||
}
|
||||
if addr < sbf.VaddrProgram {
|
||||
addr += sbf.VaddrProgram
|
||||
if addr < sbpf.VaddrProgram {
|
||||
addr += sbpf.VaddrProgram
|
||||
}
|
||||
|
||||
// Write to imm field of two slots
|
||||
|
@ -122,13 +122,13 @@ func (l *Loader) applyReloc(reloc *elf.Rel64) error {
|
|||
var addr uint64
|
||||
if l.eh.Flags == EF_SBF_V2 {
|
||||
addr = binary.LittleEndian.Uint64(l.program[rOff : rOff+8])
|
||||
if addr < sbf.VaddrProgram {
|
||||
addr += sbf.VaddrProgram
|
||||
if addr < sbpf.VaddrProgram {
|
||||
addr += sbpf.VaddrProgram
|
||||
}
|
||||
} else {
|
||||
// lol
|
||||
addr = uint64(binary.LittleEndian.Uint32(l.program[rOff+4 : rOff+8]))
|
||||
addr = clampAddUint64(addr, sbf.VaddrProgram)
|
||||
addr = clampAddUint64(addr, sbpf.VaddrProgram)
|
||||
}
|
||||
binary.LittleEndian.PutUint64(l.program[rOff:rOff+8], addr)
|
||||
}
|
||||
|
@ -155,7 +155,7 @@ func (l *Loader) applyReloc(reloc *elf.Rel64) error {
|
|||
}
|
||||
} else {
|
||||
// Syscall
|
||||
hash = sbf.SymbolHash(name)
|
||||
hash = sbpf.SymbolHash(name)
|
||||
// TODO check whether syscall is known
|
||||
}
|
||||
|
||||
|
@ -168,10 +168,10 @@ func (l *Loader) applyReloc(reloc *elf.Rel64) error {
|
|||
|
||||
func (l *Loader) getEntrypoint() error {
|
||||
offset := l.eh.Entry - l.shText.Addr
|
||||
if offset%sbf.SlotSize != 0 {
|
||||
if offset%sbpf.SlotSize != 0 {
|
||||
return fmt.Errorf("invalid entrypoint")
|
||||
}
|
||||
l.entrypoint = offset / sbf.SlotSize
|
||||
l.entrypoint = offset / sbpf.SlotSize
|
||||
return nil
|
||||
}
|
||||
|
|
@ -4,9 +4,9 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"go.firedancer.io/radiance/pkg/sbf"
|
||||
"go.firedancer.io/radiance/pkg/sbpf"
|
||||
)
|
||||
|
||||
func TestSymbolHash_Entrypoint(t *testing.T) {
|
||||
assert.Equal(t, sbf.EntrypointHash, sbf.SymbolHash("entrypoint"))
|
||||
assert.Equal(t, sbpf.EntrypointHash, sbpf.SymbolHash("entrypoint"))
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package sbf
|
||||
package sbpf
|
||||
|
||||
// Op classes
|
||||
const (
|
|
@ -1,4 +1,4 @@
|
|||
package sbf
|
||||
package sbpf
|
||||
|
||||
import (
|
||||
"fmt"
|
|
@ -1,4 +1,4 @@
|
|||
package sbf
|
||||
package sbpf
|
||||
|
||||
// Program is a loaded SBF program.
|
||||
type Program struct {
|
|
@ -1,5 +1,5 @@
|
|||
// Package sbf implements the Solana Bytecode Format.
|
||||
package sbf
|
||||
// Package sbpf implements the Solana Bytecode Format.
|
||||
package sbpf
|
||||
|
||||
import "encoding/binary"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package sbf
|
||||
package sbpf
|
||||
|
||||
// Stack is the VM's call frame stack.
|
||||
//
|
|
@ -1,4 +1,4 @@
|
|||
package sbf
|
||||
package sbpf
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
|
@ -1,4 +1,4 @@
|
|||
package sbf
|
||||
package sbpf
|
||||
|
||||
import "fmt"
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package sbf
|
||||
package sbpf
|
||||
|
||||
import (
|
||||
"errors"
|
|
@ -3,7 +3,7 @@ package sealevel
|
|||
import (
|
||||
"bytes"
|
||||
|
||||
"go.firedancer.io/radiance/pkg/sbf"
|
||||
"go.firedancer.io/radiance/pkg/sbpf"
|
||||
)
|
||||
|
||||
type TxContext struct{}
|
||||
|
@ -12,13 +12,13 @@ type Execution struct {
|
|||
Log Logger
|
||||
}
|
||||
|
||||
func (t *TxContext) newVMOpts(params *Params) *sbf.VMOpts {
|
||||
func (t *TxContext) newVMOpts(params *Params) *sbpf.VMOpts {
|
||||
execution := &Execution{
|
||||
Log: new(LogRecorder),
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
params.Serialize(&buf)
|
||||
return &sbf.VMOpts{
|
||||
return &sbpf.VMOpts{
|
||||
HeapSize: 32 * 1024,
|
||||
Syscalls: registry,
|
||||
Context: execution,
|
||||
|
|
|
@ -12,8 +12,8 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.firedancer.io/radiance/fixtures"
|
||||
"go.firedancer.io/radiance/pkg/sbf"
|
||||
"go.firedancer.io/radiance/pkg/sbf/loader"
|
||||
"go.firedancer.io/radiance/pkg/sbpf"
|
||||
"go.firedancer.io/radiance/pkg/sbpf/loader"
|
||||
)
|
||||
|
||||
func TestExecute_Memo(t *testing.T) {
|
||||
|
@ -34,7 +34,7 @@ func TestExecute_Memo(t *testing.T) {
|
|||
|
||||
require.NoError(t, program.Verify())
|
||||
|
||||
interpreter := sbf.NewInterpreter(program, opts)
|
||||
interpreter := sbpf.NewInterpreter(program, opts)
|
||||
require.NotNil(t, interpreter)
|
||||
|
||||
err = interpreter.Run()
|
||||
|
@ -48,7 +48,7 @@ func TestExecute_Memo(t *testing.T) {
|
|||
|
||||
func TestInterpreter_Noop(t *testing.T) {
|
||||
// TODO simplify API?
|
||||
loader, err := loader.NewLoaderFromBytes(fixtures.Load(t, "sbf", "noop.so"))
|
||||
loader, err := loader.NewLoaderFromBytes(fixtures.Load(t, "sbpf", "noop.so"))
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, loader)
|
||||
|
||||
|
@ -58,13 +58,13 @@ func TestInterpreter_Noop(t *testing.T) {
|
|||
|
||||
require.NoError(t, program.Verify())
|
||||
|
||||
syscalls := sbf.NewSyscallRegistry()
|
||||
syscalls := sbpf.NewSyscallRegistry()
|
||||
syscalls.Register("log", SyscallLog)
|
||||
syscalls.Register("log_64", SyscallLog64)
|
||||
|
||||
var log LogRecorder
|
||||
|
||||
interpreter := sbf.NewInterpreter(program, &sbf.VMOpts{
|
||||
interpreter := sbpf.NewInterpreter(program, &sbpf.VMOpts{
|
||||
HeapSize: 32 * 1024,
|
||||
Input: nil,
|
||||
MaxCU: 10000,
|
||||
|
@ -104,7 +104,7 @@ func (e *executeCase) run(t *testing.T) {
|
|||
opts := tx.newVMOpts(&e.Params)
|
||||
opts.Tracer = testLogger{t}
|
||||
|
||||
interpreter := sbf.NewInterpreter(program, opts)
|
||||
interpreter := sbpf.NewInterpreter(program, opts)
|
||||
require.NotNil(t, interpreter)
|
||||
|
||||
err = interpreter.Run()
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
package sealevel
|
||||
|
||||
import "go.firedancer.io/radiance/pkg/sbf"
|
||||
import (
|
||||
"go.firedancer.io/radiance/pkg/sbpf"
|
||||
)
|
||||
|
||||
var registry = Syscalls()
|
||||
|
||||
// Syscalls creates a registry of all Sealevel syscalls.
|
||||
func Syscalls() sbf.SyscallRegistry {
|
||||
reg := sbf.NewSyscallRegistry()
|
||||
func Syscalls() sbpf.SyscallRegistry {
|
||||
reg := sbpf.NewSyscallRegistry()
|
||||
reg.Register("abort", SyscallAbort)
|
||||
reg.Register("sol_log_", SyscallLog)
|
||||
reg.Register("sol_log_64_", SyscallLog64)
|
||||
|
@ -15,6 +17,6 @@ func Syscalls() sbf.SyscallRegistry {
|
|||
return reg
|
||||
}
|
||||
|
||||
func syscallCtx(vm sbf.VM) *Execution {
|
||||
func syscallCtx(vm sbpf.VM) *Execution {
|
||||
return vm.VMContext().(*Execution)
|
||||
}
|
||||
|
|
|
@ -4,11 +4,11 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/gagliardetto/solana-go"
|
||||
"go.firedancer.io/radiance/pkg/sbf"
|
||||
"go.firedancer.io/radiance/pkg/sbf/cu"
|
||||
"go.firedancer.io/radiance/pkg/sbpf"
|
||||
"go.firedancer.io/radiance/pkg/sbpf/cu"
|
||||
)
|
||||
|
||||
func SyscallLogImpl(vm sbf.VM, ptr, strlen uint64, cuIn int) (r0 uint64, cuOut int, err error) {
|
||||
func SyscallLogImpl(vm sbpf.VM, ptr, strlen uint64, cuIn int) (r0 uint64, cuOut int, err error) {
|
||||
if strlen > (1 << 30) {
|
||||
cuOut = -1
|
||||
return
|
||||
|
@ -26,9 +26,9 @@ func SyscallLogImpl(vm sbf.VM, ptr, strlen uint64, cuIn int) (r0 uint64, cuOut i
|
|||
return
|
||||
}
|
||||
|
||||
var SyscallLog = sbf.SyscallFunc2(SyscallLogImpl)
|
||||
var SyscallLog = sbpf.SyscallFunc2(SyscallLogImpl)
|
||||
|
||||
func SyscallLog64Impl(vm sbf.VM, r1, r2, r3, r4, r5 uint64, cuIn int) (r0 uint64, cuOut int, err error) {
|
||||
func SyscallLog64Impl(vm sbpf.VM, r1, r2, r3, r4, r5 uint64, cuIn int) (r0 uint64, cuOut int, err error) {
|
||||
cuOut = cuIn - CUSyscallBaseCost
|
||||
if cuOut < 0 {
|
||||
return
|
||||
|
@ -39,9 +39,9 @@ func SyscallLog64Impl(vm sbf.VM, r1, r2, r3, r4, r5 uint64, cuIn int) (r0 uint64
|
|||
return
|
||||
}
|
||||
|
||||
var SyscallLog64 = sbf.SyscallFunc5(SyscallLog64Impl)
|
||||
var SyscallLog64 = sbpf.SyscallFunc5(SyscallLog64Impl)
|
||||
|
||||
func SyscallLogCUsImpl(vm sbf.VM, cuIn int) (r0 uint64, cuOut int, err error) {
|
||||
func SyscallLogCUsImpl(vm sbpf.VM, cuIn int) (r0 uint64, cuOut int, err error) {
|
||||
cuOut = cuIn - CUSyscallBaseCost
|
||||
if cuOut < 0 {
|
||||
return
|
||||
|
@ -52,9 +52,9 @@ func SyscallLogCUsImpl(vm sbf.VM, cuIn int) (r0 uint64, cuOut int, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
var SyscallLogCUs = sbf.SyscallFunc0(SyscallLogCUsImpl)
|
||||
var SyscallLogCUs = sbpf.SyscallFunc0(SyscallLogCUsImpl)
|
||||
|
||||
func SyscallLogPubkeyImpl(vm sbf.VM, pubkeyAddr uint64, cuIn int) (r0 uint64, cuOut int, err error) {
|
||||
func SyscallLogPubkeyImpl(vm sbpf.VM, pubkeyAddr uint64, cuIn int) (r0 uint64, cuOut int, err error) {
|
||||
cuOut = cuIn - CUSyscallBaseCost
|
||||
if cuOut < 0 {
|
||||
return
|
||||
|
@ -70,4 +70,4 @@ func SyscallLogPubkeyImpl(vm sbf.VM, pubkeyAddr uint64, cuIn int) (r0 uint64, cu
|
|||
return
|
||||
}
|
||||
|
||||
var SyscallLogPubkey = sbf.SyscallFunc1(SyscallLogPubkeyImpl)
|
||||
var SyscallLogPubkey = sbpf.SyscallFunc1(SyscallLogPubkeyImpl)
|
||||
|
|
|
@ -3,12 +3,12 @@ package sealevel
|
|||
import (
|
||||
"errors"
|
||||
|
||||
"go.firedancer.io/radiance/pkg/sbf"
|
||||
"go.firedancer.io/radiance/pkg/sbpf"
|
||||
)
|
||||
|
||||
func SyscallAbortImpl(_ sbf.VM, _ int) (r0 uint64, cuOut int, err error) {
|
||||
func SyscallAbortImpl(_ sbpf.VM, _ int) (r0 uint64, cuOut int, err error) {
|
||||
err = errors.New("aborted")
|
||||
return
|
||||
}
|
||||
|
||||
var SyscallAbort = sbf.SyscallFunc0(SyscallAbortImpl)
|
||||
var SyscallAbort = sbpf.SyscallFunc0(SyscallAbortImpl)
|
||||
|
|
Loading…
Reference in New Issue