|
|
@ -27,14 +27,14 @@ import ( |
|
|
|
|
|
|
|
|
|
|
|
// Call executes within the given contract
|
|
|
|
// Call executes within the given contract
|
|
|
|
func Call(env vm.Environment, caller vm.ContractRef, addr common.Address, input []byte, gas, gasPrice, value *big.Int) (ret []byte, err error) { |
|
|
|
func Call(env vm.Environment, caller vm.ContractRef, addr common.Address, input []byte, gas, gasPrice, value *big.Int) (ret []byte, err error) { |
|
|
|
ret, _, err = exec(env, caller, &addr, &addr, input, env.Db().GetCode(addr), gas, gasPrice, value) |
|
|
|
ret, _, err = exec(env, caller, &addr, &addr, env.Db().GetCodeHash(addr), input, env.Db().GetCode(addr), gas, gasPrice, value) |
|
|
|
return ret, err |
|
|
|
return ret, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// CallCode executes the given address' code as the given contract address
|
|
|
|
// CallCode executes the given address' code as the given contract address
|
|
|
|
func CallCode(env vm.Environment, caller vm.ContractRef, addr common.Address, input []byte, gas, gasPrice, value *big.Int) (ret []byte, err error) { |
|
|
|
func CallCode(env vm.Environment, caller vm.ContractRef, addr common.Address, input []byte, gas, gasPrice, value *big.Int) (ret []byte, err error) { |
|
|
|
callerAddr := caller.Address() |
|
|
|
callerAddr := caller.Address() |
|
|
|
ret, _, err = exec(env, caller, &callerAddr, &addr, input, env.Db().GetCode(addr), gas, gasPrice, value) |
|
|
|
ret, _, err = exec(env, caller, &callerAddr, &addr, env.Db().GetCodeHash(addr), input, env.Db().GetCode(addr), gas, gasPrice, value) |
|
|
|
return ret, err |
|
|
|
return ret, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -43,13 +43,13 @@ func DelegateCall(env vm.Environment, caller vm.ContractRef, addr common.Address |
|
|
|
callerAddr := caller.Address() |
|
|
|
callerAddr := caller.Address() |
|
|
|
originAddr := env.Origin() |
|
|
|
originAddr := env.Origin() |
|
|
|
callerValue := caller.Value() |
|
|
|
callerValue := caller.Value() |
|
|
|
ret, _, err = execDelegateCall(env, caller, &originAddr, &callerAddr, &addr, input, env.Db().GetCode(addr), gas, gasPrice, callerValue) |
|
|
|
ret, _, err = execDelegateCall(env, caller, &originAddr, &callerAddr, &addr, env.Db().GetCodeHash(addr), input, env.Db().GetCode(addr), gas, gasPrice, callerValue) |
|
|
|
return ret, err |
|
|
|
return ret, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Create creates a new contract with the given code
|
|
|
|
// Create creates a new contract with the given code
|
|
|
|
func Create(env vm.Environment, caller vm.ContractRef, code []byte, gas, gasPrice, value *big.Int) (ret []byte, address common.Address, err error) { |
|
|
|
func Create(env vm.Environment, caller vm.ContractRef, code []byte, gas, gasPrice, value *big.Int) (ret []byte, address common.Address, err error) { |
|
|
|
ret, address, err = exec(env, caller, nil, nil, nil, code, gas, gasPrice, value) |
|
|
|
ret, address, err = exec(env, caller, nil, nil, crypto.Keccak256Hash(code), nil, code, gas, gasPrice, value) |
|
|
|
// Here we get an error if we run into maximum stack depth,
|
|
|
|
// Here we get an error if we run into maximum stack depth,
|
|
|
|
// See: https://github.com/ethereum/yellowpaper/pull/131
|
|
|
|
// See: https://github.com/ethereum/yellowpaper/pull/131
|
|
|
|
// and YP definitions for CREATE instruction
|
|
|
|
// and YP definitions for CREATE instruction
|
|
|
@ -59,7 +59,7 @@ func Create(env vm.Environment, caller vm.ContractRef, code []byte, gas, gasPric |
|
|
|
return ret, address, err |
|
|
|
return ret, address, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func exec(env vm.Environment, caller vm.ContractRef, address, codeAddr *common.Address, input, code []byte, gas, gasPrice, value *big.Int) (ret []byte, addr common.Address, err error) { |
|
|
|
func exec(env vm.Environment, caller vm.ContractRef, address, codeAddr *common.Address, codeHash common.Hash, input, code []byte, gas, gasPrice, value *big.Int) (ret []byte, addr common.Address, err error) { |
|
|
|
evm := env.Vm() |
|
|
|
evm := env.Vm() |
|
|
|
// Depth check execution. Fail if we're trying to execute above the
|
|
|
|
// Depth check execution. Fail if we're trying to execute above the
|
|
|
|
// limit.
|
|
|
|
// limit.
|
|
|
@ -105,7 +105,7 @@ func exec(env vm.Environment, caller vm.ContractRef, address, codeAddr *common.A |
|
|
|
// EVM. The contract is a scoped environment for this execution context
|
|
|
|
// EVM. The contract is a scoped environment for this execution context
|
|
|
|
// only.
|
|
|
|
// only.
|
|
|
|
contract := vm.NewContract(caller, to, value, gas, gasPrice) |
|
|
|
contract := vm.NewContract(caller, to, value, gas, gasPrice) |
|
|
|
contract.SetCallCode(codeAddr, code) |
|
|
|
contract.SetCallCode(codeAddr, codeHash, code) |
|
|
|
defer contract.Finalise() |
|
|
|
defer contract.Finalise() |
|
|
|
|
|
|
|
|
|
|
|
ret, err = evm.Run(contract, input) |
|
|
|
ret, err = evm.Run(contract, input) |
|
|
@ -135,7 +135,7 @@ func exec(env vm.Environment, caller vm.ContractRef, address, codeAddr *common.A |
|
|
|
return ret, addr, err |
|
|
|
return ret, addr, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func execDelegateCall(env vm.Environment, caller vm.ContractRef, originAddr, toAddr, codeAddr *common.Address, input, code []byte, gas, gasPrice, value *big.Int) (ret []byte, addr common.Address, err error) { |
|
|
|
func execDelegateCall(env vm.Environment, caller vm.ContractRef, originAddr, toAddr, codeAddr *common.Address, codeHash common.Hash, input, code []byte, gas, gasPrice, value *big.Int) (ret []byte, addr common.Address, err error) { |
|
|
|
evm := env.Vm() |
|
|
|
evm := env.Vm() |
|
|
|
// Depth check execution. Fail if we're trying to execute above the
|
|
|
|
// Depth check execution. Fail if we're trying to execute above the
|
|
|
|
// limit.
|
|
|
|
// limit.
|
|
|
@ -155,7 +155,7 @@ func execDelegateCall(env vm.Environment, caller vm.ContractRef, originAddr, toA |
|
|
|
|
|
|
|
|
|
|
|
// Iinitialise a new contract and make initialise the delegate values
|
|
|
|
// Iinitialise a new contract and make initialise the delegate values
|
|
|
|
contract := vm.NewContract(caller, to, value, gas, gasPrice).AsDelegate() |
|
|
|
contract := vm.NewContract(caller, to, value, gas, gasPrice).AsDelegate() |
|
|
|
contract.SetCallCode(codeAddr, code) |
|
|
|
contract.SetCallCode(codeAddr, codeHash, code) |
|
|
|
defer contract.Finalise() |
|
|
|
defer contract.Finalise() |
|
|
|
|
|
|
|
|
|
|
|
ret, err = evm.Run(contract, input) |
|
|
|
ret, err = evm.Run(contract, input) |
|
|
|