Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 51 additions & 4 deletions packages/rs-drive-proof-verifier/src/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3918,7 +3918,7 @@ mod tests {
})),
};
let provider = unreachable_provider();
let err = <StateTransitionProofResult as FromProof<
let err = <StateTransitionProofOutcome as FromProof<
platform::BroadcastStateTransitionRequest,
>>::maybe_from_proof(
request,
Expand Down Expand Up @@ -5121,6 +5121,53 @@ mod tests {
}
}

#[test]
fn epochs_info_descending_with_explicit_max_start_passes_guard() {
// The SDK's `fetch_current` sends a descending query with an explicit
// start (the hinted current epoch index). Any explicit start — up to
// MAX_EPOCH, the highest index that fits Drive's epoch key encoding —
// makes the request fully self-describing, so it must get past the
// explicit-start guard and proceed to proof verification (which here
// fails on the garbage proof, not on the request shape).
use dapi_grpc::platform::v0::get_epochs_info_request::GetEpochsInfoRequestV0;
use dpp::block::epoch::MAX_EPOCH;
use platform::get_epochs_info_response::{
get_epochs_info_response_v0::Result as V0Result, GetEpochsInfoResponseV0, Version,
};
let response = platform::GetEpochsInfoResponse {
version: Some(Version::V0(GetEpochsInfoResponseV0 {
result: Some(V0Result::Proof(Proof::default())),
metadata: Some(default_metadata_with_epoch(10)),
})),
};
let request = platform::GetEpochsInfoRequest {
version: Some(platform::get_epochs_info_request::Version::V0(
GetEpochsInfoRequestV0 {
start_epoch: Some(MAX_EPOCH as u32),
count: 1,
ascending: false,
prove: true,
},
)),
};
let provider = unreachable_provider();

let err =
<ExtendedEpochInfos as FromProof<platform::GetEpochsInfoRequest>>::maybe_from_proof(
request,
response,
Network::Testnet,
default_platform_version(),
&provider,
)
.unwrap_err();

assert!(
!matches!(err, Error::RequestError { .. }),
"explicit-start descending query must pass the guard, got: {err:?}"
);
}

#[test]
fn extended_epoch_info_single_bubbles_empty_version() {
// Ensures the wrapper passes through error from inner impl.
Expand Down Expand Up @@ -6023,7 +6070,7 @@ mod tests {
};
let response = platform::WaitForStateTransitionResultResponse::default();
let provider = unreachable_provider();
let err = <StateTransitionProofResult as FromProof<
let err = <StateTransitionProofOutcome as FromProof<
platform::BroadcastStateTransitionRequest,
>>::maybe_from_proof(
request,
Expand All @@ -6039,7 +6086,7 @@ mod tests {
#[test]
fn broadcast_state_transition_protocol_error_fires_before_metadata_check() {
// This test pins the ORDERING of validation in
// `StateTransitionProofResult::maybe_from_proof` for broadcast
// `StateTransitionProofOutcome::maybe_from_proof` for broadcast
// state transitions: proof extraction -> state_transition decode ->
// metadata check. An invalid state_transition payload triggers
// `ProtocolError` on decode BEFORE the missing-metadata branch is
Expand All @@ -6064,7 +6111,7 @@ mod tests {
})),
};
let provider = unreachable_provider();
let err = <StateTransitionProofResult as FromProof<
let err = <StateTransitionProofOutcome as FromProof<
platform::BroadcastStateTransitionRequest,
>>::maybe_from_proof(
request,
Expand Down
31 changes: 30 additions & 1 deletion packages/rs-drive/src/verify/system/verify_epoch_infos/v0/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ mod tests {
use crate::util::batch::grovedb_op_batch::GroveDbOpBatchV0Methods;
use crate::util::batch::GroveDbOpBatch;
use crate::util::test_helpers::setup::setup_drive_with_initial_state_structure;
use dpp::block::epoch::Epoch;
use dpp::block::epoch::{Epoch, MAX_EPOCH};

#[test]
fn should_prove_and_verify_epoch_infos_ascending() {
Expand Down Expand Up @@ -442,5 +442,34 @@ mod tests {
}
.into()
);

// Descending with a start above the current epoch does NOT skip forward to
// the newest started epoch: the initial state structure pre-creates empty
// epoch trees ahead of the current one, and the query limit is consumed by
// those empty trees, so the proof verifiably contains no epochs at all.
// This is why "fetch the current epoch" cannot be expressed as a single
// descending query from MAX_EPOCH — the SDK's `fetch_current` must first
// learn the current epoch index and use it as an explicit start (as the
// in-range `Some(1)` queries above do).
let max_start_proof = drive
.prove_epochs_infos(MAX_EPOCH, 1, false, None, platform_version)
.expect("should prove epoch infos from MAX_EPOCH");

let (_root_hash, far_future_start_infos) = Drive::verify_epoch_infos(
&max_start_proof,
1,
Some(MAX_EPOCH),
1,
false,
platform_version,
)
.expect("should verify epoch infos descending from MAX_EPOCH");

assert_eq!(
far_future_start_infos.len(),
0,
"descending from inside the pre-created empty epoch window must \
provably return no epochs, not the newest started epoch"
);
}
}
58 changes: 23 additions & 35 deletions packages/rs-sdk-ffi/src/system/queries/platform_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use crate::types::SDKHandle;
use crate::{DashSDKError, DashSDKErrorCode, DashSDKResult, DashSDKResultDataType};
use dash_sdk::dpp::block::extended_epoch_info::v0::ExtendedEpochInfoV0Getters;
use dash_sdk::dpp::block::extended_epoch_info::ExtendedEpochInfo;
use dash_sdk::platform::types::epoch::EpochQuery;
use dash_sdk::platform::{FetchMany, LimitQuery};
use dash_sdk::platform::fetch_current_no_parameters::FetchCurrent;
use std::ffi::CString;
use std::os::raw::c_void;

Expand Down Expand Up @@ -64,40 +63,29 @@ fn get_platform_status(sdk_handle: *const SDKHandle) -> Result<String, String> {

rt.block_on(async move {
// Query for the most recent epoch
let query = LimitQuery {
query: EpochQuery {
start: None,
ascending: false, // Get most recent first
},
limit: Some(1),
start_info: None,
};
match ExtendedEpochInfo::fetch_current(&sdk).await {
Ok(epoch) => {
// Calculate current block height
// This is an approximation - the actual current block height would need a different query
let block_height = epoch.first_block_height();
let core_height = epoch.first_core_block_height();

match ExtendedEpochInfo::fetch_many(&sdk, query).await {
Ok(epochs) => {
// Get the first (most recent) epoch
if let Some((_, Some(epoch))) = epochs.iter().next() {
// Calculate current block height
// This is an approximation - the actual current block height would need a different query
let block_height = epoch.first_block_height();
let core_height = epoch.first_core_block_height();

let json = format!(
r#"{{"version":{},"network":"{}","blockHeight":{},"coreHeight":{}}}"#,
10, // Protocol version
network_str,
block_height,
core_height
);
Ok(json)
} else {
// If no epochs found, return default values
let json = format!(
r#"{{"version":{},"network":"{}","blockHeight":0,"coreHeight":0}}"#,
10, network_str
);
Ok(json)
}
let json = format!(
r#"{{"version":{},"network":"{}","blockHeight":{},"coreHeight":{}}}"#,
10, // Protocol version
network_str,
block_height,
core_height
);
Ok(json)
}
Err(dash_sdk::Error::EpochNotFound) => {
// If no epochs found, return default values
let json = format!(
r#"{{"version":{},"network":"{}","blockHeight":0,"coreHeight":0}}"#,
10, network_str
);
Ok(json)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
Err(e) => Err(format!("Failed to fetch platform status: {}", e)),
}
Expand Down
Loading
Loading