opti

package module
v0.0.0-...-8a909cf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2021 License: MIT Imports: 11 Imported by: 0

README

Opti

Optimistic rollup tech, minimal and generic. VERY experimental, just exploratory code, question is: 1:1 EVM rollup with interactive fraud proof possible, without compiler and special language?

License

MIT, see LICENSE file.

Documentation

Index

Constants

View Source
const (
	GasQuickStep   uint64 = 2
	GasFastestStep uint64 = 3
	GasFastStep    uint64 = 5
	GasMidStep     uint64 = 8
	GasSlowStep    uint64 = 10
	GasExtStep     uint64 = 20
)

Gas costs

View Source
const (
	ExecBlockPre = iota

	// TODO: check transaction is included, check fee params, signature validity, etc.
	ExecTxInclusion
	ExecTxSig
	ExecTxFeesPre

	// Call pre-processing (increment call depth)
	ExecCallPre

	// Interpreter loop consists of stack/memory/gas checks, and then opcode execution.
	ExecOpcodeLoad
	ExecValidateStack
	ExecReadOnlyCheck
	ExecConstantGas
	ExecCalcMemorySize
	ExecDynamicGas
	ExecUpdateMemorySize
	// when done running, continue with ExecOpcodeLoad. Or any error
	ExecOpcodeRun

	// Any error should follow up with running call-post processing
	ExecCallPost

	// Stops execution
	ExecSTOP

	// TODO: charge tx fees
	ExecTxFeesPost

	// TODO: maybe enumerate errors separately, generalize them?
	ExecErrStackUnderflow
	ExecErrStackOverflow
	ExecErrWriteProtection
	ExecErrOutOfGas
	ExecErrGasUintOverflow
)
View Source
const AddressType = SmallByteVecMeta(20)
View Source
const Bytes32Type = RootType

Variables

View Source
var CodeType = BasicListType(ByteType, 0x6000)

See https://github.com/ethereum/EIPs/blob/master/EIPS/eip-170.md ~24.5 KB

View Source
var HistType = VectorType(RootType, 256)

256 most recent block hashes, "recent history", are available for direct access in the EVM

View Source
var InputType = ListType(ByteType, 100_000_000)

Assuming a tx input can be max 400M gas, and 4 gas is paid per zero byte, then put a 100M limit on input.

View Source
var MemoryType = ListType(ByteType, 64<<20)

TODO: 64 MB memory maximum enough or too much? Every 2x makes the tree a layer deeper, but otherwise not much cost for unused space

View Source
var RetDataType = ListType(Bytes32Type, 64<<20)

Needs to be as big as memory, all of it can be returned

View Source
var StackType = ListType(Bytes32Type, 1024)

EVM stack is max 1024 words

View Source
var SubDataType = VectorType(Bytes32Type, 1024)

1024 words to track sub-step progress. Not to be confused with the memory scratchpad slots. TODO: any operations that need more scratch space?

Functions

func StepType

func StepType() *ContainerTypeDef

Types

type Address

type Address [20]byte

func AsAddress

func AsAddress(v View, err error) (Address, error)

func (Address) View

func (addr Address) View() SmallByteVecView

type Bytes32View

type Bytes32View = RootView

type CodeView

type CodeView struct {
	*BasicListView
}

func AsCodeView

func AsCodeView(v View, err error) (*CodeView, error)

func (*CodeView) GetOp

func (v *CodeView) GetOp(pc uint64) (vm.OpCode, error)

func (*CodeView) Slice

func (v *CodeView) Slice(start uint64, end uint64) ([]byte, error)

type Config

type Config struct {
	JumpTable [256]*Operation
}

func (*Config) NextStep

func (cfg *Config) NextStep(trac StepsTrace) (*StepView, error)

func (*Config) Rules

func (cfg *Config) Rules(blockNum uint64) Rules

type ExecMode

type ExecMode byte

The interpreter is a pure function: given the last step, and optional access to a previous step, it can compute the next step. The execution mode distinguishes the various tasks around just regular opcode execution.

type HistView

type HistView struct {
	*ComplexVectorView
}

