Commit Graph

14 Commits

Author SHA1 Message Date
bmoo b09ad5cacb
code cleanup removed unused imports 2021-08-18 10:35:36 +07:00
jangko 472e4457e3
EIP-3529: Reduce the max gas refunded after a transaction
Previously max gas refunded was defined as gas_used div 2.
Here we name the constant 2 as MAX_REFUND_QUOTIENT and
change its value to 5.

The new equation will be: gas_used div MAX_REFUND_QUOTIENT
2021-06-29 07:37:17 +07:00
Jamie Lokier 0e2bc8408d
Transaction: Run all computations via EVMC `execute`
1. Send all EVM executions through the EVMC `execute` function.

   It leads to the same place in the end as calling `Computation` before, but
   `execute` is the API function used by all EVMC implementations, and it is
   very explicit what data is passed back and forth.

2. As a consequence this starts using the new `host_services` code from EVM, so
   this is a significant change to the paths used for account state processing.

3. Because we will have to remove the `newComputation` call on the host side,
   anticipating that the contract code is now saved in `host` instead of being
   copied around.  As it's saved in `host`, there is no need to pass it
   separately to `evmcExecComputation`.

Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-06-08 18:29:39 +01:00
Jamie Lokier d49fa0bb86
Transaction: Add "host services", accessors to host state from EVM
This provides "host services", functions provided by the application to an EVM.
They are a key part of EVMC compatibility, but we will switch to using these
with "native" EVM as well.

These are functions like `getStorage`, `setStorage` and `emitLog` for accessing
the account state, because the EVM is not allowed direct access to the database.

This code is adapted from `nimbus/vm/evmc_host.nim` and other places, but there
is more emphasis on being host-side only, no dependency on the EVM or
`Computation` type.  It uses `TransactionHost` and types in `host_types`.

These host services have two goals: To be compatible with EVMC, and to be a
good way for the Nimbus EVM to access the data it needs.  In our new Nimbus
internal architecture, the EVM will only access the databases and other
application state via these host service functions.

The reason for containing the EVM like this, even "native" EVM, is that having
one good interface to the data makes it a lot easier to change how the database
works, which is on the roadmap.

These functions almost have EVMC signatures, but they are not binary compatible
with EVMC.  (Binary compatibility is provided by another module).  It would be
fine for Nimbus EVM to call these functions directly when linked directly.

Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-06-08 18:29:39 +01:00
Jamie Lokier aee0fe39d2
EVM: Remove `vm_types2` everywhere, use common forks list instead
File `vm_types2` is obsolete.  Remove this file and divert all imports to the
common forks list outside the EVM, or in some cases they don't need it anyway.

Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-06-08 15:36:31 +01:00
Jamie Lokier b3a788c7ce
Transaction: Move contract address generation outside the EVM
The current EVM generates its own new contract addresses, and this is why there
are separate `msg.contractAddress` and `msg.codeAddress` fields in the
computation start message.

In EVMC, account updates are only allowed on the host side, including contract
generation, and the start message has one destination field, `msg.destination`.
The EVM cannot select addresses, only use them.  It's a sensible design.

The difference makes the current EVM incompatible with EVMC and its message
format, so this patch corrects the difference.  It moves contract address
generation to the host side.  This simplifies the EVM and its API a little.

(As an API change, this is incompatible with vm2, so it's guarded under
`evmc_enabled` to allow vm2 to continue to build and run at this time.  This is
also why there are fewer deletions than would otherwise be expected.)

Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-06-08 15:36:30 +01:00
Jamie Lokier beb750b8df
Transaction: Remove no longer used `setupComputation`
The last caller of `setupComputation` is gone, now that it's been replaced by
the single entry point for all EVM calls, `runComputation`.

With this removal, EVM's `Computation` type should no longer be used anywhere
outside the call module (except in some tests and the EVM itself).

Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-06-01 16:54:34 +01:00
Jamie Lokier 5fb3c51e5e Transaction: Skip balance & nonce updates option in `runComputation`
Add another flag to disable a processing step when a call doesn't come from
a real transaction:

- `noTransfer`: Don't update balances, nonces, code.

This is to support VM fixtures tests which require account balances and nonces
to be unchanged when running the account's code.

These tests call `c.executeOpcodes()`, an internal function of the EVM, instead
of the usual `c.execComputation()`.  It goes direct to the bytecode dispatcher,
skipping parts of `Computation` that are normally called.

But we can't keep calling `c.executeOpcodes()` and have a single entry point to
the VM, let alone an EVMC entry point.

`noTransfer` provides similar enough behaviour to calling `c.executeOpcodes()`
that these tests can use the new single entry point like everything else.

Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-06-01 18:40:41 +03:00
Jamie Lokier 306c8e92c2
Transaction: `runComputation` options for non-standard EVM behaviour
The following four flags are added, to change various steps in EVM processing
when a call doesn't come from a real transaction:

- `noIntrinsic`:  Don't charge intrinsic gas.
- `noAccessList`: Don't initialise EIP2929 access list.
- `noGasCharge`:  Don't charge sender account for gas.
- `noRefund`:     Don't apply gas refund/burn rule.

This is to support RPC and GraphQL `call` operations, which behave differently
in some ways from regular transaction calls, and to support some test suites.

In EVMC terms, all these alterations can be performed on the host side.

Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-05-29 08:23:19 +01:00
Jamie Lokier 12bf0fd346
Transaction: EIP-2930 (Berlin): Extra intrinsic gas for access list
Calculate extra intrinsic gas for an EIP-2930 transaction with access list.

While we're here, do the rest of the intrinsic gas calculation.  Make it clear,
explicit and in one place.  (Previous code delegated parts of the calculation
to `transaction.nim` but had to do the rest locally due to mismatched types.)

Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-05-29 06:54:19 +01:00
Jamie Lokier f6cc6e3ed1
Transaction: EIP-2930 (Berlin): Per-transaction extra access list
Add `accessList` to the `runComputation` API for EIP-2930 transactions.

Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-05-29 06:53:11 +01:00
Jamie Lokier 76031ccbe4
Transaction: EIP-2929 (Berlin): Initial access list
Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-05-29 06:53:11 +01:00
Jamie Lokier c6d50a0ef7
Transaction: Unified runner `runComputation` for all EVM call types
New entry point `runComputation`, for all EVM calls.
(Later the intent is `runComputationAsync`.)

As noted in commit 297d789, there are six entry points calling EVM computation,
with different parameters and expecting different behaviours.  Parameters were
dealt with in `setupComputation`.  Behaviours are unified in `runComputation`,
with options passed via `CallParams`.

This code performs the steps used when validating a transaction.  Options for
non-standard behaviour for RPC, GraphQL and tests to be added as required.

This replaces `setupComputation`, `execComputation` and `executeOpcodes`
(other than its own calls).  As a result `Computation` and other EVM types are
no longer referenced in the main program, and many imports can be dropped.

Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-05-29 06:53:11 +01:00
Jamie Lokier 94f95efd9e
Transaction: Move `setupComputation` to its own file
Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-05-29 06:53:11 +01:00