-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
416 additions
and
144 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
46 changes: 0 additions & 46 deletions
46
packages/contract_bootloader/syscall_handler/account_memorizer_handler.py
This file was deleted.
Oops, something went wrong.
94 changes: 0 additions & 94 deletions
94
packages/contract_bootloader/syscall_handler/header_memorizer_handler.py
This file was deleted.
Oops, something went wrong.
File renamed without changes.
97 changes: 97 additions & 0 deletions
97
packages/contract_bootloader/syscall_handler_memorizer/account_memorizer_handler.py
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,97 @@ | ||
from rlp import decode | ||
from typing import Tuple | ||
from contract_bootloader.memorizer.memorizer import Memorizer | ||
from contract_bootloader.memorizer.account_memorizer import ( | ||
AbstractAccountMemorizerBase, | ||
MemorizerKey, | ||
) | ||
from starkware.cairo.lang.vm.memory_segments import MemorySegmentManager | ||
from tools.py.account import Account | ||
from tools.py.rlp import get_rlp_len | ||
from tools.py.utils import little_8_bytes_chunks_to_bytes | ||
|
||
|
||
class AccountMemorizerHandler(AbstractAccountMemorizerBase): | ||
def __init__(self, segments: MemorySegmentManager, memorizer: Memorizer): | ||
super().__init__(memorizer=memorizer) | ||
self.segments = segments | ||
|
||
def get_nonce(self, key: MemorizerKey) -> Tuple[int, int]: | ||
memorizer_value_ptr = self.memorizer.read(key=key.derive()) | ||
|
||
rlp_len = get_rlp_len( | ||
rlp=self.segments.memory[memorizer_value_ptr], item_start_offset=0 | ||
) | ||
rlp = self._get_felt_range( | ||
start_addr=memorizer_value_ptr, | ||
end_addr=memorizer_value_ptr + (rlp_len + 7) // 8, | ||
) | ||
|
||
value = decode(little_8_bytes_chunks_to_bytes(rlp, rlp_len), Account).as_dict()[ | ||
"nonce" | ||
] | ||
|
||
return ( | ||
value % 0x100000000000000000000000000000000, | ||
value // 0x100000000000000000000000000000000, | ||
) | ||
|
||
def get_balance(self, key: MemorizerKey) -> Tuple[int, int]: | ||
memorizer_value_ptr = self.memorizer.read(key=key.derive()) | ||
|
||
rlp_len = get_rlp_len( | ||
rlp=self.segments.memory[memorizer_value_ptr], item_start_offset=0 | ||
) | ||
rlp = self._get_felt_range( | ||
start_addr=memorizer_value_ptr, | ||
end_addr=memorizer_value_ptr + (rlp_len + 7) // 8, | ||
) | ||
|
||
value = decode(little_8_bytes_chunks_to_bytes(rlp, rlp_len), Account).as_dict()[ | ||
"balance" | ||
] | ||
|
||
return ( | ||
value % 0x100000000000000000000000000000000, | ||
value // 0x100000000000000000000000000000000, | ||
) | ||
|
||
def get_state_root(self, key: MemorizerKey) -> Tuple[int, int]: | ||
memorizer_value_ptr = self.memorizer.read(key=key.derive()) | ||
|
||
rlp_len = get_rlp_len( | ||
rlp=self.segments.memory[memorizer_value_ptr], item_start_offset=0 | ||
) | ||
rlp = self._get_felt_range( | ||
start_addr=memorizer_value_ptr, | ||
end_addr=memorizer_value_ptr + (rlp_len + 7) // 8, | ||
) | ||
|
||
value = decode(little_8_bytes_chunks_to_bytes(rlp, rlp_len), Account).as_dict()[ | ||
"storageRoot" | ||
] | ||
|
||
return ( | ||
value % 0x100000000000000000000000000000000, | ||
value // 0x100000000000000000000000000000000, | ||
) | ||
|
||
def get_code_hash(self, key: MemorizerKey) -> Tuple[int, int]: | ||
memorizer_value_ptr = self.memorizer.read(key=key.derive()) | ||
|
||
rlp_len = get_rlp_len( | ||
rlp=self.segments.memory[memorizer_value_ptr], item_start_offset=0 | ||
) | ||
rlp = self._get_felt_range( | ||
start_addr=memorizer_value_ptr, | ||
end_addr=memorizer_value_ptr + (rlp_len + 7) // 8, | ||
) | ||
|
||
value = decode(little_8_bytes_chunks_to_bytes(rlp, rlp_len), Account).as_dict()[ | ||
"codeHash" | ||
] | ||
|
||
return ( | ||
value % 0x100000000000000000000000000000000, | ||
value // 0x100000000000000000000000000000000, | ||
) |
Oops, something went wrong.