|
13 | 13 | #![allow(dead_code)]
|
14 | 14 | #![allow(unused_imports)]
|
15 | 15 | #![allow(clippy::too_many_arguments)]
|
16 |
| - |
17 | 16 | use diem_types::{
|
18 | 17 | account_address::AccountAddress,
|
19 | 18 | transaction::{EntryFunction, TransactionPayload},
|
@@ -95,7 +94,8 @@ pub enum EntryFunctionCall {
|
95 | 94 |
|
96 | 95 | /// Generic authentication key rotation function that allows the user to rotate their authentication key from any scheme to any scheme.
|
97 | 96 | /// 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; |
99 | 99 | /// - the second signature `cap_update_table` refers to the signature by the new key (that the account owner wants to rotate to) on a
|
100 | 100 | /// valid `RotationProofChallenge`, demonstrating that the user owns the new private key, and has the authority to update the
|
101 | 101 | /// `OriginatingAddress` map with the new address mapping `<new_address, originating_address>`.
|
@@ -491,6 +491,18 @@ pub enum EntryFunctionCall {
|
491 | 491 | authorities: Vec<AccountAddress>,
|
492 | 492 | },
|
493 | 493 |
|
| 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 | + |
494 | 506 | SlowWalletSmokeTestVmUnlock {
|
495 | 507 | user_addr: AccountAddress,
|
496 | 508 | unlocked: u64,
|
@@ -824,6 +836,12 @@ impl EntryFunctionCall {
|
824 | 836 | epoch_expiry,
|
825 | 837 | } => proof_of_fee_pof_update_bid_net_reward(net_reward, epoch_expiry),
|
826 | 838 | 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), |
827 | 845 | SlowWalletSmokeTestVmUnlock {
|
828 | 846 | user_addr,
|
829 | 847 | unlocked,
|
@@ -1048,11 +1066,14 @@ pub fn account_revoke_signer_capability(
|
1048 | 1066 | /// `OriginatingAddress` map with the new address mapping `<new_address, originating_address>`.
|
1049 | 1067 | /// To verify these two signatures, we need their corresponding public key and public key scheme: we use `from_scheme` and `from_public_key_bytes`
|
1050 | 1068 | /// 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 | +/// |
1052 | 1072 | /// Here is an example attack if we don't ask for the second signature `cap_update_table`:
|
1053 | 1073 | /// 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:
|
1054 | 1074 | /// `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.) |
1056 | 1077 | ///
|
1057 | 1078 | /// But Bob likes to mess with Alice.
|
1058 | 1079 | /// 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
|
2216 | 2237 | ))
|
2217 | 2238 | }
|
2218 | 2239 |
|
| 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 | + |
2219 | 2276 | pub fn slow_wallet_smoke_test_vm_unlock(
|
2220 | 2277 | user_addr: AccountAddress,
|
2221 | 2278 | unlocked: u64,
|
@@ -3189,6 +3246,28 @@ mod decoder {
|
3189 | 3246 | }
|
3190 | 3247 | }
|
3191 | 3248 |
|
| 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 | + |
3192 | 3271 | pub fn slow_wallet_smoke_test_vm_unlock(
|
3193 | 3272 | payload: &TransactionPayload,
|
3194 | 3273 | ) -> Option<EntryFunctionCall> {
|
@@ -3566,6 +3645,14 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
|
3566 | 3645 | "safe_init_payment_multisig".to_string(),
|
3567 | 3646 | Box::new(decoder::safe_init_payment_multisig),
|
3568 | 3647 | );
|
| 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 | + ); |
3569 | 3656 | map.insert(
|
3570 | 3657 | "slow_wallet_smoke_test_vm_unlock".to_string(),
|
3571 | 3658 | Box::new(decoder::slow_wallet_smoke_test_vm_unlock),
|
|
0 commit comments