func AsHistView

func AsHistView(v View, err error) (*HistView, error)

func (*HistView) GetWord

func (v *HistView) GetWord(i uint64) ([32]byte, error)

func (*HistView) SetWord

func (v *HistView) SetWord(i uint64, w [32]byte) error

type InputView

type InputView struct {
	*BasicListView
}

func AsInputView

func AsInputView(v View, err error) (*InputView, error)

func (*InputView) Slice

func (v *InputView) Slice(start uint64, end uint64) ([]byte, error)

type MemoryView

type MemoryView struct {
	*ComplexListView
}

func AsMemoryView

func AsMemoryView(v View, err error) (*MemoryView, error)

func (*MemoryView) AppendZeroByte

func (v *MemoryView) AppendZeroByte() error

func (*MemoryView) AppendZeroBytes32

func (v *MemoryView) AppendZeroBytes32() error

func (*MemoryView) GetByte

func (v *MemoryView) GetByte(i uint64) (byte, error)

func (*MemoryView) SetByte

func (v *MemoryView) SetByte(i uint64, w byte) error

type Operation

type Operation struct {
	Proc Processor
	// contains filtered or unexported fields
}

func DefaultJumpTable

func DefaultJumpTable() [256]*Operation

type OptiTracer

type OptiTracer struct {
	Steps []*Step
}

func (*OptiTracer) CaptureEnd

func (o *OptiTracer) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error)

func (*OptiTracer) CaptureFault

func (o *OptiTracer) CaptureFault(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, depth int, err error)

func (*OptiTracer) CaptureStart

func (o *OptiTracer) CaptureStart(env *vm.EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int)

func (*OptiTracer) CaptureState

func (o *OptiTracer) CaptureState(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, rData []byte, depth int, err error)

type Processor

type Processor func(trac StepsTrace) (*StepView, error)

Takes a trace, and produces the next step

func MakePush

func MakePush(size uint64, pushByteSize uint64) Processor

type RetDataView

type RetDataView struct {
	*ComplexListView
}

func AsRetDataView

func AsRetDataView(v View, err error) (*RetDataView, error)

func EmptyReturnData

func EmptyReturnData() *RetDataView

func (*RetDataView) GetWord

func (v *RetDataView) GetWord(i uint64) ([32]byte, error)

func (*RetDataView) SetWord

func (v *RetDataView) SetWord(i uint64, w [32]byte) error

type Rules

type Rules struct {
	ChainID                                                 *big.Int
	IsHomestead, IsEIP150, IsEIP155, IsEIP158               bool
	IsByzantium, IsConstantinople, IsPetersburg, IsIstanbul bool
	IsBerlin, IsLondon                                      bool
}

type StackView

type StackView struct {
	*ComplexListView
}

func AsStackView

func AsStackView(v View, err error) (*StackView, error)

func (*StackView) Back

func (v *StackView) Back(n uint64) ([32]byte, error)

func (*StackView) GetWord

func (v *StackView) GetWord(i uint64) ([32]byte, error)

func (*StackView) PopWord

func (v *StackView) PopWord() error

func (*StackView) PushWord

func (v *StackView) PushWord(w [32]byte) error

func (*StackView) SetWord

func (v *StackView) SetWord(i uint64, w [32]byte) error

type Step

type Step struct {
	Data *StepView

	// nil if unused
	AccountProof [][]byte
	// nil if unused, requires account-proof
	StorageProof [][]byte
}

func (*Step) Copy

func (step *Step) Copy() (*Step, error)

func (*Step) MultiProof

func (step *Step) MultiProof() [][]common.Hash

func (*Step) Root

func (step *Step) Root() common.Hash

type StepView

type StepView struct {
	*ContainerView
}

func AsStep

func AsStep(v View, err error) (*StepView, error)

func OpPop

func OpPop(trac StepsTrace) (*StepView, error)

func OpStop

func OpStop(trac StepsTrace) (*StepView, error)

func (*StepView) CopyView

func (v *StepView) CopyView() (*StepView, error)

func (*StepView) GetBaseFee

