refactor!(lee): Change program_owner: ProgramId to AccountId (#722)

* feat(lee): store deployed programs as Account-shaped state, keyed by AccountId

Program-as-Account migration, first slice: V03State.programs becomes
HashMap<AccountId, Account> instead of HashMap<ProgramId, Program>,
with the elf held directly in Account.data. The map key is derived
from ProgramId via a new 1:1 From<ProgramId> for AccountId conversion
(both types are exactly 32 bytes) rather than a hash, since ProgramId
is already content-derived from the elf.

Account.program_owner stays ProgramId-typed everywhere - this only
changes how deployed programs are stored and looked up host-side, not
the dispatch/authorization model any guest program logic depends on.
Dispatch resolves a ChainedCall's program_id by converting to
AccountId, fetching the Account, and reconstructing a Program via
new_unchecked for execution.

DATA_MAX_LENGTH is raised from 100 KiB to 700 KiB to fit real program
elfs (observed 375 KB-631 KB) directly in Account.data; noted in its
docstring as a rough placeholder pending real transaction/block-size
budget analysis.

* fix(lee): store deployed programs as Account-shaped state, correct SeenShard cap

Corrects lee/state_machine internals for the Program-as-Account migration
and fixes SeenShard::MAX_DELIVERIES, which was still calibrated for the
old 100 KiB DATA_MAX_LENGTH instead of the current 700 KiB cap. Rebuilds
program artifacts and the sequencer test fixture to match.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* address PR #720 review nits

- Use FIXME instead of TODO for the temporary ProgramId->AccountId
  conversion, per review convention for patches guaranteed to be
  fixed later.
- Derive cross_zone_inbox's MAX_DELIVERIES from DATA_MAX_LENGTH
  instead of a hand-recomputed literal, so it stays in sync
  automatically the next time the cap changes.

* feat(lee): migrate Account.program_owner from ProgramId to AccountId

Account.program_owner is now AccountId-typed instead of ProgramId,
via a new bijective From<ProgramId> for AccountId / From<AccountId>
for ProgramId conversion pair (pure byte reinterpretation, not a
hash - both types are exactly 32 bytes). Adds DEFAULT_PROGRAM_OWNER
as the AccountId-typed counterpart to DEFAULT_PROGRAM_ID, used at
every program_owner comparison/claim site instead of an inline
AccountId::default().

Touches every call site across lee_core, lee (including the
guest-side privacy-preserving circuit), all 16 deployed guest
programs, wallet/wallet-ffi, indexer_ffi/indexer_service/
indexer_service_protocol, sequencer_core, testnet_initial_state,
system_accounts, cross_zone, storage, cycle_bench, and
integration_tests - mostly mechanical .into() conversions, plus two
simplifications: wallet's manual base58 encode/decode of
program_owner was dead code once it's AccountId (which already has
Display/FromStr), and the FFI crates' program_owner field now reuses
the existing generic FfiBytes32 wrapper instead of the now-unused
FfiProgramId one.

Rebuilds every guest ELF artifact and the prebuilt sequencer test
fixture via just build-artifacts, since execute_and_prove runs
against the checked-in precompiled privacy_preserving_circuit.bin,
which isn't rebuilt automatically by cargo test/check.

* chore(lee): rebuild artifacts after rebase, drop unused base58 dep

Rebases marvin/program-as-account-2 onto the updated
marvin/program-as-account (SeenShard cap fix), regenerating program
and circuit artifacts plus the sequencer test fixture to match.
Also removes lez/wallet's now-unused base58 dependency, dead since
AccountId gained its own Display/FromStr base58 encoding.

* docs(lee): trim DEFAULT_PROGRAM_OWNER and From<AccountId> for ProgramId docs

* test(lee): add known-answer tests for ProgramId/AccountId conversion, rebuild artifacts

* fix(lee): apply program_owner AccountId migration to code added after rebase

dev grew new program_owner call sites (sequencer_stake genesis/config
handling, committee_discovery, a new selective_pda_delegator test
program, and related tests) after this branch's ProgramId->AccountId
migration commit was originally written, so they predated the .into()
sweep and didn't conflict during the rebase - they just still assumed
the old ProgramId-typed field. Converts all of them, fixes a stray
unseparated hex literal clippy caught along the way, and rebuilds
artifacts against the fixed source.

* chore(lee): regenerate test fixture after rebasing onto dev

