Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
link33
plugin
Commits
79063dca
Commit
79063dca
authored
Aug 20, 2021
by
hezhengjun
Committed by
vipwzw
Aug 23, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
correct contract address generate mechanism for instruction opCreteate
parent
ac92b7a5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
8 additions
and
24 deletions
+8
-24
evm.go
plugin/dapp/evm/executor/evm.go
+2
-1
exec.go
plugin/dapp/evm/executor/exec.go
+1
-1
crypto.go
plugin/dapp/evm/executor/vm/common/crypto/crypto.go
+0
-19
evm.go
plugin/dapp/evm/executor/vm/runtime/evm.go
+3
-0
instructions.go
plugin/dapp/evm/executor/vm/runtime/instructions.go
+2
-3
No files found.
plugin/dapp/evm/executor/evm.go
View file @
79063dca
...
@@ -182,7 +182,7 @@ func (evm *EVMExecutor) GetVMConfig() *runtime.Config {
...
@@ -182,7 +182,7 @@ func (evm *EVMExecutor) GetVMConfig() *runtime.Config {
}
}
// NewEVMContext 构造一个新的EVM上下文对象
// 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
{
return
runtime
.
Context
{
CanTransfer
:
CanTransfer
,
CanTransfer
:
CanTransfer
,
Transfer
:
Transfer
,
Transfer
:
Transfer
,
...
@@ -194,5 +194,6 @@ func (evm *EVMExecutor) NewEVMContext(msg *common.Message) runtime.Context {
...
@@ -194,5 +194,6 @@ func (evm *EVMExecutor) NewEVMContext(msg *common.Message) runtime.Context {
Difficulty
:
new
(
big
.
Int
)
.
SetUint64
(
evm
.
GetDifficulty
()),
Difficulty
:
new
(
big
.
Int
)
.
SetUint64
(
evm
.
GetDifficulty
()),
GasLimit
:
msg
.
GasLimit
(),
GasLimit
:
msg
.
GasLimit
(),
GasPrice
:
msg
.
GasPrice
(),
GasPrice
:
msg
.
GasPrice
(),
TxHash
:
txHash
,
}
}
}
}
plugin/dapp/evm/executor/exec.go
View file @
79063dca
...
@@ -37,7 +37,7 @@ func (evm *EVMExecutor) Exec(tx *types.Transaction, index int) (*types.Receipt,
...
@@ -37,7 +37,7 @@ func (evm *EVMExecutor) Exec(tx *types.Transaction, index int) (*types.Receipt,
// readOnly 是否只读调用,仅执行evm abi查询时为true
// readOnly 是否只读调用,仅执行evm abi查询时为true
func
(
evm
*
EVMExecutor
)
innerExec
(
msg
*
common
.
Message
,
txHash
[]
byte
,
index
int
,
txFee
int64
,
readOnly
bool
)
(
receipt
*
types
.
Receipt
,
err
error
)
{
func
(
evm
*
EVMExecutor
)
innerExec
(
msg
*
common
.
Message
,
txHash
[]
byte
,
index
int
,
txFee
int64
,
readOnly
bool
)
(
receipt
*
types
.
Receipt
,
err
error
)
{
// 获取当前区块的上下文信息构造EVM上下文
// 获取当前区块的上下文信息构造EVM上下文
context
:=
evm
.
NewEVMContext
(
msg
)
context
:=
evm
.
NewEVMContext
(
msg
,
txHash
)
cfg
:=
evm
.
GetAPI
()
.
GetConfig
()
cfg
:=
evm
.
GetAPI
()
.
GetConfig
()
// 创建EVM运行时对象
// 创建EVM运行时对象
env
:=
runtime
.
NewEVM
(
context
,
evm
.
mStateDB
,
*
evm
.
vmCfg
,
cfg
)
env
:=
runtime
.
NewEVM
(
context
,
evm
.
mStateDB
,
*
evm
.
vmCfg
,
cfg
)
...
...
plugin/dapp/evm/executor/vm/common/crypto/crypto.go
View file @
79063dca
...
@@ -10,9 +10,6 @@ import (
...
@@ -10,9 +10,6 @@ import (
ethCrypto
"github.com/ethereum/go-ethereum/crypto"
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/33cn/plugin/plugin/dapp/evm/executor/vm/common"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/btcec"
"golang.org/x/crypto/sha3"
"golang.org/x/crypto/sha3"
...
@@ -46,22 +43,6 @@ func SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error) {
...
@@ -46,22 +43,6 @@ func SigToPub(hash, sig []byte) (*ecdsa.PublicKey, error) {
return
(
*
ecdsa
.
PublicKey
)(
pub
),
err
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 哈希
// Keccak256 计算并返回 Keccak256 哈希
func
Keccak256
(
data
...
[]
byte
)
[]
byte
{
func
Keccak256
(
data
...
[]
byte
)
[]
byte
{
d
:=
sha3
.
NewLegacyKeccak256
()
d
:=
sha3
.
NewLegacyKeccak256
()
...
...
plugin/dapp/evm/executor/vm/runtime/evm.go
View file @
79063dca
...
@@ -70,6 +70,9 @@ type Context struct {
...
@@ -70,6 +70,9 @@ type Context struct {
// GasLimit 指令,当前交易的GasLimit
// GasLimit 指令,当前交易的GasLimit
GasLimit
uint64
GasLimit
uint64
// TxHash
TxHash
[]
byte
// BlockNumber NUMBER 指令,当前区块高度
// BlockNumber NUMBER 指令,当前区块高度
BlockNumber
*
big
.
Int
BlockNumber
*
big
.
Int
// Time 指令, 当前区块打包时间
// Time 指令, 当前区块打包时间
...
...
plugin/dapp/evm/executor/vm/runtime/instructions.go
View file @
79063dca
...
@@ -631,10 +631,9 @@ func opCreate(pc *uint64, evm *EVM, callContext *callCtx) ([]byte, error) {
...
@@ -631,10 +631,9 @@ func opCreate(pc *uint64, evm *EVM, callContext *callCtx) ([]byte, error) {
callContext
.
contract
.
UseGas
(
gas
)
callContext
.
contract
.
UseGas
(
gas
)
stackvalue
:=
size
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,否则压栈创建出来的合约对象的地址
// 出错时压栈0,否则压栈创建出来的合约对象的地址
if
suberr
!=
nil
&&
suberr
!=
model
.
ErrCodeStoreOutOfGas
{
if
suberr
!=
nil
&&
suberr
!=
model
.
ErrCodeStoreOutOfGas
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment