From 171531fbf1a308c1bf4d2f6b88c6ee6924657437 Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Tue, 15 Oct 2024 16:44:10 +0200 Subject: [PATCH] Add helper for recovering authority (#750) For EIP-7702 SetCode transaction, it is necessary to identify the authority issuing an authorization. Its account's code is set to proxy to the authorization address if successful. --- eth/common/transactions_rlp.nim | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/eth/common/transactions_rlp.nim b/eth/common/transactions_rlp.nim index 5812184..d0b85a4 100644 --- a/eth/common/transactions_rlp.nim +++ b/eth/common/transactions_rlp.nim @@ -305,6 +305,23 @@ proc readTxEip4844(rlp: var Rlp, tx: var Transaction) {.raises: [RlpError].} = rlp.read(tx.R) rlp.read(tx.S) +func rlpEncodeEip7702(auth: Authorization): seq[byte] = + var w = initRlpWriter() + w.append(0x05'u8) + w.startList(3) + w.append(auth.chainId.uint64) + w.append(auth.address) + w.append(auth.nonce) + w.finish() + +func encodeForSigning*(auth: Authorization): seq[byte] = + ## Encode authorization data in preparation for signing or signature checking. + auth.rlpEncodeEip7702 + +func rlpHashForSigning*(auth: Authorization): Hash32 = + # Hash authorization without signature + keccak256(encodeForSigning(auth)) + proc read*(rlp: var Rlp, T: type Authorization): T {.raises: [RlpError].} = rlp.tryEnterList() result.chainId = rlp.read(uint64).ChainId