Skip to content

Commit 41f4fb5

Browse files
0o-de-lallyPeregrine di PianoReginald MezzoCholmondeley Von RubatoReginald Fortissimo
authored
[move] commit-reveal of PoF bids (#337)
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]>
1 parent 97ccbc7 commit 41f4fb5

40 files changed

+1411
-711
lines changed

Cargo.lock

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

framework/cached-packages/src/libra_framework_sdk_builder.rs

Lines changed: 91 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#![allow(dead_code)]
1414
#![allow(unused_imports)]
1515
#![allow(clippy::too_many_arguments)]
16-
1716
use diem_types::{
1817
account_address::AccountAddress,
1918
transaction::{EntryFunction, TransactionPayload},
@@ -95,7 +94,8 @@ pub enum EntryFunctionCall {
9594

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

494+
/// Transaction entry function for committing bid
495+
SecretBidCommit {
496+
digest: Vec<u8>,
497+
},
498+
499+
/// Transaction entry function for revealing bid
500+
SecretBidReveal {
501+
pk: Vec<u8>,
502+
entry_fee: u64,
503+
signed_msg: Vec<u8>,
504+
},
505+
494506
SlowWalletSmokeTestVmUnlock {
495507
user_addr: AccountAddress,
496508
unlocked: u64,
@@ -824,6 +836,12 @@ impl EntryFunctionCall {
824836
epoch_expiry,
825837
} => proof_of_fee_pof_update_bid_net_reward(net_reward, epoch_expiry),
826838
SafeInitPaymentMultisig { authorities } => safe_init_payment_multisig(authorities),
839+
SecretBidCommit { digest } => secret_bid_commit(digest),
840+
SecretBidReveal {
841+
pk,
842+
entry_fee,
843+
signed_msg,
844+
} => secret_bid_reveal(pk, entry_fee, signed_msg),
827845
SlowWalletSmokeTestVmUnlock {
828846
user_addr,
829847
unlocked,
@@ -1048,11 +1066,14 @@ pub fn account_revoke_signer_capability(
10481066
/// `OriginatingAddress` map with the new address mapping `<new_address, originating_address>`.
10491067
/// To verify these two signatures, we need their corresponding public key and public key scheme: we use `from_scheme` and `from_public_key_bytes`
10501068
/// to verify `cap_rotate_key`, and `to_scheme` and `to_public_key_bytes` to verify `cap_update_table`.
1051-
/// 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.
1069+
/// A scheme of 0 refers to an Ed25519 key and a scheme of 1 refers to Multi-Ed25519 keys.
1070+
/// `originating address` refers to an account's original/first address.
1071+
///
10521072
/// Here is an example attack if we don't ask for the second signature `cap_update_table`:
10531073
/// 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:
10541074
/// `OriginatingAddress[new_addr_a]` -> `addr_a`
1055-
/// 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.)
1075+
/// Alice has had bad day: her laptop blew up and she needs to reset her account on a new one.
1076+
/// (Fortunately, she still has her secret key `new_sk_a` associated with her new address `new_addr_a`, so she can do this.)
10561077
///
10571078
/// But Bob likes to mess with Alice.
10581079
/// 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,
@@ -2216,6 +2237,42 @@ pub fn safe_init_payment_multisig(authorities: Vec<AccountAddress>) -> Transacti
22162237
))
22172238
}
22182239

2240+
/// Transaction entry function for committing bid
2241+
pub fn secret_bid_commit(digest: Vec<u8>) -> TransactionPayload {
2242+
TransactionPayload::EntryFunction(EntryFunction::new(
2243+
ModuleId::new(
2244+
AccountAddress::new([
2245+
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,
2246+
0, 0, 0, 1,
2247+
]),
2248+
ident_str!("secret_bid").to_owned(),
2249+
),
2250+
ident_str!("commit").to_owned(),
2251+
vec![],
2252+
vec![bcs::to_bytes(&digest).unwrap()],
2253+
))
2254+
}
2255+
2256+
/// Transaction entry function for revealing bid
2257+
pub fn secret_bid_reveal(pk: Vec<u8>, entry_fee: u64, signed_msg: Vec<u8>) -> TransactionPayload {
2258+
TransactionPayload::EntryFunction(EntryFunction::new(
2259+
ModuleId::new(
2260+
AccountAddress::new([
2261+
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,
2262+
0, 0, 0, 1,
2263+
]),
2264+
ident_str!("secret_bid").to_owned(),
2265+
),
2266+
ident_str!("reveal").to_owned(),
2267+
vec![],
2268+
vec![
2269+
bcs::to_bytes(&pk).unwrap(),
2270+
bcs::to_bytes(&entry_fee).unwrap(),
2271+
bcs::to_bytes(&signed_msg).unwrap(),
2272+
],
2273+
))
2274+
}
2275+
22192276
pub fn slow_wallet_smoke_test_vm_unlock(
22202277
user_addr: AccountAddress,
22212278
unlocked: u64,
@@ -3189,6 +3246,28 @@ mod decoder {
31893246
}
31903247
}
31913248

3249+
pub fn secret_bid_commit(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
3250+
if let TransactionPayload::EntryFunction(script) = payload {
3251+
Some(EntryFunctionCall::SecretBidCommit {
3252+
digest: bcs::from_bytes(script.args().first()?).ok()?,
3253+
})
3254+
} else {
3255+
None
3256+
}
3257+
}
3258+
3259+
pub fn secret_bid_reveal(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
3260+
if let TransactionPayload::EntryFunction(script) = payload {
3261+
Some(EntryFunctionCall::SecretBidReveal {
3262+
pk: bcs::from_bytes(script.args().first()?).ok()?,
3263+
entry_fee: bcs::from_bytes(script.args().get(1)?).ok()?,
3264+
signed_msg: bcs::from_bytes(script.args().get(2)?).ok()?,
3265+
})
3266+
} else {
3267+
None
3268+
}
3269+
}
3270+
31923271
pub fn slow_wallet_smoke_test_vm_unlock(
31933272
payload: &TransactionPayload,
31943273
) -> Option<EntryFunctionCall> {
@@ -3566,6 +3645,14 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
35663645
"safe_init_payment_multisig".to_string(),
35673646
Box::new(decoder::safe_init_payment_multisig),
35683647
);
3648+
map.insert(
3649+
"secret_bid_commit".to_string(),
3650+
Box::new(decoder::secret_bid_commit),
3651+
);
3652+
map.insert(
3653+
"secret_bid_reveal".to_string(),
3654+
Box::new(decoder::secret_bid_reveal),
3655+
);
35693656
map.insert(
35703657
"slow_wallet_smoke_test_vm_unlock".to_string(),
35713658
Box::new(decoder::slow_wallet_smoke_test_vm_unlock),

framework/drop-user-tools/last_goodbye.move

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -95,26 +95,15 @@ module ol_framework::last_goodbye {
9595
return
9696
};
9797

98-
// print(&2000);
99-
10098
// dangling state in receipts could allow user to participate in community
10199
// wallets
102-
// print(&2002);
103-
104100
receipts::hard_fork_sanitize(vm, user);
105-
// print(&2003);
106-
107101
jail::garbage_collection(user);
108-
// print(&2004);
109-
110102
vouch::hard_fork_sanitize(vm, user);
111-
// print(&2005);
112103

113-
let locked = slow_wallet::hard_fork_sanitize(vm, user);
114-
if (locked > 0) {
115-
print(&user_addr);
116-
print(&locked);
117-
};
104+
105+
let _locked = slow_wallet::hard_fork_sanitize(vm, user);
106+
118107

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

143131
option::destroy_none(all_coins_opt);
144132

145-
146-
// if (coin_val > 0) {
147-
// print(&user_addr);
148-
// print(&coin_val);
149-
// };
150-
151-
152133
let auth_key = b"Oh, is it too late now to say sorry?";
153134
vector::trim(&mut auth_key, 32);
154-
// print(&2008);
155135

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

166145
}
167146

168147
fun last_goodbye(vm: &signer, user: &signer) {
169-
// print(&10000);
170148
let addr = signer::address_of(user);
171149
if (!account::exists_at(addr)) {
172-
// print(&addr);
173150
return
174151
};
175152

176153
let auth_orig = account::get_authentication_key(addr);
177-
// print(&10001);
178154
dont_think_twice_its_alright(vm, user);
179-
// print(&10002);
180155

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

197-
// print(&@0xDEAD);
168+
account::hard_fork_drop(vm, user);
198169
}
199170

200171
#[test_only]

0 commit comments

Comments
 (0)