Skip to content

Commit

Permalink
[move] commit-reveal of PoF bids (#337)
Browse files Browse the repository at this point in the history
Co-authored-by: Peregrine di Piano <[email protected]>
Co-authored-by: Reginald Mezzo <[email protected]>
Co-authored-by: Cholmondeley Von Rubato <[email protected]>
Co-authored-by: Reginald Fortissimo <[email protected]>
Co-authored-by: Sandra Leveret <[email protected]>
Co-authored-by: Gianna di Diminuendo <[email protected]>
Co-authored-by: Rosina Fitz Leveret <[email protected]>
Co-authored-by: Montague De Beaver <[email protected]>
Co-authored-by: Crispin Presto <[email protected]>
Co-authored-by: Basil De Presto <[email protected]>
Co-authored-by: Algernon di Leveret <[email protected]>
Co-authored-by: Vale Pianissimo <[email protected]>
Co-authored-by: Mariella Hart <[email protected]>
Co-authored-by: Crispin di Sforzando <[email protected]>
  • Loading branch information
15 people authored Mar 7, 2025
1 parent 97ccbc7 commit 41f4fb5
Show file tree
Hide file tree
Showing 40 changed files with 1,411 additions and 711 deletions.
32 changes: 16 additions & 16 deletions Cargo.lock

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

95 changes: 91 additions & 4 deletions framework/cached-packages/src/libra_framework_sdk_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#![allow(dead_code)]
#![allow(unused_imports)]
#![allow(clippy::too_many_arguments)]

use diem_types::{
account_address::AccountAddress,
transaction::{EntryFunction, TransactionPayload},
Expand Down Expand Up @@ -95,7 +94,8 @@ pub enum EntryFunctionCall {

/// Generic authentication key rotation function that allows the user to rotate their authentication key from any scheme to any scheme.
/// To authorize the rotation, we need two signatures:
/// - the first signature `cap_rotate_key` refers to the signature by the account owner's current key on a valid `RotationProofChallenge`,demonstrating that the user intends to and has the capability to rotate the authentication key of this account;
/// - the first signature `cap_rotate_key` refers to the signature by the account owner's current key on a valid `RotationProofChallenge`,
/// demonstrating that the user intends to and has the capability to rotate the authentication key of this account;
/// - the second signature `cap_update_table` refers to the signature by the new key (that the account owner wants to rotate to) on a
/// valid `RotationProofChallenge`, demonstrating that the user owns the new private key, and has the authority to update the
/// `OriginatingAddress` map with the new address mapping `<new_address, originating_address>`.
Expand Down Expand Up @@ -491,6 +491,18 @@ pub enum EntryFunctionCall {
authorities: Vec<AccountAddress>,
},

/// Transaction entry function for committing bid
SecretBidCommit {
digest: Vec<u8>,
},

/// Transaction entry function for revealing bid
SecretBidReveal {
pk: Vec<u8>,
entry_fee: u64,
signed_msg: Vec<u8>,
},

SlowWalletSmokeTestVmUnlock {
user_addr: AccountAddress,
unlocked: u64,
Expand Down Expand Up @@ -824,6 +836,12 @@ impl EntryFunctionCall {
epoch_expiry,
} => proof_of_fee_pof_update_bid_net_reward(net_reward, epoch_expiry),
SafeInitPaymentMultisig { authorities } => safe_init_payment_multisig(authorities),
SecretBidCommit { digest } => secret_bid_commit(digest),
SecretBidReveal {
pk,
entry_fee,
signed_msg,
} => secret_bid_reveal(pk, entry_fee, signed_msg),
SlowWalletSmokeTestVmUnlock {
user_addr,
unlocked,
Expand Down Expand Up @@ -1048,11 +1066,14 @@ pub fn account_revoke_signer_capability(
/// `OriginatingAddress` map with the new address mapping `<new_address, originating_address>`.
/// To verify these two signatures, we need their corresponding public key and public key scheme: we use `from_scheme` and `from_public_key_bytes`
/// to verify `cap_rotate_key`, and `to_scheme` and `to_public_key_bytes` to verify `cap_update_table`.
/// A scheme of 0 refers to an Ed25519 key and a scheme of 1 refers to Multi-Ed25519 keys. `originating address` refers to an account's original/first address.
/// A scheme of 0 refers to an Ed25519 key and a scheme of 1 refers to Multi-Ed25519 keys.
/// `originating address` refers to an account's original/first address.
///
/// Here is an example attack if we don't ask for the second signature `cap_update_table`:
/// Alice has rotated her account `addr_a` to `new_addr_a`. As a result, the following entry is created, to help Alice when recovering her wallet:
/// `OriginatingAddress[new_addr_a]` -> `addr_a`
/// Alice has had bad day: her laptop blew up and she needs to reset her account on a new one. (Fortunately, she still has her secret key `new_sk_a` associated with her new address `new_addr_a`, so she can do this.)
/// Alice has had bad day: her laptop blew up and she needs to reset her account on a new one.
/// (Fortunately, she still has her secret key `new_sk_a` associated with her new address `new_addr_a`, so she can do this.)
///
/// But Bob likes to mess with Alice.
/// Bob creates an account `addr_b` and maliciously rotates it to Alice's new address `new_addr_a`. Since we are no longer checking a PoK,
Expand Down Expand Up @@ -2216,6 +2237,42 @@ pub fn safe_init_payment_multisig(authorities: Vec<AccountAddress>) -> Transacti
))
}

/// Transaction entry function for committing bid
pub fn secret_bid_commit(digest: Vec<u8>) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1,
]),
ident_str!("secret_bid").to_owned(),
),
ident_str!("commit").to_owned(),
vec![],
vec![bcs::to_bytes(&digest).unwrap()],
))
}

