-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8ca5e37
commit a6c49dd
Showing
13 changed files
with
1,274 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
module github.com/hermeznetwork/hermez-core | ||
|
||
go 1.16 | ||
|
||
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package state | ||
|
||
// Batch | ||
type Batch struct{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
// 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package state | ||
|
||
// Proof | ||
type Proof struct{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package evm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.