Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added special address with block number and block hash #347

Merged
merged 12 commits into from
Oct 18, 2024
9 changes: 8 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,18 @@ jobs:
- name: Build
run: |
cargo build --release --bin madara
- name: Generate binary hash
id: binary_hash
run: |
BINARY_PATH=./target/release/madara
HASH=$(sha256sum $BINARY_PATH | awk '{ print $1 }')
echo "hash=$HASH" >> $GITHUB_OUTPUT
echo "Hash of the binary is: $HASH"
- name: Cache Madara binary
uses: actions/cache@v3
with:
path: target/release/madara
key: ${{ runner.os }}-madara-${{ hashFiles('Cargo.lock') }}
key: ${{ runner.os }}-madara-bin-${{ steps.binary_hash.outputs.hash }}
- name: Cache Cairo build artifacts
uses: actions/cache@v3
with:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/starknet-js-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ jobs:
- uses: actions/checkout@v3
- name: Restore Madara binary
uses: actions/cache@v3
id: cache-madara
with:
path: target/release/madara
key: ${{ runner.os }}-madara-${{ hashFiles('Cargo.lock') }}
key: ${{ runner.os }}-madara-bin-
restore-keys: |
${{ runner.os }}-madara-bin-
fail-on-cache-miss: true
- name: Restore Cairo build artifacts
uses: actions/cache@v3
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release

- fix(snos): added special address while closing block for SNOS
- fix(mempool): validator errors were ignored in `mempool/rsc/lib.rs`
- fix(primitives): fixed storage entries not being sorted in state commitment
- fix(devnet): devnet predeployed contracts stable address across systems (re)
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions configs/presets/devnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ chain_id: "MADARA_DEVNET"
native_fee_token_address: "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"
parent_fee_token_address: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"
latest_protocol_version: "0.13.2"
block_time: "30s"
block_time: "10s"
pending_block_update_time: "2s"
execution_batch_size: 16
bouncer_config:
Expand All @@ -25,5 +25,5 @@ bouncer_config:
n_events: 18446744073709551615
state_diff_size: 131072
sequencer_address: "0x123"
eth_core_contract_address: "0xE2Bb56ee936fd6433DC0F6e7e3b8365C906AA057"
eth_core_contract_address: "0xe7f1725e7734ce288f8367e1bb143e90bb3f0512"
eth_gps_statement_verifier: "0xf294781D719D2F4169cE54469C28908E6FA752C1"
12 changes: 0 additions & 12 deletions crates/client/exec/src/blockifier_state_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use blockifier::state::errors::StateError;
use blockifier::state::state_api::{StateReader, StateResult};
use mc_db::db_block_id::DbBlockId;
use mc_db::MadaraBackend;
use mp_block::BlockId;
use mp_class::ClassInfo;
use mp_convert::{felt_to_u64, ToFelt};
use starknet_api::core::{ChainId, ClassHash, CompiledClassHash, ContractAddress, Nonce};
Expand Down Expand Up @@ -41,17 +40,6 @@ impl StateReader for BlockifierStateAdapter {
) {
return Ok(Felt::ZERO);
}

return self
.backend
.get_block_hash(&BlockId::Number(requested_block_number))
.map_err(|err| {
log::warn!("Failed to retrieve block hash for block number {requested_block_number}: {err:#}");
StateError::StateReadError(format!(
"Failed to retrieve block hash for block number {requested_block_number}",
))
})?
.ok_or(StateError::OldBlockHashNotProvided);
}

let Some(on_top_of_block_id) = self.on_top_of_block_id else { return Ok(Felt::ZERO) };
Expand Down
24 changes: 23 additions & 1 deletion crates/client/mempool/src/block_production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,31 @@ impl<Mempool: MempoolProvider> BlockProductionTask<Mempool> {

// Complete the block with full bouncer capacity.
let start_time = Instant::now();
let (new_state_diff, _n_executed) =
let (mut new_state_diff, _n_executed) =
self.continue_block(self.backend.chain_config().bouncer_config.block_max_capacity)?;

// SNOS requirement: For blocks >= 10, the hash of the block 10 blocks prior
// at address 0x1 with the block number as the key
if block_n >= 10 {
let prev_block_number = block_n - 10;
let prev_block_hash = self
.backend
.get_block_hash(&BlockId::Number(prev_block_number))
.map_err(|err| {
Error::Unexpected(
format!("Error fetching block hash for block {prev_block_number}: {err:#}").into(),
)
})?
.ok_or_else(|| {
Error::Unexpected(format!("No block hash found for block number {prev_block_number}").into())
})?;
let address = Felt::ONE;
new_state_diff.storage_diffs.push(ContractStorageDiffItem {
address,
storage_entries: vec![StorageEntry { key: Felt::from(block_n), value: prev_block_hash }],
});
}

// Convert the pending block to a closed block and save to db.

let parent_block_hash = Felt::ZERO; // temp parent block hash
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use starknet_core::types::BlockId;
use starknet_types_core::felt::Felt;

use crate::errors::{StarknetRpcApiError, StarknetRpcResult};
use crate::utils::ResultExt;
use crate::Starknet;
use mc_db::db_block_id::{DbBlockId, DbBlockIdResolvable};
use starknet_core::types::BlockId;
use starknet_types_core::felt::Felt;

/// Get the value of the storage at the given address and key.
///
Expand Down Expand Up @@ -45,17 +45,25 @@ pub fn get_storage_at(
return Err(StarknetRpcApiError::BlockNotFound);
}

// Check if contract exists
starknet
.backend
.get_contract_class_hash_at(&block_id, &contract_address) // TODO: contains api without deser
.or_internal_server_error("Failed to check if contract is deployed")?
.ok_or(StarknetRpcApiError::ContractNotFound)?;
let block_number = block_id.resolve_db_block_id(&starknet.backend)?;

let skip_contract_check = matches!(
block_number,
Some(DbBlockId::Number(num)) if num >= 10 && contract_address == Felt::ONE
);

if !skip_contract_check {
starknet
.backend
.get_contract_class_hash_at(&block_id, &contract_address)
.or_internal_server_error("Failed to check if contract is deployed")?
.ok_or(StarknetRpcApiError::ContractNotFound)?;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should only return 0x0 in this case
we can therefore remove this check
this is already the implementation in the state adapter but maybe this logic should be in the db
@cchudant what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked with the juno rpc call and it has this behaviour hence implemented this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apparently you have to return ContractNotFound
https://github.com/starkware-libs/starknet-specs/blob/master/api/starknet_api_openrpc.json#L216

but we need to bring this up into full node collab channel - getNonce also returns ContractNotFound but I think it's possible to increment the nonce of an undeclared contract


let storage = starknet
.backend
.get_contract_storage_at(&block_id, &contract_address, &key)
.or_internal_server_error("Error getting contract class hash at")?
.or_internal_server_error("Error getting contract storage at")?
.unwrap_or(Felt::ZERO);

Ok(storage)
Expand Down
Loading