func (v *StepView) GetBaseFee() ([32]byte, error)

func (*StepView) GetBlockHashes

func (v *StepView) GetBlockHashes() (*HistView, error)

func (*StepView) GetBlockNumber

func (v *StepView) GetBlockNumber() (uint64, error)

func (*StepView) GetCallDepth

func (v *StepView) GetCallDepth() (uint64, error)

func (*StepView) GetCaller

func (v *StepView) GetCaller() (Address, error)

func (*StepView) GetCode

func (v *StepView) GetCode() (*CodeView, error)

func (*StepView) GetCodeAddr

func (v *StepView) GetCodeAddr() (Address, error)

func (*StepView) GetCodeHash

func (v *StepView) GetCodeHash() ([32]byte, error)

func (*StepView) GetCoinbase

func (v *StepView) GetCoinbase() (Address, error)

func (*StepView) GetCreate

func (v *StepView) GetCreate() (bool, error)

func (*StepView) GetDifficulty

func (v *StepView) GetDifficulty() ([32]byte, error)

func (*StepView) GetExecMode

func (v *StepView) GetExecMode() (ExecMode, error)

func (*StepView) GetGas

func (v *StepView) GetGas() (uint64, error)

func (*StepView) GetGasLimit

func (v *StepView) GetGasLimit() (uint64, error)

func (*StepView) GetGasPrice

func (v *StepView) GetGasPrice() (uint64, error)

func (*StepView) GetInput

func (v *StepView) GetInput() (*InputView, error)

func (*StepView) GetMemDesired

func (v *StepView) GetMemDesired() (uint64, error)

func (*StepView) GetMemLastGas

func (v *StepView) GetMemLastGas() (uint64, error)

func (*StepView) GetMemory

func (v *StepView) GetMemory() (*MemoryView, error)

func (*StepView) GetOp

func (v *StepView) GetOp() (vm.OpCode, error)

func (*StepView) GetOrigin

func (v *StepView) GetOrigin() (Address, error)

func (*StepView) GetPc

func (v *StepView) GetPc() (uint64, error)

func (*StepView) GetReadOnly

func (v *StepView) GetReadOnly() (bool, error)

func (*StepView) GetRetData

func (v *StepView) GetRetData() (*RetDataView, error)

func (*StepView) GetReturnToStep

func (v *StepView) GetReturnToStep() (uint64, error)

func (*StepView) GetStack

func (v *StepView) GetStack() (*StackView, error)

func (*StepView) GetStateRoot

func (v *StepView) GetStateRoot() ([32]byte, error)

func (*StepView) GetSubData

func (v *StepView) GetSubData() (*SubDataView, error)

func (*StepView) GetSubIndex

func (v *StepView) GetSubIndex() (uint64, error)

func (*StepView) GetSubRemaining

func (v *StepView) GetSubRemaining() (bool, error)

func (*StepView) GetTime

func (v *StepView) GetTime() (uint64, error)

func (*StepView) GetTo

func (v *StepView) GetTo() (Address, error)

func (*StepView) GetTxIndex

func (v *StepView) GetTxIndex() (uint64, error)

func (*StepView) GetValue

func (v *StepView) GetValue() ([32]byte, error)

func (*StepView) IncrementPC

func (step *StepView) IncrementPC() error

func (*StepView) ReturnGas

func (step *StepView) ReturnGas(delta uint64) error

func (*StepView) SetBaseFee

func (v *StepView) SetBaseFee(p [32]byte) error

func (*StepView) SetBlockHashes

func (v *StepView) SetBlockHashes(p *HistView) error

func (*StepView) SetBlockNumber

func (v *StepView) SetBlockNumber(p uint64) error

func (*StepView) SetCallDepth

func (v *StepView) SetCallDepth(p uint64) error

func (*StepView) SetCaller

func (v *StepView) SetCaller(p Address) error

func (*StepView) SetCode

func (v *StepView) SetCode(p *CodeView) error

func (*StepView) SetCodeAddr

func (v *StepView) SetCodeAddr(p Address) error

func (*StepView) SetCodeHash

