Skip to content

Commit

Permalink
Scarb fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
b-j-roberts committed Mar 15, 2024
1 parent 423c085 commit f9e4632
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
23 changes: 18 additions & 5 deletions src/blobstreamx.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ mod blobstreamx {
use blobstream_sn::interfaces::{
DataRoot, TendermintXErrors, IBlobstreamX, IDAOracle, ITendermintX
};
use blobstream_sn::mocks::evm_facts_registry::{IEVMFactsRegistryMockDispatcher, IEVMFactsRegistryMockDispatcherImpl};
use blobstream_sn::mocks::evm_facts_registry::{
IEVMFactsRegistryMockDispatcher, IEVMFactsRegistryMockDispatcherImpl
};
use blobstream_sn::tree::binary::merkle_proof::BinaryMerkleProof;
use core::starknet::event::EventEmitter;
use core::traits::Into;
Expand Down Expand Up @@ -408,11 +410,16 @@ mod blobstreamx {

// Get the proof nonce for the new state data commitments
let blobstreamx_l1_proof_nonce_slot: u256 = 0xfc;
let new_state_proof_nonce = herodotus_facts_registry.get_slot_value(blobstreamx_l1_contract, l1_block, blobstreamx_l1_proof_nonce_slot);
let new_state_proof_nonce = herodotus_facts_registry
.get_slot_value(blobstreamx_l1_contract, l1_block, blobstreamx_l1_proof_nonce_slot);
assert!(new_state_proof_nonce.is_some(), "No proof nonce found for block {}", l1_block);
// TODO: error handling on try_into
let new_state_proof_nonce: u64 = new_state_proof_nonce.unwrap().try_into().unwrap();
assert!(new_state_proof_nonce > self.get_state_proof_nonce(), "State proof nonce does not increase on block {}", l1_block);
assert!(
new_state_proof_nonce > self.get_state_proof_nonce(),
"State proof nonce does not increase on block {}",
l1_block
);

//// Loop though all the new state data commitments
let blobstreamx_l1_data_commitment_map_slot: u256 = 0xfe;
Expand All @@ -422,8 +429,14 @@ mod blobstreamx {
dc_slot_encoded.append_u256(current_dc_id.into());
dc_slot_encoded.append_u256(blobstreamx_l1_data_commitment_map_slot);
let dc_slot: u256 = dc_slot_encoded.keccak();
let data_commitment = herodotus_facts_registry.get_slot_value(blobstreamx_l1_contract, l1_block, dc_slot);
assert!(data_commitment.is_some(), "No data commitment found for block {} and proof nonce {}", l1_block, current_dc_id);
let data_commitment = herodotus_facts_registry
.get_slot_value(blobstreamx_l1_contract, l1_block, dc_slot);
assert!(
data_commitment.is_some(),
"No data commitment found for block {} and proof nonce {}",
l1_block,
current_dc_id
);
self.state_data_commitments.write(current_dc_id, data_commitment.unwrap());
current_dc_id += 1;
};
Expand Down
30 changes: 23 additions & 7 deletions src/tests/test_blobstreamx.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use blobstream_sn::interfaces::{
IBlobstreamXDispatcher, IBlobstreamXDispatcherTrait, Validator, ITendermintXDispatcher,
ITendermintXDispatcherTrait
};
use blobstream_sn::mocks::evm_facts_registry::{IEVMFactsRegistryMockDispatcher, IEVMFactsRegistryMockDispatcherImpl};
use blobstream_sn::mocks::evm_facts_registry::{
IEVMFactsRegistryMockDispatcher, IEVMFactsRegistryMockDispatcherImpl
};
use blobstream_sn::tests::common::{
setup_base, setup_spied, setup_succinct_gateway, TEST_START_BLOCK, TEST_END_BLOCK, TEST_HEADER,
};
Expand Down Expand Up @@ -205,22 +207,36 @@ fn blobstreamx_data_commitments_from_herodotus_facts() {
let l1_block_num: u256 = 0x100;

let hfr_dispatcher = IEVMFactsRegistryMockDispatcher { contract_address: hfr_addr };
hfr_dispatcher.set_slot_value(l1_addr, l1_block_num, 0xfc, 3.into()); // state_proofNonce at slot 0xfc

// Set the state_proofNonce slot to 3

hfr_dispatcher
.set_slot_value(l1_addr, l1_block_num, 0xfc, 3.into()); // state_proofNonce at slot 0xfc

// Add the 2 data commitments

// Slot pos = keccak256(abi.encode(map_key, state_dataCommitment_slot)) ie keccak256(abi.encode(map_key, 0xfe))
let data_commitment1_slot: u256 = 0x457c8a48b4735f56b938837eb0a8a5f9c55f23c1a85767ce3b65c3e59d3d32b7;
let data_commitment1_slot: u256 =
0x457c8a48b4735f56b938837eb0a8a5f9c55f23c1a85767ce3b65c3e59d3d32b7;
let data_commitment1: u256 = 0xe1078369756a0b28e3b8cc1fa6e0133630ccdf9d2bd5bde1d40d197793c3c8b4;
hfr_dispatcher.set_slot_value(l1_addr, l1_block_num, data_commitment1_slot, data_commitment1); // state_dataCommitment[1]
hfr_dispatcher
.set_slot_value(
l1_addr, l1_block_num, data_commitment1_slot, data_commitment1
); // state_dataCommitment[1]

let data_commitment2_slot: u256 = 0xeeac6037a1009734a3fd8a7d8347d53da92d0725658242afb43dd0d755dbe634;
let data_commitment2_slot: u256 =
0xeeac6037a1009734a3fd8a7d8347d53da92d0725658242afb43dd0d755dbe634;
let data_commitment2: u256 = 0xc2b2d9e303ad14a5aeeda362d3d4177eedb43e1e0e4e6d42f6922f2ebfb23cc6;
hfr_dispatcher.set_slot_value(l1_addr, l1_block_num, data_commitment2_slot, data_commitment2); // state_dataCommitment[2]
hfr_dispatcher
.set_slot_value(
l1_addr, l1_block_num, data_commitment2_slot, data_commitment2
); // state_dataCommitment[2]

bsx.update_data_commitments_from_facts(l1_block_num);
assert!(bsx.get_state_proof_nonce() == 3, "state proof nonce invalid");
assert!(bsx.get_state_data_commitment(0) == 0, "data commitment 0 invalid");
assert!(bsx.get_state_data_commitment(1) == data_commitment1, "data commitment 1 invalid");
assert!(bsx.get_state_data_commitment(2) == data_commitment2, "data commitment 2 invalid");
assert!(bsx.get_state_data_commitment(3) == 0, "data commitment 3 invalid");
// TODO: test invalid inputs and things
// TODO: test invalid inputs and things
}

0 comments on commit f9e4632

Please sign in to comment.