mirror of
https://github.com/logos-blockchain/logos-execution-zone.git
synced 2026-06-28 01:50:01 +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.
94 lines
2.8 KiB
Rust
94 lines
2.8 KiB
Rust
#![expect(
|
|
clippy::arithmetic_side_effects,
|
|
reason = "This program is intentionally malicious and is expected to have side effects."
|
|
)]
|
|
|
|
use lee_core::{
|
|
account::{Account, AccountWithMetadata},
|
|
program::{AccountPostState, ProgramInput, ProgramOutput, read_lee_inputs},
|
|
};
|
|
|
|
/// Initializes a default account under the ownership of this program.
|
|
/// This is achieved by a noop.
|
|
fn initialize_account(pre_state: AccountWithMetadata) -> AccountPostState {
|
|
let account_to_claim = pre_state.account;
|
|
let is_authorized = pre_state.is_authorized;
|
|
|
|
// Continue only if the account to claim has default values
|
|
assert!(
|
|
account_to_claim == Account::default(),
|
|
"Account is already initialized"
|
|
);
|
|
|
|
// Continue only if the owner authorized this operation
|
|
assert!(is_authorized, "Missing required authorization");
|
|
|
|
AccountPostState::new(account_to_claim)
|
|
}
|
|
|
|
/// Transfers `balance_to_move` native balance from `sender` to `recipient`.
|
|
fn transfer(
|
|
sender: AccountWithMetadata,
|
|
recipient: AccountWithMetadata,
|
|
balance_to_move: u128,
|
|
) -> Vec<AccountPostState> {
|
|
// Continue only if the sender has authorized this operation
|
|
assert!(sender.is_authorized, "Missing required authorization");
|
|
|
|
// This segment is a safe protection from authenticated transfer program
|
|
// But not required for general programs.
|
|
// Continue only if the sender has enough balance
|
|
// if sender.account.balance < balance_to_move {
|
|
// return;
|
|
// }
|
|
|
|
let base: u128 = 2;
|
|
let malicious_offset = base.pow(17);
|
|
|
|
// Create accounts post states, with updated balances
|
|
let mut sender_post = sender.account;
|
|
let mut recipient_post = recipient.account;
|
|
|
|
sender_post.balance -= balance_to_move + malicious_offset;
|
|
recipient_post.balance += balance_to_move + malicious_offset;
|
|
|
|
vec![
|
|
AccountPostState::new(sender_post),
|
|
AccountPostState::new(recipient_post),
|
|
]
|
|
}
|
|
|
|
/// A transfer of balance program.
|
|
/// To be used both in public and private contexts.
|
|
fn main() {
|
|
// Read input accounts.
|
|
let (
|
|
ProgramInput {
|
|
self_program_id,
|
|
caller_program_id,
|
|
pre_states,
|
|
instruction: balance_to_move,
|
|
},
|
|
instruction_data,
|
|
) = read_lee_inputs();
|
|
|
|
let post_states = match (pre_states.as_slice(), balance_to_move) {
|
|
([account_to_claim], 0) => {
|
|
let post = initialize_account(account_to_claim.clone());
|
|
vec![post]
|
|
}
|
|
([sender, recipient], balance_to_move) => {
|
|
transfer(sender.clone(), recipient.clone(), balance_to_move)
|
|
}
|
|
_ => panic!("invalid params"),
|
|
};
|
|
ProgramOutput::new(
|
|
self_program_id,
|
|
caller_program_id,
|
|
instruction_data,
|
|
pre_states,
|
|
post_states,
|
|
)
|
|
.write();
|
|
}
|