---------

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
jonesmarvin8
2026-08-18 11:26:57 -04:00
committed by GitHub
co-authored by Claude Sonnet 5
parent d52c76e2b5
commit 2ba1ecd609
90 changed files with 476 additions and 436 deletions
Generated
-1
View File
@@ -11615,7 +11615,6 @@ dependencies = [
"associated_token_account_core",
"async-stream",
"authenticated_transfer_core",
"base58",
"bincode",
"bip39",
"bridge_core",
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+4 -4
View File
@@ -26,7 +26,7 @@ async fn get_existing_account() -> Result<()> {
assert_eq!(
account.program_owner,
programs::authenticated_transfer().id()
programs::authenticated_transfer().id().into()
);
assert_eq!(account.balance, 10000);
assert!(account.data.is_empty());
@@ -146,7 +146,7 @@ async fn import_private_account() -> Result<()> {
0,
));
let account = lee::Account {
program_owner: programs::authenticated_transfer().id(),
program_owner: programs::authenticated_transfer().id().into(),
balance: 777,
data: Data::default(),
nonce: Nonce::default(),
@@ -210,7 +210,7 @@ async fn import_private_account_second_time_overrides_account_data() -> Result<(
serde_json::to_string(&key_chain).context("Failed to serialize key chain")?;
let initial_account = lee::Account {
program_owner: programs::authenticated_transfer().id(),
program_owner: programs::authenticated_transfer().id().into(),
balance: 100,
data: Data::default(),
nonce: Nonce::default(),
@@ -229,7 +229,7 @@ async fn import_private_account_second_time_overrides_account_data() -> Result<(
.await?;
let updated_account = lee::Account {
program_owner: programs::authenticated_transfer().id(),
program_owner: programs::authenticated_transfer().id().into(),
balance: 999,
data: Data::default(),
nonce: Nonce::default(),
@@ -382,7 +382,7 @@ async fn initialize_private_account() -> Result<()> {
assert_eq!(
account.program_owner,
programs::authenticated_transfer().id()
programs::authenticated_transfer().id().into()
);
assert_eq!(account.balance, 0);
assert!(account.data.is_empty());
@@ -461,7 +461,7 @@ async fn initialize_private_account_using_label() -> Result<()> {
assert_eq!(
account.program_owner,
programs::authenticated_transfer().id()
programs::authenticated_transfer().id().into()
);
log::info!("Successfully initialized private account using label");
@@ -213,7 +213,7 @@ async fn initialize_public_account() -> Result<()> {
assert_eq!(
account.program_owner,
programs::authenticated_transfer().id()
programs::authenticated_transfer().id().into()
);
assert_eq!(account.balance, 0);
assert_eq!(account.nonce.0, 1);
@@ -50,7 +50,7 @@ fn seed_inbox_config(state: &mut V03State, self_zone: [u8; 32]) {
*state = std::mem::replace(state, V03State::new()).with_public_accounts([(
inbox_config_account_id(inbox_id),
Account {
program_owner: inbox_id,
program_owner: inbox_id.into(),
balance: 0,
data: config
.to_bytes()
@@ -75,7 +75,7 @@ fn seed_wrapped_config(
*state = std::mem::replace(state, V03State::new()).with_public_accounts([(
wrapped_token_core::config_account_id(wrapped_token_id),
Account {
program_owner: wrapped_token_id,
program_owner: wrapped_token_id.into(),
data: config
.to_bytes()
.try_into()
@@ -99,7 +99,7 @@ fn seed_receiver_config(
*state = std::mem::replace(state, V03State::new()).with_public_accounts([(
receiver_config_account_id(receiver_id),
Account {
program_owner: receiver_id,
program_owner: receiver_id.into(),
data: config
.to_bytes()
.try_into()
@@ -116,7 +116,7 @@ fn seed_ping_sender_config(state: &mut V03State) {
*state = std::mem::replace(state, V03State::new()).with_public_accounts([(
sender_config_account_id(sender_id),
Account {
program_owner: sender_id,
program_owner: sender_id.into(),
data: outbox_bytes(programs::cross_zone_outbox().id())
.to_vec()
.try_into()
@@ -133,7 +133,7 @@ fn seed_bridge_lock_config(state: &mut V03State) {
*state = std::mem::replace(state, V03State::new()).with_public_accounts([(
bridge_lock_core::config_account_id(bridge_lock_id),
Account {
program_owner: bridge_lock_id,
program_owner: bridge_lock_id.into(),
data: bridge_lock_core::config_bytes(
programs::cross_zone_outbox().id(),
programs::wrapped_token().id(),
@@ -346,7 +346,7 @@ fn lock_escrows_balance_and_emits_to_outbox() {
state = state.with_public_accounts([(
holder_id,
Account {
program_owner: bridge_lock_id,
program_owner: bridge_lock_id.into(),
balance: INITIAL_BALANCE,
..Default::default()
},
@@ -469,7 +469,7 @@ fn a_second_emit_at_the_same_slot_is_rejected() {
let mut state = base_state().with_public_accounts([(
holder_id,
Account {
program_owner: programs::bridge_lock().id(),
program_owner: programs::bridge_lock().id().into(),
balance: INITIAL_BALANCE,
..Default::default()
},
@@ -517,7 +517,7 @@ fn two_emitters_share_an_ordinal_without_colliding() {
let mut state = base_state().with_public_accounts([(
holder_id,
Account {
program_owner: bridge_lock_id,
program_owner: bridge_lock_id.into(),
balance: INITIAL_BALANCE,
..Default::default()
},
@@ -607,7 +607,7 @@ fn a_lock_naming_another_target_program_is_rejected() {
let mut state = base_state().with_public_accounts([(
holder_id,
Account {
program_owner: bridge_lock_id,
program_owner: bridge_lock_id.into(),
balance: INITIAL_BALANCE,
..Default::default()
},
@@ -653,7 +653,7 @@ fn a_lock_naming_other_mint_accounts_is_rejected() {
let mut state = base_state().with_public_accounts([(
holder_id,
Account {
program_owner: bridge_lock_id,
program_owner: bridge_lock_id.into(),
balance: INITIAL_BALANCE,
..Default::default()
},
@@ -712,7 +712,7 @@ fn a_lock_with_a_substituted_config_account_is_rejected() {
(
holder_id,
Account {
program_owner: bridge_lock_id,
program_owner: bridge_lock_id.into(),
balance: INITIAL_BALANCE,
..Default::default()
},
@@ -720,7 +720,7 @@ fn a_lock_with_a_substituted_config_account_is_rejected() {
(
decoy_id,
Account {
program_owner: bridge_lock_id,
program_owner: bridge_lock_id.into(),
data: bridge_lock_core::config_bytes([3; 8], [4; 8])
.to_vec()
.try_into()
@@ -777,7 +777,7 @@ fn a_lock_before_the_pins_are_set_is_rejected() {
let state = base_state().with_public_accounts([(
holder_id,
Account {
program_owner: bridge_lock_id,
program_owner: bridge_lock_id.into(),
balance: INITIAL_BALANCE,
..Default::default()
},
@@ -1181,7 +1181,7 @@ fn mint_replay_rejected() {
state = state.with_public_accounts([(
seen_id,
Account {
program_owner: inbox_id,
program_owner: inbox_id.into(),
balance: 0,
data: shard
.to_bytes()
@@ -1258,7 +1258,7 @@ fn a_delivery_from_a_second_block_at_the_same_id_is_refused() {
state = state.with_public_accounts([(
seen_id,
Account {
program_owner: inbox_id,
program_owner: inbox_id.into(),
balance: 0,
data: shard
.to_bytes()
+2 -2
View File
@@ -139,11 +139,11 @@ async fn restore_keys_from_seed() -> Result<()> {
assert_eq!(
acc1.account.program_owner,
programs::authenticated_transfer().id()
programs::authenticated_transfer().id().into()
);
assert_eq!(
acc2.account.program_owner,
programs::authenticated_transfer().id()
programs::authenticated_transfer().id().into()
);
assert_eq!(acc1.account.balance, 100);
@@ -55,7 +55,7 @@ async fn deploy_and_execute_program() -> Result<()> {
let post_state_account = get_account(&ctx, account_id).await?;
let expected_data: &[u8] = &[];
assert_eq!(post_state_account.program_owner, claimer.id());
assert_eq!(post_state_account.program_owner, claimer.id().into());
assert_eq!(post_state_account.balance, 0);
assert_eq!(post_state_account.data.as_ref(), expected_data);
assert_eq!(post_state_account.nonce.0, 1);
@@ -139,10 +139,8 @@ async fn stake_transaction_joins_the_bedrock_committee() -> Result<()> {
info!("Waiting for the Stake transaction's block to land");
poll_until("stake to take ownership", 30, || async {
Ok(
get_account(&ctx, ownership_id).await?.program_owner
== programs::sequencer_stake().id(),
)
Ok(get_account(&ctx, ownership_id).await?.program_owner
== programs::sequencer_stake().id().into())
})
.await?;
@@ -151,7 +149,7 @@ async fn stake_transaction_joins_the_bedrock_committee() -> Result<()> {
.context("Failed to read the stake ownership account")?;
assert_eq!(
ownership_account.program_owner,
programs::sequencer_stake().id(),
programs::sequencer_stake().id().into(),
"ownership account should now be owned by sequencer_stake"
);
assert_eq!(
+1 -1
View File
@@ -269,7 +269,7 @@ fn build_privacy_transaction() -> PrivacyPreservingTransaction {
Account {
balance: 100,
nonce: Nonce(0xdead_beef),
program_owner: program.id(),
program_owner: program.id().into(),
data: Data::default(),
},
true,
+6 -6
View File
@@ -26,7 +26,7 @@ use lee::{
Account, AccountId, PrivateKey, PublicKey,
privacy_preserving_transaction::circuit::ProgramWithDependencies, program::Program,
};
use lee_core::program::DEFAULT_PROGRAM_ID;
use lee_core::program::DEFAULT_PROGRAM_OWNER;
use wallet::{account::HumanReadableAccount, program_facades::vault::Vault};
use wallet_ffi::{
FfiAccount, FfiAccountIdWithPrivacy, FfiAccountIdentity, FfiAccountList, FfiBytes32,
@@ -634,7 +634,7 @@ fn test_wallet_ffi_get_account_public() -> Result<()> {
assert_eq!(
account.program_owner,
programs::authenticated_transfer().id()
programs::authenticated_transfer().id().into()
);
assert_eq!(account.balance, 10000);
assert!(account.data.is_empty());
@@ -674,7 +674,7 @@ fn test_wallet_ffi_get_account_private() -> Result<()> {
assert_eq!(
account.program_owner,
programs::authenticated_transfer().id()
programs::authenticated_transfer().id().into()
);
assert_eq!(account.balance, 10000);
assert!(account.data.is_empty());
@@ -843,7 +843,7 @@ fn wallet_ffi_init_public_account_auth_transfer() -> Result<()> {
.unwrap();
(&out_account).try_into().unwrap()
};
assert_eq!(account.program_owner, DEFAULT_PROGRAM_ID);
assert_eq!(account.program_owner, DEFAULT_PROGRAM_OWNER);
// Call the init funciton
let mut transfer_result = FfiTransferResult::default();
@@ -872,7 +872,7 @@ fn wallet_ffi_init_public_account_auth_transfer() -> Result<()> {
};
assert_eq!(
account.program_owner,
programs::authenticated_transfer().id()
programs::authenticated_transfer().id().into()
);
unsafe {
@@ -932,7 +932,7 @@ fn wallet_ffi_init_private_account_auth_transfer() -> Result<()> {
};
assert_eq!(
account.program_owner,
programs::authenticated_transfer().id()
programs::authenticated_transfer().id().into()
);
unsafe {
@@ -8,9 +8,9 @@ use lee_core::{
account::{Account, AccountId, AccountWithMetadata},
encryption::ViewingPublicKey,
program::{
AccountPostState, BlockValidityWindow, CallerData, ChainedCall, Claim, DEFAULT_PROGRAM_ID,
MAX_NUMBER_CHAINED_CALLS, PdaSeed, ProgramId, ProgramOutput, TimestampValidityWindow,
validate_execution,
AccountPostState, BlockValidityWindow, CallerData, ChainedCall, Claim,
DEFAULT_PROGRAM_OWNER, MAX_NUMBER_CHAINED_CALLS, PdaSeed, ProgramId, ProgramOutput,
TimestampValidityWindow, validate_execution,
},
};
use risc0_zkvm::{guest::env, serde::to_vec};
@@ -239,7 +239,7 @@ impl ExecutionState {
for (account_id, post) in execution_state
.pre_states
.iter()
.filter(|a| a.account.program_owner == DEFAULT_PROGRAM_ID)
.filter(|a| a.account.program_owner == DEFAULT_PROGRAM_OWNER)
.map(|a| {
let post = execution_state
.post_states
@@ -251,7 +251,7 @@ impl ExecutionState {
.map(|(pre, post)| (pre.account_id, post))
{
assert_ne!(
post.program_owner, DEFAULT_PROGRAM_ID,
post.program_owner, DEFAULT_PROGRAM_OWNER,
"Account {account_id} was modified but not claimed"
);
}
@@ -412,7 +412,7 @@ impl ExecutionState {
// The invoked program can only claim accounts with default program id.
assert_eq!(
post.account().program_owner,
DEFAULT_PROGRAM_ID,
DEFAULT_PROGRAM_OWNER,
"Cannot claim an initialized account {pre_account_id}"
);
@@ -486,7 +486,7 @@ impl ExecutionState {
}
}
post.account_mut().program_owner = program_id;
post.account_mut().program_owner = AccountId::from(program_id);
}
post_states_entry.insert_entry(post.into_account());
+6 -28
View File
@@ -1,7 +1,4 @@
use std::{
fmt::{Display, Write as _},
str::FromStr,
};
use std::{fmt::Display, str::FromStr};
use base58::{FromBase58 as _, ToBase58 as _};
use borsh::{BorshDeserialize, BorshSerialize};
@@ -10,7 +7,7 @@ use risc0_zkvm::sha::{Impl, Sha256 as _};
use serde::{Deserialize, Serialize};
use serde_with::{DeserializeFromStr, SerializeDisplay};
use crate::{NullifierSecretKey, program::ProgramId};
use crate::NullifierSecretKey;
pub mod data;
@@ -93,34 +90,15 @@ pub type Balance = u128;
/// Account to be used both in public and private contexts.
#[derive(
Default, Clone, Eq, PartialEq, Serialize, Deserialize, BorshSerialize, BorshDeserialize,
Debug, Default, Clone, Eq, PartialEq, Serialize, Deserialize, BorshSerialize, BorshDeserialize,
)]
pub struct Account {
pub program_owner: ProgramId,
pub program_owner: AccountId,
pub balance: Balance,
pub data: Data,
pub nonce: Nonce,
}
impl std::fmt::Debug for Account {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let program_owner_hex = self
.program_owner
.iter()
.flat_map(|n| n.to_le_bytes())
.fold(String::new(), |mut acc, bytes| {
write!(acc, "{bytes:02x}").expect("writing to string should not fail");
acc
});
f.debug_struct("Account")
.field("program_owner", &program_owner_hex)
.field("balance", &self.balance)
.field("data", &self.data)
.field("nonce", &self.nonce)
.finish()
}
}
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct AccountWithMetadata {
pub account: Account,
@@ -243,14 +221,14 @@ mod tests {
fn default_program_owner_account_data_creation() {
let new_acc = Account::default();
assert_eq!(new_acc.program_owner, DEFAULT_PROGRAM_ID);
assert_eq!(new_acc.program_owner, DEFAULT_PROGRAM_ID.into());
}
#[cfg(feature = "host")]
#[test]
fn account_with_metadata_constructor() {
let account = Account {
program_owner: [1, 2, 3, 4, 5, 6, 7, 8],
program_owner: [1, 2, 3, 4, 5, 6, 7, 8].into(),
balance: 1337,
data: b"testing_account_with_metadata_constructor"
.to_vec()
+4 -4
View File
@@ -218,7 +218,7 @@ mod tests {
PublicAction {
pre: AccountWithMetadata::new(
Account {
program_owner: [1, 2, 3, 4, 5, 6, 7, 8],
program_owner: [1, 2, 3, 4, 5, 6, 7, 8].into(),
balance: 12_345_678_901_234_567_890,
data: b"test data".to_vec().try_into().unwrap(),
nonce: Nonce(0xFFFF_FFFF_FFFF_FFFE),
@@ -227,7 +227,7 @@ mod tests {
AccountId::new([0; 32]),
),
post: Account {
program_owner: [1, 2, 3, 4, 5, 6, 7, 8],
program_owner: [1, 2, 3, 4, 5, 6, 7, 8].into(),
balance: 100,
data: b"post state data".to_vec().try_into().unwrap(),
nonce: Nonce(0xFFFF_FFFF_FFFF_FFFF),
@@ -236,7 +236,7 @@ mod tests {
PublicAction {
pre: AccountWithMetadata::new(
Account {
program_owner: [9, 9, 9, 8, 8, 8, 7, 7],
program_owner: [9, 9, 9, 8, 8, 8, 7, 7].into(),
balance: 123_123_123_456_456_567_112,
data: b"test data".to_vec().try_into().unwrap(),
nonce: Nonce(9_999_999_999_999_999_999_999),
@@ -245,7 +245,7 @@ mod tests {
AccountId::new([1; 32]),
),
post: Account {
program_owner: [2, 3, 4, 5, 6, 7, 8, 9],
program_owner: [2, 3, 4, 5, 6, 7, 8, 9].into(),
balance: 200,
data: b"post state data 2".to_vec().try_into().unwrap(),
nonce: Nonce(0xFFFF_FFFF_FFFF_FFFD),
+1 -3
View File
@@ -66,9 +66,7 @@ impl Commitment {
bytes.extend_from_slice(account_id.value());
let account_bytes_with_hashed_data = {
let mut this = Vec::new();
for word in &account.program_owner {
this.extend_from_slice(&word.to_le_bytes());
}
this.extend_from_slice(account.program_owner.as_ref());
this.extend_from_slice(&account.balance.to_le_bytes());
this.extend_from_slice(&account.nonce.0.to_le_bytes());
let hashed_data: [u8; 32] = Impl::hash_bytes(&account.data)
+6 -11
View File
@@ -21,9 +21,7 @@ impl Account {
#[must_use]
pub fn to_bytes(&self) -> Vec<u8> {
let mut bytes = Vec::new();
for word in &self.program_owner {
bytes.extend_from_slice(&word.to_le_bytes());
}
bytes.extend_from_slice(self.program_owner.as_ref());
bytes.extend_from_slice(&self.balance.to_le_bytes());
bytes.extend_from_slice(&self.nonce.0.to_le_bytes());
let data_length: u32 = u32::try_from(self.data.len()).expect("Invalid u32");
@@ -37,15 +35,12 @@ impl Account {
pub fn from_cursor(cursor: &mut Cursor<&[u8]>) -> Result<Self, LeeCoreError> {
use crate::account::{Nonce, data::Data};
let mut u32_bytes = [0_u8; 4];
let mut u128_bytes = [0_u8; 16];
// program owner
let mut program_owner = [0_u32; 8];
for word in &mut program_owner {
cursor.read_exact(&mut u32_bytes)?;
*word = u32::from_le_bytes(u32_bytes);
}
let mut program_owner_bytes = [0_u8; 32];
cursor.read_exact(&mut program_owner_bytes)?;
let program_owner = AccountId::new(program_owner_bytes);
// balance
cursor.read_exact(&mut u128_bytes)?;
@@ -183,7 +178,7 @@ mod tests {
#[test]
fn enconding() {
let account = Account {
program_owner: [1, 2, 3, 4, 5, 6, 7, 8],
program_owner: [1, 2, 3, 4, 5, 6, 7, 8].into(),
balance: 123_456_789_012_345_678_901_234_567_890_123_456,
nonce: 42_u128.into(),
data: b"hola mundo".to_vec().try_into().unwrap(),
@@ -244,7 +239,7 @@ mod tests {
#[test]
fn account_to_bytes_roundtrip() {
let account = Account {
program_owner: [1, 2, 3, 4, 5, 6, 7, 8],
program_owner: [1, 2, 3, 4, 5, 6, 7, 8].into(),
balance: 123_456_789_012_345_678_901_234_567_890_123_456,
nonce: 42_u128.into(),
data: b"hola mundo".to_vec().try_into().unwrap(),
+1 -1
View File
@@ -234,7 +234,7 @@ mod tests {
let receiver_ss = SharedSecretKey::decapsulate(&epk, &d, &z).unwrap();
let account = Account {
program_owner: [12_u32; 8],
program_owner: [12_u32; 8].into(),
balance: 999,
..Account::default()
};
+29 -7
View File
@@ -11,6 +11,10 @@ use crate::{
};
pub const DEFAULT_PROGRAM_ID: ProgramId = [0; 8];
/// TODO: Placeholder `program_owner` for uninitialized `Account`.
pub const DEFAULT_PROGRAM_OWNER: AccountId = AccountId::new([0; 32]);
pub const MAX_NUMBER_CHAINED_CALLS: usize = 10;
pub type ProgramId = [u32; 8];
@@ -27,6 +31,19 @@ impl From<ProgramId> for AccountId {
}
}
impl From<AccountId> for ProgramId {
fn from(account_id: AccountId) -> Self {
let mut program_id = [0_u32; 8];
for (word, chunk) in program_id
.iter_mut()
.zip(account_id.value().chunks_exact(4))
{
*word = u32::from_le_bytes(chunk.try_into().expect("chunk is exactly 4 bytes"));
}
program_id
}
}
pub type InstructionData = Vec<u32>;
pub struct ProgramInput<T> {
pub self_program_id: ProgramId,
@@ -308,7 +325,7 @@ impl AccountPostState {
/// if the account's program owner is the default program ID.
#[must_use]
pub fn new_claimed_if_default(account: Account, claim: Claim) -> Self {
let is_default_owner = account.program_owner == DEFAULT_PROGRAM_ID;
let is_default_owner = account.program_owner == DEFAULT_PROGRAM_OWNER;
Self {
account,
claim: is_default_owner.then_some(claim),
@@ -608,11 +625,11 @@ pub enum ExecutionValidationError {
ModifiedProgramOwner { account_id: AccountId },
#[error(
"Trying to decrease balance of account {account_id} owned by {owner_program_id:?} in a program {executing_program_id:?} which is not the owner"
"Trying to decrease balance of account {account_id} owned by {owner_account_id:?} in a program {executing_program_id:?} which is not the owner"
)]
UnauthorizedBalanceDecrease {
account_id: AccountId,
owner_program_id: ProgramId,
owner_account_id: AccountId,
executing_program_id: ProgramId,
},
@@ -691,6 +708,10 @@ pub fn validate_execution(
post_states: &[AccountPostState],
executing_program_id: ProgramId,
) -> Result<(), ExecutionValidationError> {
// `program_owner` is `AccountId`-typed; convert once up front rather than at each
// comparison below (see `From<ProgramId> for AccountId`'s doc comment).
let executing_account_id = AccountId::from(executing_program_id);
// 1. Check account ids are all different
if !validate_uniqueness_of_account_ids(pre_states) {
return Err(ExecutionValidationError::PreStateAccountIdsNotUnique);
@@ -725,11 +746,11 @@ pub fn validate_execution(
// 5. Decreasing balance only allowed if owned by executing program
if post.account.balance < pre.account.balance
&& account_program_owner != executing_program_id
&& account_program_owner != executing_account_id
{
return Err(ExecutionValidationError::UnauthorizedBalanceDecrease {
account_id: pre.account_id,
owner_program_id: account_program_owner,
owner_account_id: account_program_owner,
executing_program_id,
});
}
@@ -738,7 +759,7 @@ pub fn validate_execution(
// default values
if pre.account.data != post.account.data
&& pre.account != Account::default()
&& account_program_owner != executing_program_id
&& account_program_owner != executing_account_id
{
return Err(ExecutionValidationError::UnauthorizedDataModification {
account_id: pre.account_id,
@@ -748,7 +769,8 @@ pub fn validate_execution(
// 7. If a post state has default program owner, the pre state must have been a default
// account
if post.account.program_owner == DEFAULT_PROGRAM_ID && pre.account != Account::default() {
if post.account.program_owner == DEFAULT_PROGRAM_OWNER && pre.account != Account::default()
{
return Err(
ExecutionValidationError::NonDefaultAccountWithDefaultOwner {
account_id: pre.account_id,
+61 -3
View File
@@ -132,7 +132,7 @@ fn program_output_try_with_block_validity_window_empty_range_fails() {
#[test]
fn post_state_new_with_claim_constructor() {
let account = Account {
program_owner: [1, 2, 3, 4, 5, 6, 7, 8],
program_owner: [1, 2, 3, 4, 5, 6, 7, 8].into(),
balance: 1337,
data: vec![0xde, 0xad, 0xbe, 0xef].try_into().unwrap(),
nonce: 10_u128.into(),
@@ -147,7 +147,7 @@ fn post_state_new_with_claim_constructor() {
#[test]
fn post_state_new_without_claim_constructor() {
let account = Account {
program_owner: [1, 2, 3, 4, 5, 6, 7, 8],
program_owner: [1, 2, 3, 4, 5, 6, 7, 8].into(),
balance: 1337,
data: vec![0xde, 0xad, 0xbe, 0xef].try_into().unwrap(),
nonce: 10_u128.into(),
@@ -162,7 +162,7 @@ fn post_state_new_without_claim_constructor() {
#[test]
fn post_state_account_getter() {
let mut account = Account {
program_owner: [1, 2, 3, 4, 5, 6, 7, 8],
program_owner: [1, 2, 3, 4, 5, 6, 7, 8].into(),
balance: 1337,
data: vec![0xde, 0xad, 0xbe, 0xef].try_into().unwrap(),
nonce: 10_u128.into(),
@@ -339,3 +339,61 @@ fn compute_public_authorized_pdas_no_caller_returns_empty() {
let result = compute_public_authorized_pdas(None, &[seed]);
assert!(result.is_empty());
}
#[test]
fn account_id_from_program_id_reinterprets_words_as_le_bytes() {
let program_id: ProgramId = [
0x0403_0201,
0x0807_0605,
0x0c0b_0a09,
0x100f_0e0d,
0x1413_1211,
0x1817_1615,
0x1c1b_1a19,
0x201f_1e1d,
];
let expected: [u8; 32] = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32,
];
assert_eq!(AccountId::from(program_id).value(), &expected);
}
#[test]
fn account_id_from_default_program_id_is_default_program_owner() {
assert_eq!(AccountId::from(DEFAULT_PROGRAM_ID), DEFAULT_PROGRAM_OWNER);
}
#[test]
fn program_id_from_account_id_reinterprets_le_bytes_as_words() {
let account_id = AccountId::new([
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
26, 27, 28, 29, 30, 31, 32,
]);
let expected: ProgramId = [
0x0403_0201,
0x0807_0605,
0x0c0b_0a09,
0x100f_0e0d,
0x1413_1211,
0x1817_1615,
0x1c1b_1a19,
0x201f_1e1d,
];
assert_eq!(ProgramId::from(account_id), expected);
}
#[test]
fn program_id_account_id_conversion_round_trips() {
let program_id: ProgramId = [
0x1122_3344,
0x5566_7788,
0x99aa_bbcc,
0xddee_ff00,
0xcafe_babe,
0xdead_beef,
0x0bad_f00d,
0xfeed_face,
];
assert_eq!(ProgramId::from(AccountId::from(program_id)), program_id);
}
@@ -50,7 +50,7 @@ fn prove_privacy_preserving_execution_circuit_public_and_private_pre_accounts()
let program = crate::test_methods::simple_balance_transfer();
let sender = AccountWithMetadata::new(
Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 100,
..Account::default()
},
@@ -65,14 +65,14 @@ fn prove_privacy_preserving_execution_circuit_public_and_private_pre_accounts()
let balance_to_move: u128 = 37;
let expected_sender_post = Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 100 - balance_to_move,
nonce: Nonce::default(),
data: Data::default(),
};
let expected_recipient_post = Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: balance_to_move,
nonce: Nonce::private_account_nonce_init(&recipient_account_id),
data: Data::default(),
@@ -134,7 +134,7 @@ fn prove_privacy_preserving_execution_circuit_fully_private() {
Account {
balance: 100,
nonce: sender_nonce,
program_owner: program.id(),
program_owner: program.id().into(),
data: Data::default(),
},
true,
@@ -165,13 +165,13 @@ fn prove_privacy_preserving_execution_circuit_fully_private() {
let program = crate::test_methods::simple_balance_transfer();
let expected_private_account_1 = Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 100 - balance_to_move,
nonce: sender_nonce.private_account_nonce_increment(&sender_keys.nsk()),
..Default::default()
};
let expected_private_account_2 = Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: balance_to_move,
nonce: Nonce::private_account_nonce_init(&recipient_account_id),
..Default::default()
@@ -317,7 +317,7 @@ fn update_note_view_tag_is_the_supplied_value() {
let identifier: u128 = 99;
let account_id = AccountId::for_regular_private_account(&keys.npk(), &keys.vpk(), identifier);
let account = Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 1,
..Account::default()
};
@@ -499,7 +499,7 @@ fn private_pda_withdraw() {
let recipient_id = AccountId::new([88; 32]);
let recipient_pre = AccountWithMetadata::new(
Account {
program_owner: simple_transfer.id(),
program_owner: simple_transfer.id().into(),
balance: 10000,
..Account::default()
},
@@ -544,7 +544,7 @@ fn shared_account_receives_via_simple_transfer() {
let sender_id = AccountId::new([99; 32]);
let sender = AccountWithMetadata::new(
Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 1000,
..Account::default()
},
@@ -684,7 +684,7 @@ fn private_authorized_update_encrypts_regular_kind_with_identifier() {
);
let ssk = SharedSecretKey::encapsulate_deterministic(&keys.vpk(), &esk).0;
let account = Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 1,
..Account::default()
};
@@ -729,7 +729,7 @@ fn seeded_regular_account(
) -> (AccountId, AccountWithMetadata, lee_core::MembershipProof) {
let account_id = AccountId::for_regular_private_account(&keys.npk(), &keys.vpk(), identifier);
let account = Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 1,
..Account::default()
};
@@ -898,7 +898,7 @@ fn unauthorized_private_init_can_be_claimed() {
&output.private_actions[0].nullifier,
)
.unwrap();
assert_eq!(claimed.program_owner, program_id);
assert_eq!(claimed.program_owner, program_id.into());
}
/// A program that asserts authorization over its pre-states rejects a regular private account
@@ -949,7 +949,7 @@ fn pda_update_attempt(
derivation_identifier,
);
let pda_account = Account {
program_owner: simple_transfer_id,
program_owner: simple_transfer_id.into(),
balance: 1,
..Account::default()
};
@@ -7,7 +7,7 @@ fn transition_from_authenticated_transfer_program_invocation_default_account_des
let initial_data = [(
account_id,
Account {
program_owner: crate::test_methods::simple_balance_transfer().id(),
program_owner: crate::test_methods::simple_balance_transfer().id().into(),
balance: 100,
..Account::default()
},
@@ -64,7 +64,7 @@ fn transition_from_authenticated_transfer_program_invocation_non_default_account
(
account_id1,
Account {
program_owner: crate::test_methods::simple_balance_transfer().id(),
program_owner: crate::test_methods::simple_balance_transfer().id().into(),
balance: 100,
..Account::default()
},
@@ -72,7 +72,7 @@ fn transition_from_authenticated_transfer_program_invocation_non_default_account
(
account_id2,
Account {
program_owner: crate::test_methods::simple_balance_transfer().id(),
program_owner: crate::test_methods::simple_balance_transfer().id().into(),
balance: 200,
..Account::default()
},
@@ -106,7 +106,7 @@ fn transition_from_sequence_of_authenticated_transfer_program_invocations() {
let initial_data = [(
account_id1,
Account {
program_owner: crate::test_methods::simple_balance_transfer().id(),
program_owner: crate::test_methods::simple_balance_transfer().id().into(),
balance: 100,
..Account::default()
},
+19 -19
View File
@@ -5,7 +5,7 @@ fn circuit_fails_if_visibility_masks_have_incorrect_lenght() {
let program = crate::test_methods::simple_balance_transfer();
let public_account_1 = AccountWithMetadata::new(
Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 100,
..Account::default()
},
@@ -14,7 +14,7 @@ fn circuit_fails_if_visibility_masks_have_incorrect_lenght() {
);
let public_account_2 = AccountWithMetadata::new(
Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 0,
..Account::default()
},
@@ -40,7 +40,7 @@ fn circuit_fails_if_invalid_auth_keys_are_provided() {
let recipient_keys = test_private_account_keys_2();
let private_account_1 = AccountWithMetadata::new(
Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 100,
..Account::default()
},
@@ -100,7 +100,7 @@ fn circuit_should_fail_if_new_private_account_with_non_default_balance_is_provid
let recipient_keys = test_private_account_keys_2();
let private_account_1 = AccountWithMetadata::new(
Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 100,
..Account::default()
},
@@ -160,7 +160,7 @@ fn circuit_should_fail_if_new_private_account_with_non_default_program_owner_is_
let recipient_keys = test_private_account_keys_2();
let private_account_1 = AccountWithMetadata::new(
Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 100,
..Account::default()
},
@@ -170,7 +170,7 @@ fn circuit_should_fail_if_new_private_account_with_non_default_program_owner_is_
let private_account_2 = AccountWithMetadata::new(
Account {
// Non default program_owner
program_owner: [0, 1, 2, 3, 4, 5, 6, 7],
program_owner: [0, 1, 2, 3, 4, 5, 6, 7].into(),
..Account::default()
},
true,
@@ -220,7 +220,7 @@ fn circuit_should_fail_if_new_private_account_with_non_default_data_is_provided(
let recipient_keys = test_private_account_keys_2();
let private_account_1 = AccountWithMetadata::new(
Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 100,
..Account::default()
},
@@ -280,7 +280,7 @@ fn circuit_should_fail_if_new_private_account_with_non_default_nonce_is_provided
let recipient_keys = test_private_account_keys_2();
let private_account_1 = AccountWithMetadata::new(
Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 100,
..Account::default()
},
@@ -341,7 +341,7 @@ fn circuit_should_fail_if_new_private_account_is_provided_with_default_values_bu
let recipient_keys = test_private_account_keys_2();
let private_account_1 = AccountWithMetadata::new(
Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 100,
..Account::default()
},
@@ -401,7 +401,7 @@ fn private_pda_without_binding_fails() {
let keys = test_private_account_keys_1();
let public_account_1 = AccountWithMetadata::new(
Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 100,
..Account::default()
},
@@ -820,7 +820,7 @@ fn undeclaring_public_delegation(
let pre_state = AccountWithMetadata::new(
Account {
program_owner: delegator.id(),
program_owner: delegator.id().into(),
..Account::default()
},
false,
@@ -1001,7 +1001,7 @@ fn private_pda_top_level_reuse_rejected_by_binding_check() {
let account_id = AccountId::for_private_pda(&program.id(), &seed, &npk, &keys.vpk(), u128::MAX);
let owned_pre_state = AccountWithMetadata::new(
Account {
program_owner: program.id(),
program_owner: program.id().into(),
..Account::default()
},
false,
@@ -1024,7 +1024,7 @@ fn private_accounts_can_only_be_initialized_once() {
let sender_nonce = Nonce(0xdead_beef);
let sender_private_account = Account {
program_owner: crate::test_methods::simple_balance_transfer().id(),
program_owner: crate::test_methods::simple_balance_transfer().id().into(),
balance: 100,
nonce: sender_nonce,
data: Data::default(),
@@ -1049,7 +1049,7 @@ fn private_accounts_can_only_be_initialized_once() {
.unwrap();
let sender_private_account = Account {
program_owner: crate::test_methods::simple_balance_transfer().id(),
program_owner: crate::test_methods::simple_balance_transfer().id().into(),
balance: 100,
nonce: sender_nonce,
data: Data::default(),
@@ -1079,7 +1079,7 @@ fn circuit_should_fail_if_there_are_repeated_ids() {
let sender_keys = test_private_account_keys_1();
let private_account_1 = AccountWithMetadata::new(
Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 100,
..Account::default()
},
@@ -1291,7 +1291,7 @@ fn private_account_claimed_then_used_without_init_flag_should_fail() {
// Prepare new state of account
let account_metadata = {
let mut acc = authorized_account;
acc.account.program_owner = crate::test_methods::claimer().id();
acc.account.program_owner = crate::test_methods::claimer().id().into();
acc
};
@@ -1349,13 +1349,13 @@ fn two_private_pda_family_members_receive_and_spend() {
V03State::new().with_public_accounts(public_state_from_balances(&[(funder_id, 500)]));
let alice_pda_0_account = Account {
program_owner: simple_transfer_id,
program_owner: simple_transfer_id.into(),
balance: amount,
nonce: Nonce::private_account_nonce_init(&alice_pda_0_id),
..Account::default()
};
let alice_pda_1_account = Account {
program_owner: simple_transfer_id,
program_owner: simple_transfer_id.into(),
balance: amount,
nonce: Nonce::private_account_nonce_init(&alice_pda_1_id),
..Account::default()
@@ -1506,7 +1506,7 @@ fn two_private_pda_family_members_receive_and_spend() {
// Re-fund alice_pda_1 top-level via simple_transfer using a private-PDA update with an
// external seed.
let alice_pda_1_account_after_spend = Account {
program_owner: simple_transfer_id,
program_owner: simple_transfer_id.into(),
balance: 0,
nonce: alice_pda_1_account
.nonce
+12 -12
View File
@@ -18,7 +18,7 @@ fn claiming_mechanism() {
assert_eq!(state.get_account_by_id(to), Account::default());
let expected_recipient_post = Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: amount,
nonce: Nonce(1),
..Account::default()
@@ -86,7 +86,7 @@ fn authorized_public_account_claiming_succeeds() {
assert_eq!(
state.get_account_by_id(account_id),
Account {
program_owner: program.id(),
program_owner: program.id().into(),
nonce: Nonce(1),
..Account::default()
}
@@ -114,7 +114,7 @@ fn public_chained_call() {
);
let expected_to_post = Account {
program_owner: crate::test_methods::simple_balance_transfer().id(),
program_owner: crate::test_methods::simple_balance_transfer().id().into(),
balance: amount * 2, // The `chain_caller` chains the program twice
..Account::default()
};
@@ -197,7 +197,7 @@ fn execution_that_requires_authentication_of_a_program_derived_account_id_succee
);
let expected_to_post = Account {
program_owner: crate::test_methods::simple_balance_transfer().id(),
program_owner: crate::test_methods::simple_balance_transfer().id().into(),
balance: amount, // The `chain_caller` chains the program twice
..Account::default()
};
@@ -244,7 +244,7 @@ fn claiming_mechanism_within_chain_call() {
let expected_to_post = Account {
// The expected program owner is the authenticated transfer program
program_owner: simple_transfer.id(),
program_owner: simple_transfer.id().into(),
balance: amount,
nonce: Nonce(1),
..Account::default()
@@ -299,7 +299,7 @@ fn authorized_public_account_claiming_succeeds_when_executed_privately() {
let program_id = program.id();
let sender_keys = test_private_account_keys_1();
let sender_private_account = Account {
program_owner: program_id,
program_owner: program_id.into(),
balance: 100,
..Account::default()
};
@@ -361,7 +361,7 @@ fn authorized_public_account_claiming_succeeds_when_executed_privately() {
assert_eq!(
state.get_account_by_id(recipient_account_id),
Account {
program_owner: program_id,
program_owner: program_id.into(),
balance,
nonce: Nonce(1),
..Account::default()
@@ -380,7 +380,7 @@ fn private_chained_call(number_of_calls: u32) {
let initial_balance = 100;
let from_account = AccountWithMetadata::new(
Account {
program_owner: simple_transfers.id(),
program_owner: simple_transfers.id().into(),
balance: initial_balance,
..Account::default()
},
@@ -389,7 +389,7 @@ fn private_chained_call(number_of_calls: u32) {
);
let to_account = AccountWithMetadata::new(
Account {
program_owner: simple_transfers.id(),
program_owner: simple_transfers.id().into(),
..Account::default()
},
true,
@@ -510,7 +510,7 @@ fn claiming_mechanism_cannot_claim_initialied_accounts() {
state.force_insert_account(
account_id,
Account {
program_owner: [1, 2, 3, 4, 5, 6, 7, 8],
program_owner: [1, 2, 3, 4, 5, 6, 7, 8].into(),
..Account::default()
},
);
@@ -549,7 +549,7 @@ fn malicious_program_cannot_break_balance_validation_if_not_in_genesis() {
(
sender_id,
Account {
program_owner: modified_transfer_id,
program_owner: modified_transfer_id.into(),
balance: sender_init_balance,
..Account::default()
},
@@ -557,7 +557,7 @@ fn malicious_program_cannot_break_balance_validation_if_not_in_genesis() {
(
recipient_id,
Account {
program_owner: modified_transfer_id,
program_owner: modified_transfer_id.into(),
balance: recipient_init_balance,
..Account::default()
},
@@ -13,12 +13,12 @@ fn flash_swap_successful() {
let amount_out: u128 = 100;
let vault_account = Account {
program_owner: token.id(),
program_owner: token.id().into(),
balance: initial_balance,
..Account::default()
};
let receiver_account = Account {
program_owner: token.id(),
program_owner: token.id().into(),
balance: 0,
..Account::default()
};
@@ -64,12 +64,12 @@ fn flash_swap_callback_keeps_funds_rollback() {
let amount_out: u128 = 100;
let vault_account = Account {
program_owner: token.id(),
program_owner: token.id().into(),
balance: initial_balance,
..Account::default()
};
let receiver_account = Account {
program_owner: token.id(),
program_owner: token.id().into(),
balance: 0,
..Account::default()
};
@@ -121,12 +121,12 @@ fn flash_swap_self_call_targets_correct_program() {
let initial_balance: u128 = 1000;
let vault_account = Account {
program_owner: token.id(),
program_owner: token.id().into(),
balance: initial_balance,
..Account::default()
};
let receiver_account = Account {
program_owner: token.id(),
program_owner: token.id().into(),
balance: 0,
..Account::default()
};
@@ -167,7 +167,7 @@ fn flash_swap_standalone_invariant_check_rejected() {
let vault_id = AccountId::for_public_pda(&initiator.id(), &PdaSeed::new([0_u8; 32]));
let vault_account = Account {
program_owner: token.id(),
program_owner: token.id().into(),
balance: 1000,
..Account::default()
};
+1 -1
View File
@@ -82,7 +82,7 @@ fn get_account_by_account_id_non_default_account() {
let initial_data = [(
account_id,
Account {
program_owner: crate::test_methods::simple_balance_transfer().id(),
program_owner: crate::test_methods::simple_balance_transfer().id().into(),
balance: 100,
..Account::default()
},
+3 -3
View File
@@ -110,7 +110,7 @@ impl V03State {
#[must_use]
pub fn with_account_owned_by_burner_program(mut self) -> Self {
let account = Account {
program_owner: crate::test_methods::burner().id(),
program_owner: crate::test_methods::burner().id().into(),
balance: 100,
..Default::default()
};
@@ -187,7 +187,7 @@ fn public_state_from_balances(initial_data: &[(AccountId, u128)]) -> HashMap<Acc
(
account_id,
Account {
program_owner: crate::test_methods::simple_balance_transfer().id(),
program_owner: crate::test_methods::simple_balance_transfer().id().into(),
balance,
..Account::default()
},
@@ -447,7 +447,7 @@ fn deshielded_balance_transfer_for_tests(
fn valid_private_transfer_tx_and_state() -> (V03State, PrivacyPreservingTransaction) {
let sender_keys = test_private_account_keys_1();
let sender_private_account = Account {
program_owner: crate::test_methods::simple_balance_transfer().id(),
program_owner: crate::test_methods::simple_balance_transfer().id().into(),
balance: 100,
nonce: Nonce(0xdead_beef),
..Account::default()
@@ -8,7 +8,7 @@ fn transition_from_privacy_preserving_transaction_shielded() {
let mut state = V03State::new().with_public_accounts([(
sender_keys.account_id(),
Account {
program_owner: crate::test_methods::simple_balance_transfer().id(),
program_owner: crate::test_methods::simple_balance_transfer().id().into(),
balance: 200,
..Account::default()
},
@@ -49,7 +49,7 @@ fn transition_from_privacy_preserving_transaction_private() {
let sender_nonce = Nonce(0xdead_beef);
let sender_private_account = Account {
program_owner: crate::test_methods::simple_balance_transfer().id(),
program_owner: crate::test_methods::simple_balance_transfer().id().into(),
balance: 100,
nonce: sender_nonce,
data: Data::default(),
@@ -75,7 +75,7 @@ fn transition_from_privacy_preserving_transaction_private() {
let expected_new_commitment_1 = Commitment::new(
&sender_account_id,
&Account {
program_owner: crate::test_methods::simple_balance_transfer().id(),
program_owner: crate::test_methods::simple_balance_transfer().id().into(),
nonce: sender_nonce.private_account_nonce_increment(&sender_keys.nsk()),
balance: sender_private_account.balance - balance_to_move,
data: Data::default(),
@@ -89,7 +89,7 @@ fn transition_from_privacy_preserving_transaction_private() {
let expected_new_commitment_2 = Commitment::new(
&recipient_account_id,
&Account {
program_owner: crate::test_methods::simple_balance_transfer().id(),
program_owner: crate::test_methods::simple_balance_transfer().id().into(),
nonce: Nonce::private_account_nonce_init(&recipient_account_id),
balance: balance_to_move,
..Account::default()
@@ -171,7 +171,7 @@ fn transition_from_privacy_preserving_transaction_deshielded() {
let sender_nonce = Nonce(0xdead_beef);
let sender_private_account = Account {
program_owner: crate::test_methods::simple_balance_transfer().id(),
program_owner: crate::test_methods::simple_balance_transfer().id().into(),
balance: 100,
nonce: sender_nonce,
data: Data::default(),
@@ -182,7 +182,7 @@ fn transition_from_privacy_preserving_transaction_deshielded() {
.with_public_accounts([(
recipient_keys.account_id(),
Account {
program_owner: crate::test_methods::simple_balance_transfer().id(),
program_owner: crate::test_methods::simple_balance_transfer().id().into(),
balance: recipient_initial_balance,
..Account::default()
},
@@ -210,7 +210,7 @@ fn transition_from_privacy_preserving_transaction_deshielded() {
let expected_new_commitment = Commitment::new(
&sender_account_id,
&Account {
program_owner: crate::test_methods::simple_balance_transfer().id(),
program_owner: crate::test_methods::simple_balance_transfer().id().into(),
nonce: sender_nonce.private_account_nonce_increment(&sender_keys.nsk()),
balance: sender_private_account.balance - balance_to_move,
data: Data::default(),
@@ -245,7 +245,7 @@ fn burner_program_should_fail_in_privacy_preserving_circuit() {
let program = crate::test_methods::burner();
let public_account = AccountWithMetadata::new(
Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 100,
..Account::default()
},
@@ -268,7 +268,7 @@ fn minter_program_should_fail_in_privacy_preserving_circuit() {
let program = crate::test_methods::minter();
let public_account = AccountWithMetadata::new(
Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 0,
..Account::default()
},
@@ -291,7 +291,7 @@ fn nonce_changer_program_should_fail_in_privacy_preserving_circuit() {
let program = crate::test_methods::nonce_changer();
let public_account = AccountWithMetadata::new(
Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 0,
..Account::default()
},
@@ -314,7 +314,7 @@ fn data_changer_program_should_fail_for_non_owned_account_in_privacy_preserving_
let program = crate::test_methods::data_changer();
let public_account = AccountWithMetadata::new(
Account {
program_owner: [0, 1, 2, 3, 4, 5, 6, 7],
program_owner: [0, 1, 2, 3, 4, 5, 6, 7].into(),
balance: 0,
..Account::default()
},
@@ -337,7 +337,7 @@ fn data_changer_program_should_fail_for_too_large_data_in_privacy_preserving_cir
let program = crate::test_methods::data_changer();
let public_account = AccountWithMetadata::new(
Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 0,
..Account::default()
},
@@ -368,7 +368,7 @@ fn extra_output_program_should_fail_in_privacy_preserving_circuit() {
let program = crate::test_methods::extra_output();
let public_account = AccountWithMetadata::new(
Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 0,
..Account::default()
},
@@ -391,7 +391,7 @@ fn missing_output_program_should_fail_in_privacy_preserving_circuit() {
let program = crate::test_methods::missing_output();
let public_account_1 = AccountWithMetadata::new(
Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 0,
..Account::default()
},
@@ -400,7 +400,7 @@ fn missing_output_program_should_fail_in_privacy_preserving_circuit() {
);
let public_account_2 = AccountWithMetadata::new(
Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 0,
..Account::default()
},
@@ -423,7 +423,7 @@ fn program_owner_changer_should_fail_in_privacy_preserving_circuit() {
let program = crate::test_methods::program_owner_changer();
let public_account = AccountWithMetadata::new(
Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 0,
..Account::default()
},
@@ -446,7 +446,7 @@ fn transfer_from_non_owned_account_should_fail_in_privacy_preserving_circuit() {
let program = crate::test_methods::simple_balance_transfer();
let public_account_1 = AccountWithMetadata::new(
Account {
program_owner: [0, 1, 2, 3, 4, 5, 6, 7],
program_owner: [0, 1, 2, 3, 4, 5, 6, 7].into(),
balance: 100,
..Account::default()
},
@@ -455,7 +455,7 @@ fn transfer_from_non_owned_account_should_fail_in_privacy_preserving_circuit() {
);
let public_account_2 = AccountWithMetadata::new(
Account {
program_owner: program.id(),
program_owner: program.id().into(),
balance: 0,
..Account::default()
},
@@ -483,7 +483,7 @@ fn malicious_authorization_changer_should_fail_in_privacy_preserving_circuit() {
let sender_account = AccountWithMetadata::new(
Account {
program_owner: simple_transfers.id(),
program_owner: simple_transfers.id().into(),
balance: 100,
..Default::default()
},
@@ -96,7 +96,7 @@ fn program_should_fail_if_it_drops_a_declared_account() {
(
AccountId::new([1; 32]),
Account {
program_owner: crate::test_methods::dropped_account().id(),
program_owner: crate::test_methods::dropped_account().id().into(),
balance: 100,
..Account::default()
},
@@ -104,7 +104,7 @@ fn program_should_fail_if_it_drops_a_declared_account() {
(
AccountId::new([2; 32]),
Account {
program_owner: crate::test_methods::dropped_account().id(),
program_owner: crate::test_methods::dropped_account().id().into(),
balance: 0,
..Account::default()
},
@@ -136,7 +136,7 @@ fn program_should_fail_if_modifies_program_owner_with_only_non_default_program_o
let initial_data = [(
AccountId::new([1; 32]),
Account {
program_owner: crate::test_methods::simple_balance_transfer().id(),
program_owner: crate::test_methods::simple_balance_transfer().id().into(),
..Account::default()
},
)];
@@ -268,7 +268,7 @@ fn program_should_fail_if_transfers_balance_from_non_owned_account() {
let program_id = crate::test_methods::simple_balance_transfer().id();
assert_ne!(
state.get_account_by_id(sender_account_id).program_owner,
program_id
program_id.into()
);
let message = public_transaction::Message::try_new(
program_id,
@@ -285,8 +285,8 @@ fn program_should_fail_if_transfers_balance_from_non_owned_account() {
assert!(matches!(
result,
Err(LeeError::InvalidProgramBehavior(InvalidProgramBehaviorError::ExecutionValidationFailed(
ExecutionValidationError::UnauthorizedBalanceDecrease { account_id: err_account_id, owner_program_id, executing_program_id }
))) if err_account_id == sender_account_id && owner_program_id != program_id && executing_program_id == program_id
ExecutionValidationError::UnauthorizedBalanceDecrease { account_id: err_account_id, owner_account_id, executing_program_id }
))) if err_account_id == sender_account_id && owner_account_id != program_id.into() && executing_program_id == program_id
));
}
@@ -303,7 +303,7 @@ fn program_should_fail_if_modifies_data_of_non_owned_account() {
assert_ne!(state.get_account_by_id(account_id), Account::default());
assert_ne!(
state.get_account_by_id(account_id).program_owner,
program_id
program_id.into()
);
let message =
public_transaction::Message::try_new(program_id, vec![account_id], vec![], vec![0])
@@ -356,7 +356,7 @@ fn program_should_fail_if_does_not_preserve_total_balance_by_burning() {
let account_id = AccountId::new([252; 32]);
assert_eq!(
state.get_account_by_id(account_id).program_owner,
program_id
program_id.into()
);
let balance_to_burn: u128 = 1;
assert!(state.get_account_by_id(account_id).balance > balance_to_burn);
@@ -8,7 +8,7 @@ use lee_core::{
BlockId, Commitment, Nullifier, PrivacyPreservingCircuitOutput, PublicAction, Timestamp,
account::{Account, AccountId, AccountWithMetadata},
program::{
CallerData, ChainedCall, Claim, DEFAULT_PROGRAM_ID, compute_public_authorized_pdas,
CallerData, ChainedCall, Claim, DEFAULT_PROGRAM_OWNER, compute_public_authorized_pdas,
validate_execution,
},
};
@@ -224,7 +224,7 @@ impl ValidatedStateDiff {
// The invoked program can only claim accounts with default program id.
ensure!(
post.account().program_owner == DEFAULT_PROGRAM_ID,
post.account().program_owner == DEFAULT_PROGRAM_OWNER,
InvalidProgramBehaviorError::ClaimedNonDefaultAccount { account_id }
);
@@ -251,7 +251,7 @@ impl ValidatedStateDiff {
}
}
post.account_mut().program_owner = chained_call.program_id;
post.account_mut().program_owner = AccountId::from(chained_call.program_id);
}
// Update the state diff
@@ -297,7 +297,7 @@ impl ValidatedStateDiff {
// Check that all modified uninitialized accounts where claimed
for (account_id, post) in state_diff.iter().filter_map(|(account_id, post)| {
let pre = state.get_account_by_id(*account_id);
if pre.program_owner != DEFAULT_PROGRAM_ID {
if pre.program_owner != DEFAULT_PROGRAM_OWNER {
return None;
}
if pre == *post {
@@ -306,7 +306,7 @@ impl ValidatedStateDiff {
Some((*account_id, post))
}) {
ensure!(
post.program_owner != DEFAULT_PROGRAM_ID,
post.program_owner != DEFAULT_PROGRAM_OWNER,
InvalidProgramBehaviorError::DefaultAccountModifiedWithoutClaim { account_id }
);
}
@@ -18,7 +18,7 @@ fn public_state_from_balances(initial_data: &[(AccountId, u128)]) -> HashMap<Acc
(
account_id,
Account {
program_owner: crate::test_methods::simple_balance_transfer().id(),
program_owner: crate::test_methods::simple_balance_transfer().id().into(),
balance,
..Account::default()
},
@@ -126,7 +126,7 @@ fn privacy_malicious_programs_cannot_drain_public_victim() {
// Build attacker's private account and its local commitment tree.
let attacker_account = Account {
program_owner: crate::test_methods::simple_balance_transfer().id(),
program_owner: crate::test_methods::simple_balance_transfer().id().into(),
balance: 100,
..Account::default()
};
@@ -146,7 +146,7 @@ fn privacy_malicious_programs_cannot_drain_public_victim() {
*victim_id.value(),
victim_account.balance,
victim_account.nonce.0,
victim_account.program_owner,
victim_account.program_owner.into(),
*recipient_id.value(),
victim_balance,
);
@@ -284,7 +284,7 @@ fn privacy_malicious_programs_cannot_drain_private_victim() {
// Build attacker's private account and its local commitment tree.
let attacker_account = Account {
program_owner: crate::test_methods::simple_balance_transfer().id(),
program_owner: crate::test_methods::simple_balance_transfer().id().into(),
balance: 100,
..Account::default()
};
@@ -439,7 +439,7 @@ fn malicious_programs_cannot_drain_victim_without_signature() {
*victim_id.value(),
victim_account.balance,
victim_account.nonce.0,
victim_account.program_owner,
victim_account.program_owner.into(),
*recipient_id.value(),
victim_balance,
);
@@ -60,7 +60,7 @@ fn main() {
// Victim has not signed anything — this flag is forged entirely by P1's logic.
let victim = AccountWithMetadata {
account: Account {
program_owner: victim_program_owner,
program_owner: victim_program_owner.into(),
balance: victim_balance,
data: Data::default(),
nonce: Nonce(victim_nonce),
@@ -75,7 +75,7 @@ fn main() {
// on the recipient — a check that would block the transfer.
let recipient = AccountWithMetadata {
account: Account {
program_owner: auth_transfer_id,
program_owner: auth_transfer_id.into(),
balance: 0,
data: Data::default(),
nonce: Nonce(0),
@@ -30,7 +30,7 @@ fn main() {
let mut pre_for_callee = pre.clone();
pre_for_callee.is_authorized = true;
pre_for_callee.account.program_owner = self_program_id;
pre_for_callee.account.program_owner = self_program_id.into();
let chained_call = ChainedCall {
program_id: callee_program_id,
@@ -19,7 +19,7 @@ fn main() {
let account_pre = &pre.account;
let mut account_post = account_pre.clone();
account_post.program_owner = [0, 1, 2, 3, 4, 5, 6, 7];
account_post.program_owner = [0, 1, 2, 3, 4, 5, 6, 7].into();
ProgramOutput::new(
self_program_id,
@@ -31,7 +31,7 @@ fn main() {
let pda_for_callee = |is_authorized| {
let mut for_callee = pda.clone();
for_callee.is_authorized = is_authorized;
for_callee.account.program_owner = self_program_id;
for_callee.account.program_owner = self_program_id.into();
for_callee
};
+1 -1
View File
@@ -201,7 +201,7 @@ pub fn build_inbox_init_config_tx(self_zone: ZoneId) -> lee::PublicTransaction {
#[must_use]
pub fn build_holding_account(holder: AccountId, amount: Balance) -> (AccountId, Account) {
let account = Account {
program_owner: programs::bridge_lock().id(),
program_owner: programs::bridge_lock().id().into(),
balance: amount,
..Default::default()
};
+1 -1
View File
@@ -202,7 +202,7 @@ typedef struct FfiPublicTransactionBody {
* byte arrays since C doesn't have native u128 support.
*/
typedef struct FfiAccount {
struct FfiProgramId program_owner;
struct FfiBytes32 program_owner;
/**
* Balance as little-endian [u8; 16].
*/
+9 -10
View File
@@ -1,6 +1,4 @@
use indexer_service_protocol::ProgramId;
use crate::api::types::{FfiBytes32, FfiProgramId, FfiU128};
use crate::api::types::{FfiBytes32, FfiU128};
/// Account data structure - C-compatible version of lee Account.
///
@@ -8,7 +6,7 @@ use crate::api::types::{FfiBytes32, FfiProgramId, FfiU128};
/// byte arrays since C doesn't have native u128 support.
#[repr(C)]
pub struct FfiAccount {
pub program_owner: FfiProgramId,
pub program_owner: FfiBytes32,
/// Balance as little-endian [u8; 16].
pub balance: FfiU128,
/// Pointer to account data bytes.
@@ -40,11 +38,8 @@ impl From<lee::Account> for FfiAccount {
let (data, data_len, data_cap) = data.into_inner().into_raw_parts();
let program_owner = FfiProgramId {
data: program_owner,
};
Self {
program_owner,
program_owner: FfiBytes32::from_account_id(&program_owner),
balance: balance.into(),
data,
data_len,
@@ -66,7 +61,9 @@ impl From<FfiAccount> for indexer_service_protocol::Account {
} = value;
Self {
program_owner: ProgramId(program_owner.data),
program_owner: indexer_service_protocol::AccountId {
value: program_owner.data,
},
balance: balance.into(),
data: indexer_service_protocol::Data(unsafe {
Vec::from_raw_parts(data, data_len, data_cap)
@@ -88,7 +85,9 @@ impl From<&FfiAccount> for indexer_service_protocol::Account {
} = value;
Self {
program_owner: ProgramId(program_owner.data),
program_owner: indexer_service_protocol::AccountId {
value: program_owner.data,
},
balance: balance.into(),
data: indexer_service_protocol::Data(unsafe {
Vec::from_raw_parts(data, data_len, data_cap)
+1 -1
View File
@@ -131,7 +131,7 @@ impl FromStr for AccountId {
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, JsonSchema)]
pub struct Account {
pub program_owner: ProgramId,
pub program_owner: AccountId,
pub balance: u128,
pub data: Data,
pub nonce: Nonce,
+4 -2
View File
@@ -105,7 +105,9 @@ impl MockIndexerService {
accounts.insert(
*account_id,
Account {
program_owner: ProgramId([i as u32; 8]),
program_owner: AccountId {
value: [i as u8; 32],
},
balance: 1000 * (i as u128 + 1),
data: Data(vec![0xaa, 0xbb, 0xcc]),
nonce: i as u128,
@@ -386,7 +388,7 @@ fn mock_privacy_preserving_tx(
public_actions: vec![PublicActionWithID {
account_id: account_ids[tx_idx as usize % account_ids.len()],
post_state: Account {
program_owner: ProgramId([1_u32; 8]),
program_owner: AccountId { value: [1_u8; 32] },
balance: 500,
data: Data(vec![0xdd, 0xee]),
nonce: block_id as u128,
+2 -1
View File
@@ -133,7 +133,8 @@ pub fn add_liquidity(
};
pool_post.data = Data::from(&pool_post_definition);
let token_program_id = user_holding_a.account.program_owner;
let token_program_id: lee_core::program::ProgramId =
user_holding_a.account.program_owner.into();
// Chain call for Token A (UserHoldingA -> Vault_A)
let call_token_a = ChainedCall::new(
+2 -1
View File
@@ -111,7 +111,8 @@ pub fn new_definition(
let pool_pda_seed = compute_pool_pda_seed(definition_token_a_id, definition_token_b_id);
let pool_post = AccountPostState::new_claimed_if_default(pool_post, Claim::Pda(pool_pda_seed));
let token_program_id = user_holding_a.account.program_owner;
let token_program_id: lee_core::program::ProgramId =
user_holding_a.account.program_owner.into();
// Chain call for Token A (user_holding_a -> Vault_A)
let vault_a_seed = compute_vault_pda_seed(pool.account_id, definition_token_a_id);
+2 -1
View File
@@ -113,7 +113,8 @@ pub fn remove_liquidity(
pool_post.data = Data::from(&pool_post_definition);
let token_program_id = user_holding_a.account.program_owner;
let token_program_id: lee_core::program::ProgramId =
user_holding_a.account.program_owner.into();
// Chaincall for Token A withdraw
let call_token_a = ChainedCall::new(
+2 -2
View File
@@ -182,7 +182,7 @@ fn swap_logic(
);
assert!(withdraw_amount != 0, "Withdraw amount should be nonzero");
let token_program_id = user_deposit.account.program_owner;
let token_program_id: lee_core::program::ProgramId = user_deposit.account.program_owner.into();
let mut chained_calls = Vec::new();
chained_calls.push(ChainedCall::new(
@@ -314,7 +314,7 @@ fn exact_output_swap_logic(
"Required input exceeds maximum amount in"
);
let token_program_id = user_deposit.account.program_owner;
let token_program_id: lee_core::program::ProgramId = user_deposit.account.program_owner.into();
let mut chained_calls = Vec::new();
chained_calls.push(ChainedCall::new(
+77 -77
View File
@@ -511,7 +511,7 @@ impl AccountWithMetadataForTests {
fn user_holding_a() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: TOKEN_PROGRAM_ID,
program_owner: TOKEN_PROGRAM_ID.into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::token_a_definition_id(),
@@ -527,7 +527,7 @@ impl AccountWithMetadataForTests {
fn user_holding_b() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: TOKEN_PROGRAM_ID,
program_owner: TOKEN_PROGRAM_ID.into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::token_b_definition_id(),
@@ -543,7 +543,7 @@ impl AccountWithMetadataForTests {
fn vault_a_init() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: TOKEN_PROGRAM_ID,
program_owner: TOKEN_PROGRAM_ID.into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::token_a_definition_id(),
@@ -559,7 +559,7 @@ impl AccountWithMetadataForTests {
fn vault_b_init() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: TOKEN_PROGRAM_ID,
program_owner: TOKEN_PROGRAM_ID.into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::token_b_definition_id(),
@@ -575,7 +575,7 @@ impl AccountWithMetadataForTests {
fn vault_a_init_high() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: TOKEN_PROGRAM_ID,
program_owner: TOKEN_PROGRAM_ID.into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::token_a_definition_id(),
@@ -591,7 +591,7 @@ impl AccountWithMetadataForTests {
fn vault_b_init_high() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: TOKEN_PROGRAM_ID,
program_owner: TOKEN_PROGRAM_ID.into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::token_b_definition_id(),
@@ -607,7 +607,7 @@ impl AccountWithMetadataForTests {
fn vault_a_init_low() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: TOKEN_PROGRAM_ID,
program_owner: TOKEN_PROGRAM_ID.into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::token_a_definition_id(),
@@ -623,7 +623,7 @@ impl AccountWithMetadataForTests {
fn vault_b_init_low() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: TOKEN_PROGRAM_ID,
program_owner: TOKEN_PROGRAM_ID.into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::token_b_definition_id(),
@@ -639,7 +639,7 @@ impl AccountWithMetadataForTests {
fn vault_a_init_zero() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: TOKEN_PROGRAM_ID,
program_owner: TOKEN_PROGRAM_ID.into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::token_a_definition_id(),
@@ -655,7 +655,7 @@ impl AccountWithMetadataForTests {
fn vault_b_init_zero() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: TOKEN_PROGRAM_ID,
program_owner: TOKEN_PROGRAM_ID.into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::token_b_definition_id(),
@@ -671,7 +671,7 @@ impl AccountWithMetadataForTests {
fn pool_lp_init() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: TOKEN_PROGRAM_ID,
program_owner: TOKEN_PROGRAM_ID.into(),
balance: 0_u128,
data: Data::from(&TokenDefinition::Fungible {
name: String::from("test"),
@@ -688,7 +688,7 @@ impl AccountWithMetadataForTests {
fn pool_lp_with_wrong_id() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: TOKEN_PROGRAM_ID,
program_owner: TOKEN_PROGRAM_ID.into(),
balance: 0_u128,
data: Data::from(&TokenDefinition::Fungible {
name: String::from("test"),
@@ -705,7 +705,7 @@ impl AccountWithMetadataForTests {
fn user_holding_lp_uninit() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: TOKEN_PROGRAM_ID,
program_owner: TOKEN_PROGRAM_ID.into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::token_lp_definition_id(),
@@ -721,7 +721,7 @@ impl AccountWithMetadataForTests {
fn user_holding_lp_init() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: TOKEN_PROGRAM_ID,
program_owner: TOKEN_PROGRAM_ID.into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::token_lp_definition_id(),
@@ -737,7 +737,7 @@ impl AccountWithMetadataForTests {
fn pool_definition_init() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: ProgramId::default(),
program_owner: ProgramId::default().into(),
balance: 0_u128,
data: Data::from(&PoolDefinition {
definition_token_a_id: IdForTests::token_a_definition_id(),
@@ -761,7 +761,7 @@ impl AccountWithMetadataForTests {
fn pool_definition_init_reserve_a_zero() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: ProgramId::default(),
program_owner: ProgramId::default().into(),
balance: 0_u128,
data: Data::from(&PoolDefinition {
definition_token_a_id: IdForTests::token_a_definition_id(),
@@ -785,7 +785,7 @@ impl AccountWithMetadataForTests {
fn pool_definition_init_reserve_b_zero() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: ProgramId::default(),
program_owner: ProgramId::default().into(),
balance: 0_u128,
data: Data::from(&PoolDefinition {
definition_token_a_id: IdForTests::token_a_definition_id(),
@@ -809,7 +809,7 @@ impl AccountWithMetadataForTests {
fn pool_definition_init_reserve_a_low() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: ProgramId::default(),
program_owner: ProgramId::default().into(),
balance: 0_u128,
data: Data::from(&PoolDefinition {
definition_token_a_id: IdForTests::token_a_definition_id(),
@@ -833,7 +833,7 @@ impl AccountWithMetadataForTests {
fn pool_definition_init_reserve_b_low() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: ProgramId::default(),
program_owner: ProgramId::default().into(),
balance: 0_u128,
data: Data::from(&PoolDefinition {
definition_token_a_id: IdForTests::token_a_definition_id(),
@@ -857,7 +857,7 @@ impl AccountWithMetadataForTests {
fn pool_definition_swap_test_1() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: ProgramId::default(),
program_owner: ProgramId::default().into(),
balance: 0_u128,
data: Data::from(&PoolDefinition {
definition_token_a_id: IdForTests::token_a_definition_id(),
@@ -881,7 +881,7 @@ impl AccountWithMetadataForTests {
fn pool_definition_swap_test_2() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: ProgramId::default(),
program_owner: ProgramId::default().into(),
balance: 0_u128,
data: Data::from(&PoolDefinition {
definition_token_a_id: IdForTests::token_a_definition_id(),
@@ -905,7 +905,7 @@ impl AccountWithMetadataForTests {
fn pool_definition_swap_exact_output_test_1() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: ProgramId::default(),
program_owner: ProgramId::default().into(),
balance: 0_u128,
data: Data::from(&PoolDefinition {
definition_token_a_id: IdForTests::token_a_definition_id(),
@@ -929,7 +929,7 @@ impl AccountWithMetadataForTests {
fn pool_definition_swap_exact_output_test_2() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: ProgramId::default(),
program_owner: ProgramId::default().into(),
balance: 0_u128,
data: Data::from(&PoolDefinition {
definition_token_a_id: IdForTests::token_a_definition_id(),
@@ -953,7 +953,7 @@ impl AccountWithMetadataForTests {
fn pool_definition_add_zero_lp() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: ProgramId::default(),
program_owner: ProgramId::default().into(),
balance: 0_u128,
data: Data::from(&PoolDefinition {
definition_token_a_id: IdForTests::token_a_definition_id(),
@@ -977,7 +977,7 @@ impl AccountWithMetadataForTests {
fn pool_definition_add_successful() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: ProgramId::default(),
program_owner: ProgramId::default().into(),
balance: 0_u128,
data: Data::from(&PoolDefinition {
definition_token_a_id: IdForTests::token_a_definition_id(),
@@ -1001,7 +1001,7 @@ impl AccountWithMetadataForTests {
fn pool_definition_remove_successful() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: ProgramId::default(),
program_owner: ProgramId::default().into(),
balance: 0_u128,
data: Data::from(&PoolDefinition {
definition_token_a_id: IdForTests::token_a_definition_id(),
@@ -1025,7 +1025,7 @@ impl AccountWithMetadataForTests {
fn pool_definition_inactive() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: ProgramId::default(),
program_owner: ProgramId::default().into(),
balance: 0_u128,
data: Data::from(&PoolDefinition {
definition_token_a_id: IdForTests::token_a_definition_id(),
@@ -1049,7 +1049,7 @@ impl AccountWithMetadataForTests {
fn pool_definition_with_wrong_id() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: ProgramId::default(),
program_owner: ProgramId::default().into(),
balance: 0_u128,
data: Data::from(&PoolDefinition {
definition_token_a_id: IdForTests::token_a_definition_id(),
@@ -1073,7 +1073,7 @@ impl AccountWithMetadataForTests {
fn vault_a_with_wrong_id() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: TOKEN_PROGRAM_ID,
program_owner: TOKEN_PROGRAM_ID.into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::token_a_definition_id(),
@@ -1089,7 +1089,7 @@ impl AccountWithMetadataForTests {
fn vault_b_with_wrong_id() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: TOKEN_PROGRAM_ID,
program_owner: TOKEN_PROGRAM_ID.into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::token_b_definition_id(),
@@ -1105,7 +1105,7 @@ impl AccountWithMetadataForTests {
fn pool_definition_active() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: ProgramId::default(),
program_owner: ProgramId::default().into(),
balance: 0_u128,
data: Data::from(&PoolDefinition {
definition_token_a_id: IdForTests::token_a_definition_id(),
@@ -1349,7 +1349,7 @@ impl IdForExeTests {
impl AccountsForExeTests {
fn user_token_a_holding() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_a_definition_id(),
@@ -1361,7 +1361,7 @@ impl AccountsForExeTests {
fn user_token_b_holding() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_b_definition_id(),
@@ -1373,7 +1373,7 @@ impl AccountsForExeTests {
fn pool_definition_init() -> Account {
Account {
program_owner: programs::amm().id(),
program_owner: programs::amm().id().into(),
balance: 0_u128,
data: Data::from(&PoolDefinition {
definition_token_a_id: IdForExeTests::token_a_definition_id(),
@@ -1393,7 +1393,7 @@ impl AccountsForExeTests {
fn token_a_definition_account() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenDefinition::Fungible {
name: String::from("test"),
@@ -1406,7 +1406,7 @@ impl AccountsForExeTests {
fn token_b_definition_acc() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenDefinition::Fungible {
name: String::from("test"),
@@ -1419,7 +1419,7 @@ impl AccountsForExeTests {
fn token_lp_definition_acc() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenDefinition::Fungible {
name: String::from("LP Token"),
@@ -1432,7 +1432,7 @@ impl AccountsForExeTests {
fn vault_a_init() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_a_definition_id(),
@@ -1444,7 +1444,7 @@ impl AccountsForExeTests {
fn vault_b_init() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_b_definition_id(),
@@ -1456,7 +1456,7 @@ impl AccountsForExeTests {
fn user_token_lp_holding() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_lp_definition_id(),
@@ -1468,7 +1468,7 @@ impl AccountsForExeTests {
fn vault_a_swap_1() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_a_definition_id(),
@@ -1480,7 +1480,7 @@ impl AccountsForExeTests {
fn vault_b_swap_1() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_b_definition_id(),
@@ -1492,7 +1492,7 @@ impl AccountsForExeTests {
fn pool_definition_swap_1() -> Account {
Account {
program_owner: programs::amm().id(),
program_owner: programs::amm().id().into(),
balance: 0_u128,
data: Data::from(&PoolDefinition {
definition_token_a_id: IdForExeTests::token_a_definition_id(),
@@ -1512,7 +1512,7 @@ impl AccountsForExeTests {
fn user_token_a_holding_swap_1() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_a_definition_id(),
@@ -1524,7 +1524,7 @@ impl AccountsForExeTests {
fn user_token_b_holding_swap_1() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_b_definition_id(),
@@ -1536,7 +1536,7 @@ impl AccountsForExeTests {
fn vault_a_swap_2() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_a_definition_id(),
@@ -1548,7 +1548,7 @@ impl AccountsForExeTests {
fn vault_b_swap_2() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_b_definition_id(),
@@ -1560,7 +1560,7 @@ impl AccountsForExeTests {
fn pool_definition_swap_2() -> Account {
Account {
program_owner: programs::amm().id(),
program_owner: programs::amm().id().into(),
balance: 0_u128,
data: Data::from(&PoolDefinition {
definition_token_a_id: IdForExeTests::token_a_definition_id(),
@@ -1580,7 +1580,7 @@ impl AccountsForExeTests {
fn user_token_a_holding_swap_2() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_a_definition_id(),
@@ -1592,7 +1592,7 @@ impl AccountsForExeTests {
fn user_token_b_holding_swap_2() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_b_definition_id(),
@@ -1604,7 +1604,7 @@ impl AccountsForExeTests {
fn vault_a_add() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_a_definition_id(),
@@ -1616,7 +1616,7 @@ impl AccountsForExeTests {
fn vault_b_add() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_b_definition_id(),
@@ -1628,7 +1628,7 @@ impl AccountsForExeTests {
fn pool_definition_add() -> Account {
Account {
program_owner: programs::amm().id(),
program_owner: programs::amm().id().into(),
balance: 0_u128,
data: Data::from(&PoolDefinition {
definition_token_a_id: IdForExeTests::token_a_definition_id(),
@@ -1648,7 +1648,7 @@ impl AccountsForExeTests {
fn user_token_a_holding_add() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_a_definition_id(),
@@ -1660,7 +1660,7 @@ impl AccountsForExeTests {
fn user_token_b_holding_add() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_b_definition_id(),
@@ -1672,7 +1672,7 @@ impl AccountsForExeTests {
fn user_token_lp_holding_add() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_lp_definition_id(),
@@ -1684,7 +1684,7 @@ impl AccountsForExeTests {
fn token_lp_definition_add() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenDefinition::Fungible {
name: String::from("LP Token"),
@@ -1697,7 +1697,7 @@ impl AccountsForExeTests {
fn vault_a_remove() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_a_definition_id(),
@@ -1709,7 +1709,7 @@ impl AccountsForExeTests {
fn vault_b_remove() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_b_definition_id(),
@@ -1721,7 +1721,7 @@ impl AccountsForExeTests {
fn pool_definition_remove() -> Account {
Account {
program_owner: programs::amm().id(),
program_owner: programs::amm().id().into(),
balance: 0_u128,
data: Data::from(&PoolDefinition {
definition_token_a_id: IdForExeTests::token_a_definition_id(),
@@ -1741,7 +1741,7 @@ impl AccountsForExeTests {
fn user_token_a_holding_remove() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_a_definition_id(),
@@ -1753,7 +1753,7 @@ impl AccountsForExeTests {
fn user_token_b_holding_remove() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_b_definition_id(),
@@ -1765,7 +1765,7 @@ impl AccountsForExeTests {
fn user_token_lp_holding_remove() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_lp_definition_id(),
@@ -1777,7 +1777,7 @@ impl AccountsForExeTests {
fn token_lp_definition_remove() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenDefinition::Fungible {
name: String::from("LP Token"),
@@ -1790,7 +1790,7 @@ impl AccountsForExeTests {
fn token_lp_definition_init_inactive() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenDefinition::Fungible {
name: String::from("LP Token"),
@@ -1803,7 +1803,7 @@ impl AccountsForExeTests {
fn vault_a_init_inactive() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_a_definition_id(),
@@ -1815,7 +1815,7 @@ impl AccountsForExeTests {
fn vault_b_init_inactive() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_b_definition_id(),
@@ -1827,7 +1827,7 @@ impl AccountsForExeTests {
fn pool_definition_inactive() -> Account {
Account {
program_owner: programs::amm().id(),
program_owner: programs::amm().id().into(),
balance: 0_u128,
data: Data::from(&PoolDefinition {
definition_token_a_id: IdForExeTests::token_a_definition_id(),
@@ -1847,7 +1847,7 @@ impl AccountsForExeTests {
fn user_token_a_holding_new_init() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_a_definition_id(),
@@ -1859,7 +1859,7 @@ impl AccountsForExeTests {
fn user_token_b_holding_new_init() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_b_definition_id(),
@@ -1871,7 +1871,7 @@ impl AccountsForExeTests {
fn user_token_lp_holding_new_init() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_lp_definition_id(),
@@ -1883,7 +1883,7 @@ impl AccountsForExeTests {
fn token_lp_definition_new_init() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenDefinition::Fungible {
name: String::from("LP Token"),
@@ -1896,7 +1896,7 @@ impl AccountsForExeTests {
fn pool_definition_new_init() -> Account {
Account {
program_owner: programs::amm().id(),
program_owner: programs::amm().id().into(),
balance: 0_u128,
data: Data::from(&PoolDefinition {
definition_token_a_id: IdForExeTests::token_a_definition_id(),
@@ -1916,7 +1916,7 @@ impl AccountsForExeTests {
fn user_token_lp_holding_init_zero() -> Account {
Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForExeTests::token_lp_definition_id(),
@@ -2901,7 +2901,7 @@ fn swap_exact_output_overflow_protection() {
let pool = AccountWithMetadata {
account: Account {
program_owner: ProgramId::default(),
program_owner: ProgramId::default().into(),
balance: 0,
data: Data::from(&PoolDefinition {
definition_token_a_id: IdForTests::token_a_definition_id(),
@@ -2923,7 +2923,7 @@ fn swap_exact_output_overflow_protection() {
let vault_a = AccountWithMetadata {
account: Account {
program_owner: TOKEN_PROGRAM_ID,
program_owner: TOKEN_PROGRAM_ID.into(),
balance: 0,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::token_a_definition_id(),
@@ -2937,7 +2937,7 @@ fn swap_exact_output_overflow_protection() {
let vault_b = AccountWithMetadata {
account: Account {
program_owner: TOKEN_PROGRAM_ID,
program_owner: TOKEN_PROGRAM_ID.into(),
balance: 0,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::token_b_definition_id(),
@@ -11,7 +11,7 @@ pub fn burn_from_associated_token_account(
ata_program_id: ProgramId,
amount: u128,
) -> (Vec<AccountPostState>, Vec<ChainedCall>) {
let token_program_id = holder_ata.account.program_owner;
let token_program_id: lee_core::program::ProgramId = holder_ata.account.program_owner.into();
assert!(owner.is_authorized, "Owner authorization is missing");
let definition_id = TokenHolding::try_from(&holder_ata.account.data)
.expect("Holder ATA must hold a valid token")
@@ -10,7 +10,8 @@ pub fn create_associated_token_account(
ata_program_id: ProgramId,
) -> (Vec<AccountPostState>, Vec<ChainedCall>) {
// No authorization check needed: create is idempotent, so anyone can call it safely.
let token_program_id = token_definition.account.program_owner;
let token_program_id: lee_core::program::ProgramId =
token_definition.account.program_owner.into();
let ata_seed = associated_token_account_core::verify_ata_and_get_seed(
&ata_account,
&owner,
@@ -33,7 +33,7 @@ fn owner_account() -> AccountWithMetadata {
fn definition_account() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: TOKEN_PROGRAM_ID,
program_owner: TOKEN_PROGRAM_ID.into(),
balance: 0,
data: Data::from(&TokenDefinition::Fungible {
name: "TEST".to_string(),
@@ -58,7 +58,7 @@ fn uninitialized_ata_account() -> AccountWithMetadata {
fn initialized_ata_account() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: TOKEN_PROGRAM_ID,
program_owner: TOKEN_PROGRAM_ID.into(),
balance: 0,
data: Data::from(&TokenHolding::Fungible {
definition_id: definition_id(),
@@ -11,7 +11,7 @@ pub fn transfer_from_associated_token_account(
ata_program_id: ProgramId,
amount: u128,
) -> (Vec<AccountPostState>, Vec<ChainedCall>) {
let token_program_id = sender_ata.account.program_owner;
let token_program_id: lee_core::program::ProgramId = sender_ata.account.program_owner.into();
assert!(owner.is_authorized, "Owner authorization is missing");
let definition_id = TokenHolding::try_from(&sender_ata.account.data)
.expect("Sender ATA must hold a valid token")
@@ -2,7 +2,8 @@ use authenticated_transfer_core::Instruction;
use lee_core::{
account::{Account, AccountWithMetadata},
program::{
AccountPostState, Claim, DEFAULT_PROGRAM_ID, ProgramInput, ProgramOutput, read_lee_inputs,
AccountPostState, Claim, DEFAULT_PROGRAM_OWNER, ProgramInput, ProgramOutput,
read_lee_inputs,
},
};
@@ -48,7 +49,7 @@ fn transfer(
.expect("Recipient balance overflow");
// Claim recipient account if it has default program owner
if recipient_post_account.program_owner == DEFAULT_PROGRAM_ID {
if recipient_post_account.program_owner == DEFAULT_PROGRAM_OWNER {
AccountPostState::new_claimed(recipient_post_account, Claim::Authorized)
} else {
AccountPostState::new(recipient_post_account)
+4 -2
View File
@@ -131,7 +131,8 @@ fn lock(
// genuine holding: a caller cannot substitute an account owned by some other
// program to emit the mint without an actual lock.
assert_eq!(
holder.account.program_owner, self_program_id,
holder.account.program_owner,
self_program_id.into(),
"holder account must be a bridge_lock holding"
);
assert_eq!(
@@ -217,7 +218,8 @@ fn init_config(
// `new_claimed_if_default` alone would not stop a later self-owned rewrite.
if config.account != Account::default() {
assert_eq!(
config.account.program_owner, self_program_id,
config.account.program_owner,
self_program_id.into(),
"bridge-lock config PDA is owned by another program"
);
assert_eq!(
+4 -3
View File
@@ -60,9 +60,10 @@ fn main() {
}
// Verify all clock accounts are owned by this program (assigned at genesis).
if pre_01.account.program_owner != self_program_id
|| pre_10.account.program_owner != self_program_id
|| pre_50.account.program_owner != self_program_id
let self_account_id: lee_core::account::AccountId = self_program_id.into();
if pre_01.account.program_owner != self_account_id
|| pre_10.account.program_owner != self_account_id
|| pre_50.account.program_owner != self_account_id
{
panic!("Clock accounts must be owned by the clock program");
}
+2 -1
View File
@@ -191,7 +191,8 @@ fn init_config(
// rewriting its own config data on a later call.
if config_meta.account != Account::default() {
assert_eq!(
config_meta.account.program_owner, self_program_id,
config_meta.account.program_owner,
self_program_id.into(),
"inbox config PDA is owned by another program"
);
assert_eq!(
+1 -1
View File
@@ -78,7 +78,7 @@ fn main() {
vec![
ChainedCall::new(
faucet_for_transfer.account.program_owner,
faucet_for_transfer.account.program_owner.into(),
vec![faucet_for_transfer, recipient],
&authenticated_transfer_core::Instruction::Transfer { amount },
)
+1 -1
View File
@@ -87,7 +87,7 @@ fn main() {
pinata_token_holding_for_chain_call.is_authorized = true;
let chained_call = ChainedCall::new(
pinata_token_holding_post.program_owner,
pinata_token_holding_post.program_owner.into(),
vec![
pinata_token_holding_for_chain_call,
winner_token_holding.clone(),
+2 -1
View File
@@ -123,7 +123,8 @@ fn init_config(
// `new_claimed_if_default` alone would not stop a later self-owned rewrite.
if config.account != Account::default() {
assert_eq!(
config.account.program_owner, self_program_id,
config.account.program_owner,
self_program_id.into(),
"receiver config PDA is owned by another program"
);
assert_eq!(
+2 -1
View File
@@ -131,7 +131,8 @@ fn init_config(
// `new_claimed_if_default` alone would not stop a later self-owned rewrite.
if config.account != Account::default() {
assert_eq!(
config.account.program_owner, self_program_id,
config.account.program_owner,
self_program_id.into(),
"ping-sender config PDA is owned by another program"
);
assert_eq!(
+11 -7
View File
@@ -3,7 +3,7 @@ use std::collections::btree_map::Entry;
use lee_core::{
account::{AccountId, AccountWithMetadata},
program::{
AccountPostState, ChainedCall, Claim, DEFAULT_PROGRAM_ID, InstructionData, ProgramId,
AccountPostState, ChainedCall, Claim, DEFAULT_PROGRAM_OWNER, InstructionData, ProgramId,
ProgramInput, ProgramOutput, read_lee_inputs,
},
};
@@ -98,7 +98,8 @@ fn decode_config(
"not the sequencer_stake config account"
);
assert_eq!(
config_account.account.program_owner, self_program_id,
config_account.account.program_owner,
self_program_id.into(),
"config account is not owned by sequencer_stake"
);
SequencerStakeConfig::from_bytes(config_account.account.data.as_ref())
@@ -133,10 +134,11 @@ fn stake(
// An ownership account stays claimed after a full exit, so what a call is
// doing follows from the config entry, not from the account's owner.
let is_claimed = ownership_account.account.program_owner != DEFAULT_PROGRAM_ID;
let is_claimed = ownership_account.account.program_owner != DEFAULT_PROGRAM_OWNER;
if is_claimed {
assert_eq!(
ownership_account.account.program_owner, self_program_id,
ownership_account.account.program_owner,
self_program_id.into(),
"not a sequencer_stake ownership account"
);
let record = StakeRecord::from_bytes(ownership_account.account.data.as_ref())
@@ -207,7 +209,7 @@ fn stake(
// chained-call pre-states reflect state as of when each call runs
let mut ownership_account_claimed = ownership_account;
ownership_account_claimed.account = ownership_account_data;
ownership_account_claimed.account.program_owner = self_program_id;
ownership_account_claimed.account.program_owner = self_program_id.into();
let mover_call = ChainedCall {
program_id: mover_program_id,
@@ -267,7 +269,8 @@ fn unstake_request(
"must sign for the ownership account"
);
assert_eq!(
ownership_account.account.program_owner, self_program_id,
ownership_account.account.program_owner,
self_program_id.into(),
"not a sequencer_stake ownership account"
);
@@ -335,7 +338,8 @@ fn finalize_unstake(
);
assert_eq!(
ownership_account.account.program_owner, self_program_id,
ownership_account.account.program_owner,
self_program_id.into(),
"not a sequencer_stake ownership account"
);
+27 -27
View File
@@ -33,7 +33,7 @@ impl AccountForTests {
fn definition_account_auth() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: [5_u32; 8],
program_owner: [5_u32; 8].into(),
balance: 0_u128,
data: Data::from(&TokenDefinition::Fungible {
name: String::from("test"),
@@ -50,7 +50,7 @@ impl AccountForTests {
fn definition_account_without_auth() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: [5_u32; 8],
program_owner: [5_u32; 8].into(),
balance: 0_u128,
data: Data::from(&TokenDefinition::Fungible {
name: String::from("test"),
@@ -67,7 +67,7 @@ impl AccountForTests {
fn holding_different_definition() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: [5_u32; 8],
program_owner: [5_u32; 8].into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::pool_definition_id_diff(),
@@ -83,7 +83,7 @@ impl AccountForTests {
fn holding_same_definition_with_authorization() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: [5_u32; 8],
program_owner: [5_u32; 8].into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::pool_definition_id(),
@@ -99,7 +99,7 @@ impl AccountForTests {
fn holding_same_definition_without_authorization() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: [5_u32; 8],
program_owner: [5_u32; 8].into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::pool_definition_id(),
@@ -115,7 +115,7 @@ impl AccountForTests {
fn holding_same_definition_without_authorization_overflow() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: [5_u32; 8],
program_owner: [5_u32; 8].into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::pool_definition_id(),
@@ -131,7 +131,7 @@ impl AccountForTests {
fn definition_account_post_burn() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: [5_u32; 8],
program_owner: [5_u32; 8].into(),
balance: 0_u128,
data: Data::from(&TokenDefinition::Fungible {
name: String::from("test"),
@@ -148,7 +148,7 @@ impl AccountForTests {
fn holding_account_post_burn() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: [5_u32; 8],
program_owner: [5_u32; 8].into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::pool_definition_id(),
@@ -172,7 +172,7 @@ impl AccountForTests {
fn init_mint() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: [0_u32; 8],
program_owner: [0_u32; 8].into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::pool_definition_id(),
@@ -188,7 +188,7 @@ impl AccountForTests {
fn holding_account_same_definition_mint() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: [5_u32; 8],
program_owner: [5_u32; 8].into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::pool_definition_id(),
@@ -204,7 +204,7 @@ impl AccountForTests {
fn definition_account_mint() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: [5_u32; 8],
program_owner: [5_u32; 8].into(),
balance: 0_u128,
data: Data::from(&TokenDefinition::Fungible {
name: String::from("test"),
@@ -221,7 +221,7 @@ impl AccountForTests {
fn holding_same_definition_with_authorization_and_large_balance() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: [5_u32; 8],
program_owner: [5_u32; 8].into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::pool_definition_id(),
@@ -237,7 +237,7 @@ impl AccountForTests {
fn definition_account_with_authorization_nonfungible() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: [5_u32; 8],
program_owner: [5_u32; 8].into(),
balance: 0_u128,
data: Data::from(&TokenDefinition::NonFungible {
name: String::from("test"),
@@ -262,7 +262,7 @@ impl AccountForTests {
fn holding_account_init() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: [5_u32; 8],
program_owner: [5_u32; 8].into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::pool_definition_id(),
@@ -278,7 +278,7 @@ impl AccountForTests {
fn definition_account_unclaimed() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: [0_u32; 8],
program_owner: [0_u32; 8].into(),
balance: 0_u128,
data: Data::from(&TokenDefinition::Fungible {
name: String::from("test"),
@@ -295,7 +295,7 @@ impl AccountForTests {
fn holding_account_unclaimed() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: [0_u32; 8],
program_owner: [0_u32; 8].into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::pool_definition_id(),
@@ -311,7 +311,7 @@ impl AccountForTests {
fn holding_account2_init() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: [5_u32; 8],
program_owner: [5_u32; 8].into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::pool_definition_id(),
@@ -327,7 +327,7 @@ impl AccountForTests {
fn holding_account2_init_post_transfer() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: [5_u32; 8],
program_owner: [5_u32; 8].into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::pool_definition_id(),
@@ -343,7 +343,7 @@ impl AccountForTests {
fn holding_account_init_post_transfer() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: [5_u32; 8],
program_owner: [5_u32; 8].into(),
balance: 0_u128,
data: Data::from(&TokenHolding::Fungible {
definition_id: IdForTests::pool_definition_id(),
@@ -359,7 +359,7 @@ impl AccountForTests {
fn holding_account_master_nft() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: [5_u32; 8],
program_owner: [5_u32; 8].into(),
balance: 0_u128,
data: Data::from(&TokenHolding::NftMaster {
definition_id: IdForTests::pool_definition_id(),
@@ -375,7 +375,7 @@ impl AccountForTests {
fn holding_account_master_nft_insufficient_balance() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: [5_u32; 8],
program_owner: [5_u32; 8].into(),
balance: 0_u128,
data: Data::from(&TokenHolding::NftMaster {
definition_id: IdForTests::pool_definition_id(),
@@ -391,7 +391,7 @@ impl AccountForTests {
fn holding_account_master_nft_after_print() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: [5_u32; 8],
program_owner: [5_u32; 8].into(),
balance: 0_u128,
data: Data::from(&TokenHolding::NftMaster {
definition_id: IdForTests::pool_definition_id(),
@@ -407,7 +407,7 @@ impl AccountForTests {
fn holding_account_printed_nft() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: [0_u32; 8],
program_owner: [0_u32; 8].into(),
balance: 0_u128,
data: Data::from(&TokenHolding::NftPrintedCopy {
definition_id: IdForTests::pool_definition_id(),
@@ -423,7 +423,7 @@ impl AccountForTests {
fn holding_account_with_master_nft_transferred_to() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: [0_u32; 8],
program_owner: [0_u32; 8].into(),
balance: 0_u128,
data: Data::from(&TokenHolding::NftMaster {
definition_id: IdForTests::pool_definition_id(),
@@ -439,7 +439,7 @@ impl AccountForTests {
fn holding_account_master_nft_post_transfer() -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: [5_u32; 8],
program_owner: [5_u32; 8].into(),
balance: 0_u128,
data: Data::from(&TokenHolding::NftMaster {
definition_id: IdForTests::pool_definition_id(),
@@ -534,7 +534,7 @@ impl IdForTests {
fn new_definition_non_default_first_account_should_fail() {
let definition_account = AccountWithMetadata {
account: Account {
program_owner: [1, 2, 3, 4, 5, 6, 7, 8],
program_owner: [1, 2, 3, 4, 5, 6, 7, 8].into(),
..Account::default()
},
is_authorized: true,
@@ -563,7 +563,7 @@ fn new_definition_non_default_second_account_should_fail() {
};
let holding_account = AccountWithMetadata {
account: Account {
program_owner: [1, 2, 3, 4, 5, 6, 7, 8],
program_owner: [1, 2, 3, 4, 5, 6, 7, 8].into(),
..Account::default()
},
is_authorized: true,
+2 -2
View File
@@ -49,7 +49,7 @@ fn main() {
vec![
ChainedCall::new(
sender.account.program_owner,
sender.account.program_owner.into(),
vec![sender, recipient_vault_for_callee],
&AuthTransferInstruction::Transfer { amount },
)
@@ -73,7 +73,7 @@ fn main() {
vec![
ChainedCall::new(
owner_vault_for_callee.account.program_owner,
owner_vault_for_callee.account.program_owner.into(),
vec![owner_vault_for_callee, owner],
&AuthTransferInstruction::Transfer { amount },
)
+2 -1
View File
@@ -145,7 +145,8 @@ fn init_config(
// rewriting its own config data on a later call.
if config.account != Account::default() {
assert_eq!(
config.account.program_owner, self_program_id,
config.account.program_owner,
self_program_id.into(),
"wrapped-token config PDA is owned by another program"
);
assert_eq!(
@@ -191,7 +191,7 @@ mod tests {
(
staked.account_id,
Account {
program_owner: programs::sequencer_stake().id(),
program_owner: programs::sequencer_stake().id().into(),
balance: staked.balance,
data: StakeRecord {
sequencer_key: staked.key,
@@ -206,7 +206,7 @@ mod tests {
});
let config = Account {
program_owner: programs::sequencer_stake().id(),
program_owner: programs::sequencer_stake().id().into(),
data: SequencerStakeConfig {
minimum_sequencer_stake: MINIMUM,
entries: stakes
+21 -21
View File
@@ -1619,7 +1619,7 @@ async fn block_production_aborts_when_clock_account_data_is_corrupted() {
// 0,
// );
// let sender_private_account = Account {
// program_owner: programs::authenticated_transfer().id(),
// program_owner: programs::authenticated_transfer().id().into(),
// balance: 100,
// nonce: Nonce(0xdead_beef),
// data: Data::default(),
@@ -1746,7 +1746,7 @@ fn time_locked_transfer_succeeds_when_deadline_has_passed() {
state.force_insert_account(
recipient_id,
Account {
program_owner: programs::authenticated_transfer().id(),
program_owner: programs::authenticated_transfer().id().into(),
..Account::default()
},
);
@@ -1756,7 +1756,7 @@ fn time_locked_transfer_succeeds_when_deadline_has_passed() {
state.force_insert_account(
sender_id,
Account {
program_owner: test_programs::time_locked_transfer().id(),
program_owner: test_programs::time_locked_transfer().id().into(),
balance: 100,
..Account::default()
},
@@ -1795,7 +1795,7 @@ fn time_locked_transfer_fails_when_deadline_is_in_the_future() {
state.force_insert_account(
recipient_id,
Account {
program_owner: programs::authenticated_transfer().id(),
program_owner: programs::authenticated_transfer().id().into(),
..Account::default()
},
);
@@ -1805,7 +1805,7 @@ fn time_locked_transfer_fails_when_deadline_is_in_the_future() {
state.force_insert_account(
sender_id,
Account {
program_owner: test_programs::time_locked_transfer().id(),
program_owner: test_programs::time_locked_transfer().id().into(),
balance: 100,
..Account::default()
},
@@ -1880,14 +1880,14 @@ fn pinata_cooldown_claim_succeeds_after_cooldown() {
state.force_insert_account(
winner_id,
Account {
program_owner: programs::authenticated_transfer().id(),
program_owner: programs::authenticated_transfer().id().into(),
..Account::default()
},
);
state.force_insert_account(
pinata_id,
Account {
program_owner: test_programs::pinata_cooldown().id(),
program_owner: test_programs::pinata_cooldown().id().into(),
balance: 1000,
data: pinata_cooldown_data(prize, cooldown_ms, last_claim_timestamp)
.try_into()
@@ -1927,14 +1927,14 @@ fn pinata_cooldown_claim_fails_during_cooldown() {
state.force_insert_account(
winner_id,
Account {
program_owner: programs::authenticated_transfer().id(),
program_owner: programs::authenticated_transfer().id().into(),
..Account::default()
},
);
state.force_insert_account(
pinata_id,
Account {
program_owner: test_programs::pinata_cooldown().id(),
program_owner: test_programs::pinata_cooldown().id().into(),
balance: 1000,
data: pinata_cooldown_data(prize, cooldown_ms, last_claim_timestamp)
.try_into()
@@ -1973,7 +1973,7 @@ fn pda_mechanism_with_pinata_token_program() {
balance: 150,
};
let expected_winner_token_holding_post = Account {
program_owner: token.id(),
program_owner: token.id().into(),
data: Data::from(&expected_winner_account_holding),
..Account::default()
};
@@ -1984,7 +1984,7 @@ fn pda_mechanism_with_pinata_token_program() {
state.force_insert_account(
pinata_definition_id,
Account {
program_owner: pinata_token.id(),
program_owner: pinata_token.id().into(),
// Difficulty: 3
data: vec![3; 33].try_into().unwrap(),
..Account::default()
@@ -2011,7 +2011,7 @@ fn pda_mechanism_with_pinata_token_program() {
state.force_insert_account(
pinata_token_definition_id,
Account {
program_owner: token.id(),
program_owner: token.id().into(),
data: Data::from(&token_definition),
..Account::default()
},
@@ -2019,7 +2019,7 @@ fn pda_mechanism_with_pinata_token_program() {
state.force_insert_account(
pinata_token_holding_id,
Account {
program_owner: token.id(),
program_owner: token.id().into(),
data: Data::from(&token_holding),
..Account::default()
},
@@ -2027,7 +2027,7 @@ fn pda_mechanism_with_pinata_token_program() {
state.force_insert_account(
winner_token_holding_id,
Account {
program_owner: token.id(),
program_owner: token.id().into(),
data: Data::from(&winner_holding),
..Account::default()
},
@@ -2953,7 +2953,7 @@ fn diag_sequencer_stake_claims_ownership_account() {
(
funding_id,
Account {
program_owner: programs::authenticated_transfer().id(),
program_owner: programs::authenticated_transfer().id().into(),
balance: amount,
..Account::default()
},
@@ -2996,7 +2996,7 @@ fn diag_sequencer_stake_claims_ownership_account() {
let ownership_account = state.get_account_by_id(ownership_id);
assert_eq!(
ownership_account.program_owner,
programs::sequencer_stake().id(),
programs::sequencer_stake().id().into(),
"ownership account should be claimed by sequencer_stake"
);
assert_eq!(ownership_account.balance, amount);
@@ -3071,7 +3071,7 @@ fn stake_test_state(funding_id: AccountId, funding_balance: u128) -> V03State {
(
funding_id,
Account {
program_owner: programs::authenticated_transfer().id(),
program_owner: programs::authenticated_transfer().id().into(),
balance: funding_balance,
..Account::default()
},
@@ -3267,7 +3267,7 @@ fn an_ownership_account_cannot_stand_in_for_the_config_account() {
assert_eq!(
state.get_account_by_id(other_ownership_id).program_owner,
programs::sequencer_stake().id(),
programs::sequencer_stake().id().into(),
"the stand-in is owned by sequencer_stake, so ownership alone would not catch it"
);
@@ -3304,7 +3304,7 @@ fn a_fully_exited_ownership_account_can_stake_again() {
(
funding_id,
Account {
program_owner: programs::authenticated_transfer().id(),
program_owner: programs::authenticated_transfer().id().into(),
balance: amount,
..Account::default()
},
@@ -3368,7 +3368,7 @@ fn a_fully_exited_ownership_account_can_stake_again() {
assert_eq!(state.get_account_by_id(ownership_id).balance, 0);
assert_eq!(
state.get_account_by_id(ownership_id).program_owner,
programs::sequencer_stake().id(),
programs::sequencer_stake().id().into(),
"the ownership account stays claimed after a full exit"
);
@@ -3401,7 +3401,7 @@ fn genesis_stakes_the_bootstrap_sequencer_at_the_configured_account() {
let stake_account = state.get_account_by_id(bootstrap_stake_account_id(&config));
assert_eq!(
stake_account.program_owner,
programs::sequencer_stake().id()
programs::sequencer_stake().id().into()
);
assert_eq!(
stake_account.balance,
+1 -1
View File
@@ -31,7 +31,7 @@ fn initial_state() -> lee::V03State {
(
id,
Account {
program_owner: programs::authenticated_transfer().id(),
program_owner: programs::authenticated_transfer().id().into(),
balance,
..Account::default()
},
+5 -5
View File
@@ -32,7 +32,7 @@ pub fn pinata_account_id() -> AccountId {
#[must_use]
pub fn pinata_account() -> Account {
Account {
program_owner: programs::pinata().id(),
program_owner: programs::pinata().id().into(),
balance: 1_500_000,
// Difficulty: 3
data: vec![3; 33].try_into().expect("Should fit"),
@@ -48,7 +48,7 @@ pub fn faucet_account_id() -> AccountId {
#[must_use]
pub fn faucet_account() -> Account {
Account {
program_owner: programs::authenticated_transfer().id(),
program_owner: programs::authenticated_transfer().id().into(),
balance: u128::MAX,
..Account::default()
}
@@ -62,7 +62,7 @@ pub fn bridge_account_id() -> AccountId {
#[must_use]
pub fn bridge_account() -> Account {
Account {
program_owner: programs::authenticated_transfer().id(),
program_owner: programs::authenticated_transfer().id().into(),
..Account::default()
}
}
@@ -82,7 +82,7 @@ pub fn sequencer_stake_config_account_id() -> AccountId {
#[must_use]
pub fn sequencer_stake_config_account() -> Account {
Account {
program_owner: programs::sequencer_stake().id(),
program_owner: programs::sequencer_stake().id().into(),
data: sequencer_stake_core::SequencerStakeConfig {
minimum_sequencer_stake: DEFAULT_MINIMUM_SEQUENCER_STAKE,
entries: BTreeMap::new(),
@@ -97,7 +97,7 @@ pub fn sequencer_stake_config_account() -> Account {
#[must_use]
pub fn clock_account() -> Account {
Account {
program_owner: programs::clock().id(),
program_owner: programs::clock().id().into(),
data: ClockAccountData {
block_id: 0,
timestamp: 0,
+3 -4
View File
@@ -4,6 +4,7 @@ use key_protocol::key_management::{
KeyChain, key_tree::chain_index::ChainIndex, secret_holders::SecretSpendingKey,
};
use lee::{Account, AccountId, Data, PrivateKey, PublicKey, V03State, program::Program};
use lee_core::program::DEFAULT_PROGRAM_OWNER;
use serde::{Deserialize, Serialize};
const PRIVATE_KEY_PUB_ACC_A: [u8; 32] = [
@@ -26,8 +27,6 @@ const SSK_PRIV_ACC_B: [u8; 32] = [
180, 43, 120, 55, 151, 50, 21, 113, 22, 254, 83, 148, 56,
];
const DEFAULT_PROGRAM_OWNER: [u32; 8] = [0, 0, 0, 0, 0, 0, 0, 0];
const PUB_ACC_A_INITIAL_BALANCE: u128 = 10000;
const PUB_ACC_B_INITIAL_BALANCE: u128 = 20000;
@@ -155,7 +154,7 @@ fn initial_private_accounts() -> Vec<(lee_core::Commitment, lee_core::Nullifier)
let mut acc = init_comm_data.account.clone();
acc.program_owner = programs::authenticated_transfer().id();
acc.program_owner = programs::authenticated_transfer().id().into();
(
lee_core::Commitment::new(&account_id, &acc),
@@ -191,7 +190,7 @@ fn initial_public_accounts() -> HashMap<AccountId, Account> {
(
acc_data.account_id,
Account {
program_owner: programs::authenticated_transfer().id(),
program_owner: programs::authenticated_transfer().id().into(),
balance: acc_data.balance,
..Default::default()
},
+4 -7
View File
@@ -83,7 +83,7 @@ pub struct FfiU128 {
/// byte arrays since C doesn't have native u128 support.
#[repr(C)]
pub struct FfiAccount {
pub program_owner: FfiProgramId,
pub program_owner: FfiBytes32,
/// Balance as little-endian [u8; 16].
pub balance: FfiU128,
/// Pointer to account data bytes.
@@ -97,7 +97,7 @@ pub struct FfiAccount {
impl Default for FfiAccount {
fn default() -> Self {
Self {
program_owner: FfiProgramId::default(),
program_owner: FfiBytes32::default(),
balance: FfiU128::default(),
data: std::ptr::null(),
data_len: 0,
@@ -331,11 +331,8 @@ impl From<lee::Account> for FfiAccount {
ptr::null()
};
let program_owner = FfiProgramId {
data: value.program_owner,
};
Self {
program_owner,
program_owner: value.program_owner.into(),
balance: value.balance.into(),
data,
data_len,
@@ -358,7 +355,7 @@ impl TryFrom<&FfiAccount> for lee::Account {
Data::default()
};
Ok(Self {
program_owner: value.program_owner.data,
program_owner: value.program_owner.into(),
balance: value.balance.into(),
data,
nonce: lee_core::account::Nonce(value.nonce.into()),
+8 -8
View File
@@ -179,13 +179,6 @@ typedef struct FfiAccountList {
uintptr_t count;
} FfiAccountList;
/**
* Program ID - 8 u32 values (32 bytes total).
*/
typedef struct FfiProgramId {
uint32_t data[8];
} FfiProgramId;
/**
* U128 - 16 bytes little endian.
*/
@@ -200,7 +193,7 @@ typedef struct FfiU128 {
* byte arrays since C doesn't have native u128 support.
*/
typedef struct FfiAccount {
struct FfiProgramId program_owner;
struct FfiBytes32 program_owner;
/**
* Balance as little-endian [u8; 16].
*/
@@ -257,6 +250,13 @@ typedef struct FfiAccountIdentity {
struct FfiU128 identifier;
} FfiAccountIdentity;
/**
* Program ID - 8 u32 values (32 bytes total).
*/
typedef struct FfiProgramId {
uint32_t data[8];
} FfiProgramId;
/**
* Result of a generic transaction operation.
*/
-1
View File
@@ -38,7 +38,6 @@ humantime-serde.workspace = true
humantime.workspace = true
tokio = { workspace = true, features = ["macros"] }
clap.workspace = true
base58.workspace = true
hex.workspace = true
rand.workspace = true
itertools.workspace = true
+3 -23
View File
@@ -1,6 +1,5 @@
use std::str::FromStr;
use base58::{FromBase58 as _, ToBase58 as _};
use derive_more::Display;
use lee::AccountId;
use serde::{Deserialize, Serialize};
@@ -103,12 +102,7 @@ impl std::fmt::Display for HumanReadableAccount {
impl From<lee::Account> for HumanReadableAccount {
fn from(account: lee::Account) -> Self {
let program_owner = account
.program_owner
.iter()
.flat_map(|n| n.to_le_bytes())
.collect::<Vec<u8>>()
.to_base58();
let program_owner = account.program_owner.to_string();
let data = hex::encode(account.data);
Self {
balance: account.balance,
@@ -121,24 +115,10 @@ impl From<lee::Account> for HumanReadableAccount {
impl From<HumanReadableAccount> for lee::Account {
fn from(account: HumanReadableAccount) -> Self {
let mut program_owner_bytes = [0_u8; 32];
let decoded_program_owner = account
let program_owner: lee::AccountId = account
.program_owner
.from_base58()
.parse()
.expect("Invalid base58 in HumanReadableAccount.program_owner");
assert!(
decoded_program_owner.len() == 32,
"HumanReadableAccount.program_owner must decode to exactly 32 bytes"
);
program_owner_bytes.copy_from_slice(&decoded_program_owner);
let mut program_owner = [0_u32; 8];
for (index, chunk) in program_owner_bytes.chunks_exact(4).enumerate() {
let chunk: [u8; 4] = chunk
.try_into()
.expect("chunk length is guaranteed to be 4");
program_owner[index] = u32::from_le_bytes(chunk);
}
let data = hex::decode(&account.data).expect("Invalid hex in HumanReadableAccount.data");
let data = data
+3 -3
View File
@@ -2,7 +2,7 @@ use anyhow::{Context as _, Result};
use clap::Subcommand;
use itertools::Itertools as _;
use key_protocol::key_management::{KeyChain, key_tree::chain_index::ChainIndex};
use lee::{Account, PublicKey};
use lee::{Account, AccountId, PublicKey};
use lee_core::Identifier;
use token_core::{TokenDefinition, TokenHolding};
@@ -643,8 +643,8 @@ impl WalletSubcommand for ImportSubcommand {
/// Formats account details for display, returning (description, `json_view`).
fn format_account_details(account: &Account) -> (String, String) {
let auth_tr_prog_id = programs::authenticated_transfer().id();
let token_prog_id = programs::token().id();
let auth_tr_prog_id: AccountId = programs::authenticated_transfer().id().into();
let token_prog_id: AccountId = programs::token().id().into();
match &account.program_owner {
o if *o == auth_tr_prog_id => {
Binary file not shown.
+4 -4
View File
@@ -314,7 +314,7 @@ fn token_holding(
) -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0,
data: Data::from(&TokenHolding::Fungible {
definition_id,
@@ -334,7 +334,7 @@ fn token_definition(
) -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: programs::token().id(),
program_owner: programs::token().id().into(),
balance: 0,
data: Data::from(&TokenDefinition::Fungible {
name: String::from("test"),
@@ -372,7 +372,7 @@ fn token_burn_pre_states() -> Vec<AccountWithMetadata> {
fn clock_account(account_id: AccountId, block_id: u64) -> AccountWithMetadata {
AccountWithMetadata {
account: Account {
program_owner: programs::clock().id(),
program_owner: programs::clock().id().into(),
balance: 0,
data: ClockAccountData {
block_id,
@@ -426,7 +426,7 @@ fn amm_pool_account() -> AccountWithMetadata {
let lp_supply = (reserve_a * reserve_b).isqrt();
AccountWithMetadata {
account: Account {
program_owner: programs::amm().id(),
program_owner: programs::amm().id().into(),
balance: 0,
data: Data::from(&PoolDefinition {
definition_token_a_id: amm_token_a_def_id(),
+3 -3
View File
@@ -51,7 +51,7 @@ pub fn prove_auth_transfer_in_ppe() -> anyhow::Result<(PrivacyPreservingCircuitO
// Recipient stays default-owned so the first call can claim it.
let sender = AccountWithMetadata {
account: Account {
program_owner: auth_transfer_id,
program_owner: auth_transfer_id.into(),
balance: 1_000_000,
..Account::default()
},
@@ -117,7 +117,7 @@ fn prove_chain_caller(
// would cause a state mismatch on subsequent chained calls.
let recipient_pre = AccountWithMetadata {
account: Account {
program_owner: auth_transfer_id,
program_owner: auth_transfer_id.into(),
..Account::default()
},
is_authorized: true,
@@ -125,7 +125,7 @@ fn prove_chain_caller(
};
let sender_pre = AccountWithMetadata {
account: Account {
program_owner: auth_transfer_id,
program_owner: auth_transfer_id.into(),
balance: 1_000_000,
..Account::default()
},