Skip to content

Commit

Permalink
storage slot correct endiannes
Browse files Browse the repository at this point in the history
  • Loading branch information
Okm165 committed Jul 24, 2024
1 parent 81f48a5 commit ebfa454
Show file tree
Hide file tree
Showing 4 changed files with 581 additions and 778 deletions.
6 changes: 3 additions & 3 deletions cairo/src/memorizer/storage_memorizer.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct StorageKey {
pub chain_id: felt252,
pub block_number: felt252,
pub address: felt252,
pub storage_slot: u256,
pub key: u256,
}

#[generate_trait]
Expand All @@ -26,8 +26,8 @@ pub impl StorageMemorizerImpl of StorageMemorizerTrait {
key.chain_id,
key.block_number,
key.address,
key.storage_slot.low.into(),
key.storage_slot.high.into(),
key.key.high.into(),
key.key.low.into(),
]
.span()
)
Expand Down
9 changes: 5 additions & 4 deletions packages/contract_bootloader/memorizer/storage_memorizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,24 +39,25 @@ def from_int(cls, values: List[int]):
or values[4] >= 0x100000000000000000000000000000000
):
raise ValueError("Storage slot value not u128")
storage_slot_low = values[3] % 0x100000000000000000000000000000000
storage_slot_high = values[4] % 0x100000000000000000000000000000000
storage_slot_high = values[3] % 0x100000000000000000000000000000000
storage_slot_low = values[4] % 0x100000000000000000000000000000000
return cls(
values[0], values[1], values[2], (storage_slot_low, storage_slot_high)
values[0], values[1], values[2], (storage_slot_high, storage_slot_low)
)

def derive(self) -> int:
return poseidon_hash_many(
[
self.chain_id,
self.block_number,
self.address,
self.storage_slot[0],
self.storage_slot[1],
]
)

def to_dict(self):
storage_slot_value = (self.storage_slot[1] << 128) + self.storage_slot[0]
storage_slot_value = (self.storage_slot[0] << 128) + self.storage_slot[1]

return {
"chain_id": self.chain_id,
Expand Down
1 change: 1 addition & 0 deletions packages/contract_bootloader/syscall_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def _call_contract_helper(
dict_raw_ptrs=calldata[0 : Memorizer.size()],
dict_manager=self.dict_manager,
)
print(memorizer.dict_ptr)

idx = Memorizer.size()
key = StorageMemorizerKey.from_int(
Expand Down
Loading

0 comments on commit ebfa454

Please sign in to comment.