Skip to content
Closed
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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ jobs:
--wasm target/wasm32v1-none/release/tholos.wasm \
--output-dir /tmp/tholos-sdk-regenerated \
--overwrite
sha256sum target/wasm32v1-none/release/tholos.wasm
sha256sum packages/tholos-sdk/src/index.ts /tmp/tholos-sdk-regenerated/src/index.ts
diff -u packages/tholos-sdk/src/index.ts /tmp/tholos-sdk-regenerated/src/index.ts || true
if ! diff -rq packages/tholos-sdk/src /tmp/tholos-sdk-regenerated/src; then
echo "::error::packages/tholos-sdk/src is out of date with contracts/tholos's current public interface. Regenerate it (see packages/tholos-sdk/README.md) and commit the result."
exit 1
Expand Down
14 changes: 14 additions & 0 deletions contracts/tholos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ pub enum Error {
ResolverNotInCommittee = 19,
RotationTargetAlreadyResolver = 20,
NotProposer = 21,
/// The caller is the asserter of the assertion they are trying to dispute.
/// An asserter disputing their own assertion would consume the one dispute
/// slot without any economic risk (they receive both bonds back regardless
/// of the resolver vote), nullifying the bond-forfeiture deterrent.
SelfDispute = 22,
}

const DAY_IN_LEDGERS: u32 = 17280;
Expand Down Expand Up @@ -624,6 +629,15 @@ impl Tholos {
return Err(Error::NotPending);
}

// An asserter must not be allowed to dispute their own assertion.
// Doing so would consume the one dispute slot and guarantee the asserter
// receives both bonds back regardless of the resolver vote (since
// `resolve` pays the winner, and winner == asserter == disputer either
// way), nullifying the bond-forfeiture deterrent entirely.
if disputer == assertion.asserter {
return Err(Error::SelfDispute);
}

let window: u64 = Self::get(&env, &DataKey::ChallengeWindow)?;
if env.ledger().timestamp() > assertion.opened_at + window {
return Err(Error::ChallengeWindowClosed);
Expand Down
35 changes: 35 additions & 0 deletions contracts/tholos/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,41 @@ fn test_cannot_dispute_an_already_disputed_assertion() {
assert_eq!(result, Err(Ok(Error::NotPending)));
}

#[test]
fn test_asserter_cannot_dispute_own_assertion() {
// An asserter disputing their own assertion would consume the one dispute
// slot while facing no economic risk (they receive both bonds back
// regardless of the resolver vote), nullifying the bond-forfeiture
// deterrent. The fix adds `Error::SelfDispute = 22` and rejects the call
// before any state is mutated or any bond is transferred.
let f = Fixture::new();
let asserter = f.funded_address();

let id = f.client.assert_outcome(&asserter, &true);
let asserter_balance_after_assert = f.token.balance(&asserter);

let result = f.client.try_dispute(&asserter, &id);

// Must return SelfDispute and leave the assertion untouched.
assert_eq!(result, Err(Ok(Error::SelfDispute)));
assert_eq!(
f.client.get_assertion_state(&id).status,
Status::Pending,
"assertion must still be Pending after a rejected self-dispute"
);
assert_eq!(
f.client.get_assertion_state(&id).disputer,
None,
"disputer must remain None after a rejected self-dispute"
);
// No second bond transfer must have occurred.
assert_eq!(
f.token.balance(&asserter),
asserter_balance_after_assert,
"asserter balance must be unchanged after a rejected self-dispute"
);
}

#[test]
fn test_non_resolver_cannot_vote() {
let f = Fixture::new();
Expand Down
Loading
Loading