Fix #131: Storage optimisation + Fix #136: Cryptographic hardening for RefundVault - #251
Conversation
…ic hardening (accensa#136) Issue accensa#131 — Move yield-related keys (YieldStrategy, DeployedPrincipal, HarvestedYield, ReserveRatio, MaxDeployRatio) from Instance to Persistent storage so non-yield calls (deposit, refund, withdraw, pause) no longer pay the read/write byte cost of loading them. Persistent entries receive TTL bumping on every write via persist_yield_ttl. Issue accensa#136 — Add domain separator (SHA-256 of the contract address, stored at initialisation) and a monotonic operation nonce incremented on every successful state-changing call. Events now carry the nonce so off-chain indexers can detect replays or reorderings. Separate vault instances produce distinct domain separators, preventing cross-contract replay of signed authorisations. New getter functions get_domain_separator and get_nonce expose these values. Tests verify nonce monotonicity, cross-instance separator uniqueness, and nonce absence on failed calls. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
|
@fredericklamar342-prog Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
MergeKeeper review Scope: in scope for linked issue The pull request successfully implements storage optimization for yield keys and cryptographic hardening with domain separators and monotonic nonces for RefundVault as requested in issues #131 and #136, complete with tests. Reviewed commit: |
|
MergeKeeper merge status Status: blocked Reason: One or more required CI checks failed. Failing checks:
Next steps:
|
Summary
This PR addresses both Issue #131 (storage layout optimisation) and Issue #136 (cryptographic malleability audit and hardening) for the
RefundVaultcontract.Issue #131 — Optimise Storage Layout and Instance Data Footprint
Problem: Yield-related keys (
YieldStrategy,DeployedPrincipal,HarvestedYield,ReserveRatio,MaxDeployRatio) were stored in Instance storage, which is loaded on every contract invocation — including non-yield calls likedeposit,refund,withdraw,pause, and admin transfers. This led to unnecessarily high read/write byte fees on the most common operations.Fix:
persist_yield_ttlhelper.get_yield_info()reads from Persistent storage.docs/storage-audit.mdentries for the affected keys.Acceptance criteria met:
Issue #136 — Audit and Fix Cryptographic Malleability in RefundVault Signatures
Audit finding: RefundVault does not use custom signature verification — it relies entirely on Soroban's built-in
require_auth()mechanism (Ed25519, inherently canonical). There are no ECDSA paths to malleate.Hardening added (defense-in-depth):
Domain Separator (
get_domain_separator): A SHA-256 hash of the contract address, stored atinitializeand never changed. Off-chain systems should bind signed authorizations to this value so a replay against a different vault deployment is rejected. Separate instances produce distinct separators.Monotonic Nonce (
get_nonce): Au64counter incremented on every successful state-changing call (deposit,refund,withdraw,deploy_to_yield,withdraw_from_yield,harvest_yield). Events carry the nonce so off-chain indexers can detect replays or reorderings.Acceptance criteria met:
Tests added
test_domain_separator_is_set_on_initializetest_domain_separator_differs_per_instancetest_nonce_starts_at_zerotest_nonce_increments_on_deposittest_nonce_increments_on_refundtest_nonce_increments_on_withdrawtest_nonce_does_not_increment_on_failed_operationtest_nonce_is_strictly_monotonicEvent assertion tests (
test_events_emitted,test_yield_deployed_event,test_yield_harvested_event) updated to verify the nonce field.Files changed
contracts/refund-vault/src/lib.rs— Storage class changes, domain separator, nonce, event nonce fieldscontracts/refund-vault/src/test.rs— New domain-separator/nonce tests, updated event assertionscontracts/refund-vault/src/yield_tests.rs— Updated event assertions for nonce fieldCHANGELOG.md— Entries for both issuesFixes #136
Fixes #131