nimbus-eth1/nimbus/transaction
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
..
call_common.nim unify evm call for both json-rpc and graphql 2021-10-31 12:24:40 +07:00
call_evm.nim unify evm call for both json-rpc and graphql 2021-10-31 12:24:40 +07:00
evmc_host_glue.nim EVMC: Byte-endian conversions for 256-bit numeric values 2021-12-10 16:23:27 +00:00
evmc_vm_glue.nim EVMC: Binary compatibility on the VM side for calling `execute` 2021-06-08 18:29:39 +01:00
host_call_nested.nim EVMC: Byte-endian conversions for 256-bit numeric values 2021-12-10 16:23:27 +00:00
host_services.nim EVMC: Byte-endian conversions for 256-bit numeric values 2021-12-10 16:23:27 +00:00
host_trace.nim EVMC: Improve host call tracing and fix nested call C stack usage 2021-08-12 07:48:56 +07:00
host_types.nim EVMC: Use the same host interface for nested calls as top-level 2021-08-17 17:18:26 +01:00