mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-28 15:46:43 +00:00
Pass IsDelegateCall to precompile calls
This commit is contained in:
parent
db336b3fcb
commit
5d14fa58be
4 changed files with 12 additions and 12 deletions
|
|
@ -43,7 +43,7 @@ type PrecompiledContract interface {
|
|||
}
|
||||
|
||||
type DynamicGasPrecompiledContract interface {
|
||||
RunAndCalculateGas(evm *EVM, sender common.Address, input []byte, suppliedGas uint64) (ret []byte, remainingGas uint64, err error) // Run runs the precompiled contract and calculate gas dynamically
|
||||
RunAndCalculateGas(evm *EVM, sender common.Address, isDelegateCall bool, input []byte, suppliedGas uint64) (ret []byte, remainingGas uint64, err error) // Run runs the precompiled contract and calculate gas dynamically
|
||||
}
|
||||
|
||||
// PrecompiledContractsHomestead contains the default set of pre-compiled Ethereum
|
||||
|
|
@ -172,9 +172,9 @@ func ActivePrecompiles(rules params.Rules) []common.Address {
|
|||
// - the returned bytes,
|
||||
// - the _remaining_ gas,
|
||||
// - any error that occurred
|
||||
func RunPrecompiledContract(p PrecompiledContract, evm *EVM, sender common.Address, input []byte, suppliedGas uint64) (ret []byte, remainingGas uint64, err error) {
|
||||
func RunPrecompiledContract(p PrecompiledContract, evm *EVM, sender common.Address, isDelegateCall bool, input []byte, suppliedGas uint64) (ret []byte, remainingGas uint64, err error) {
|
||||
if dp, ok := p.(DynamicGasPrecompiledContract); ok {
|
||||
return dp.RunAndCalculateGas(evm, sender, input, suppliedGas)
|
||||
return dp.RunAndCalculateGas(evm, sender, isDelegateCall, input, suppliedGas)
|
||||
}
|
||||
gasCost := p.RequiredGas(input)
|
||||
if suppliedGas < gasCost {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ func FuzzPrecompiledContracts(f *testing.F) {
|
|||
return
|
||||
}
|
||||
inWant := string(input)
|
||||
vm.RunPrecompiledContract(p, nil, common.Address{}, input, gas)
|
||||
vm.RunPrecompiledContract(p, nil, common.Address{}, false, input, gas)
|
||||
if inHave := string(input); inWant != inHave {
|
||||
t.Errorf("Precompiled %v modified input data", a)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ func testPrecompiled(addr string, test precompiledTest, t *testing.T) {
|
|||
in := common.Hex2Bytes(test.Input)
|
||||
gas := p.RequiredGas(in)
|
||||
t.Run(fmt.Sprintf("%s-Gas=%d", test.Name, gas), func(t *testing.T) {
|
||||
if res, _, err := vm.RunPrecompiledContract(p, nil, common.Address{}, in, gas); err != nil {
|
||||
if res, _, err := vm.RunPrecompiledContract(p, nil, common.Address{}, false, in, gas); err != nil {
|
||||
t.Error(err)
|
||||
} else if common.Bytes2Hex(res) != test.Expected {
|
||||
t.Errorf("Expected %v, got %v", test.Expected, common.Bytes2Hex(res))
|
||||
|
|
@ -121,7 +121,7 @@ func testPrecompiledOOG(addr string, test precompiledTest, t *testing.T) {
|
|||
gas := p.RequiredGas(in) - 1
|
||||
|
||||
t.Run(fmt.Sprintf("%s-Gas=%d", test.Name, gas), func(t *testing.T) {
|
||||
_, _, err := vm.RunPrecompiledContract(p, nil, common.Address{}, in, gas)
|
||||
_, _, err := vm.RunPrecompiledContract(p, nil, common.Address{}, false, in, gas)
|
||||
if err.Error() != "out of gas" {
|
||||
t.Errorf("Expected error [out of gas], got [%v]", err)
|
||||
}
|
||||
|
|
@ -138,7 +138,7 @@ func testPrecompiledFailure(addr string, test precompiledFailureTest, t *testing
|
|||
in := common.Hex2Bytes(test.Input)
|
||||
gas := p.RequiredGas(in)
|
||||
t.Run(test.Name, func(t *testing.T) {
|
||||
_, _, err := vm.RunPrecompiledContract(p, nil, common.Address{}, in, gas)
|
||||
_, _, err := vm.RunPrecompiledContract(p, nil, common.Address{}, false, in, gas)
|
||||
if err.Error() != test.ExpectedError {
|
||||
t.Errorf("Expected error [%v], got [%v]", test.ExpectedError, err)
|
||||
}
|
||||
|
|
@ -170,7 +170,7 @@ func benchmarkPrecompiled(addr string, test precompiledTest, bench *testing.B) {
|
|||
bench.ResetTimer()
|
||||
for i := 0; i < bench.N; i++ {
|
||||
copy(data, in)
|
||||
res, _, err = vm.RunPrecompiledContract(p, nil, common.Address{}, data, reqGas)
|
||||
res, _, err = vm.RunPrecompiledContract(p, nil, common.Address{}, false, data, reqGas)
|
||||
}
|
||||
bench.StopTimer()
|
||||
elapsed := uint64(time.Since(start))
|
||||
|
|
|
|||
|
|
@ -232,7 +232,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
|
|||
}
|
||||
|
||||
if isPrecompile {
|
||||
ret, gas, err = RunPrecompiledContract(p, evm, caller.Address(), input, gas)
|
||||
ret, gas, err = RunPrecompiledContract(p, evm, caller.Address(), false, input, gas)
|
||||
} else {
|
||||
// Initialise a new contract and set the code that is to be used by the EVM.
|
||||
// The contract is a scoped environment for this execution context only.
|
||||
|
|
@ -295,7 +295,7 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte,
|
|||
|
||||
// It is allowed to call precompiles, even via delegatecall
|
||||
if p, isPrecompile := evm.precompile(addr); isPrecompile {
|
||||
ret, gas, err = RunPrecompiledContract(p, evm, caller.Address(), input, gas)
|
||||
ret, gas, err = RunPrecompiledContract(p, evm, caller.Address(), false, input, gas)
|
||||
} else {
|
||||
addrCopy := addr
|
||||
// Initialise a new contract and set the code that is to be used by the EVM.
|
||||
|
|
@ -343,7 +343,7 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by
|
|||
// NOTE: caller must, at all times be a contract. It should never happen
|
||||
// that caller is something other than a Contract.
|
||||
parent := caller.(*Contract)
|
||||
ret, gas, err = RunPrecompiledContract(p, evm, parent.CallerAddress, input, gas)
|
||||
ret, gas, err = RunPrecompiledContract(p, evm, parent.CallerAddress, true, input, gas)
|
||||
} else {
|
||||
addrCopy := addr
|
||||
// Initialise a new contract and make initialise the delegate values
|
||||
|
|
@ -392,7 +392,7 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte
|
|||
}
|
||||
|
||||
if p, isPrecompile := evm.precompile(addr); isPrecompile {
|
||||
ret, gas, err = RunPrecompiledContract(p, evm, caller.Address(), input, gas)
|
||||
ret, gas, err = RunPrecompiledContract(p, evm, caller.Address(), false, input, gas)
|
||||
} else {
|
||||
// At this point, we use a copy of address. If we don't, the go compiler will
|
||||
// leak the 'contract' to the outer scope, and make allocation for 'contract'
|
||||
|
|
|
|||
Loading…
Reference in a new issue