Skip to content

Commit

Permalink
7002: clarify endianness in pseudocode
Browse files Browse the repository at this point in the history
  • Loading branch information
lightclient committed Sep 26, 2024
1 parent ab9d01f commit 941a222
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions EIPS/eip-7002.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def add_withdrawal_request(Bytes48: validator_pubkey, uint64: amount):
queue_storage_slot = WITHDRAWAL_REQUEST_QUEUE_STORAGE_OFFSET + queue_tail_index * 3
sstore(WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS, queue_storage_slot, msg.sender)
sstore(WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS, queue_storage_slot + 1, validator_pubkey[0:32])
sstore(WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS, queue_storage_slot + 2, validator_pubkey[32:48] ++ amount)
sstore(WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS, queue_storage_slot + 2, validator_pubkey[32:48] ++ uint64_to_little_endian(amount))
sstore(WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS, WITHDRAWAL_REQUEST_QUEUE_TAIL_STORAGE_SLOT, queue_tail_index + 1)
```

Expand Down Expand Up @@ -178,6 +178,12 @@ def read_withdrawal_requests():
# Helpers #
###########

def little_endian_to_uint64(data: bytes) -> uint64:
return uint64(int.from_bytes(data, 'little'))

def uint64_to_little_endian(num: uint64) -> bytes:
return num.to_bytes(8, 'little')

class ValidatorWithdrawalRequest(object):
source_address: Bytes20
validator_pubkey: Bytes48
Expand All @@ -196,7 +202,7 @@ def dequeue_withdrawal_requests():
validator_pubkey = (
sload(WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS, queue_storage_slot + 1)[0:32] + sload(WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS, queue_storage_slot + 2)[0:16]
)
amount = sload(WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS, queue_storage_slot + 2)[16:24]
amount = little_endian_to_uint64(sload(WITHDRAWAL_REQUEST_PREDEPLOY_ADDRESS, queue_storage_slot + 2)[16:24])
req = ValidatorWithdrawalRequest(
source_address=Bytes20(source_address),
validator_pubkey=Bytes48(validator_pubkey),
Expand Down

0 comments on commit 941a222

Please sign in to comment.