Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Jul 16, 2024
1 parent 1008fb4 commit 1d6191d
Show file tree
Hide file tree
Showing 10 changed files with 416 additions and 144 deletions.
4 changes: 2 additions & 2 deletions packages/contract_bootloader/dryrun_syscall_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
MemorizerFunctionId as HeaderMemorizerFunctionId,
MemorizerKey as HeaderMemorizerKey,
)
from contract_bootloader.dryrun_syscall_handler.header_memorizer_handler import (
from contract_bootloader.dryrun_syscall_handler_memorizer.header_memorizer_handler import (
DryRunHeaderMemorizerHandler,
)
from contract_bootloader.dryrun_syscall_handler.account_memorizer_handler import (
from contract_bootloader.dryrun_syscall_handler_memorizer.account_memorizer_handler import (
DryRunAccountMemorizerHandler,
)

Expand Down
4 changes: 2 additions & 2 deletions packages/contract_bootloader/syscall_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
MemorizerFunctionId as AccountMemorizerFunctionId,
MemorizerKey as AccountMemorizerKey,
)
from contract_bootloader.syscall_handler.account_memorizer_handler import (
from contract_bootloader.syscall_handler_memorizer.account_memorizer_handler import (
AccountMemorizerHandler,
)
from contract_bootloader.syscall_handler.header_memorizer_handler import (
from contract_bootloader.syscall_handler_memorizer.header_memorizer_handler import (
HeaderMemorizerHandler,
)

Expand Down

This file was deleted.

This file was deleted.

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,
)
Loading

0 comments on commit 1d6191d

Please sign in to comment.