Commit 79063dca authored by hezhengjun's avatar hezhengjun Committed by vipwzw

correct contract address generate mechanism for instruction opCreteate

parent ac92b7a5
......@@ -182,7 +182,7 @@ func (evm *EVMExecutor) GetVMConfig() *runtime.Config {
}
// NewEVMContext 构造一个新的EVM上下文对象
func (evm *EVMExecutor) NewEVMContext(msg *common.Message) runtime.Context {
func (evm *EVMExecutor) NewEVMContext(msg *common.Message, txHash []byte) runtime.Context {
return runtime.Context{
CanTransfer: CanTransfer,
Transfer: Transfer,
......@@ -194,5 +194,6 @@ func (evm *EVMExecutor) NewEVMContext(msg *common.Message) runtime.Context {
Difficulty: new(big.Int).SetUint64(evm.GetDifficulty()),
GasLimit: msg.GasLimit(),
GasPrice: msg.GasPrice(),
TxHash: txHash,
}
}
......@@ -37,7 +37,7 @@ func (evm *EVMExecutor) Exec(tx *types.Transaction, index int) (*types.Receipt,
// readOnly 是否只读调用,仅执行evm abi查询时为true
func (evm *EVMExecutor) innerExec(msg *common.Message, txHash []byte, index int, txFee int64, readOnly bool) (receipt *types.Receipt, err error) {
// 获取当前区块的上下文信息构造EVM上下文
context := evm.NewEVMContext(msg)
context := evm.NewEVMContext(msg, txHash)
cfg := evm.GetAPI().GetConfig()
// 创建EVM运行时对象
env := runtime.NewEVM(context, evm.mStateDB, *evm.vmCfg, cfg)
......
......@@ -10,9 +10,6 @@ import (
ethCrypto "github.com/ethereum/go-ethereum/crypto"
"github.com/33cn/chain33/common/address"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/types"
"github.com/33cn/plugin/plugin/dapp/evm/executor/vm/common"
"github.com/btcsuite/btcd/btcec"
"golang.org/x/crypto/sha3"
......@@ -46,22 +43,6 @@ func SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error) {
return (*ecdsa.PublicKey)(pub), err
}
// RandomContractAddress 随机生成一个新的地址,给新创建的合约地址使用
func RandomContractAddress() *common.Address {
c, err := crypto.New(types.GetSignName("", types.SECP256K1))
if err != nil {
return nil
}
key, err := c.GenKey()
if err != nil {
return nil
}
acc := address.PubKeyToAddress(key.PubKey().Bytes())
ret := common.StringToAddress(address.ExecAddress(acc.String()))
return ret
}
// Keccak256 计算并返回 Keccak256 哈希
func Keccak256(data ...[]byte) []byte {
d := sha3.NewLegacyKeccak256()
......
......@@ -70,6 +70,9 @@ type Context struct {
// GasLimit 指令,当前交易的GasLimit
GasLimit uint64
// TxHash
TxHash []byte
// BlockNumber NUMBER 指令,当前区块高度
BlockNumber *big.Int
// Time 指令, 当前区块打包时间
......
......@@ -631,10 +631,9 @@ func opCreate(pc *uint64, evm *EVM, callContext *callCtx) ([]byte, error) {
callContext.contract.UseGas(gas)
stackvalue := size
// 调用合约创建逻辑
addr := crypto.RandomContractAddress()
res, _, returnGas, suberr := evm.Create(callContext.contract, *addr, input, gas, "innerContract", "", value.Uint64())
addr := common.NewContractAddress(evm.Origin, evm.TxHash)
res, _, returnGas, suberr := evm.Create(callContext.contract, addr, input, gas, "innerContract", "", value.Uint64())
// 出错时压栈0,否则压栈创建出来的合约对象的地址
if suberr != nil && suberr != model.ErrCodeStoreOutOfGas {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment