nimbus-eth1/nimbus/vm
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
..
interpreter evm: fixes EIP2929 opcodes 2021-09-22 11:58:06 +07:00
blake2b_f.nim
blscurve.nim bump submodules 2021-01-20 11:50:07 +07:00
code_stream.nim reset explicit import paths for local modules 2021-04-01 12:53:22 +01:00
computation.nim move stateDB from VMState to chainDB 2021-10-28 18:57:08 +07:00
evmc_api.nim EVMC: Add missing EIP-2929 (Berlin) functions to EVMC host 2021-08-11 19:47:34 +07:00
evmc_helpers.nim EVMC: Byte-endian conversions for 256-bit numeric values 2021-12-10 16:23:27 +00:00
evmc_host.nim move stateDB from VMState to chainDB 2021-10-28 18:57:08 +07:00
interpreter.nim EVM: Remove `vm_forks` everywhere, use common forks list instead 2021-06-08 15:36:31 +01:00
interpreter_dispatch.nim code cleanup removed unused imports 2021-08-18 10:35:36 +07:00
map_to_curve_g1.nim
memory.nim reset explicit import paths for local modules 2021-04-01 12:53:22 +01:00
message.nim reset explicit import paths for local modules 2021-04-01 12:53:22 +01:00
precompiles.nim Tracing: Remove some trace messages that occur a lot during sync 2021-07-27 14:12:55 +01:00
stack.nim reset explicit import paths for local modules 2021-04-01 12:53:22 +01:00
state.nim move stateDB from VMState to chainDB 2021-10-28 18:57:08 +07:00
state_transactions.nim code cleanup removed unused imports 2021-08-18 10:35:36 +07:00
transaction_tracer.nim move stateDB from VMState to chainDB 2021-10-28 18:57:08 +07:00
types.nim move stateDB from VMState to chainDB 2021-10-28 18:57:08 +07:00