Skip to content

Commit

Permalink
Merge branch 'com-wallet-tests' into release-7.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Feb 27, 2024
2 parents 40abb11 + c80d3ec commit 8775cbf
Show file tree
Hide file tree
Showing 32 changed files with 4,742 additions and 3,827 deletions.
333 changes: 153 additions & 180 deletions framework/cached-packages/src/libra_framework_sdk_builder.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module diem_framework::diem_governance {

use ol_framework::libra_coin::LibraCoin;
use ol_framework::epoch_boundary;
use ol_framework::testnet;
// use diem_std::debug::print;


Expand Down Expand Up @@ -591,6 +592,16 @@ module diem_framework::diem_governance {
epoch_boundary::trigger_epoch(&framework_signer);
}

// helper to use on smoke tests only. Will fail on m
public entry fun smoke_trigger_epoch(core_resources: &signer) acquires
GovernanceResponsbility { // doesn't need a signer
assert!(testnet::is_not_mainnet(), 666);
system_addresses::assert_ol(core_resources);
let framework_signer = get_signer(@ol_framework);
epoch_boundary::smoke_trigger_epoch(&framework_signer);
}



/// Return the voting power a stake pool has with respect to governance proposals.
fun get_voting_power(_pool_address: address): u64 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module ol_framework::community_wallet {
public fun is_init(addr: address):bool {
exists<CommunityWallet>(addr)
}

public fun set_comm_wallet(sender: &signer) {
let addr = signer::address_of(sender);
if (!is_init(addr)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ module ol_framework::community_wallet_init {
const ENOT_QUALIFY_COMMUNITY_WALLET: u64 = 2;
/// Recipient does not have a slow wallet
const EPAYEE_NOT_SLOW_WALLET: u64 = 8;
/// Too few signers for Match Index
const ETOO_FEW_SIGNERS: u64 = 9;
/// This account needs to be donor directed.
const ENOT_DONOR_VOICE: u64 = 3;
/// This account needs a multisig enabled
const ENOT_MULTISIG: u64 = 4;
/// The multisig does not have minimum MINIMUM_AUTH signers and MINIMUM_SIGS approvals in config
const ESIG_THRESHOLD: u64 = 5;
/// config has few authorities on multisig
const ETOO_FEW_AUTH: u64 = 9;
/// config has too few signatures required for each proposal to pass
const ESIG_THRESHOLD_CONFIG: u64 = 5;
/// The multisig threshold is not better than MINIMUM_SIGS/MINIMUM_AUTH
const ESIG_THRESHOLD_RATIO: u64 = 6;
/// Signers may be sybil
Expand All @@ -47,7 +47,6 @@ module ol_framework::community_wallet_init {
const MINIMUM_AUTH: u64 = 3;


#[test_only]
public fun migrate_community_wallet_account(vm: &signer, dv_account:
&signer) {
use diem_framework::system_addresses;
Expand All @@ -63,44 +62,52 @@ module ol_framework::community_wallet_init {

public entry fun init_community(
sig: &signer,
init_signers: vector<address>
check_addresses: vector<address>,
check_threshold: u64,
) {
// policy is to have at least m signers as auths on the account.
let len = vector::length(&init_signers);
assert!(len >= MINIMUM_AUTH, error::invalid_argument(ETOO_FEW_SIGNERS));

// enforce n/m multi auth
let n = if (len == 3) { 2 }
else {
(MINIMUM_SIGS * len) / MINIMUM_AUTH
};

let (fam, _, _) = ancestry::any_family_in_list(*&init_signers);
assert!(!fam, error::invalid_argument(ESIGNERS_SYBIL));
check_proposed_auths(&check_addresses, check_threshold);

// set as donor directed with any liquidation going to contemporary
// matching index (not liquidated to historical community wallets)

donor_voice_txs::make_donor_voice(sig, init_signers, n);
donor_voice_txs::make_donor_voice(sig);
if (!donor_voice_txs::is_liquidate_to_match_index(signer::address_of(sig))) {
donor_voice_txs::set_liquidate_to_match_index(sig, true);
};
match_index::opt_into_match_index(sig);

community_wallet::set_comm_wallet(sig);
}

fun check_proposed_auths(initial_authorities: &vector<address>, num_signers:
u64) {
// // enforce n/m multi auth
// let n = if (len == 3) { 2 }
// else {
// (MINIMUM_SIGS * len) / MINIMUM_AUTH
// };

assert!(num_signers >= MINIMUM_SIGS, error::invalid_argument(ESIG_THRESHOLD_CONFIG));

// policy is to have at least m signers as auths on the account.
let len = vector::length(initial_authorities);
assert!(len >= MINIMUM_AUTH, error::invalid_argument(ETOO_FEW_AUTH));

let (fam, _, _) = ancestry::any_family_in_list(*initial_authorities);
assert!(!fam, error::invalid_argument(ESIGNERS_SYBIL));

}

/// convenience function to check if the account can be caged
/// after all the structs are in place
public entry fun finalize_and_cage(sig: &signer, initial_authorities: vector<address>, num_signers: u64) {
let addr = signer::address_of(sig);
assert!(community_wallet::is_init(addr), error::invalid_argument(ENO_CW_FLAG));

assert!(donor_voice_txs::is_liquidate_to_match_index(addr), error::invalid_argument(ENOT_MATCH_INDEX_LIQ));

multi_action::finalize_and_cage(sig, initial_authorities, num_signers);
community_wallet::set_comm_wallet(sig);

assert!(multisig_thresh(addr), error::invalid_argument(ESIG_THRESHOLD_RATIO));
assert!(!multisig_common_ancestry(addr), error::invalid_argument(ESIGNERS_SYBIL));
assert!(!multisig_common_ancestry(addr),
error::invalid_argument(ESIGNERS_SYBIL));
assert!(community_wallet::is_init(addr), error::invalid_argument(ENO_CW_FLAG));

}

Expand Down Expand Up @@ -192,7 +199,7 @@ module ol_framework::community_wallet_init {
n_of_m: u64,
vote_duration_epochs: u64
) {
assert!(n_of_m >= MINIMUM_SIGS , error::invalid_argument(ETOO_FEW_SIGNERS));
assert!(n_of_m >= MINIMUM_SIGS , error::invalid_argument(ETOO_FEW_AUTH));

let current_signers = multi_action::get_authorities(multisig_address);

Expand All @@ -204,7 +211,7 @@ module ol_framework::community_wallet_init {

// Verify the signers will not fall below the threshold the signers will fall below threshold
if (!is_add_operation) {
assert!((vector::length(&current_signers) - 1) > MINIMUM_AUTH, error::invalid_argument(ESIG_THRESHOLD));
assert!((vector::length(&current_signers) - 1) > MINIMUM_AUTH, error::invalid_argument(ESIG_THRESHOLD_CONFIG));
};

multi_action::propose_governance(
Expand Down
14 changes: 13 additions & 1 deletion framework/libra-framework/sources/ol_sources/epoch_boundary.move
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ module diem_framework::epoch_boundary {
// must be mainnet
assert!(!testnet::is_not_mainnet(), ETRIGGER_EPOCH_MAINNET);
// must get root permission from governance.move
system_addresses::assert_ol(framework_signer);
system_addresses::assert_diem_framework(framework_signer);
let _ = can_trigger(); // will abort if false

// update the state and flip the Bit
Expand All @@ -240,6 +240,18 @@ module diem_framework::epoch_boundary {
epoch_boundary(framework_signer, state.closing_epoch, 0);
}

// utility to use in smoke tests
public fun smoke_trigger_epoch(framework_signer: &signer) acquires BoundaryBit,
BoundaryStatus {
// cannot call thsi on mainnet
// only for smoke testing
assert!(testnet::is_not_mainnet(), 666);
// must get 0x1 sig from governance.move
system_addresses::assert_diem_framework(framework_signer);
let state = borrow_global_mut<BoundaryBit>(@ol_framework);
epoch_boundary(framework_signer, state.closing_epoch, 0);
}

#[view]
/// check to see if the epoch Boundary Bit is true
public fun can_trigger(): bool acquires BoundaryBit {
Expand Down
17 changes: 0 additions & 17 deletions framework/libra-framework/sources/ol_sources/ol_account.move
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,6 @@ module ol_framework::ol_account {
/// what limit should be set for new account creation while using transfer()
const MAX_COINS_FOR_INITIALIZE: u64 = 1000 * 1000000;

// Create a "caged" account, where there is no signer that can could
// new state, and only the existing state can be modified by modules. This
// is useful for multi_action.move
const CAGE_AUTH_KEY: vector<u8> = x"00000000000000000000000000000000000000000000000000000000000ca9ed";


struct BurnTracker has key {
prev_supply: u64,
Expand Down Expand Up @@ -105,18 +100,6 @@ module ol_framework::ol_account {
(resource_account_sig, cap)
}

/// Similar to a resource account, except that no SignerCapability is stored
// anywhere. State cannot be added, but only mutated by relevant modules
public(friend) fun cage_this_account(user: &signer): &signer {
account::rotate_authentication_key_internal(user, CAGE_AUTH_KEY);
user
}

#[view]
public fun is_cage(addr: address): bool {
account::get_authentication_key(addr) == CAGE_AUTH_KEY
}

fun create_impl(sender: &signer, maybe_new_user: address) {
let new_signer = account::create_account(maybe_new_user);
coin::register<LibraCoin>(&new_signer);
Expand Down
4 changes: 2 additions & 2 deletions framework/libra-framework/sources/ol_sources/safe.move
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ module ol_framework::safe {
/// init_gov fails gracefully if the governance is already initialized.
/// init_type will throw errors if the type is already initialized.

public fun init_payment_multisig(sponsor: &signer, init_signers: vector<address>, cfg_n_signers: u64) acquires RootMultiSigRegistry {
multi_action::init_gov(sponsor, cfg_n_signers, &init_signers);
public fun init_payment_multisig(sponsor: &signer) acquires RootMultiSigRegistry {
multi_action::init_gov(sponsor);
multi_action::init_type<PaymentType>(sponsor, true);
add_to_registry(signer::address_of(sponsor));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ module ol_framework::test_burn {

let (communityA, _cap) = ol_account::ol_create_resource_account(alice, b"0x1");
let addr_A = signer::address_of(&communityA);
community_wallet_init::init_community(&communityA, vals); // make all the vals signers
community_wallet_init::init_community(&communityA, vals, 2); // make all the vals signers

let (communityB, _cap) = ol_account::ol_create_resource_account(bob, b"0xdeadbeef");
let addr_B = signer::address_of(&communityB);
community_wallet_init::init_community(&communityB, vals); // make all the vals signers
community_wallet_init::init_community(&communityB, vals, 2); // make all the vals signers

let eve_donation_to_A = 75;
ol_account::transfer(eve, addr_A, eve_donation_to_A);
Expand Down Expand Up @@ -143,11 +143,11 @@ module ol_framework::test_burn {

let (communityA, _cap) = ol_account::ol_create_resource_account(alice, b"0x1");
let addr_A = signer::address_of(&communityA);
community_wallet_init::init_community(&communityA, vals); // make all the vals signers
community_wallet_init::init_community(&communityA, vals, 2); // make all the vals signers

let (communityB, _cap) = ol_account::ol_create_resource_account(bob, b"0xdeadbeef");
let addr_B = signer::address_of(&communityB);
community_wallet_init::init_community(&communityB, vals); // make all the vals signers
community_wallet_init::init_community(&communityB, vals, 2); // make all the vals signers

let eve_donation_to_A = 75;
ol_account::transfer(eve, addr_A, eve_donation_to_A);
Expand Down Expand Up @@ -253,11 +253,11 @@ module ol_framework::test_burn {

let (communityA, _cap) = ol_account::ol_create_resource_account(alice, b"0x1");
let addr_A = signer::address_of(&communityA);
community_wallet_init::init_community(&communityA, vals); // make all the vals signers
community_wallet_init::init_community(&communityA, vals, 2); // make all the vals signers

let (communityB, _cap) = ol_account::ol_create_resource_account(bob, b"0xdeadbeef");
let addr_B = signer::address_of(&communityB);
community_wallet_init::init_community(&communityB, vals); // make all the vals signers
community_wallet_init::init_community(&communityB, vals, 2); // make all the vals signers

let eve_donation_to_A = 75;
ol_account::transfer(eve, addr_A, eve_donation_to_A);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
assert!(community_wallet::is_init(community_wallet_address), 7357001); //TODO: find appropriate error codes

// the usual initialization should fix the structs
community_wallet_init::init_community(community, auths);
community_wallet_init::init_community(community, auths, 2);
// confirm the bug
assert!(!multisig_account::is_multisig(community_wallet_address), 7357002);

Expand All @@ -47,7 +47,7 @@
}

#[test(root = @ol_framework, alice = @0x1000a, bob = @0x1000b, carol = @0x1000c, dave = @0x1000d)]
#[expected_failure(abort_code = 196618, location = 0x1::ol_account)]
#[expected_failure(abort_code = 196619, location = 0x1::ol_account)]
fun cw_sponsor_cant_transfer(root: &signer, alice: &signer, bob: &signer, carol: &signer, dave: &signer,) {
mock::genesis_n_vals(root, 4);
mock::ol_initialize_coin_and_fund_vals(root, 1000, true);
Expand All @@ -62,7 +62,7 @@
// Alice is a vanilla account and should be able to transfer
ol_account::transfer(alice, @0x1000b, 100);

community_wallet_init::init_community(alice, signers);
community_wallet_init::init_community(alice, signers, 2);

// After being set as a community wallet, the owner loses control over the wallet
ol_account::transfer(alice, @0x1000b, 100);
Expand All @@ -82,7 +82,7 @@
vector::push_back(&mut signers, signer::address_of(bob));
vector::push_back(&mut signers, signer::address_of(carol));

community_wallet_init::init_community(alice, signers);
community_wallet_init::init_community(alice, signers, 2);

}

Expand Down Expand Up @@ -112,7 +112,7 @@
vector::push_back(&mut signers, signer::address_of(dave));
vector::push_back(&mut signers, signer::address_of(eve));

community_wallet_init::init_community(alice, signers);
community_wallet_init::init_community(alice, signers, 2);

// fix it by calling multi auth:
community_wallet_init::finalize_and_cage(alice, signers, 2);
Expand Down Expand Up @@ -187,7 +187,7 @@
vector::push_back(&mut signers, signer::address_of(dave));
vector::push_back(&mut signers, signer::address_of(eve));

community_wallet_init::init_community(alice, signers);
community_wallet_init::init_community(alice, signers, 2);

// fix it by calling multi auth:
community_wallet_init::finalize_and_cage(alice, signers, 2);
Expand Down Expand Up @@ -237,7 +237,6 @@

}


#[test(root = @ol_framework, alice = @0x1000a, bob = @0x1000b)]
#[expected_failure(abort_code = 65542, location = 0x1::community_wallet_init)]
fun cw_init_with_n_and_m_below_minimum_sigs(root: &signer, alice: &signer, bob: &signer) {
Expand All @@ -254,7 +253,7 @@

community_wallet_init::migrate_community_wallet_account(root, alice);

donor_voice_txs::make_donor_voice(alice, signers, 1);
donor_voice_txs::test_helper_make_donor_voice(root, alice);

// try to cage the address by calling multi auth
community_wallet_init::finalize_and_cage(alice, signers, 1);
Expand All @@ -278,7 +277,7 @@

community_wallet_init::migrate_community_wallet_account(root, alice);

donor_voice_txs::make_donor_voice(alice, signers, 1);
donor_voice_txs::test_helper_make_donor_voice(root, alice);

// try to cage the address by calling multi auth
community_wallet_init::finalize_and_cage(alice, signers, 1);
Expand All @@ -302,7 +301,7 @@

community_wallet_init::migrate_community_wallet_account(root, alice);

donor_voice_txs::make_donor_voice(alice, signers, 1);
donor_voice_txs::test_helper_make_donor_voice(root, alice);

// try to cage the address by calling multi auth
community_wallet_init::finalize_and_cage(alice, signers, 1);
Expand Down
Loading

0 comments on commit 8775cbf

Please sign in to comment.