Description:
This PR resolves #305 by implementing a gas cost tracking module and adding optimization hooks for key operations to support cost observability and arbitrary budget limit enforcement.
Key Changes:
- GasTracker Module (
src/gas.rs): Introduced a flexible gas monitoring and limits enforcement module, storing limits in contract instance storage. - Observability Hooks injected: Added
start_trackingandend_trackinglifecycle hooks into the primary entrypoints:create_eventplace_betresolve_marketdistribute_payouts
- Gas Event Publications: Included explicit reporting via
soroban_sdk::events::publishemittinggas_usedanalytics symbols alongside their corresponding market action keys for indexing. - Admin Configuration (Optional Caps): Exposes
set_limitallowing contract administrators to dynamically define the gas capacity limits for explicit contract functions. - Optimization Guidelines: Embedded explicit optimization rules as NatSpec-style comments directly inside the
GasTrackerdocumentation covering maps, batching, and memory caching strategies.
Verification:
- Validated compatibility with existing structs.
- Verified test correctness: All 440 property and unit tests complete successfully, maintaining the >95% confidence baseline.
Summary: Fixed two critical bugs in error code handling and added regression tests to prevent future regressions in error context diagnostics.
-
Error Code Format (GasBudgetExceeded)
- Issue:
Error::GasBudgetExceeded.code()returned"GAS BUDGET EXCEEDED"(spaces) instead of"GAS_BUDGET_EXCEEDED"(underscores) - Impact: Pattern-matching on error codes failed in external systems and error handlers
- Fix: Changed line 1378 in
src/err.rsto use underscores
- Issue:
-
Technical Details Operation Name
- Issue:
ErrorHandler::get_technical_details()passederror.code()as theop=argument instead ofcontext.operation - Impact: Operation names were not recorded in technical details, breaking diagnostic logs
- Fix: Changed line 1276 in
src/err.rsto usecontext.operation.to_string()
- Issue:
Three new regression tests added to src/err.rs (#[cfg(test)] block):
test result: ok. 11 passed; 0 failed
Regression Tests:
✓ test_gas_budget_exceeded_description_is_exhaustive
✓ test_gas_budget_exceeded_code_uses_underscores
✓ test_technical_details_contains_operation_name
All existing error tests continue to pass:
✓ test_error_categorization
✓ test_error_recovery_strategy
✓ test_detailed_error_message_does_not_panic
✓ test_error_context_validation_valid
✓ test_error_context_validation_empty_operation_fails
✓ test_validate_error_recovery_no_duplicate_check
✓ test_error_analytics
✓ test_technical_details_not_placeholder
- Pattern-Matching Attacks: Consumers of error codes depend on canonical string representations. Inconsistent spacing/formatting breaks external error routing and security policies.
- Information Disclosure: Missing operation names in technical details prevent proper audit logging and forensic analysis of failed operations.
- Error Code Consistency: All error codes use uppercase with underscores (no spaces)
- Exhaustive Descriptions: Every Error variant maps to a unique, non-empty description
- Technical Details Completeness: Operation context is always recorded in diagnostic strings for traceability
- ✗ Not validating error descriptions against contract specification (deferred to documentation)
- ✗ Not implementing persistent error audit trails (on-chain logging is stateless)
- ✗ Not adding encryption/signing to error messages (external systems handle transport security)
Summary: Align the workspace dependency baseline with the supported Stellar/Soroban release line by updating the root workspace dependency from soroban-sdk = "22.0.0" to soroban-sdk = "25.0.0" and documenting the required post-bump verification.
- Workspace dependency bump: Updated the root workspace dependency in
Cargo.tomlso all contract crates inherit Soroban SDK25.0.0. - Root README added: Added
README.mddescribing the workspace baseline, focused verification command, and documentation links. - Audit documentation: Added
docs/security/SOROBAN_SDK_AUDIT.mdand linked it fromdocs/README.mdfor auditors and integrators.
Rust tooling was not installed in the execution environment for this task, so cargo update / cargo test -p predictify-hybrid could not be run here.
Recommended verification on a machine with Cargo installed:
cargo update -p soroban-sdk
cargo test -p predictify-hybrid- Unsupported dependency risk: Building contracts against an unsupported Soroban SDK line can produce artifacts that diverge from the current Stellar runtime expectations.
- Integrator drift: A stale workspace pin can cause downstream consumers to compile and test against an obsolete contract environment.
- Single source of truth: All workspace crates inherit the Soroban SDK version from the root workspace manifest.
- Documented upgrade path: The supported dependency target and required verification steps are now explicit in repository docs.
- Reviewability: Auditors can identify the upgrade touchpoint immediately from the root manifest and linked audit note.
- Not claiming Soroban 25 runtime compatibility without a real Cargo test pass
- Not manually editing
Cargo.lock - Not changing contract behavior beyond the workspace dependency target and supporting docs