Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion ERROR_CODES.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,6 @@ This document provides a comprehensive reference of all `ContractError` variants
| **78** | `InvalidWasmHash` | `execute_upgrade` was called with an all-zero or otherwise invalid WASM hash. | Supply the valid WASM hash of the new contract build. |
| **79** | `NoPendingTreasury` | `accept_treasury` was called but no pending treasury is set. | The admin must call `set_treasury` first to register a pending treasury. |
| **80** | `DuplicateResolver` | The same address appears more than once in a resolver configuration. Two triggers share this code (both in `validate_resolvers`, `contracts/escrow/src/internal.rs`): (1) **duplicate multi-resolver** — an address is repeated in a `ResolverSet::Multi` list; (2) **fallback equality** — `primary_resolver == backup_resolver` in a `ResolverSet::Fallback`. Kept distinct from `ConflictingRoles` (23), which means a resolver also holds the Seller or Buyer role. | Ensure every multi-resolver address is unique and that a fallback escrow's primary and backup resolvers are different accounts. |
| **81** | `EvidenceLimitReached` | `submit_dispute_evidence` was called but the escrow's evidence log already holds `MAX_EVIDENCE_ENTRIES` (5) entries. | No further evidence can be added; rely on the entries already logged. |
| **81** | `DirectUnpauseBlocked` | `unpause_contract` was called directly while `GLOBAL_CONFIG_FLAG_TIMELOCKED_UNPAUSE_ONLY` is set. | Use `queue_unpause_contract` then `execute_unpause_contract` instead of unpausing directly. |
| **82** | `InvalidSplitBps` | A `ResolutionType::Split(bps)` resolution carries a payee share greater than `BASIS_POINTS` (`10_000`). | Supply a split share at or below 10,000 basis points. |
| **83** | `EvidenceLimitReached` | `submit_dispute_evidence` was called but the escrow's evidence log already holds `MAX_EVIDENCE_ENTRIES` (5) entries. | No further evidence can be added; rely on the entries already logged. |
2 changes: 1 addition & 1 deletion EVENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ The tables below list all 61 event topics. The `Payload fields` column is the ex
| `RecoveryWithdraw` | `(symbol_short!("Recovery"), symbol_short!("Withdraw"))` | `schema_version: u32`<br>`escrow_id: u64`<br>`buyer: Address`<br>`amount: i128`<br>`timestamp: u64` | Recovery-mode withdrawal to the buyer. |
| `RecoveryModeUpdated` | `(symbol_short!("Recovery"), symbol_short!("ModeUpd"))` | `schema_version: u32`<br>`enabled: bool`<br>`caller: Address`<br>`timestamp: u64` | Recovery mode enabled or disabled. |

> Note: the source doc comments on the three `Timelock*` emitters mention an `operation as u32` topic. The actual `publish` calls use only the two-symbol tuples shown above; `operation` is a payload field, not a topic. This table documents the emitted reality.
> Note: the three `Timelock*` emitters publish only the two-symbol tuples shown above; `operation` is a payload field, not a topic. `test_admin_event_emissions::timelock_events_stamp_current_schema_version_and_standard_topics` pins this shape.

## Example XDR payloads

Expand Down
8 changes: 7 additions & 1 deletion bindings/src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ export const enum ErrorCode {
InvalidWasmHash = 78,
NoPendingTreasury = 79,
DuplicateResolver = 80,
EvidenceLimitReached = 81,
DirectUnpauseBlocked = 81,
InvalidSplitBps = 82,
EvidenceLimitReached = 83,
}

