Skip to content

Commit 8ede7c2

Browse files
fix(vapp): soft-revert on insufficient balance (#221)
* fix(vapp): soft-revert clear on insufficient balance instead of panicking * fix(vapp): extend soft-revert to transfer/withdraw/delegate and fix punishment or_default * fix(vapp): use get().ok_or on clear prover lookup to avoid default leaf * style(vapp): apply stable rustfmt to satisfy ci * test(vapp): cover ProverDelegatedSignerMismatch with real delegation `test_clear_delegated_signer_mismatch` now short-circuits on `ProverDoesNotExist` after the `get().ok_or(..)` prover lookup change, so the delegated-signer panic path is uncovered. Add a sibling test that registers the prover, installs a delegate via `Delegate`, and submits a Clear whose bid is signed by the original (now non-delegated) key — forcing the handler past the existence check and into the signer comparison. --------- Co-authored-by: fakedev9999 <taehoon@succinct.xyz>
1 parent 48f60ee commit 8ede7c2

9 files changed

Lines changed: 541 additions & 196 deletions

File tree

crates/vapp/src/errors.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,50 @@ use thiserror::Error;
77

88
use crate::storage::StorageError;
99

10+
/// An error returned by the vApp state transition function.
11+
///
12+
/// `Panic` halts block production. `Revert` is itself a valid state transition: the offending
13+
/// tx id is retired, balances are untouched, and the cursor advances.
14+
#[derive(Debug, Error, PartialEq)]
15+
#[allow(missing_docs)]
16+
pub enum VAppError {
17+
#[error("vapp panicked: {0}")]
18+
Panic(#[from] VAppPanic),
19+
20+
#[error("vapp reverted: {0}")]
21+
Revert(#[from] VAppRevert),
22+
}
23+
24+
/// A recoverable state transition failure. The driver logs and advances the cursor.
25+
#[derive(Debug, Clone, Error, PartialEq)]
26+
#[allow(missing_docs)]
27+
pub enum VAppRevert {
28+
#[error(
29+
"Clear rejected: account {account} cannot cover cost: required {required}, balance {balance}"
30+
)]
31+
InsufficientClearBalance { account: Address, required: U256, balance: U256 },
32+
33+
#[error(
34+
"Clear rejected: account {account} cannot cover punishment for unexecutable request: required {required}, balance {balance}"
35+
)]
36+
InsufficientPunishmentBalance { account: Address, required: U256, balance: U256 },
37+
38+
#[error(
39+
"Delegate rejected: prover owner {account} cannot cover delegation fee: required {required}, balance {balance}"
40+
)]
41+
InsufficientDelegateBalance { account: Address, required: U256, balance: U256 },
42+
43+
#[error(
44+
"Transfer rejected: account {account} cannot cover amount + fee: required {required}, balance {balance}"
45+
)]
46+
InsufficientTransferBalance { account: Address, required: U256, balance: U256 },
47+
48+
#[error(
49+
"Withdraw rejected: account {account} cannot cover amount (+ fee on self-withdraw): required {required}, balance {balance}"
50+
)]
51+
InsufficientWithdrawBalance { account: Address, required: U256, balance: U256 },
52+
}
53+
1054
/// An unrecoverable error that will prevent a transaction from being included in the ledger.
1155
#[derive(Debug, Error, PartialEq)]
1256
#[allow(missing_docs)]

crates/vapp/src/state.rs

Lines changed: 125 additions & 80 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)