eth/tracers: extend tracers for CREATE2

Signed-off-by: YaoZengzeng <yaozengzeng@zju.edu.cn>
This commit is contained in:
YaoZengzeng 2018-09-01 18:37:08 +08:00
parent 62e94895da
commit c49e754692
4 changed files with 34 additions and 16 deletions

File diff suppressed because one or more lines are too long

View file

@ -38,7 +38,7 @@
var op = log.op.toString(); var op = log.op.toString();
} }
// If a new contract is being created, add to the call stack // 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 inOff = log.stack.peek(1).valueOf();
var inEnd = inOff + log.stack.peek(2).valueOf(); var inEnd = inOff + log.stack.peek(2).valueOf();
@ -116,8 +116,8 @@
// Pop off the last call and get the execution results // Pop off the last call and get the execution results
var call = this.callstack.pop(); 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 // If the call was a CREATE or CREATE2, retrieve the contract address and output code
call.gasUsed = '0x' + bigInt(call.gasIn - call.gasCost - log.getGas()).toString(16); call.gasUsed = '0x' + bigInt(call.gasIn - call.gasCost - log.getGas()).toString(16);
delete call.gasIn; delete call.gasCost; delete call.gasIn; delete call.gasCost;

View file

@ -89,6 +89,9 @@
var from = log.contract.getAddress(); var from = log.contract.getAddress();
this.lookupAccount(toContract(from, db.getNonce(from)), db); this.lookupAccount(toContract(from, db.getNonce(from)), db);
break; break;
case "CREATE2":
var from = log.contract.getAddress();
this.lookupAccount(toContract2(from, log.stack.peek(3).toString(16), db.getCode(from)), db);
case "CALL": case "CALLCODE": case "DELEGATECALL": case "STATICCALL": case "CALL": case "CALLCODE": case "DELEGATECALL": case "STATICCALL":
this.lookupAccount(toAddress(log.stack.peek(1).toString(16)), db); this.lookupAccount(toAddress(log.stack.peek(1).toString(16)), db);
break; break;

View file

@ -365,6 +365,21 @@ func New(code string) (*Tracer, error) {
copy(makeSlice(ctx.PushFixedBuffer(20), 20), contract[:]) copy(makeSlice(ctx.PushFixedBuffer(20), 20), contract[:])
return 1 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))
}
salt := common.HexToHash(ctx.GetString(-2))
code := common.CopyBytes(makeSlice(ctx.GetBuffer(-1)))
ctx.Pop3()
contract := crypto.CreateAddress2(from, salt, code)
copy(makeSlice(ctx.PushFixedBuffer(20), 20), contract[:])
return 1
})
tracer.vm.PushGlobalGoFunction("isPrecompiled", func(ctx *duktape.Context) int { tracer.vm.PushGlobalGoFunction("isPrecompiled", func(ctx *duktape.Context) int {
_, ok := vm.PrecompiledContractsByzantium[common.BytesToAddress(popSlice(ctx))] _, ok := vm.PrecompiledContractsByzantium[common.BytesToAddress(popSlice(ctx))]
ctx.PushBoolean(ok) ctx.PushBoolean(ok)