-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement EIP-7702 part 3: Delegation Designation and Gas Costs
- Loading branch information
Showing
13 changed files
with
262 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Nimbus | ||
# Copyright (c) 2024 Status Research & Development GmbH | ||
# Licensed under either of | ||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or | ||
# http://www.apache.org/licenses/LICENSE-2.0) | ||
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or | ||
# http://opensource.org/licenses/MIT) | ||
# at your option. This file may not be copied, modified, or distributed except | ||
# according to those terms. | ||
|
||
{.push raises: [].} | ||
|
||
import | ||
../evm/code_bytes, | ||
results, | ||
stew/assign2, | ||
eth/common/eth_types, | ||
eth/common/eth_types_rlp, | ||
eth/keys | ||
|
||
const | ||
DelegationPrefix = [0xef.byte, 0x01, 0x00] | ||
Magic = 0x05 | ||
|
||
func authority*(auth: Authorization): Opt[EthAddress] = | ||
var w = initRlpWriter() | ||
w.appendRawBytes([Magic.byte]) | ||
w.append(auth.chainId.uint64) | ||
w.append(auth.address) | ||
w.append(auth.nonce) | ||
let sigHash = keccakHash(w.finish()) | ||
|
||
var bytes: array[65, byte] | ||
assign(bytes.toOpenArray(0, 31), auth.R.toBytesBE()) | ||
assign(bytes.toOpenArray(32, 63), auth.S.toBytesBE()) | ||
bytes[64] = auth.y_parity.byte | ||
|
||
let sig = Signature.fromRaw(bytes).valueOr: | ||
return Opt.none(EthAddress) | ||
|
||
let pubkey = recover(sig, SkMessage(sigHash.data)).valueOr: | ||
return Opt.none(EthAddress) | ||
|
||
ok(pubkey.toCanonicalAddress()) | ||
|
||
func parseDelegation*(code: CodeBytesRef): bool = | ||
if code.len != 23: | ||
return false | ||
|
||
if not code.hasPrefix(DelegationPrefix): | ||
return false | ||
|
||
true | ||
|
||
func addressToDelegation*(auth: EthAddress): array[23, byte] = | ||
assign(result.toOpenArray(0, 2), DelegationPrefix) | ||
assign(result.toOpenArray(3, 22), auth) | ||
|
||
func parseDelegationAddress*(code: CodeBytesRef): Opt[EthAddress] = | ||
if code.len != 23: | ||
return Opt.none(EthAddress) | ||
|
||
if not code.hasPrefix(DelegationPrefix): | ||
return Opt.none(EthAddress) | ||
|
||
Opt.some(slice[20](code, 3, 22)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.