mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 18:32:23 +00:00
eth/tracer: extend create2
This commit is contained in:
parent
e79821cabe
commit
2b46018eb6
4 changed files with 46 additions and 17 deletions
File diff suppressed because one or more lines are too long
|
|
@ -38,7 +38,7 @@
|
|||
var op = log.op.toString();
|
||||
}
|
||||
// If a new contract is being created, add to the call stack
|
||||
if (syscall && op == 'CREATE') {
|
||||
if (syscall && (op == 'CREATE' || op == "CREATE2")) {
|
||||
var inOff = log.stack.peek(1).valueOf();
|
||||
var inEnd = inOff + log.stack.peek(2).valueOf();
|
||||
|
||||
|
|
@ -116,7 +116,7 @@
|
|||
// Pop off the last call and get the execution results
|
||||
var call = this.callstack.pop();
|
||||
|
||||
if (call.type == 'CREATE') {
|
||||
if (call.type == 'CREATE' || call.type == "CREATE2") {
|
||||
// If the call was a CREATE, retrieve the contract address and output code
|
||||
call.gasUsed = '0x' + bigInt(call.gasIn - call.gasCost - log.getGas()).toString(16);
|
||||
delete call.gasIn; delete call.gasCost;
|
||||
|
|
|
|||
|
|
@ -86,6 +86,13 @@
|
|||
var from = log.contract.getAddress();
|
||||
this.lookupAccount(toContract(from, db.getNonce(from)), db);
|
||||
break;
|
||||
case "CREATE2":
|
||||
var from = log.contract.getAddress();
|
||||
// stack: salt, size, offset, endowment
|
||||
var offset = log.stack.peek(1).valueOf()
|
||||
var size = log.stack.peek(2).valueOf()
|
||||
this.lookupAccount(toContract2(from, log.stack.peek(3).toString(16), log.memory.slice(offset, size)), db);
|
||||
break;
|
||||
case "CALL": case "CALLCODE": case "DELEGATECALL": case "STATICCALL":
|
||||
this.lookupAccount(toAddress(log.stack.peek(1).toString(16)), db);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -367,6 +367,28 @@ func New(code string) (*Tracer, error) {
|
|||
copy(makeSlice(ctx.PushFixedBuffer(20), 20), contract[:])
|
||||
return 1
|
||||
})
|
||||
tracer.vm.PushGlobalGoFunction("toContract2", func(ctx *duktape.Context) int {
|
||||
var from common.Address
|
||||
if ptr, size := ctx.GetBuffer(-3); ptr != nil {
|
||||
from = common.BytesToAddress(makeSlice(ptr, size))
|
||||
} else {
|
||||
from = common.HexToAddress(ctx.GetString(-3))
|
||||
}
|
||||
// Retrieve salt hex string from js stack
|
||||
salt := common.HexToHash(ctx.GetString(-2))
|
||||
// Retrieve code slice from js stack
|
||||
var code []byte
|
||||
if ptr, size := ctx.GetBuffer(-1); ptr != nil {
|
||||
code = common.CopyBytes(makeSlice(ptr, size))
|
||||
} else {
|
||||
code = common.FromHex(ctx.GetString(-1))
|
||||
}
|
||||
codeHash := crypto.Keccak256(code)
|
||||
ctx.Pop3()
|
||||
contract := crypto.CreateAddress2(from, salt, codeHash)
|
||||
copy(makeSlice(ctx.PushFixedBuffer(20), 20), contract[:])
|
||||
return 1
|
||||
})
|
||||
tracer.vm.PushGlobalGoFunction("isPrecompiled", func(ctx *duktape.Context) int {
|
||||
_, ok := vm.PrecompiledContractsByzantium[common.BytesToAddress(popSlice(ctx))]
|
||||
ctx.PushBoolean(ok)
|
||||
|
|
|
|||
Loading…
Reference in a new issue