/** Human-readable message for every contract error code. */
Expand Down Expand Up @@ -237,6 +239,10 @@ export const ERROR_MESSAGES: Readonly<Record<ErrorCode, string>> = {
"No pending treasury is set for accept_treasury.",
[ErrorCode.DuplicateResolver]:
"The same address appears more than once in the resolver configuration.",
[ErrorCode.DirectUnpauseBlocked]:
"Direct unpause is blocked while timelocked unpause is required; queue and execute it instead.",
[ErrorCode.InvalidSplitBps]:
"The split resolution's payee share exceeds the maximum of 10,000 basis points.",
[ErrorCode.EvidenceLimitReached]:
"The escrow's dispute evidence log has reached its maximum number of entries.",
};
Expand Down
130 changes: 69 additions & 61 deletions contracts/escrow/gas_baseline.json
Original file line number Diff line number Diff line change
@@ -1,143 +1,151 @@
{
"_comment": "Corrected per-invocation harness baseline measured on main b16ac31; set_admin includes #1233 invalidation: CPU +49.69%, memory +8.36% vs main.",
"_comment": "Gas baselines for contracts/escrow/src/test_gas_profile.rs. Regenerate with `make bench-gas-update` after an intentional change.",
"appeal_dispute": {
"cpu_insns": 541433,
"mem_bytes": 192437
"cpu_insns": 638398,
"mem_bytes": 216157
},
"approve_refund": {
"cpu_insns": 729201,
"mem_bytes": 233139
"cpu_insns": 812693,
"mem_bytes": 244298
},
"auto_release": {
"cpu_insns": 783497,
"mem_bytes": 241473
"cpu_insns": 856213,
"mem_bytes": 252793
},
"batch_create_escrow(10)": {
"cpu_insns": 4706587,
"mem_bytes": 1165214
"cpu_insns": 4811967,
"mem_bytes": 1202084
},
"bounded_basket_read(3 tokens)": {
"cpu_insns": 237094,
"mem_bytes": 116321
},
"bounded_basket_write(3 tokens)": {
"cpu_insns": 717081,
"mem_bytes": 233104
},
"cancel_escrow (Pending)": {
"cpu_insns": 400025,
"mem_bytes": 131728
"cpu_insns": 432900,
"mem_bytes": 136943
},
"co_signed_release": {
"cpu_insns": 798450,
"mem_bytes": 266823
"cpu_insns": 860201,
"mem_bytes": 278149
},
"confirm_delivery": {
"cpu_insns": 977929,
"mem_bytes": 289450
"cpu_insns": 934515,
"mem_bytes": 272816
},
"create_basket_escrow(3 tokens)": {
"cpu_insns": 706707,
"mem_bytes": 227080
"cpu_insns": 717081,
"mem_bytes": 233104
},
"create_escrow": {
"cpu_insns": 531704,
"mem_bytes": 178808
"cpu_insns": 542242,
"mem_bytes": 182495
},
"create_escrow_multi(3-of-3)": {
"cpu_insns": 524968,
"mem_bytes": 184748
"cpu_insns": 532050,
"mem_bytes": 188212
},
"create_escrow_with_fallback": {
"cpu_insns": 511941,
"mem_bytes": 183168
"cpu_insns": 519023,
"mem_bytes": 186632
},
"emergency_drain": {
"cpu_insns": 698874,
"mem_bytes": 242181
"cpu_insns": 774053,
"mem_bytes": 252880
},
"ensure_action_not_paused": {
"cpu_insns": 76489,
"mem_bytes": 38070
},
"finalize_dispute": {
"cpu_insns": 1090984,
"mem_bytes": 340472
"cpu_insns": 1025599,
"mem_bytes": 321714
},
"fund_escrow": {
"cpu_insns": 841675,
"mem_bytes": 264025
"cpu_insns": 904406,
"mem_bytes": 276326
},
"get_escrow (view)": {
"cpu_insns": 184036,
"mem_bytes": 87939
"cpu_insns": 202170,
"mem_bytes": 91794
},
"get_fee_config (view)": {
"cpu_insns": 93838,
"mem_bytes": 41130
},
"get_stats (view)": {
"cpu_insns": 2255866,
"mem_bytes": 537231
"cpu_insns": 3174918,
"mem_bytes": 720684
},
"initialize": {
"cpu_insns": 99902,
"mem_bytes": 39735
},
"mark_shipped": {
"cpu_insns": 396144,
"mem_bytes": 134559
"cpu_insns": 442250,
"mem_bytes": 140114
},
"multicall(fund x3)": {
"cpu_insns": 2728749,
"mem_bytes": 710827
"cpu_insns": 2941841,
"mem_bytes": 757582
},
"mutual_cancel": {
"cpu_insns": 717662,
"mem_bytes": 230956
"cpu_insns": 798557,
"mem_bytes": 242165
},
"pause_contract": {
"cpu_insns": 164065,
"mem_bytes": 56607
},
"post_message": {
"cpu_insns": 343336,
"mem_bytes": 143670
"cpu_insns": 364124,
"mem_bytes": 147930
},
"raise_dispute": {
"cpu_insns": 517163,
"mem_bytes": 197985
"cpu_insns": 555232,
"mem_bytes": 206844
},
"request_refund": {
"cpu_insns": 409119,
"mem_bytes": 137880
"cpu_insns": 473358,
"mem_bytes": 147817
},
"resolve_dispute (Refund)": {
"cpu_insns": 649844,
"mem_bytes": 221531
"cpu_insns": 631617,
"mem_bytes": 218720
},
"resolve_dispute (Release)": {
"cpu_insns": 649844,
"mem_bytes": 221531
"cpu_insns": 630446,
"mem_bytes": 218720
},
"rotate_resolver": {
"cpu_insns": 276055,
"mem_bytes": 106877
"cpu_insns": 296227,
"mem_bytes": 111378
},
"set_admin": {
"cpu_insns": 214788,
"mem_bytes": 59336
},
"set_arbitration_fee": {
"cpu_insns": 171664,
"mem_bytes": 57065
"cpu_insns": 176940,
"mem_bytes": 57277
},
"set_fee": {
"cpu_insns": 167648,
"mem_bytes": 56464
"cpu_insns": 172924,
"mem_bytes": 56676
},
"set_protocol_fee": {
"cpu_insns": 171664,
"mem_bytes": 57065
"cpu_insns": 176940,
"mem_bytes": 57277
},
"unpause_contract": {
"cpu_insns": 165535,
"mem_bytes": 56863
"cpu_insns": 170811,
"mem_bytes": 57075
},
"vote (multi-resolver, first)": {
"cpu_insns": 299009,
"mem_bytes": 134101
"cpu_insns": 317615,
"mem_bytes": 138237
}
}
35 changes: 9 additions & 26 deletions contracts/escrow/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,29 +187,6 @@ fn clear_all_timelock_proposals(env: &Env, canceller: &Address) {
}
}

