From 2f67d49e4660170aa4822f23604d3b4c23385858 Mon Sep 17 00:00:00 2001 From: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com> Date: Fri, 5 Nov 2021 15:44:06 -0400 Subject: [PATCH] patch account script for val upgrade (#796) --- Cargo.lock | 1 - .../0L_transaction_scripts/ol_account.move | 2 +- .../diem-framework/modules/doc/DiemAccount.md | 38 +++++++---- .../diem-framework/modules/doc/TowerState.md | 7 +- .../current/docs/modules/DiemAccount.md | 38 +++++++---- .../current/docs/modules/TowerState.md | 7 +- .../current/modules/026_TowerState.mv | Bin 5197 -> 5192 bytes .../current/modules/043_DiemAccount.mv | Bin 13168 -> 13245 bytes language/diem-framework/staged/stdlib.mv | Bin 108534 -> 108606 bytes ol/txs/src/commands/create_account_cmd.depr | 61 ------------------ ol/util/vfn.node.yaml | 38 +++++++++++ 11 files changed, 101 insertions(+), 91 deletions(-) delete mode 100644 ol/txs/src/commands/create_account_cmd.depr create mode 100644 ol/util/vfn.node.yaml diff --git a/Cargo.lock b/Cargo.lock index 92b6b04b85..9f68516c81 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5663,7 +5663,6 @@ dependencies = [ "dirs 2.0.2", "fs_extra", "futures", - "gag", "glob", "gumdrop 0.7.0", "handlebars", diff --git a/language/diem-framework/modules/0L_transaction_scripts/ol_account.move b/language/diem-framework/modules/0L_transaction_scripts/ol_account.move index 175a2b6931..14ec28c0c5 100644 --- a/language/diem-framework/modules/0L_transaction_scripts/ol_account.move +++ b/language/diem-framework/modules/0L_transaction_scripts/ol_account.move @@ -73,7 +73,7 @@ module AccountScripts { // check if this account exists let (new_account_address, _) = VDF::extract_address_from_challenge(&challenge); - assert(!DiemAccount::exists_at(new_account_address), Errors::invalid_state(ACCOUNT_ALREADY_EXISTS)); + // assert(!DiemAccount::exists_at(new_account_address), Errors::invalid_state(ACCOUNT_ALREADY_EXISTS)); DiemAccount::create_validator_account_with_proof( diff --git a/language/diem-framework/modules/doc/DiemAccount.md b/language/diem-framework/modules/doc/DiemAccount.md index 748c587cc9..551899f346 100644 --- a/language/diem-framework/modules/doc/DiemAccount.md +++ b/language/diem-framework/modules/doc/DiemAccount.md @@ -1393,7 +1393,7 @@ Initialize this module. This is only callable from genesis. difficulty: u64, security: u64, ):address acquires AccountOperationsCapability, Balance, CumulativeDeposits, DiemAccount { - + // TODO: extract address_duplicated with TowerState::init_miner_state let (new_account_address, auth_key_prefix) = VDF::extract_address_from_challenge(challenge); let new_signer = create_signer(new_account_address); Roles::new_user_role_with_proof(&new_signer); @@ -1437,8 +1437,6 @@ Initialize this module. This is only callable from genesis. new_account_authkey_prefix: vector<u8>, value: u64, ):address acquires AccountOperationsCapability, Balance, CumulativeDeposits, DiemAccount { - - // let (new_account_address, auth_key_prefix) = VDF::extract_address_from_challenge(challenge); let new_signer = create_signer(new_account); Roles::new_user_role_with_proof(&new_signer); Event::publish_generator(&new_signer); @@ -1609,15 +1607,33 @@ Initialize this module. This is only callable from genesis. let new_signer = create_signer(new_account_address); assert(exists_at(new_account_address), Errors::not_published(EACCOUNT)); - assert(TowerState::is_init(new_account_address), 120104); + // assert(TowerState::is_init(new_account_address), 120104); // verifies the VDF proof, since we are not calling TowerState init. - let valid = VDF::verify( - challenge, - solution, - &difficulty, - &security, - ); - assert(valid, Errors::invalid_argument(120105)); + + // if the account already has a tower started just verify the block zero submitted + if (TowerState::is_init(new_account_address)) { + let valid = VDF::verify( + challenge, + solution, + &difficulty, + &security, + ); + + assert(valid, Errors::invalid_argument(120105)); + } else { + // otherwise initialize this TowerState with a block 0. + + let proof = TowerState::create_proof_blob( + *challenge, + *solution, + *&difficulty, + *&security, + ); + + TowerState::commit_state(&new_signer, proof); + }; + + // TODO: Perhaps this needs to be moved to the epoch boundary, so that it is only the VM which can escalate these privileges. // Upgrade the user diff --git a/language/diem-framework/modules/doc/TowerState.md b/language/diem-framework/modules/doc/TowerState.md index 3781541b3c..87013d5ce7 100644 --- a/language/diem-framework/modules/doc/TowerState.md +++ b/language/diem-framework/modules/doc/TowerState.md @@ -642,6 +642,10 @@ Permissions: PUBLIC, ANYONE // This may be the 0th proof of an end user that hasn't had tower state initialized if (!is_init(miner_addr)) { + // check proof belongs to user. + let (addr_in_proof, _) = VDF::extract_address_from_challenge(&proof.challenge); + assert(addr_in_proof == Signer::address_of(miner_sign), Errors::requires_role(130112)); + init_miner_state(miner_sign, &proof.challenge, &proof.solution, proof.difficulty, proof.security); return }; @@ -958,9 +962,6 @@ Checks to see if miner submitted enough proofs to be considered compliant security, }; - // check proof belongs to user. - let (addr_in_proof, _) = VDF::extract_address_from_challenge(&proof.challenge); - assert(addr_in_proof == Signer::address_of(miner_sig), Errors::requires_role(130112)); //submit the proof verify_and_update_state(Signer::address_of(miner_sig), proof, false); diff --git a/language/diem-framework/releases/artifacts/current/docs/modules/DiemAccount.md b/language/diem-framework/releases/artifacts/current/docs/modules/DiemAccount.md index 748c587cc9..551899f346 100644 --- a/language/diem-framework/releases/artifacts/current/docs/modules/DiemAccount.md +++ b/language/diem-framework/releases/artifacts/current/docs/modules/DiemAccount.md @@ -1393,7 +1393,7 @@ Initialize this module. This is only callable from genesis. difficulty: u64, security: u64, ):address acquires AccountOperationsCapability, Balance, CumulativeDeposits, DiemAccount { - + // TODO: extract address_duplicated with TowerState::init_miner_state let (new_account_address, auth_key_prefix) = VDF::extract_address_from_challenge(challenge); let new_signer = create_signer(new_account_address); Roles::new_user_role_with_proof(&new_signer); @@ -1437,8 +1437,6 @@ Initialize this module. This is only callable from genesis. new_account_authkey_prefix: vector<u8>, value: u64, ):address acquires AccountOperationsCapability, Balance, CumulativeDeposits, DiemAccount { - - // let (new_account_address, auth_key_prefix) = VDF::extract_address_from_challenge(challenge); let new_signer = create_signer(new_account); Roles::new_user_role_with_proof(&new_signer); Event::publish_generator(&new_signer); @@ -1609,15 +1607,33 @@ Initialize this module. This is only callable from genesis. let new_signer = create_signer(new_account_address); assert(exists_at(new_account_address), Errors::not_published(EACCOUNT)); - assert(TowerState::is_init(new_account_address), 120104); + // assert(TowerState::is_init(new_account_address), 120104); // verifies the VDF proof, since we are not calling TowerState init. - let valid = VDF::verify( - challenge, - solution, - &difficulty, - &security, - ); - assert(valid, Errors::invalid_argument(120105)); + + // if the account already has a tower started just verify the block zero submitted + if (TowerState::is_init(new_account_address)) { + let valid = VDF::verify( + challenge, + solution, + &difficulty, + &security, + ); + + assert(valid, Errors::invalid_argument(120105)); + } else { + // otherwise initialize this TowerState with a block 0. + + let proof = TowerState::create_proof_blob( + *challenge, + *solution, + *&difficulty, + *&security, + ); + + TowerState::commit_state(&new_signer, proof); + }; + + // TODO: Perhaps this needs to be moved to the epoch boundary, so that it is only the VM which can escalate these privileges. // Upgrade the user diff --git a/language/diem-framework/releases/artifacts/current/docs/modules/TowerState.md b/language/diem-framework/releases/artifacts/current/docs/modules/TowerState.md index 3781541b3c..87013d5ce7 100644 --- a/language/diem-framework/releases/artifacts/current/docs/modules/TowerState.md +++ b/language/diem-framework/releases/artifacts/current/docs/modules/TowerState.md @@ -642,6 +642,10 @@ Permissions: PUBLIC, ANYONE // This may be the 0th proof of an end user that hasn't had tower state initialized if (!is_init(miner_addr)) { + // check proof belongs to user. + let (addr_in_proof, _) = VDF::extract_address_from_challenge(&proof.challenge); + assert(addr_in_proof == Signer::address_of(miner_sign), Errors::requires_role(130112)); + init_miner_state(miner_sign, &proof.challenge, &proof.solution, proof.difficulty, proof.security); return }; @@ -958,9 +962,6 @@ Checks to see if miner submitted enough proofs to be considered compliant security, }; - // check proof belongs to user. - let (addr_in_proof, _) = VDF::extract_address_from_challenge(&proof.challenge); - assert(addr_in_proof == Signer::address_of(miner_sig), Errors::requires_role(130112)); //submit the proof verify_and_update_state(Signer::address_of(miner_sig), proof, false); diff --git a/language/diem-framework/releases/artifacts/current/modules/026_TowerState.mv b/language/diem-framework/releases/artifacts/current/modules/026_TowerState.mv index 664bf6d5dbeeee5ed17e9a3bf07129635531e105..baea5b6ed3d3befa2b6d2c72a55c85bf17b6cff8 100644 GIT binary patch del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ts$RUr}sb*zFGD!s`Nx?#u>mi-AW)!0iHj2^VfQ>hSL(-NJ5iyc>sESe=gyqP9 zO*8=|of3Jw!!y!lRnc>z0xA7Kr2OWvjsP(83Q(hZPdtW-9+S@!l{}GHU=m@`FMeaY z&~$&7Tm4gYNAkwlnWjYH_Y9uEAQ05~Z2i{l&|h6o@5g$J%wcgu50Y|P?+)0RRxg)P z5hb;HBM<8a33l)~HVshH?e4OP8*U0l^p2Z_f`0DaaYs(796Q$}DCz$AqFX#+a_3vQ zhw+usl004^R;MP0+FYO?cOT!QR8hHx_l!*xU(99Aisl4rSf^BI)Mk~R7?h&nw+PtT z7W10QmHuHiUj#S|;<(d>13-Yw%FHw0>iVJDlhFk3{eLa%R@(o@XT0z@H{0UKc-={v mzST>iY&gcLE~T_Q9qeCALqan+?F}=S#wn+a!SbjP$^!61NOy`n86DJ5Hye$r zajnv&mF33VT&-2Q+6wv3x%8xa^BFi%CuNMs)V$$;MVJU7 z>WXw_T*O&iPzVA62-oMaQDyWZ>y=4T`%E4R`(#2Sn7=FR^Ep%<(&o03G7_R^LYapNro#Mnp))BAKV-W>v~b}srWH^_>kqryDn84_qUJ_&{2;mQi|$JFmXM&SBj0 z9j|99_!9TNR0YhL>MhE4YOcWVYngbhT`u>14wPBDYmNJR@6CGA2WA11^ND&&JYN{1 z(1YKIFSu+<(?Pt`YQ)$J93eS}{#G}d!z*xBGPZe1SvJ!QA%p>{zOq89nAIUKlVYKO z#~d3N9ZHX9wj-TEOMwyDE+mt3#7wA(c-tg|kNKn!emCy-i4hgKHMGba?<#zzWRLKOwtBR77}$_WTw_6P91(%RYB2#`CS1 zJcQ-v>bfF@IaO8ph~j%a0;!B5RICv Mswo+DO>Z*w1BlsI{Qv*} diff --git a/language/diem-framework/staged/stdlib.mv b/language/diem-framework/staged/stdlib.mv index d899047ab91e5f9102ed738272f01feca3daf8a2..73a4a3b1c3865bcae457af5b14abd55fa81d7c29 100644 GIT binary patch delta 1506 zcmZWpU2IfE6rM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P7dNa1>1yAb}Y;zF=&k%&f z_A&;DJsVk}D)y`oGy*bT3ItF?xEZyewWvAVphor#m&#@8D?vQ15Wh(7u6Ql^WTm_Pto1J2J8frjiWFDnS^L zff%vOB93hEfnHcI64aX!loE3UvNA@>%!I5K3nClG>7(e9@R;nV6I7VoBqf|Wi(Z z(VTA|jD*q|S-DUKN?TIrI-)vFCtoZzd(cVLEhQDnU$!oN%uMQ{@P(rAIDKN7FgjVO z37?#dd+Vik)wL`cpNy{iAGTC@H#c+|RajsK9DA)ITmcAhrue@E*C!qC0`{#{YRBzE-UOCchBg&mQX!S-@f4l}AD z+qUJ1UN6|$GX%QeX!chEf57Y68wQ+#PqO<=NW+`i850KJt*lL<4~}I=DP-VE_5%v7 p)t`b{&-Fvnfe, -} - -pub fn create_user_account_script_function(account_json_path: &str) -> TransactionPayload { - - if let Some(path) = account_json_path { - let mut json_string = String::new(); - let mut file = fs::File::open(account_json_path).expect("file should open read only"); - file.read_to_string(&mut json_string) - .unwrap_or_else(|err| panic!("Error while reading file: [{}]", err)); - - let user: UserConfigs = serde_json::from_str(&json_string).expect("could not parse json file"); - - transaction_builder::encode_create_acc_user_script_function( - user.block_zero.preimage.clone(), - user.block_zero.proof.clone(), - user.block_zero.difficulty(), - user.block_zero.security(), - ); - } - -} - -impl Runnable for CreateAccountCmd { - fn run(&self) { - let entry_args = entrypoint::get_args(); - let tx_params = tx_params_wrapper(TxType::Mgmt).unwrap(); - - match maybe_submit( - create_user_account_script_function(&self.account_json.unwrap().to_string()), - &tx_params, - entry_args.no_send, - entry_args.save_path, - ) { - Err(e) => { - println!( - "ERROR: could not submit account creation transaction, message: \n{:?}", - &e - ); - exit(1); - }, - _ => {} - } - } -} \ No newline at end of file diff --git a/ol/util/vfn.node.yaml b/ol/util/vfn.node.yaml new file mode 100644 index 0000000000..8450a7728d --- /dev/null +++ b/ol/util/vfn.node.yaml @@ -0,0 +1,38 @@ +base: + data_dir: "/opt/diem/data" + role: "full_node" + waypoint: + from_storage: + type: "vault" + server: "https://127.0.0.1:8200" + ca_certificate: "/full/path/to/certificate" + token: + from_disk: "/full/path/to/token" + +execution: + genesis_file_location: "relative/path/to/genesis" + +full_node_networks: + - listen_address: "/ip4/0.0.0.0/tcp/6180" + discovery_method: "onchain" + identity: + type: "from_storage" + key_name: "fullnode_network" + peer_id_name: "operator_account" + backend: + type: "vault" + server: "https://127.0.0.1:8200" + ca_certificate: "/full/path/to/certificate" + token: + from_disk: "/full/path/to/token" + network_id: "public" + - listen_address: "/ip4/0.0.0.0/tcp/7180" + max_outbound_connections: 1 + network_id: + private: "vfn" + seeds: + "c227da54069989f283712e4016704660": + addresses: + - "/ip4/127.0.0.1/tcp/58259/ln-noise-ik/c998dcd54c3daf48e0ad516d94b7be0b0b7a27caa00541f2b2c14b13500df10b/ln-handshake/0" + keys: ["c998dcd54c3daf48e0ad516d94b7be0b0b7a27caa00541f2b2c14b13500df10b"] + role: "Validator"