Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.
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
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ require (
github.com/ethereum/go-ethereum v1.10.12
github.com/jmoiron/sqlx v1.3.4
github.com/lib/pq v1.10.4
github.com/holiman/uint256 v1.2.0
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
)
582 changes: 582 additions & 0 deletions go.sum

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions state/batch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package state

// Batch
type Batch struct{}
34 changes: 34 additions & 0 deletions state/batchprocessor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package state

import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)

// BatchProcessor is used to process a batch of transactions
type BatchProcessor struct{}

// ProcessBatch processes all transactions inside a batch
func (b *BatchProcessor) ProcessBatch(batch Batch) error {
return nil
}

// ProcessTransaction processes a transaction inside a batch
func (b *BatchProcessor) ProcessTransaction(tx types.Transaction) error {
return nil
}

// CheckTransaction checks a transaction is valid inside a batch context
func (b *BatchProcessor) CheckTransaction(tx types.Transaction) error {
return nil
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm missing a function:
func (s *State) ConsolidateBatch(batch) error to update the info when a consolidated batch is detected

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method added

// Commits the batch state into state
func (b *BatchProcessor) Commit() (*common.Hash, *Proof, error) {
return nil, nil, nil
}

// Rollback does not apply batch state into state
func (b *BatchProcessor) Rollback() error {
return nil
}
8 changes: 8 additions & 0 deletions state/db/interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package db

// KeyValuer interface that a compatible DB backend should implement
type KeyValuer interface {
Put(key string, data []byte) error
// Get IMPORTANT: should return nil, nil in case of no data found!!!!
Get(key string) ([]byte, error)
}
4 changes: 4 additions & 0 deletions state/proof.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package state

// Proof
type Proof struct{}
10 changes: 10 additions & 0 deletions state/runtime/evm/evm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package evm

// EVM is the Ethereum Virtual Machine
type EVM struct {
}

// NewEVM creates a new EVM
func NewEVM() *EVM {
return &EVM{}
}
1 change: 1 addition & 0 deletions state/runtime/evm/intructions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package evm
75 changes: 75 additions & 0 deletions state/runtime/evm/memory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package evm

import "github.com/holiman/uint256"

type Memory struct {
data []byte
}

// NewMemory is the constructor
func NewMemory() *Memory {
return &Memory{}
}

// Set sets a value at memory offset
func (m *Memory) Set(offset uint64, size uint64, value []byte) {
if size > 0 {
if offset+size > uint64(len(m.data)) {
panic("invalid memory")
}
copy(m.data[offset:offset+size], value)
}
}

// Set32 sets the 32 bytes starting at offset to the value of val, left-padded with zeroes to
// 32 bytes.
func (m *Memory) Set32(offset uint64, val *uint256.Int) {
// length of store may never be less than offset + size.
// The store should be resized PRIOR to setting the memory
if offset+32 > uint64(len(m.data)) {
panic("invalid memory: store empty")
}
// Zero the memory area
copy(m.data[offset:offset+32], []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})
// Fill in relevant bits
val.WriteToSlice(m.data[offset:])
}

// Get returns size bytes from memory offset as a new slice
func (m *Memory) GetCopy(offset, size int64) (cpy []byte) {
if size == 0 {
return nil
}

if len(m.data) > int(offset) {
cpy = make([]byte, size)
copy(cpy, m.data[offset:offset+size])

return
}

return
}

// GetPtr returns size bytes from memory offset
func (m *Memory) GetPtr(offset, size int64) []byte {
if size == 0 {
return nil
}

if len(m.data) > int(offset) {
return m.data[offset : offset+size]
}

return nil
}

// Len returns the length of the backing slice
func (m *Memory) Len() int {
return len(m.data)
}

// Data returns the backing slice
func (m *Memory) Data() []byte {
return m.data
}
Loading