Problem Statement. decrement_locked reads, mutates in-memory, then writes the whole
Map<Address, i128>. Because Map is a Soroban instance-storage value, every read
deserializes and every write serializes — an O(N) instance-storage ratchet every time a
token is decremented.
Why it matters. Beyond CPU cost, the bigger risk is that during
batch_create_packages, intermediate locked-map reads are technically the contract's
"current" state, but a reentered call would see them and could overcommit.
Technical Context. lib.rs::decrement_locked is invoked after every claim,
disburse, revoke, cancel_package, and refund. Each call serializes a fresh map.
Expected Outcome. Switch from Map to a per-token instance-storage Symbol → i128
(TotalLocked: token) and read/write one cell per call.
Acceptance Criteria.
- All four call sites (claim, disburse, revoke, cancel_package, refund) use the new
accessor.
- Existing
aid_escrow_tests.rs continues to pass unchanged.
- Gas profiling of
gas_profiling.rs shows measurable improvement for batch ops
(positive or neutral).
Implementation Notes. Use env.storage().instance().set(&TotalLocked::Token(token), &new) and a typed accessor via contracttype enum.
Files or modules likely to be affected. app/onchain/contracts/aid_escrow/src/lib.rs,
tests/aid_escrow_tests.rs, tests/gas_profiling.rs.
Dependencies. #18 (incremental aggregates).
Difficulty. Hard
Estimated effort. L
Backlog item #16 from `docs/maintainer-issue-backlog.md.
Problem Statement.
decrement_lockedreads, mutates in-memory, then writes the wholeMap<Address, i128>. BecauseMapis a Soroban instance-storage value, every readdeserializes and every write serializes — an O(N) instance-storage ratchet every time a
token is decremented.
Why it matters. Beyond CPU cost, the bigger risk is that during
batch_create_packages, intermediate locked-map reads are technically the contract's"current" state, but a reentered call would see them and could overcommit.
Technical Context.
lib.rs::decrement_lockedis invoked after everyclaim,disburse,revoke,cancel_package, andrefund. Each call serializes a fresh map.Expected Outcome. Switch from Map to a per-token instance-storage
Symbol → i128(
TotalLocked: token) and read/write one cell per call.Acceptance Criteria.
accessor.
aid_escrow_tests.rscontinues to pass unchanged.gas_profiling.rsshows measurable improvement for batch ops(positive or neutral).
Implementation Notes. Use
env.storage().instance().set(&TotalLocked::Token(token), &new)and a typed accessor viacontracttypeenum.Files or modules likely to be affected.
app/onchain/contracts/aid_escrow/src/lib.rs,tests/aid_escrow_tests.rs,tests/gas_profiling.rs.Dependencies. #18 (incremental aggregates).
Difficulty. Hard
Estimated effort. L
Backlog item #16 from `docs/maintainer-issue-backlog.md.