mirror of
https://github.com/logos-blockchain/lssa.git
synced 2026-06-05 00:29:39 +00:00
BREAKING CHANGE:
- Crate `nssa` renamed to `lee`; update `Cargo.toml` dependencies from `nssa = { workspace = true }` to `lee = { workspace = true }`.
- Crate `nssa_core` renamed to `lee_core`; update similarly.
- Crate `key_protocol` moved under `lee`; update `Cargo.toml` dependencies from `key_protocol = { workspace = true }` to `lee_key_protocol = { workspace = true }`.
- Type `NSSATransaction` (in `common`) renamed to `LeeTransaction`.
- Error type `nssa::error::NssaError` renamed to `lee::error::LeeError`.
- Error type `nssa_core::error::NssaCoreError` renamed to `lee_core::error::LeeCoreError`.
- All `use nssa::` and `use nssa_core::` import paths must be updated to `use lee::` and `use lee_core::` respectively.
- Guest programs must replace `write_nssa_outputs` with `write_lee_outputs`.
- The sequencer RocksDB column family for the chain state was renamed. Existing databases are incompatible and must be wiped before running the new version.
- Domain separators updated: `"NSSA_seed"` → `"LEE_seed"` (key derivation), `"NSSA/v0.2/KDF-SHA256/"` → `"LEE/v0.2/KDF-SHA256/"` (encryption KDF), `"/NSSA/v0.2/AccountId/PDA/"` →
`"/LEE/v0.2/AccountId/PDA/"` (public PDA address derivation). All previously derived keys, encrypted outputs, and public PDA addresses are invalidated.
156 lines
4.2 KiB
Rust
156 lines
4.2 KiB
Rust
use std::io;
|
|
|
|
use lee_core::{
|
|
account::{Account, AccountId},
|
|
program::ProgramId,
|
|
};
|
|
use thiserror::Error;
|
|
|
|
#[macro_export]
|
|
macro_rules! ensure {
|
|
($cond:expr, $err:expr) => {
|
|
if !$cond {
|
|
return Err($err.into());
|
|
}
|
|
};
|
|
}
|
|
|
|
#[derive(Error, Debug)]
|
|
pub enum LeeError {
|
|
#[error("Invalid input: {0}")]
|
|
InvalidInput(String),
|
|
|
|
#[error("Program violated execution rules")]
|
|
InvalidProgramBehavior(#[from] InvalidProgramBehaviorError),
|
|
|
|
#[error("Serialization error: {0}")]
|
|
InstructionSerializationError(String),
|
|
|
|
#[error("Invalid private key")]
|
|
InvalidPrivateKey,
|
|
|
|
#[error("IO error: {0}")]
|
|
Io(#[from] io::Error),
|
|
|
|
#[error("Invalid Public Key")]
|
|
InvalidPublicKey(#[source] k256::schnorr::Error),
|
|
|
|
#[error("Invalid hex for public key")]
|
|
InvalidHexPublicKey(#[source] hex::FromHexError),
|
|
|
|
#[error("Failed to write program input: {0}")]
|
|
ProgramWriteInputFailed(String),
|
|
|
|
#[error("Failed to execute program: {0}")]
|
|
ProgramExecutionFailed(String),
|
|
|
|
#[error("Failed to prove program: {0}")]
|
|
ProgramProveFailed(String),
|
|
|
|
#[error("Invalid transaction: {0}")]
|
|
TransactionDeserializationError(String),
|
|
|
|
#[error("Core error")]
|
|
Core(#[from] lee_core::error::LeeCoreError),
|
|
|
|
#[error("Program output deserialization error: {0}")]
|
|
ProgramOutputDeserializationError(String),
|
|
|
|
#[error("Circuit output deserialization error: {0}")]
|
|
CircuitOutputDeserializationError(String),
|
|
|
|
#[error("Invalid privacy preserving execution circuit proof")]
|
|
InvalidPrivacyPreservingProof,
|
|
|
|
#[error("Circuit proving error")]
|
|
CircuitProvingError(String),
|
|
|
|
#[error("Invalid program bytecode")]
|
|
InvalidProgramBytecode(#[source] anyhow::Error),
|
|
|
|
#[error("Program already exists")]
|
|
ProgramAlreadyExists,
|
|
|
|
#[error("Chain of calls is too long")]
|
|
MaxChainedCallsDepthExceeded,
|
|
|
|
#[error("Max account nonce reached")]
|
|
MaxAccountNonceReached,
|
|
|
|
#[error("Execution outside of the validity window")]
|
|
OutOfValidityWindow,
|
|
}
|
|
|
|
#[derive(Error, Debug)]
|
|
pub enum InvalidProgramBehaviorError {
|
|
#[error(
|
|
"Inconsistent pre-state for account {account_id} : expected {expected:?}, actual {actual:?}"
|
|
)]
|
|
InconsistentAccountPreState {
|
|
account_id: AccountId,
|
|
// Boxed to reduce the size of the error type
|
|
expected: Box<Account>,
|
|
actual: Box<Account>,
|
|
},
|
|
|
|
#[error("Unauthorized account marked as authorized")]
|
|
InvalidAccountAuthorization { account_id: AccountId },
|
|
|
|
#[error("Authorized account marked as not authorized")]
|
|
AuthorizedAccountMarkedAsNotAuthorized { account_id: AccountId },
|
|
|
|
#[error("Program ID mismatch: expected {expected:?}, actual {actual:?}")]
|
|
MismatchedProgramId {
|
|
expected: ProgramId,
|
|
actual: ProgramId,
|
|
},
|
|
|
|
#[error("Caller program ID mismatch: expected {expected:?}, actual {actual:?}")]
|
|
MismatchedCallerProgramId {
|
|
expected: Option<ProgramId>,
|
|
actual: Option<ProgramId>,
|
|
},
|
|
|
|
#[error(transparent)]
|
|
ExecutionValidationFailed(#[from] lee_core::program::ExecutionValidationError),
|
|
|
|
#[error("Trying to claim account {account_id} which is not default")]
|
|
ClaimedNonDefaultAccount { account_id: AccountId },
|
|
|
|
#[error("Trying to claim account {account_id} which is not authorized")]
|
|
ClaimedUnauthorizedAccount { account_id: AccountId },
|
|
|
|
#[error("PDA claim mismatch: expected {expected:?}, actual {actual:?}")]
|
|
MismatchedPdaClaim {
|
|
expected: AccountId,
|
|
actual: AccountId,
|
|
},
|
|
|
|
#[error("Default account {account_id} was modified without being claimed")]
|
|
DefaultAccountModifiedWithoutClaim { account_id: AccountId },
|
|
|
|
#[error("Called program {program_id:?} which is not listed in dependencies")]
|
|
UndeclaredProgramDependency { program_id: ProgramId },
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
|
|
#[derive(Debug)]
|
|
enum TestError {
|
|
TestErr,
|
|
}
|
|
|
|
fn test_function_ensure(cond: bool) -> Result<(), TestError> {
|
|
ensure!(cond, TestError::TestErr);
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[test]
|
|
fn ensure_works() {
|
|
assert!(test_function_ensure(true).is_ok());
|
|
assert!(test_function_ensure(false).is_err());
|
|
}
|
|
}
|