Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ members = [
"lez/programs/ping_sender",
"lez/programs/ping_receiver",
"lez/programs/sequencer_stake",
"lez/programs/signature",
"lez/programs/signature/core",
"lez/cross_zone",
"lez/core_ffi",

Expand Down Expand Up @@ -145,6 +147,7 @@ bridge_lock_core = { path = "lez/programs/bridge_lock/core" }
wrapped_token_core = { path = "lez/programs/wrapped_token/core" }
ping_core = { path = "lez/programs/ping_core" }
sequencer_stake_core = { path = "lez/programs/sequencer_stake/core" }
signature_core = { path = "lez/programs/signature/core" }
cross_zone = { path = "lez/cross_zone" }
build_utils = { path = "build_utils" }
test_guest_core = { path = "test_guest_core" }
Expand Down
Binary file not shown.
Binary file modified artifacts/lez/programs/bridge.bin
Binary file not shown.
Binary file modified artifacts/lez/programs/bridge_lock.bin
Binary file not shown.
Binary file modified artifacts/lez/programs/clock.bin
Binary file not shown.
Binary file modified artifacts/lez/programs/cross_zone_inbox.bin
Binary file not shown.
Binary file modified artifacts/lez/programs/cross_zone_outbox.bin
Binary file not shown.
Binary file modified artifacts/lez/programs/fee.bin
Binary file not shown.
Binary file modified artifacts/lez/programs/ping_receiver.bin
Binary file not shown.
Binary file modified artifacts/lez/programs/ping_sender.bin
Binary file not shown.
Binary file modified artifacts/lez/programs/sequencer_stake.bin
Binary file not shown.
Binary file added artifacts/lez/programs/signature.bin
Binary file not shown.
Binary file modified artifacts/lez/programs/system_upgrader.bin
Binary file not shown.
Binary file modified artifacts/lez/programs/wrapped_token.bin
Binary file not shown.
22 changes: 10 additions & 12 deletions integration_tests/tests/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
use anyhow::{Context as _, Result};
use integration_tests::{
TestContext,
config::INITIAL_PUBLIC_BALANCES_FOR_WALLET,
config::{default_public_accounts_for_wallet, private_funder_account_id},
private_mention,
utils::{get_account, new_account},
};
use key_protocol::key_management::KeyChain;
use lee::{Account, test_utils::TestSigner};
use lee_core::{account::Nonce, signing_key::SIGNATURE_PROGRAM_ID};
use lee_core::{account::Nonce, signing_key::signature_program_id};
use tokio::test;
use wallet::{
account::{AccountIdWithPrivacy, HumanReadableAccount, Label},
Expand All @@ -27,23 +27,21 @@ use wallet::{
async fn get_existing_account() -> Result<()> {
let ctx = TestContext::new().await?;

let account_id = ctx.existing_public_accounts()[0];
let account_id = private_funder_account_id();
let account = get_account(&ctx, account_id).await?;
let signer = TestSigner::from(
ctx.wallet()
.storage()
.key_chain()
.pub_account_secret(account_id)
.context("the wallet holds the account")?,
);
let (secret, balance) = default_public_accounts_for_wallet()
.into_iter()
.find(|(secret, _)| lee::signature::public_account_id(secret) == account_id)
.context("the funder is a default public account")?;
let signer = TestSigner::from(&secret);

// It gets used as a funder for private accounts on genesis twice, so it signed twice.
assert_eq!(account.nonce.0, 2);
// Genesis credits the account, and its key rotated with each signature.
assert_eq!(
account.data,
Account::funded(INITIAL_PUBLIC_BALANCES_FOR_WALLET[0])
.with_actor_state(SIGNATURE_PROGRAM_ID, signer.key_state(Nonce(2)).into())
Account::funded(balance)
.with_actor_state(signature_program_id(), signer.key_state(Nonce(2)).into())
.data
);

Expand Down
4 changes: 2 additions & 2 deletions integration_tests/tests/cross_zone_state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use lee::{
};
use lee_core::{
account::Account, native_token::TransferError, program::SyncMessage,
signing_key::SIGNATURE_PROGRAM_ID,
signing_key::signature_program_id,
};
use ping_core::{
CrossZoneEmission, ReceiverMessage, outbox_bytes, ping_record_pda, ping_record_seed,
Expand Down Expand Up @@ -3216,5 +3216,5 @@ fn holds_only_its_key(state: &V03State, account: AccountId) -> bool {
.data
.actor_states
.keys()
.all(|program| *program == SIGNATURE_PROGRAM_ID)
.all(|program| *program == signature_program_id())
}
4 changes: 2 additions & 2 deletions integration_tests/tests/key_rotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use lee::{AccountId, program::Program, test_utils::TestSigner};
use lee_core::{
account::{ActorState, Nonce},
native_token::Message,
signing_key::SIGNATURE_PROGRAM_ID,
signing_key::signature_program_id,
};
use sequencer_service_rpc::RpcClient as _;
use tokio::test;
Expand Down Expand Up @@ -64,7 +64,7 @@ async fn stored_key(ctx: &TestContext, account_id: AccountId) -> Result<(Nonce,
let account = get_account(ctx, account_id).await?;
Ok((
account.nonce,
account.data.actor_state(SIGNATURE_PROGRAM_ID).clone(),
account.data.actor_state(signature_program_id()).clone(),
))
}

Expand Down
151 changes: 151 additions & 0 deletions integration_tests/tests/manual_rotation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
#![expect(
clippy::tests_outside_test_module,
reason = "We don't care about these in tests"
)]

//! Manual key rotation through the wallet, against a running sequencer.

use anyhow::{Context as _, Result};
use integration_tests::{
TestContext, private_mention, public_mention,
utils::{get_account, new_account, send, wait_for_inclusion},
};
use lee::{AccountId, signature::PublicAccountSecret};
use lee_core::{
account::{ActorState, Nonce},
signing_key::{KeyType, signature_program_id},
};
use tokio::test;
use wallet::cli::{Command, SubcommandReturnValue, account::AccountSubcommand, execute_subcommand};

/// Rotates `accounts`, paid by `fee_payer`, and waits for inclusion.
async fn rotate_key(
ctx: &mut TestContext,
accounts: &[AccountId],
fee_payer: AccountId,
) -> Result<()> {
let command = Command::Account(AccountSubcommand::RotateKey {
accounts: accounts.iter().copied().map(public_mention).collect(),
fee_payer: private_mention(fee_payer),
});
let SubcommandReturnValue::TransactionExecuted { tx_hash } =
execute_subcommand(ctx.wallet_mut(), command).await?
else {
anyhow::bail!("rotate-key returns its transaction hash");
};
wait_for_inclusion(ctx, tx_hash).await
}

fn secret(ctx: &TestContext, account: AccountId) -> Result<PublicAccountSecret> {
ctx.wallet()
.storage()
.key_chain()
.pub_account_secret(account)
.cloned()
.context("the wallet holds the account")
}

/// The account's nonce and the key the chain stores for it.
async fn stored_key(ctx: &TestContext, account: AccountId) -> Result<(Nonce, ActorState)> {
let account = get_account(ctx, account).await?;
Ok((
account.nonce,
account.data.actor_state(signature_program_id()).clone(),
))
}

/// The key the account gets from its `counter`-th manual rotation at `nonce`.
fn rotated(secret: &PublicAccountSecret, nonce: Nonce, counter: u32) -> ActorState {
lee::signature::key_state_with_counter(secret, KeyType::Schnorr, nonce, counter).into()
}

#[test]
async fn a_manually_rotated_account_signs_again_at_the_same_nonce() -> Result<()> {
let mut ctx = TestContext::new().await?;
let account = ctx.existing_public_accounts()[0];
let receiver = ctx.existing_public_accounts()[1];
let fee_payer = ctx.existing_private_accounts()[0];
let secret = secret(&ctx, account)?;
let (nonce, _) = stored_key(&ctx, account).await?;

rotate_key(&mut ctx, &[account], fee_payer).await?;
assert_eq!(
stored_key(&ctx, account).await?,
(nonce, rotated(&secret, nonce, 1)),
"the key is replaced and the nonce is unchanged"
);
let tx_hash = send(
&mut ctx,
public_mention(account),
public_mention(receiver),
1,
)
.await?;
wait_for_inclusion(&ctx, tx_hash).await?;
let (after, _) = stored_key(&ctx, account).await?;
assert_eq!(after.0, nonce.0 + 1, "the rotated key signed");
Ok(())
}

#[test]
async fn a_second_manual_rotation_at_a_nonce_takes_the_next_counter() -> Result<()> {
let mut ctx = TestContext::new().await?;
let account = ctx.existing_public_accounts()[0];
let fee_payer = ctx.existing_private_accounts()[0];
let secret = secret(&ctx, account)?;
let (nonce, _) = stored_key(&ctx, account).await?;

for counter in 1..=2 {
rotate_key(&mut ctx, &[account], fee_payer).await?;
assert_eq!(
stored_key(&ctx, account).await?,
(nonce, rotated(&secret, nonce, counter))
);
}
Ok(())
}

#[test]
async fn a_batch_rotates_two_accounts_manually() -> Result<()> {
let mut ctx = TestContext::new().await?;
let accounts = [
ctx.existing_public_accounts()[0],
ctx.existing_public_accounts()[1],
];
let fee_payer = ctx.existing_private_accounts()[0];
let before = [
stored_key(&ctx, accounts[0]).await?.0,
stored_key(&ctx, accounts[1]).await?.0,
];

rotate_key(&mut ctx, &accounts, fee_payer).await?;

for (account, nonce) in accounts.into_iter().zip(before) {
let secret = secret(&ctx, account)?;
assert_eq!(
stored_key(&ctx, account).await?,
(nonce, rotated(&secret, nonce, 1))
);
}
Ok(())
}

#[test]
async fn a_fresh_account_is_rotated_manually_at_nonce_zero() -> Result<()> {
let mut ctx = TestContext::new().await?;
let account = new_account(&mut ctx, false, None).await?;
let fee_payer = ctx.existing_private_accounts()[0];
let secret = secret(&ctx, account)?;

rotate_key(&mut ctx, &[account], fee_payer).await?;

assert_eq!(
stored_key(&ctx, account).await?,
(Nonce(0), rotated(&secret, Nonce(0), 1))
);
assert_eq!(
ctx.wallet().current_signing_key(account, &secret).await?,
(KeyType::Schnorr, 1)
);
Ok(())
}
4 changes: 2 additions & 2 deletions integration_tests/tests/wallet_ffi_getters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use lee_core::{
account::Nonce,
native_token::NATIVE_TOKEN_PROGRAM_ID,
program::PROGRAM_LOADER_ACCOUNT_ID,
signing_key::{SIGNATURE_PROGRAM_ID, SigningKeyState},
signing_key::{SigningKeyState, signature_program_id},
};

#[test]
Expand Down Expand Up @@ -121,7 +121,7 @@ fn test_wallet_ffi_get_account_public() -> Result<()> {
assert_eq!(
account.data,
Account::funded(INITIAL_PUBLIC_BALANCES_FOR_WALLET[0])
.with_actor_state(SIGNATURE_PROGRAM_ID, signer.key_state(Nonce(2)).into())
.with_actor_state(signature_program_id(), signer.key_state(Nonce(2)).into())
.data
);
assert_eq!(account.nonce.0, 2);
Expand Down
4 changes: 2 additions & 2 deletions lee/key_protocol/src/key_management/key_tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,8 @@ mod tests {

assert!(tree.key_map.contains_key(&ChainIndex::root()));
assert!(tree.account_id_map.contains_key(&AccountId::new([
110, 125, 111, 198, 184, 104, 121, 139, 210, 17, 104, 106, 188, 89, 89, 91, 14, 148,
135, 35, 69, 250, 36, 200, 169, 24, 22, 55, 243, 101, 66, 223
193, 39, 108, 113, 200, 143, 119, 133, 79, 138, 244, 5, 134, 56, 22, 128, 163, 104, 52,
216, 18, 51, 247, 93, 242, 165, 148, 103, 222, 161, 229, 151
])));
}

Expand Down
9 changes: 3 additions & 6 deletions lee/privacy_preserving_circuit/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use lee_core::{
execution_state::{PrivatePart, TransactionEntry},
native_token::NATIVE_TOKEN_PROGRAM_ID,
program::{PROGRAM_LOADER_ACCOUNT_ID, ProgramId, read_input_frame},
signing_key::SIGNATURE_PROGRAM_ID,
};
use private_backend::PrivateBackend;
use risc0_zkvm::guest::env;
Expand Down Expand Up @@ -39,14 +38,12 @@ fn main() {

// The sequencer checks disclosed images against chain state.
// For undisclosed images, `to_claim` checks header immutability and derives the membership
// root. The native token, loader and signature program accounts belong to the protocol and
// cannot claim guest images.
// root. The native token and loader accounts belong to the protocol and cannot claim guest
// images.
assert!(
!program_image_witnesses.iter().any(|witness| {
let account_id = witness.account_id();
account_id == NATIVE_TOKEN_PROGRAM_ID
|| account_id == PROGRAM_LOADER_ACCOUNT_ID
|| account_id == SIGNATURE_PROGRAM_ID
account_id == NATIVE_TOKEN_PROGRAM_ID || account_id == PROGRAM_LOADER_ACCOUNT_ID
}),
"A reserved program account has no deployable bytecode to claim"
);
Expand Down
5 changes: 0 additions & 5 deletions lee/program_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use lee_core::{
account::{AccountId, ActorState},
native_token::NATIVE_TOKEN_PROGRAM_ID,
program::{PROGRAM_LOADER_ACCOUNT_ID, ProgramId, ReceiveInput, Response, Transition},
signing_key::SIGNATURE_PROGRAM_ID,
};

/// Hard cap on a deployed program's segment chain length, bounding a resolution walk.
Expand Down Expand Up @@ -294,10 +293,6 @@ fn reject_reserved_target(account_id: AccountId) {
account_id, PROGRAM_LOADER_ACCOUNT_ID,
"the loader's own dispatch address is not a deployable target"
);
assert_ne!(
account_id, SIGNATURE_PROGRAM_ID,
"the signature program has no deployable bytecode"
);
}

fn header_write<'state>(
Expand Down
Loading
Loading