EVM兼容思路

EVM结构.png

对于EVM虚拟机,觉得可以从两方面进行抽象,实现拓展;

  1. VM层进行抽象,从根本上来说,EVM只对外暴漏了两个方法调用CallCreate.

    type VM interface{
        Create(caller types.ContractRef, code []byte, gas uint64, val sdk.Int) (ret []byte, contractAddr sdk.AccAddress, gasLeft uint64, err error)
      
        Call(caller types.ContractRef, toAddr sdk.AccAddress, input []byte, gas uint64, val sdk.Int) (ret []byte, gasLeft uint64, err error)
    }
    
  2. 解释器层抽象,解释器的功能比较单纯,给定合约和输入,得到输出。

    type Interpreter interface {
        Run(contract *Contract, input []byte, static bool) ([]byte, error)
    }
    
    

你可能感兴趣的:(EVM兼容思路)