nimbus-eth1/nimbus
Jamie Lokier 6ef9bfd21b
EVMC: Byte-endian conversions for 256-bit numeric values
Perform byte-endian conversion for 256-bit numeric values, but not 256-bit
hashes.  These conversions are necessary for EVMC binary compatibility.

In new EVMC, all host-side conversions are explicit, calling `flip256`.

These conversions are performed in the EVMC "glue" code, which deals with the
binary interface, so the host services aren't aware of conversions.

We intend to skip these conversions when Nimbus host calls Nimbus EVM, even
when it's a shared library, using a negotiated EVMC extension.  But for now
we're focused on correctness and cross-validation with third party EVMs.

The overhead of endian conversion is not too high because most EVMC host calls
access the database anyway.  `getTxContext` does not, so the conversions from
that are cached here.  Also, well-optimised EVMs don't call it often.

It is arguable whether endian conversion should occur for storage slots (`key`).

In favour of no conversion: Slot keys are 32-byte blobs, and this is clear in
the EVMC definition where slot keys are `evmc_bytes32` (not `evmc_uint256be`),
meaning treating as a number is _not_ expected by EVMC.  Although they are
often small numbers, sometimes they are a hash from the contract code plus a
number.  Slot keys are hashed on the host side with Keccak256 before any
database calls, so the host side does not look at them numerically.

In favour of conversion: They are often small numbers and it is helpful to log
them as such, rather than a long string of zero digits with 1-2 non-zero.  The
representation in JSON has leading zeros removed, like a number rather than a
32-byte blob.  There is also an interesting space optimisation when the keys
are used unhashed in storage.

Nimbus currently treats slot keys on the host side as numbers, and the tests
pass when endian conversion is done.  So to remain consistent with other parts
of Nimbus we convert slot keys.

Signed-off-by: Jamie Lokier <jamie@shareable.org>
2021-12-10 16:23:27 +00:00
..
accounts config: remove accounts management from NimbusConfiguration 2021-09-07 22:02:29 +07:00
db move stateDB from VMState to chainDB 2021-10-28 18:57:08 +07:00
graphql unify evm call for both json-rpc and graphql 2021-10-31 12:24:40 +07:00
p2p Arrow Glacier fork 2021-12-10 13:40:51 +00:00
rpc unify evm call for both json-rpc and graphql 2021-10-31 12:24:40 +07:00
sync code cleanup removed unused imports 2021-08-18 10:35:36 +07:00
transaction EVMC: Byte-endian conversions for 256-bit numeric values 2021-12-10 16:23:27 +00:00
utils Arrow Glacier fork 2021-12-10 13:40:51 +00:00
vm EVMC: Byte-endian conversions for 256-bit numeric values 2021-12-10 16:23:27 +00:00
vm2 move stateDB from VMState to chainDB 2021-10-28 18:57:08 +07:00
block_types.nim reduce compiler warnings 2019-11-13 21:49:39 +07:00
chain_config.nim Arrow Glacier fork 2021-12-10 13:40:51 +00:00
conf_utils.nim config: replace stdlib parseOpt with nim-confutils 2021-09-18 17:34:46 +07:00
config.nim config: fix new config based on input from jamie and zahary 2021-09-18 17:34:51 +07:00
constants.nim unify evm call for both json-rpc and graphql 2021-10-31 12:24:40 +07:00
context.nim config: remove global rng from NimbusConfiguration 2021-09-07 22:02:29 +07:00
errors.nim remove unused eraseReturnData 2020-01-20 18:36:58 +02:00
forks.nim preparation for London hard fork 2021-06-29 07:34:45 +07:00
genesis.nim Run everything fluffy with chronosStrictException (#889) 2021-11-18 17:52:44 +01:00
genesis_alloc.nim add goerli testnet genesis data[skip ci] 2020-04-09 19:13:17 +03:00
launcher.nim Premix-related changes 2019-01-28 12:38:23 +02:00
lightchain_shell.nim Some renames 2018-05-28 13:22:28 +03:00
makefile Basic tests for Clique PoA/Consensus engine 2021-06-17 08:03:57 +01:00
nim.cfg NAT port mapping 2019-04-17 03:56:28 +02:00
nimbus.nim fixes related to nim-json-rpc bump 2021-11-30 14:13:20 +07:00
sealer.nim config: replace stdlib parseOpt with nim-confutils 2021-09-18 17:34:46 +07:00
tracer.nim move stateDB from VMState to chainDB 2021-10-28 18:57:08 +07:00
transaction.nim EIP-3529: Reduce the max gas refunded after a transaction 2021-06-29 07:37:17 +07:00
utils.nim config: remove accounts management from NimbusConfiguration 2021-09-07 22:02:29 +07:00
validation.nim reduce compiler warnings 2019-11-13 21:49:39 +07:00
vm_compile_info.nim config: replace stdlib parseOpt with nim-confutils 2021-09-18 17:34:46 +07:00
vm_computation.nim EVM: Apply EIP-6 in the code (affects both vm and vm2) 2021-06-08 15:36:30 +01:00
vm_gas_costs.nim EIP-3529: Replace SSTORE_CLEARS_SCHEDULE 2021-06-29 07:37:17 +07:00
vm_internals.nim vm2: Remove vm2 `forks_list` everywhere, use common forks list 2021-06-08 15:36:31 +01:00
vm_precompiles.nim re-named some v2*.nim sources to its original name *.nim (without the v2) 2021-04-28 15:24:14 +03:00
vm_state.nim cleanup: remove unused accessLogs code from vm_state 2021-10-28 11:30:18 +07:00
vm_state_transactions.nim Transaction: Prepare txRefundGas to support txCallEvm 2021-05-03 19:51:20 +01:00
vm_types.nim cleanup: remove unused accessLogs code from vm_state 2021-10-28 11:30:18 +07:00