/// Transaction entry function for revealing bid
pub fn secret_bid_reveal(pk: Vec<u8>, entry_fee: u64, signed_msg: Vec<u8>) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 1,
]),
ident_str!("secret_bid").to_owned(),
),
ident_str!("reveal").to_owned(),
vec![],
vec![
bcs::to_bytes(&pk).unwrap(),
bcs::to_bytes(&entry_fee).unwrap(),
bcs::to_bytes(&signed_msg).unwrap(),
],
))
}

pub fn slow_wallet_smoke_test_vm_unlock(
user_addr: AccountAddress,
unlocked: u64,
Expand Down Expand Up @@ -3189,6 +3246,28 @@ mod decoder {
}
}

pub fn secret_bid_commit(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::SecretBidCommit {
digest: bcs::from_bytes(script.args().first()?).ok()?,
})
} else {
None
}
}

pub fn secret_bid_reveal(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::SecretBidReveal {
pk: bcs::from_bytes(script.args().first()?).ok()?,
entry_fee: bcs::from_bytes(script.args().get(1)?).ok()?,
signed_msg: bcs::from_bytes(script.args().get(2)?).ok()?,
})
} else {
None
}
}

pub fn slow_wallet_smoke_test_vm_unlock(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
Expand Down Expand Up @@ -3566,6 +3645,14 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
"safe_init_payment_multisig".to_string(),
Box::new(decoder::safe_init_payment_multisig),
);
map.insert(
"secret_bid_commit".to_string(),
Box::new(decoder::secret_bid_commit),
);
map.insert(
"secret_bid_reveal".to_string(),
Box::new(decoder::secret_bid_reveal),
);
map.insert(
"slow_wallet_smoke_test_vm_unlock".to_string(),
Box::new(decoder::slow_wallet_smoke_test_vm_unlock),
Expand Down
37 changes: 4 additions & 33 deletions framework/drop-user-tools/last_goodbye.move
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,15 @@ module ol_framework::last_goodbye {
return
};

// print(&2000);

// dangling state in receipts could allow user to participate in community
// wallets
// print(&2002);

receipts::hard_fork_sanitize(vm, user);
// print(&2003);

jail::garbage_collection(user);
// print(&2004);

vouch::hard_fork_sanitize(vm, user);
// print(&2005);

let locked = slow_wallet::hard_fork_sanitize(vm, user);
if (locked > 0) {
print(&user_addr);
print(&locked);
};

let _locked = slow_wallet::hard_fork_sanitize(vm, user);


// remove a pledge account if there is one, so that coins there are
// not dangling
Expand All @@ -138,20 +127,11 @@ module ol_framework::last_goodbye {
let good_capital = option::extract(&mut all_coins_opt);
burn::burn_and_track(good_capital);
};
// print(&2001);

option::destroy_none(all_coins_opt);


// if (coin_val > 0) {
// print(&user_addr);
// print(&coin_val);
// };


let auth_key = b"Oh, is it too late now to say sorry?";
vector::trim(&mut auth_key, 32);
// print(&2008);

// Oh, is it too late now to say sorry?
// Yeah, I know that I let you down
Expand All @@ -161,22 +141,17 @@ module ol_framework::last_goodbye {
// another function can be called to drop the account::Account completely
// and then the offline db tools can safely remove the key from db.
account::rotate_authentication_key_internal(user, auth_key);
// print(&2009);

}

fun last_goodbye(vm: &signer, user: &signer) {
// print(&10000);
let addr = signer::address_of(user);
if (!account::exists_at(addr)) {
// print(&addr);
return
};

let auth_orig = account::get_authentication_key(addr);
// print(&10001);
dont_think_twice_its_alright(vm, user);
// print(&10002);

let new_auth = account::get_authentication_key(addr);
// if the account is a validator they stay on ark a
Expand All @@ -189,12 +164,8 @@ module ol_framework::last_goodbye {
// Just hear this and then I'll go
// You gave me more to live for
// More than you'll ever know
// print(&10003);
account::hard_fork_drop(vm, user);
// print(&10004);


// print(&@0xDEAD);
account::hard_fork_drop(vm, user);
}

#[test_only]
Expand Down
Loading

0 comments on commit 41f4fb5

Please sign in to comment.