-
Notifications
You must be signed in to change notification settings - Fork 5
feat: vm.PrecompiledStatefulContract can make CALLs
#40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This matches the pattern used by `ava-labs/coreth` `NativeAssetCall`.
| // | ||
| // ****** SECURITY ****** | ||
|
|
||
| var _ PrecompileEnvironment = (*evmCallArgs)(nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These have all been moved to the new environment type in environment.libevm.go.
| return e.callContract(call, addr, input, gas, value, opts...) | ||
| } | ||
|
|
||
| func (e *environment) callContract(typ callType, addr common.Address, input []byte, gas uint64, value *uint256.Int, opts ...CallOption) ([]byte, uint64, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is the primary implementation of the PR. Everything else was a necessary refactor to fix the Caller and Self addresses for the incoming call types.
Why this should be merged
Allow stateful precompiles to call other contracts; e.g. for
ava-labs/coreth'sNativeAssetCall.How this works
The
vm.PrecompileEnvironment.Call()method is added to mirrorvm.EVM.Call()in behaviour and in all syntax except the first argument,caller—the caller is the precompile itself, which is deterministic. An option to override the caller is included for backwards compatibility withNativeAssetCallbut it MUST NOT otherwise be used.Determining the correct
ContractRefto use as thecalleruncovered existing bugs in thelibevm.AddressContextvalues passed to the precompile. Specifically, theSelfandCalleraddresses underCallCode()andDelegateCall()invocation of the precompile were incorrect. These are fixed via a refactor to abstract env behaviour into a newenvironmenttype although most of this is existing code just in a new file. Note that this fix means that stateful precompiles now behave as Solidity developers expect (other than #41).The
evmCallArgsfield for read-write inheritance is replaced with a call-type field that indicates theEVMmethod through which the precompile was invoked. This implies RW inheritance (i.e.StaticCall()vs not) while also allowing other behaviour and simplifying the construction of anevmCallArgs.How this was tested
An integration test exercises typical behaviour of a precompile calling another contract: origin (EOA) -> regular bytecode contract -> precompile -> any other contract. This demonstrates plumbing of data as well as correct setting of the
caller.The existing test of new precompiles is updated to demonstrate the fix of the
AddressContextvalues.