func (v *StepView) SetCodeHash(p [32]byte) error

func (*StepView) SetCoinbase

func (v *StepView) SetCoinbase(p Address) error

func (*StepView) SetCreate

func (v *StepView) SetCreate(p bool) error

func (*StepView) SetDifficulty

func (v *StepView) SetDifficulty(p [32]byte) error

func (*StepView) SetExecMode

func (v *StepView) SetExecMode(p ExecMode) error

func (*StepView) SetGas

func (v *StepView) SetGas(p uint64) error

func (*StepView) SetGasLimit

func (v *StepView) SetGasLimit(p uint64) error

func (*StepView) SetGasPrice

func (v *StepView) SetGasPrice(p uint64) error

func (*StepView) SetInput

func (v *StepView) SetInput(p *InputView) error

func (*StepView) SetMemDesired

func (v *StepView) SetMemDesired(p uint64) error

func (*StepView) SetMemLastGas

func (v *StepView) SetMemLastGas(p uint64) error

func (*StepView) SetMemory

func (v *StepView) SetMemory(p *MemoryView) error

func (*StepView) SetOp

func (v *StepView) SetOp(p vm.OpCode) error

func (*StepView) SetOrigin

func (v *StepView) SetOrigin(p Address) error

func (*StepView) SetPc

func (v *StepView) SetPc(p uint64) error

func (*StepView) SetReadOnly

func (v *StepView) SetReadOnly(p bool) error

func (*StepView) SetRetData

func (v *StepView) SetRetData(p *RetDataView) error

func (*StepView) SetReturnToStep

func (v *StepView) SetReturnToStep(p uint64) error

func (*StepView) SetStack

func (v *StepView) SetStack(p *StackView) error

func (*StepView) SetStateRoot

func (v *StepView) SetStateRoot(p [32]byte) error

func (*StepView) SetSubData

func (v *StepView) SetSubData(p *SubDataView) error

func (*StepView) SetSubIndex

func (v *StepView) SetSubIndex(p uint64) error

func (*StepView) SetSubRemaining

func (v *StepView) SetSubRemaining(p bool) error

func (*StepView) SetTime

func (v *StepView) SetTime(p uint64) error

func (*StepView) SetTo

func (v *StepView) SetTo(p Address) error

func (*StepView) SetTxIndex

func (v *StepView) SetTxIndex(p uint64) error

func (*StepView) SetValue

func (v *StepView) SetValue(p [32]byte) error

func (*StepView) UseGas

func (step *StepView) UseGas(delta uint64) (ok bool, err error)

type Steps

type Steps []*StepView

func (*Steps) Append

func (steps *Steps) Append(step *StepView) error

func (*Steps) ByIndex

func (steps *Steps) ByIndex(i uint64) *StepView

func (*Steps) Last

func (steps *Steps) Last() *StepView

func (*Steps) Length

func (steps *Steps) Length() uint64

type StepsTrace

type StepsTrace interface {
	// nil if empty steps
	Last() *StepView
	// nil if invalid index
	ByIndex(i uint64) *StepView
	Length() uint64
}

func GenerateProof

func GenerateProof(code []byte, value [32]byte, from Address, to Address, gas uint64) (StepsTrace, error)

type SubDataView

type SubDataView struct {
	*ComplexVectorView
}

func AsSubDataView

func AsSubDataView(v View, err error) (*SubDataView, error)

func (*SubDataView) GetWord

func (v *SubDataView) GetWord(i uint64) ([32]byte, error)

func (*SubDataView) SetWord

func (v *SubDataView) SetWord(i uint64, w [32]byte) error

type VerifierStateDB

type VerifierStateDB interface {
	vm.StateDB
	GetProof(addr common.Address) ([][]byte, error)
	GetProofByHash(addrHash common.Hash) ([][]byte, error)
	GetStorageProof(a common.Address, key common.Hash) ([][]byte, error)
	IntermediateRoot(deleteEmptyObjects bool) common.Hash
}

type WritableStepsTrace

type WritableStepsTrace interface {
	StepsTrace
	Append(step *StepView) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL