fix(sdk): validate batch base structure before signing#3133
Draft
thepastaclaw wants to merge 28 commits into
Draft
fix(sdk): validate batch base structure before signing#3133thepastaclaw wants to merge 28 commits into
thepastaclaw wants to merge 28 commits into
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Issue being fixed or feature implemented
Follow-up to #3096 per shumkov's review:
extend client-side base-structure validation coverage for SDK batch transition builders where DPP already exposes it.
PR #3096 added validation to identity and address transitions. This PR applies the same DPP constructor-backed validation path to document and token transition builders.
What was done?
Enabled the
dppbatch-base-structure-validationfeature fordash-sdk, so the DPPBatchTransition::new_*constructors validate base structure before signing.from_documentconstructors, and broader per-document pre-sign validation parity remains follow-up work.Document transitions touched:
create.rs,delete.rs,replace.rs,purchase.rs,set_price.rs,transfer.rsToken builders touched:
burn.rs,claim.rs,config_update.rs,destroy.rs,purchase.rs,emergency_action.rs,freeze.rs,mint.rs,set_price.rs,transfer.rs,unfreeze.rsContract transitions:
put_contract.rsalready had structure validation viaensure_valid_state_transition_structure, so no changes were needed there.Review follow-up removed the redundant post-sign SDK
validate_batch_base_structurewrapper calls. The DPP constructors are now the single source of truth, and signing only adds signature fields that the base-structure validator does not inspect.Latest review follow-ups preserve both singular
ProtocolError::ConsensusError(...)and pluralProtocolError::ConsensusErrors(...)across wasm-sdk state-transition boundaries as structuredWasmSdkError.consensusErrorsentries. Singular wasm consensus errors now also promote their consensus code to the top-levelWasmSdkError.code, while plural batches keepcode = -1and expose per-error codes inconsensusErrors. They also remove a redundant innerbatch-base-structure-validationcfg inside the state-transition-signing-only DPP sign helper, keep token pre-sign validation accumulating batch-level and per-transition consensus errors, clarify document-side pre-sign scope, and map rs-sdk-ffi protocol consensus errors to readableDashSDKError { code, message }values without changing the C ABI.The Swift
SDKErrorpublic case set remains frozen for source compatibility: public throwing wrappers continue to throw scalarSDKErrorvalues, and protocol failures map to.protocolError(String)with the original human-readable message and no hidden embedded payload. Structured Swift consensus details are available only while the original FFIDashSDKError*is alive viaSDKError.fromDashSDKErrorWithConsensusErrors(_:)/SDKError.consensusErrors(fromDashSDKError:), or when a caller explicitly wraps known details inSDKDetailedError. They are intentionally not retained on scalarSDKErrorafter the wrapper frees the FFI pointer; this avoids the previously attempted best-effort(code, message)sidecar because it could misattribute same-signature concurrent failures.How Has This Been Tested?
cargo fmt --all -- --checkcargo check -p dpp --no-default-features --features state-transition-signing(passes with existing unused-import warnings in
dppunder that reducedfeature set)
cargo check -p wasm-sdkcargo test -p wasm-sdk protocol_consensus_errors --libcargo check -p rs-sdk-fficargo test -p dpp validate_base_structure --libcargo clippy -p dpp --no-default-features --features state-transition-signing --all-targets -- -D warningscargo clippy -p dpp --no-default-features --features state-transition-signing --all-targets -- -D warningscargo clippy -p wasm-sdk -p rs-sdk-ffi --all-targets -- -D warningscargo test --manifest-path packages/rs-sdk-ffi/Cargo.toml --lib sdk_protocol_consensus -- --nocapturecargo clippy -p rs-sdk-ffi --all-targets -- -D warningscargo test -p wasm-sdk protocol_consensus_errors --libcargo clippy -p wasm-sdk --all-targets -- -D warningscargo check -p wasm-sdkxcrun swift-format lint --strict packages/swift-sdk/SwiftTests/Tests/SwiftDashSDKTests/SDKErrorTests.swiftgit diff --checkgit commit --amend:cargo fmt --all -- --check+workspace
cargo checkswift buildinpackages/swift-sdkattempted locally; blocked becauseDashSDKFFI.xcframeworkdoes not contain a binary artifact in this worktree(cd packages/swift-sdk/SwiftTests && swift test --disable-sandbox --filter SDKErrorTests)attempted locally; blocked becauseDashSDKFFI.xcframeworkdoes not contain a binary artifact in this worktreeBreaking Changes
dpp::ProtocolErroris now#[non_exhaustive]and includes pluralConsensusErrors, so downstream Rust crates that exhaustively matchProtocolErrorneed a wildcard arm.