mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-13 22:04:52 +00:00
d8a1adacaa
* Part of EIP-4895: add withdrawals processing to block processing.
* Refactoring: extracted the engine API handler bodies into procs.
Intending to implement the V2 versions next. (I need the bodies to be
in separate procs so that multiple versions can use them.)
* Working on Engine API changes for Shanghai.
* Updated nim-web3, resolved ambiguity in Hash256 type.
* Updated nim-eth3 to point to master, now that I've merged that.
* I'm confused about what's going on with engine_client.
But let's try resolving this Hash256 ambiguity.
* Still trying to fix this conflict with the Hash256 types.
* Does this work now that nimbus-eth2 has been updated?
* Corrected blockValue in getPayload responses back to UInt256.
c834f67a37
* Working on getting the withdrawals-related tests to pass.
* Fixing more of those Hash256 ambiguities.
(I'm not sure why the nim-web3 library introduced a conflicting type
named Hash256, but right now I just want to get this code to compile again.)
* Bumped a couple of libraries to fix some error messages.
* Needed to get "make fluffy-tools" to pass, too.
* Getting "make nimbus_verified_proxy" to build.
66 lines
2.0 KiB
Nim
66 lines
2.0 KiB
Nim
import
|
|
eth/[trie, rlp, common/eth_types_rlp, trie/db],
|
|
stew/byteutils
|
|
|
|
export eth_types_rlp
|
|
|
|
{.push raises: [].}
|
|
|
|
proc calcRootHash[T](items: openArray[T]): Hash256
|
|
{.gcsafe, raises: [RlpError]} =
|
|
var tr = initHexaryTrie(newMemoryDB())
|
|
for i, t in items:
|
|
tr.put(rlp.encode(i), rlp.encode(t))
|
|
return tr.rootHash
|
|
|
|
template calcTxRoot*(transactions: openArray[Transaction]): Hash256 =
|
|
calcRootHash(transactions)
|
|
|
|
template calcWithdrawalsRoot*(withdrawals: openArray[Withdrawal]): Hash256 =
|
|
calcRootHash(withdrawals)
|
|
|
|
template calcReceiptRoot*(receipts: openArray[Receipt]): Hash256 =
|
|
calcRootHash(receipts)
|
|
|
|
func generateAddress*(address: EthAddress, nonce: AccountNonce): EthAddress =
|
|
result[0..19] = keccakHash(rlp.encodeList(address, nonce)).data.toOpenArray(12, 31)
|
|
|
|
type ContractSalt* = object
|
|
bytes*: array[32, byte]
|
|
|
|
const ZERO_CONTRACTSALT* = default(ContractSalt)
|
|
|
|
func generateSafeAddress*(address: EthAddress, salt: ContractSalt,
|
|
data: openArray[byte]): EthAddress =
|
|
const prefix = [0xff.byte]
|
|
let
|
|
dataHash = keccakHash(data)
|
|
hashResult = withKeccakHash:
|
|
h.update(prefix)
|
|
h.update(address)
|
|
h.update(salt.bytes)
|
|
h.update(dataHash.data)
|
|
|
|
result[0..19] = hashResult.data.toOpenArray(12, 31)
|
|
|
|
func hash*(b: BlockHeader): Hash256 {.inline.} =
|
|
rlpHash(b)
|
|
|
|
proc crc32*(crc: uint32, buf: openArray[byte]): uint32 =
|
|
const kcrc32 = [ 0'u32, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190,
|
|
0x6b6b51f4, 0x4db26158, 0x5005713c, 0xedb88320'u32, 0xf00f9344'u32, 0xd6d6a3e8'u32,
|
|
0xcb61b38c'u32, 0x9b64c2b0'u32, 0x86d3d2d4'u32, 0xa00ae278'u32, 0xbdbdf21c'u32]
|
|
|
|
var crcu32 = not crc
|
|
for b in buf:
|
|
crcu32 = (crcu32 shr 4) xor kcrc32[int((crcu32 and 0xF) xor (uint32(b) and 0xF'u32))]
|
|
crcu32 = (crcu32 shr 4) xor kcrc32[int((crcu32 and 0xF) xor (uint32(b) shr 4'u32))]
|
|
|
|
result = not crcu32
|
|
|
|
proc short*(h: Hash256): string =
|
|
var bytes: array[6, byte]
|
|
bytes[0..2] = h.data[0..2]
|
|
bytes[^3..^1] = h.data[^3..^1]
|
|
bytes.toHex
|