Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evm integration #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pixelplex-dev
Copy link

Related requests:

filestar-project/specs-actors#7
filestar-project/geth#1
filestar-project/solidity#1

Background


The main goal is to add ability of smart managing data in filestar network. Smart-contracts is a convinient and efficient solution for it. The idea is to add implementation of Ethereum Virtual Machine (EVM) and ways to communicate with it from FileStar.

Proposal


First of all, it's a EVM realization. It's located at evm-adapter library and play a key role in our model.

//create new stateDB 
func NewEVM(chain types.ChainAdapter, config *types.Config) (*EVM, error)
​
//init with existing stateDB
func NewEVMWithStateDB(chain types.ChainAdapter, db types.StateDB, config *types.Config) (*EVM, error)


The ChainAdapter provides access to chain functionality.

type ChainAdapter interface {
	// Blockchain access
	//// Get block hash by block number
	GetBlockHashByNum(uint64) Hash
	// Address call suicide
	DeleteAddress(Address)
	// CallAddress
	CallAddress(Address, uint256.Int, []byte) ([]byte, error)
	// CreateContract
	CreateContract(from Address, code []byte, salt []byte, amount *big.Int) (ret []byte, contractAddr Address, leftOverGas uint64, err error)
	//  SetStateDB
	SetStateDB(StateDB)
	//  SetCleanPointer
	SetCleanPointer(bool)
​
	//Get Actor nonce
	GetNonce(Address) uint64
	//Set Actor nonce
	SetNonce(Address, uint64)
	// Balance managing
	//// Get balance by address
	GetBalance(Address) *big.Int
	//// Transfer tokens (from, to, value)
	TransferTokens(Address, Address, *big.Int)
}
  • GetBlockHashByNum - get block hash by block number, used by Solidity (opcode BLOCKHASH)
  • DeleteAddress - delete actor by address (opcode SUICIDE)
  • CallAddress - call actor method by address with params(params serialized with cBor, opcode CALLACTOR)
  • CreateContract - create new actor (opcode opCreate)
  • SetStateDB - set shared stateDB for evms (used for CallAddress and CreateContract)
  • SetCleanPointer - set flag for cleaning shared stateDB
  • GetNonce - get nonce from address
  • SetNonce - set nonce for address
  • GetBalance - get balance by address
  • TransferTokens - transfer tokens from sender to reciever

    To use EVM, at first, you need to implement this interface on your chain. It's like a bridge between lotus and EVM.

    Another important moment is a CallActor - Actor, for whose we create this bridge.

    actors/builtin/contract/contract_actor.go - here is new actor methods impl.
    And here is new structs:
type EvmLogs struct {
	// Consensus fields:
	// address of the contract that generated the event
	Address types.Address
	// list of topics provided by the contract.
	Topics []byte
	// supplied by the contract, usually ABI-encoded
	Data []byte// The Removed field is true if this log was reverted due to a chain reorganisation.
	// You must pay attention to this field if you receive logs through a filter query.
	Removed bool
}
​
// used as argument to new actor methods
type ContractParams struct {
	Code         []byte        // code of contract or call signature
	Value        lotusbig.Int  // value to transfer
	Salt         []byte        // salt if it is contract creation
	CommitStatus bool          // signaling, that need add changes to database
}
​
type ContractResult struct {
	Value   []byte          // return of evm call
	GasUsed int64           // amount of gas used
	Address types.Address   // address of new actor
	Logs    []EvmLogs       // logs generated by evm
}


Also, we add extra functionality for EVM - new operation code CALLACTOR, special for FileStar network. Now it's possible to call specific actor from solidity code for your own purposes.

Effect


It's really important for FileStar ecosystem in the way of managing data. this improvement is aimed at users. Now they are able to store, manage or manipulate with data in a new smart way. Observing the success of Ethereum, we hope that this technology will show itself well in practice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants