diff --git a/Cargo.lock b/Cargo.lock index 2c5b8d897e..047bece820 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9798,7 +9798,7 @@ dependencies = [ [[package]] name = "starcoin-framework" version = "11.0.0" -source = "git+https://github.com/starcoinorg/starcoin-framework?rev=3e879a168036dceaa60c57c8e2b9228283476f81#3e879a168036dceaa60c57c8e2b9228283476f81" +source = "git+https://github.com/starcoinorg/starcoin-framework?rev=9eaa8f97aa40d3ab19bfbe90fb720ac63268a613#9eaa8f97aa40d3ab19bfbe90fb720ac63268a613" dependencies = [ "anyhow", "include_dir", diff --git a/Cargo.toml b/Cargo.toml index f2e7051406..bf0bdc9e1c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -444,7 +444,7 @@ starcoin-crypto = { git = "https://github.com/starcoinorg/starcoin-crypto", rev starcoin-decrypt = { path = "commons/decrypt" } starcoin-dev = { path = "vm/dev" } starcoin-executor = { path = "executor" } -starcoin-framework = { git = "https://github.com/starcoinorg/starcoin-framework", rev = "3e879a168036dceaa60c57c8e2b9228283476f81" } +starcoin-framework = { git = "https://github.com/starcoinorg/starcoin-framework", rev = "9eaa8f97aa40d3ab19bfbe90fb720ac63268a613" } starcoin-genesis = { path = "genesis" } starcoin-logger = { path = "commons/logger" } starcoin-metrics = { path = "commons/metrics" } diff --git a/chain/tests/test_force_upgrade.rs b/chain/tests/test_force_upgrade.rs index b34b3052e2..1dc56568cd 100644 --- a/chain/tests/test_force_upgrade.rs +++ b/chain/tests/test_force_upgrade.rs @@ -1,16 +1,21 @@ +use std::str::FromStr; +use std::sync::Arc; + use anyhow::format_err; + use starcoin_accumulator::Accumulator; use starcoin_chain_api::{ChainReader, ChainWriter}; use starcoin_config::NodeConfig; use starcoin_consensus::Consensus; use starcoin_statedb::ChainStateDB; -use starcoin_transaction_builder::{build_transfer_from_association, DEFAULT_EXPIRATION_TIME}; +use starcoin_transaction_builder::{ + build_burn_illegal_stc_txn_with_association, build_transfer_from_association, + DEFAULT_EXPIRATION_TIME, +}; use starcoin_types::account_address::AccountAddress; use starcoin_vm_runtime::force_upgrade_management::get_force_upgrade_block_number; use starcoin_vm_types::on_chain_config::Version; use starcoin_vm_types::{account_config, state_view::StateReaderExt}; -use std::str::FromStr; -use std::sync::Arc; use test_helper::executor::get_balance; #[stest::test] @@ -130,16 +135,20 @@ pub fn test_force_upgrade_1() -> anyhow::Result<()> { let txns_num = txns_num + 2; assert_eq!(miner.get_txn_accumulator().num_leaves(), txns_num); + let black1_balance = get_balance(black1, miner.chain_state()); + println!("Black 1 balance is: {:?}", black1_balance); assert_eq!( - get_balance(black1, miner.chain_state()), - 0, - "Upgrade Failed, Balance of black list account not 0" + black1_balance, + initial_balance + 1, + "Force-Upgrading Failed, Balance of black-1 account changed!" ); + let black2_balance = get_balance(black2, miner.chain_state()); + println!("Black 2 balance is: {:?}", black2_balance); assert_eq!( - get_balance(black2, miner.chain_state()), - 0, - "Upgrade Failed, Balance of black list account not 0" + black2_balance, + initial_balance + 2, + "Force-upgrading Failed, Balance of black-2 account changed!" ); assert_eq!(get_balance(rand3, miner.chain_state()), initial_balance + 3); @@ -147,6 +156,58 @@ pub fn test_force_upgrade_1() -> anyhow::Result<()> { block2 }; + // Apply block number 3, this will call StdlibUpgrade::burn_illegal_token_from_frozen_address + { + let burn_black_txn_1 = build_burn_illegal_stc_txn_with_association( + &black1, + association_sequence_num + 4, + initial_balance + 1, + config.net(), + ); + let burn_black_txn_2 = build_burn_illegal_stc_txn_with_association( + &black2, + association_sequence_num + 5, + initial_balance + 2, + config.net(), + ); + + let (block_template, _excluded) = miner + .create_block_template( + account_config::association_address(), + None, + vec![burn_black_txn_1, burn_black_txn_2], + vec![], + Some(block_gas_limit), + ) + .unwrap(); + + let block3 = miner + .consensus() + .create_block(block_template, miner.time_service().as_ref())?; + + miner.apply(block3.clone())?; + + // 1 meta + 3 txns = 4 txns + //let txns_num = txns_num + 3; + //let leaves_num = miner.get_txn_accumulator().num_leaves(); + //assert_eq!(leaves_num, txns_num); + + let black1_balance = get_balance(black1, miner.chain_state()); + println!("Black 1 balance is: {:?}", black1_balance); + assert_eq!( + black1_balance, 0, + "Burning Failed, Balance of black-1 account is not 0" + ); + + let black2_balance = get_balance(black2, miner.chain_state()); + println!("Black 2 balance is: {:?}", black2_balance); + assert_eq!( + black2_balance, 0, + "Burning Failed, Balance of black-2 account is not 0" + ); + block3 + }; + // apply block number 2 to another chain { // !!!non-zero balance @@ -160,8 +221,14 @@ pub fn test_force_upgrade_1() -> anyhow::Result<()> { let txns_num = txns_num + 2; assert_eq!(chain_to_apply.get_txn_accumulator().num_leaves(), txns_num); - assert_eq!(get_balance(black1, chain_to_apply.chain_state()), 0); - assert_eq!(get_balance(black2, chain_to_apply.chain_state()), 0); + assert_eq!( + get_balance(black1, chain_to_apply.chain_state()), + initial_balance + 1 + ); + assert_eq!( + get_balance(black2, chain_to_apply.chain_state()), + initial_balance + 2 + ); assert_eq!( get_balance(rand3, chain_to_apply.chain_state()), initial_balance + 3 diff --git a/network/src/service.rs b/network/src/service.rs index 31b6cfcd64..f248dda7ea 100644 --- a/network/src/service.rs +++ b/network/src/service.rs @@ -40,7 +40,7 @@ use std::ops::RangeInclusive; use std::sync::Arc; const BARNARD_HARD_FORK_PEER_VERSION_STRING_PREFIX: &str = "barnard_rollback_block_fix"; -const BARNARD_HARD_FORK_VERSION: [i32; 3] = [1, 13, 11]; +const BARNARD_HARD_FORK_VERSION: [i32; 3] = [1, 13, 12]; pub struct NetworkActorService { /// Worker and inner have ChainInfo instances separately. There might be some way to solve the problem. @@ -930,7 +930,7 @@ mod test { assert!(!greater_barnard_fork_version(&v3)); let v4 = String::from("starcoin/1.12.9 (build:v1.12.9) (kele01)"); assert!(!greater_barnard_fork_version(&v4)); - let v5 = String::from("starcoin/1.13.12 (build:v1.13.12-alpha) (kele01)"); + let v5 = String::from("starcoin/1.13.13 (build:v1.13.13-alpha) (kele01)"); assert!(greater_barnard_fork_version(&v5)); } } diff --git a/storage/src/upgrade.rs b/storage/src/upgrade.rs index 2e45d0d4d4..67b9c44c23 100644 --- a/storage/src/upgrade.rs +++ b/storage/src/upgrade.rs @@ -22,10 +22,10 @@ use std::cmp::Ordering; pub struct DBUpgrade; -pub static BARNARD_HARD_FORK_HEIGHT: BlockNumber = 16057000; +pub static BARNARD_HARD_FORK_HEIGHT: BlockNumber = 16080000; pub static BARNARD_HARD_FORK_HASH: Lazy = Lazy::new(|| { HashValue::from_hex_literal( - "0x1dd5987fa3b8bffad60f7a7756e73acd7b6808fed5a174200bf49e9f5de2d073", + "0x2dd593a9ac3e44d4a70423d39ffbd94930dba00b4682fcde9ebb2be8950bae7c", ) .expect("") }); diff --git a/vm/stdlib/compiled/12/11-12/stdlib.blob b/vm/stdlib/compiled/12/11-12/stdlib.blob index afcfdca18b..c52968714f 100644 Binary files a/vm/stdlib/compiled/12/11-12/stdlib.blob and b/vm/stdlib/compiled/12/11-12/stdlib.blob differ diff --git a/vm/stdlib/compiled/12/11-12/stdlib/036_Account.mv b/vm/stdlib/compiled/12/11-12/stdlib/036_Account.mv index aa65760485..a2b45f221f 100644 Binary files a/vm/stdlib/compiled/12/11-12/stdlib/036_Account.mv and b/vm/stdlib/compiled/12/11-12/stdlib/036_Account.mv differ diff --git a/vm/stdlib/compiled/12/11-12/stdlib/051_FrozenConfig.mv b/vm/stdlib/compiled/12/11-12/stdlib/051_FrozenConfig.mv index d8bef1911c..b977c290cd 100644 Binary files a/vm/stdlib/compiled/12/11-12/stdlib/051_FrozenConfig.mv and b/vm/stdlib/compiled/12/11-12/stdlib/051_FrozenConfig.mv differ diff --git a/vm/stdlib/compiled/12/11-12/stdlib/064_StdlibUpgradeScripts.mv b/vm/stdlib/compiled/12/11-12/stdlib/064_StdlibUpgradeScripts.mv index 3b340b742e..05d869e69b 100644 Binary files a/vm/stdlib/compiled/12/11-12/stdlib/064_StdlibUpgradeScripts.mv and b/vm/stdlib/compiled/12/11-12/stdlib/064_StdlibUpgradeScripts.mv differ diff --git a/vm/stdlib/compiled/12/11-12/stdlib/065_Genesis.mv b/vm/stdlib/compiled/12/11-12/stdlib/065_Genesis.mv index 33844f2593..78701566bc 100644 Binary files a/vm/stdlib/compiled/12/11-12/stdlib/065_Genesis.mv and b/vm/stdlib/compiled/12/11-12/stdlib/065_Genesis.mv differ diff --git a/vm/stdlib/compiled/12/stdlib/036_Account.mv b/vm/stdlib/compiled/12/stdlib/036_Account.mv index aa65760485..a2b45f221f 100644 Binary files a/vm/stdlib/compiled/12/stdlib/036_Account.mv and b/vm/stdlib/compiled/12/stdlib/036_Account.mv differ diff --git a/vm/stdlib/compiled/12/stdlib/051_FrozenConfig.mv b/vm/stdlib/compiled/12/stdlib/051_FrozenConfig.mv index d8bef1911c..b977c290cd 100644 Binary files a/vm/stdlib/compiled/12/stdlib/051_FrozenConfig.mv and b/vm/stdlib/compiled/12/stdlib/051_FrozenConfig.mv differ diff --git a/vm/stdlib/compiled/12/stdlib/064_StdlibUpgradeScripts.mv b/vm/stdlib/compiled/12/stdlib/064_StdlibUpgradeScripts.mv index 3b340b742e..05d869e69b 100644 Binary files a/vm/stdlib/compiled/12/stdlib/064_StdlibUpgradeScripts.mv and b/vm/stdlib/compiled/12/stdlib/064_StdlibUpgradeScripts.mv differ diff --git a/vm/stdlib/compiled/12/stdlib/065_Genesis.mv b/vm/stdlib/compiled/12/stdlib/065_Genesis.mv index 33844f2593..78701566bc 100644 Binary files a/vm/stdlib/compiled/12/stdlib/065_Genesis.mv and b/vm/stdlib/compiled/12/stdlib/065_Genesis.mv differ diff --git a/vm/stdlib/compiled/latest/error_descriptions/error_descriptions.errmap b/vm/stdlib/compiled/latest/error_descriptions/error_descriptions.errmap index 687ca02f73..c68f41f91d 100644 Binary files a/vm/stdlib/compiled/latest/error_descriptions/error_descriptions.errmap and b/vm/stdlib/compiled/latest/error_descriptions/error_descriptions.errmap differ diff --git a/vm/stdlib/compiled/latest/stdlib/036_Account.mv b/vm/stdlib/compiled/latest/stdlib/036_Account.mv index aa65760485..a2b45f221f 100644 Binary files a/vm/stdlib/compiled/latest/stdlib/036_Account.mv and b/vm/stdlib/compiled/latest/stdlib/036_Account.mv differ diff --git a/vm/stdlib/compiled/latest/stdlib/051_FrozenConfig.mv b/vm/stdlib/compiled/latest/stdlib/051_FrozenConfig.mv index d8bef1911c..b977c290cd 100644 Binary files a/vm/stdlib/compiled/latest/stdlib/051_FrozenConfig.mv and b/vm/stdlib/compiled/latest/stdlib/051_FrozenConfig.mv differ diff --git a/vm/stdlib/compiled/latest/stdlib/064_StdlibUpgradeScripts.mv b/vm/stdlib/compiled/latest/stdlib/064_StdlibUpgradeScripts.mv index 3b340b742e..05d869e69b 100644 Binary files a/vm/stdlib/compiled/latest/stdlib/064_StdlibUpgradeScripts.mv and b/vm/stdlib/compiled/latest/stdlib/064_StdlibUpgradeScripts.mv differ diff --git a/vm/stdlib/compiled/latest/stdlib/065_Genesis.mv b/vm/stdlib/compiled/latest/stdlib/065_Genesis.mv index 33844f2593..78701566bc 100644 Binary files a/vm/stdlib/compiled/latest/stdlib/065_Genesis.mv and b/vm/stdlib/compiled/latest/stdlib/065_Genesis.mv differ diff --git a/vm/transaction-builder/src/lib.rs b/vm/transaction-builder/src/lib.rs index 0019c4512b..630b9184b9 100644 --- a/vm/transaction-builder/src/lib.rs +++ b/vm/transaction-builder/src/lib.rs @@ -1,15 +1,18 @@ // Copyright (c) The Starcoin Core Contributors // SPDX-License-Identifier: Apache-2.0 +use std::convert::TryInto; + use anyhow::Result; -use starcoin_config::{genesis_config::G_TOTAL_STC_AMOUNT, ChainNetwork}; use starcoin_crypto::hash::PlainCryptoHash; use starcoin_crypto::HashValue; + +use starcoin_config::{genesis_config::G_TOTAL_STC_AMOUNT, ChainNetwork}; use starcoin_types::account::Account; use starcoin_vm_types::access::ModuleAccess; use starcoin_vm_types::account_address::AccountAddress; use starcoin_vm_types::account_config; -use starcoin_vm_types::account_config::{core_code_address, genesis_address}; +use starcoin_vm_types::account_config::{association_address, core_code_address, genesis_address}; use starcoin_vm_types::file_format::CompiledModule; use starcoin_vm_types::genesis_config::ChainId; use starcoin_vm_types::identifier::Identifier; @@ -25,7 +28,6 @@ use starcoin_vm_types::transaction::{ TransactionPayload, }; use starcoin_vm_types::value::MoveValue; -use std::convert::TryInto; use stdlib::{module_to_package, stdlib_package}; pub use stdlib::{stdlib_compiled_modules, stdlib_modules, StdLibOptions, StdlibVersion}; @@ -910,3 +912,47 @@ pub fn build_signed_empty_txn( let signature = prikey.sign(&txn); SignedUserTransaction::new(txn, signature) } + +// Build a signed user transaction for burning illegal tokens from a frozen address. +// This function creates a signed user transaction that attempts to burn illegal tokens +// from a frozen address. The transaction is signed by the `signer` and is intended for the `recipient`. +// +// # Arguments +// - `signer`: A reference to the `Account` that will sign the transaction. +// - `recipient`: A reference to the `AccountAddress` of the recipient. +// - `seq_num`: The sequence number of the transaction. +// - `amount`: The amount of tokens to be burned, represented as a `u128`. +// - `net`: A reference to the `ChainNetwork` which provides the chain ID for the transaction. +// +// # Returns +// - A `SignedUserTransaction` that is signed by the `signer` with the specified transaction details. +pub fn build_burn_illegal_stc_txn_with_association( + recipient: &AccountAddress, + seq_num: u64, + amount: u128, + net: &ChainNetwork, +) -> SignedUserTransaction { + let raw_txn = RawUserTransaction::new_with_default_gas_token( + association_address(), + seq_num, + TransactionPayload::ScriptFunction(ScriptFunction::new( + ModuleId::new( + core_code_address(), + Identifier::new("StdlibUpgradeScripts").unwrap(), + ), + Identifier::new("burn_illegal_token_from_frozen_address").unwrap(), + vec![], + vec![ + bcs_ext::to_bytes(&recipient).unwrap(), + bcs_ext::to_bytes(&amount).unwrap(), + ], + )), + 10000000, + 1, + 1000 + 60 * 60, + net.chain_id(), + ); + net.genesis_config() + .sign_with_association(raw_txn) + .expect("Sign with association failed") +} diff --git a/vm/vm-runtime/src/force_upgrade_management.rs b/vm/vm-runtime/src/force_upgrade_management.rs index eb0a10712b..834d4f4970 100644 --- a/vm/vm-runtime/src/force_upgrade_management.rs +++ b/vm/vm-runtime/src/force_upgrade_management.rs @@ -15,7 +15,8 @@ pub fn get_force_upgrade_block_number(chain_id: &ChainId) -> u64 { } else if chain_id.is_halley() || chain_id.is_proxima() { 300 } else if chain_id.is_barnard() { - 16085000 + // add 8000 + BARNARD_HARD_FORK_HEIGHT + 16088000 } else { FORCE_UPGRADE_BLOCK_NUMBER }