Skip to content

Commit 5734085

Browse files
authored
Audit Fixes 2: Migration overwrites the suspension status (#557)
1 parent d538013 commit 5734085

File tree

1 file changed

+58
-27
lines changed

1 file changed

+58
-27
lines changed

framework/contracts/account/src/migrate.rs

Lines changed: 58 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,83 @@
1-
use abstract_sdk::feature_objects::RegistryContract;
2-
use abstract_sdk::std::{account::state::ACCOUNT_ID, ACCOUNT};
3-
use abstract_std::account::ModuleInstallConfig;
4-
use abstract_std::objects::module::ModuleInfo;
1+
use abstract_sdk::std::ACCOUNT;
2+
use abstract_std::account::MigrateMsg;
53
use abstract_std::objects::module_version::assert_contract_upgrade;
6-
use abstract_std::{account::MigrateMsg, objects::AccountId};
7-
use abstract_std::{
8-
account::{
9-
state::{AccountInfo, WhitelistedModules, INFO, SUSPENSION_STATUS, WHITELISTED_MODULES},
10-
UpdateSubAccountAction,
11-
},
12-
objects::{
13-
gov_type::GovernanceDetails,
14-
ownership::{self},
15-
},
16-
registry::state::LOCAL_ACCOUNT_SEQUENCE,
17-
};
18-
use abstract_std::{native_addrs, AbstractError, IBC_CLIENT};
19-
use cosmwasm_std::{wasm_execute, DepsMut, Env};
4+
5+
use abstract_std::AbstractError;
6+
use cosmwasm_std::{DepsMut, Env};
207
use cw2::{get_contract_version, set_contract_version};
218
use semver::Version;
229

23-
use crate::{
24-
modules::{_install_modules, MIGRATE_CONTEXT},
25-
msg::ExecuteMsg,
26-
};
27-
2810
use crate::contract::{AccountResponse, AccountResult, CONTRACT_VERSION};
2911

12+
/// This migration function allows migrating from 2 types of contract
13+
/// - Previous Abstract Account version (This is the first part of the function)
14+
/// - XION Account, to allow upgrading their account to a more feature rich account (second part of the function)
15+
/// All other contracts cannot be migrated to this version
3016
#[cfg_attr(feature = "export", cosmwasm_std::entry_point)]
31-
pub fn migrate(mut deps: DepsMut, env: Env, _msg: MigrateMsg) -> AccountResult {
17+
pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> AccountResult {
3218
let version: Version = CONTRACT_VERSION.parse().unwrap();
3319

3420
let current_contract_version = get_contract_version(deps.storage)?;
3521
// If we already have an abstract account, we just migrate like normal
3622
if current_contract_version.contract == ACCOUNT {
3723
assert_contract_upgrade(deps.storage, ACCOUNT, version)?;
3824
set_contract_version(deps.storage, ACCOUNT, CONTRACT_VERSION)?;
39-
return Ok(AccountResponse::action("migrate"));
25+
Ok(AccountResponse::action("migrate"))
26+
} else {
27+
#[cfg(feature = "xion")]
28+
{
29+
// We might want to migrate from a XION account
30+
migrate_from_xion_account(deps, _env, current_contract_version)
31+
}
32+
#[cfg(not(feature = "xion"))]
33+
{
34+
Err(AbstractError::ContractNameMismatch {
35+
from: current_contract_version.contract,
36+
to: ACCOUNT.to_string(),
37+
})?
38+
}
4039
}
40+
}
41+
42+
#[cfg(feature = "xion")]
43+
pub fn migrate_from_xion_account(
44+
mut deps: DepsMut,
45+
env: Env,
46+
current_contract_version: cw2::ContractVersion,
47+
) -> AccountResult {
48+
use crate::{
49+
modules::{_install_modules, MIGRATE_CONTEXT},
50+
msg::ExecuteMsg,
51+
};
52+
use ::{
53+
abstract_sdk::feature_objects::RegistryContract,
54+
abstract_sdk::std::account::state::ACCOUNT_ID,
55+
abstract_std::account::ModuleInstallConfig,
56+
abstract_std::objects::module::ModuleInfo,
57+
abstract_std::objects::AccountId,
58+
abstract_std::{
59+
account::{
60+
state::{
61+
AccountInfo, WhitelistedModules, INFO, SUSPENSION_STATUS, WHITELISTED_MODULES,
62+
},
63+
UpdateSubAccountAction,
64+
},
65+
objects::{
66+
gov_type::GovernanceDetails,
67+
ownership::{self},
68+
},
69+
registry::state::LOCAL_ACCOUNT_SEQUENCE,
70+
},
71+
abstract_std::{native_addrs, IBC_CLIENT},
72+
cosmwasm_std::wasm_execute,
73+
};
4174

42-
// else this means that we are migrating from another contract, we assert it's `account` and create an abstract account
4375
if current_contract_version.contract != "account" {
4476
Err(AbstractError::ContractNameMismatch {
4577
from: current_contract_version.contract,
4678
to: ACCOUNT.to_string(),
4779
})?;
4880
}
49-
5081
// Use CW2 to set the contract version, this is needed for migrations
5182
set_contract_version(deps.storage, ACCOUNT, CONTRACT_VERSION)?;
5283

0 commit comments

Comments
 (0)