/// Cancel all outstanding proposals when the admin changes. A rejected
/// execution cannot do this itself: Soroban rolls back state and events on error.
fn invalidate_timelocks_on_rotation(env: &Env) {
// TimelockOperation discriminants are append-only; update the upper bound
// when a new operation is added.
for operation in 1..=(TimelockOperation::SetTimelockDelay as u32) {
if let Some(proposal) = storage::read_timelock_proposal(env, operation) {
storage::remove_timelock_proposal(env, operation);
env.storage()
.instance()
.set(&DataKey::InvalidatedTimelockOp(operation), &true);
// Cancellation is automatic, not an action signed by the new admin.
emit_timelock_cancelled(
env,
operation,
proposal.proposer.clone(),
env.current_contract_address(),
);
emit_timelock_admin_mismatch(env, operation, proposal.proposer);
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -1095,9 +1072,7 @@ impl Escrow {
.persistent()
.get(&DataKey::UpgradeHistory)
.unwrap_or_else(|| soroban_sdk::Vec::new(&env));
let next_version = u32::try_from(history.len())
.unwrap_or(u32::MAX)
.saturating_add(1);
let next_version = history.len().saturating_add(1);
history.push_back(crate::types::UpgradeRecord {
wasm_hash: new_wasm_hash.clone(),
upgraded_at: env.ledger().timestamp(),
Expand Down Expand Up @@ -1204,6 +1179,10 @@ impl Escrow {
caller: Address,
treasury: Address,
) -> Result<(), ContractError> {
// Validate before hashing so an unusable treasury can never enter the
// timelock queue and only fail once the proposal is already executable.
validate_treasury_change(&env, &treasury)?;

let mut params = Vec::new(&env);
params.push_back(treasury.into_val(&env));
queue_timelock_op(&env, &caller, TimelockOperation::SetTreasury as u32, params)
Expand Down Expand Up @@ -1238,6 +1217,10 @@ impl Escrow {
caller: Address,
new_collector: Address,
) -> Result<(), ContractError> {
// Validate before hashing so an unusable collector can never enter the
// timelock queue and only fail once the proposal is already executable.
validate_fee_collector_change(&env, &new_collector)?;

let mut params = Vec::new(&env);
params.push_back(new_collector.into_val(&env));
queue_timelock_op(
Expand Down
Loading