Skip to content

Commit

Permalink
Add helper for recovering authority (#750)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
etan-status authored Oct 15, 2024
1 parent b736906 commit 171531f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions eth/common/transactions_rlp.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 171531f

Please sign in to comment.