Skip to content

Commit

Permalink
fix: 🐛 Fixed unresolved dependencies + felt252wrapper conversions
Browse files Browse the repository at this point in the history
  • Loading branch information
antiyro committed Jan 5, 2024
1 parent f3bd754 commit d748e09
Show file tree
Hide file tree
Showing 10 changed files with 1,381 additions and 494 deletions.
1,830 changes: 1,360 additions & 470 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ members = [
"crates/client/settlement",
"starknet-rpc-test",
"starknet-e2e-test",
"madara-test-runner",
]
# All previous except for `starknet-rpc-test` and `starknet-e2e-test`
# We don't want `cargo test` to trigger its tests
Expand Down Expand Up @@ -197,9 +196,6 @@ mc-settlement = { path = "crates/client/settlement" }
# Madara runtime
madara-runtime = { path = "crates/runtime" }

# Madara test runner
madara-test-runner = { path = "madara-test-runner" }

# Starknet dependencies
# Cairo Virtual Machine
cairo-vm = { git = "https://github.com/keep-starknet-strange/cairo-rs", branch = "no_std-support-21eff70", default-features = false, features = [
Expand Down
12 changes: 6 additions & 6 deletions crates/client/deoxys/src/state_updates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,26 +258,26 @@ where

for (address, diffs) in &state_update.state_diff.storage_diffs {
let contract_address = ContractAddress(PatriciaKey(
(*address).try_into().map_err(|_| BuildCommitmentStateDiffError::ConversionError)?,
Felt252Wrapper::from(*address).try_into().map_err(|_| BuildCommitmentStateDiffError::ConversionError)?,
));
for storage_diff in diffs {
let storage_key = StarknetStorageKey(PatriciaKey(
storage_diff.key.try_into().map_err(|_| BuildCommitmentStateDiffError::ConversionError)?,
Felt252Wrapper::from(storage_diff.key).try_into().map_err(|_| BuildCommitmentStateDiffError::ConversionError)?,
));
let value = storage_diff.value;

match commitment_state_diff.storage_updates.entry(contract_address) {
Entry::Occupied(mut entry) => {
entry.get_mut().insert(
storage_key,
value.try_into().map_err(|_| BuildCommitmentStateDiffError::ConversionError)?,
Felt252Wrapper::from(value).try_into().map_err(|_| BuildCommitmentStateDiffError::ConversionError)?,
);
}
Entry::Vacant(entry) => {
let mut contract_storage = IndexMap::default();
contract_storage.insert(
storage_key,
value.try_into().map_err(|_| BuildCommitmentStateDiffError::ConversionError)?,
Felt252Wrapper::from(value).try_into().map_err(|_| BuildCommitmentStateDiffError::ConversionError)?,
);
entry.insert(contract_storage);
}
Expand All @@ -298,9 +298,9 @@ where

for nonce in &state_update.state_diff.nonces {
let contract_address = ContractAddress(PatriciaKey(
(*nonce.0).try_into().map_err(|_| BuildCommitmentStateDiffError::ConversionError)?,
Felt252Wrapper::from(*nonce.0).try_into().map_err(|_| BuildCommitmentStateDiffError::ConversionError)?,
));
let nonce_value = Nonce((*nonce.1).try_into().map_err(|_| BuildCommitmentStateDiffError::ConversionError)?);
let nonce_value = Nonce(Felt252Wrapper::from(*nonce.1).try_into().map_err(|_| BuildCommitmentStateDiffError::ConversionError)?);
commitment_state_diff.address_to_nonce.insert(contract_address, nonce_value);
}

Expand Down
14 changes: 7 additions & 7 deletions crates/client/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,9 +859,9 @@ where
transactions: transaction_hashes,
status: actual_status,
block_hash: block_hash.into(),
parent_hash: parent_blockhash.into(),
parent_hash: Felt252Wrapper::from(parent_blockhash).into(),
block_number: starknet_block.header().block_number,
new_root: starknet_block.header().global_state_root.into(),
new_root: Felt252Wrapper::from(starknet_block.header().global_state_root).into(),
timestamp: starknet_block.header().block_timestamp,
sequencer_address: Felt252Wrapper::from(starknet_block.header().sequencer_address).into(),
};
Expand Down Expand Up @@ -1114,9 +1114,9 @@ where
let block_with_txs = BlockWithTxs {
status: actual_status,
block_hash: block_hash.into(),
parent_hash: starknet_block.header().parent_block_hash.into(),
parent_hash: Felt252Wrapper::from(starknet_block.header().parent_block_hash).into(),
block_number: starknet_block.header().block_number,
new_root: starknet_block.header().global_state_root.into(),
new_root: Felt252Wrapper::from(starknet_block.header().global_state_root).into(),
timestamp: starknet_block.header().block_timestamp,
sequencer_address: Felt252Wrapper::from(starknet_block.header().sequencer_address).into(),
transactions,
Expand Down Expand Up @@ -1153,7 +1153,7 @@ where

let old_root = if starknet_block.header().block_number > 0 {
let parent_block_hash =
(TryInto::<FieldElement>::try_into(starknet_block.header().parent_block_hash)).unwrap();
(TryInto::<FieldElement>::try_into(Felt252Wrapper::from(starknet_block.header().parent_block_hash))).unwrap();
let substrate_parent_block_hash =
self.substrate_block_hash_from_starknet_block(BlockId::Hash(parent_block_hash)).map_err(|e| {
error!("'{e}'");
Expand All @@ -1162,14 +1162,14 @@ where

let parent_block =
get_block_by_block_hash(self.client.as_ref(), substrate_parent_block_hash).unwrap_or_default();
parent_block.header().global_state_root.into()
Felt252Wrapper::from(parent_block.header().global_state_root).into()
} else {
FieldElement::default()
};

Ok(StateUpdate {
block_hash: starknet_block.header().hash::<H>().into(),
new_root: starknet_block.header().global_state_root.into(),
new_root: Felt252Wrapper::from(starknet_block.header().global_state_root).into(),
old_root,
state_diff: StateDiff {
storage_diffs: Vec::new(),
Expand Down
1 change: 1 addition & 0 deletions crates/client/settlement/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ mp-digest-log = { workspace = true, features = ["std"] }
mp-hashers = { workspace = true, default-features = true }
mp-messages = { workspace = true, default-features = true }
mp-snos-output = { workspace = true, default-features = true }
mp-felt = { workspace = true, default-features = true }
mp-transactions = { workspace = true, default-features = true }
starknet-crypto = { workspace = true, default-features = true }
starknet_api = { workspace = true, default-features = true }
Expand Down
3 changes: 2 additions & 1 deletion crates/client/settlement/src/sync_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::sync::Arc;
use futures::StreamExt;
use futures_timer::Delay;
use mp_block::Block as StarknetBlock;
use mp_felt::Felt252Wrapper;
use mp_hashers::HasherT;
use mp_messages::{MessageL1ToL2, MessageL2ToL1};
use mp_snos_output::StarknetOsOutput;
Expand Down Expand Up @@ -184,7 +185,7 @@ where
let fee_token_address = substrate_client.runtime_api().fee_token_address(substrate_hash)?;

let config_hash = pedersen_hash_array(&[
StarkFelt::from(FieldElement::from_byte_slice_be(SN_OS_CONFIG_HASH_VERSION.as_bytes()).unwrap()),
StarkFelt::from(Felt252Wrapper::from(FieldElement::from_byte_slice_be(SN_OS_CONFIG_HASH_VERSION.as_bytes()).unwrap())),
chain_id.into(),
fee_token_address.0.0,
]);
Expand Down
2 changes: 1 addition & 1 deletion crates/pallets/starknet/src/blockifier_state_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl<T: Config> State for BlockifierStateAdapter<T> {

fn increment_nonce(&mut self, contract_address: ContractAddress) -> StateResult<()> {
let current_nonce = Pallet::<T>::nonce(contract_address);
let current_nonce: FieldElement = current_nonce.0.into();
let current_nonce: FieldElement = Felt252Wrapper::from(current_nonce.0).into();
let new_nonce: Nonce = Felt252Wrapper(current_nonce + FieldElement::ONE).into();

crate::Nonces::<T>::insert(contract_address, new_nonce);
Expand Down
6 changes: 3 additions & 3 deletions crates/primitives/commitments/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,12 @@ where
/// for details.
pub fn calculate_event_hash<H: HasherT>(event: &Event) -> FieldElement {
let keys_hash = H::compute_hash_on_elements(
&event.content.keys.iter().map(|key| FieldElement::from(key.0)).collect::<Vec<FieldElement>>(),
&event.content.keys.iter().map(|key| FieldElement::from(Felt252Wrapper::from(key.0))).collect::<Vec<FieldElement>>(),
);
let data_hash = H::compute_hash_on_elements(
&event.content.data.0.iter().map(|data| FieldElement::from(*data)).collect::<Vec<FieldElement>>(),
&event.content.data.0.iter().map(|data| FieldElement::from(Felt252Wrapper::from(*data))).collect::<Vec<FieldElement>>(),
);
let from_address = FieldElement::from(event.from_address.0.0);
let from_address = FieldElement::from(Felt252Wrapper::from(event.from_address.0.0));
H::compute_hash_on_elements(&[from_address, keys_hash, data_hash])
}

Expand Down
2 changes: 1 addition & 1 deletion crates/primitives/transactions/src/compute_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ impl DeployTransaction {
block_number: Option<u64>,
) -> FieldElement {
let prefix = FieldElement::from_byte_slice_be(DEPLOY_PREFIX).unwrap();
let version = self.version.0.into();
let version = Felt252Wrapper::from(self.version.0).into();
let constructor_calldata = compute_hash_on_elements(convert_calldata(&self.constructor_calldata));
let constructor = starknet_keccak(b"constructor");

Expand Down
1 change: 0 additions & 1 deletion starknet-e2e-test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ starknet_api = { workspace = true, default-features = true }

# Madara
madara-runtime = { workspace = true }
madara-test-runner = { workspace = true }
mc-settlement = { workspace = true }
mp-messages = { workspace = true }
mp-snos-output = { workspace = true }
Expand Down

0 comments on commit d748e09

Please sign in to comment.