Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[move] commit-reveal of PoF bids #318

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
d6e050e
APIs for reading/setting bids with estimated net_reward.
0o-de-lally Jun 13, 2024
ac3f2a2
make bidding by net reward the default
0o-de-lally Jun 13, 2024
64a5323
implements minimal commit-reveal for bids
0o-de-lally Sep 18, 2024
fcf0c7f
test ability to read messages
0o-de-lally Sep 18, 2024
35f0a0d
add external tx api
0o-de-lally Sep 18, 2024
c2139ab
patch epoch help for tests
0o-de-lally Sep 18, 2024
98595b2
add commit and reveal tests
0o-de-lally Sep 18, 2024
87bd97a
reveal test passing, and checking correct aborts
0o-de-lally Sep 18, 2024
4ee76ea
patch block.move on epoch interval adjustment
0o-de-lally Sep 18, 2024
66ba523
adds convenience function to check remaining seconds in epoch, and im…
0o-de-lally Sep 18, 2024
16209ab
finally implement the hash commit
0o-de-lally Sep 18, 2024
d207ee8
remove signed message state, don't require signing keypair to be of t…
0o-de-lally Sep 19, 2024
814dbe4
randomness test was a noop
0o-de-lally Sep 19, 2024
a0dc6e2
storing entry_fee instead of net reward
0o-de-lally Sep 25, 2024
247a9d1
check for current bidding, and save historical
0o-de-lally Sep 25, 2024
053fbce
sorting of list of secret bids
0o-de-lally Sep 26, 2024
5125830
major surgery to replace secret_bid with pof auction state 16/383 tes…
0o-de-lally Sep 26, 2024
933a690
patching tests
0o-de-lally Sep 27, 2024
1a32338
create some default supply constants for testsuite
0o-de-lally Sep 27, 2024
aad93fa
standardize mock supply initialization, epoch burn sanity tested
0o-de-lally Sep 27, 2024
2471ce9
patch track_fees test
0o-de-lally Sep 27, 2024
e89dbb5
patch burn_tracker_increment
0o-de-lally Sep 27, 2024
8b799d2
patch test_epoch_drip
0o-de-lally Sep 27, 2024
45daa9e
patch safe_root_security_fee
0o-de-lally Sep 27, 2024
292b658
patch reward_happy_case
0o-de-lally Sep 27, 2024
d009df2
patch epoch drip again
0o-de-lally Sep 27, 2024
00fcf1b
patch donor voice tests, had an incorrect assertion
0o-de-lally Sep 27, 2024
5b7bb9f
remove retract bid test
0o-de-lally Sep 27, 2024
1e39c2b
refactor jailing to happen in musical chairs
0o-de-lally Sep 30, 2024
e982022
add sanity test for bidders qualifying
0o-de-lally Sep 30, 2024
520957c
cleanup
0o-de-lally Sep 30, 2024
f136275
all tests passing
0o-de-lally Sep 30, 2024
fa1cf01
Merge branch 'main' into secret-bid
0o-de-lally Jan 7, 2025
7d83cc6
clippy
0o-de-lally Jan 7, 2025
119d6c7
fmt
0o-de-lally Jan 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions framework/cached-packages/src/libra_framework_sdk_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,12 @@ pub enum EntryFunctionCall {
epoch_expiry: u64,
},

/// update the bid using estimated net reward instead of the internal bid variables
ProofOfFeePofUpdateBidNetReward {
net_reward: u64,
epoch_expiry: u64,
},

/// This function initiates governance for the multisig. It is called by the sponsor address, and is only callable once.
/// init_gov fails gracefully if the governance is already initialized.
/// init_type will throw errors if the type is already initialized.
Expand Down Expand Up @@ -808,6 +814,10 @@ impl EntryFunctionCall {
ProofOfFeePofUpdateBid { bid, epoch_expiry } => {
proof_of_fee_pof_update_bid(bid, epoch_expiry)
}
ProofOfFeePofUpdateBidNetReward {
net_reward,
epoch_expiry,
} => proof_of_fee_pof_update_bid_net_reward(net_reward, epoch_expiry),
SafeInitPaymentMultisig { authorities } => safe_init_payment_multisig(authorities),
SlowWalletSmokeTestVmUnlock {
user_addr,
Expand Down Expand Up @@ -2147,6 +2157,28 @@ pub fn proof_of_fee_pof_update_bid(bid: u64, epoch_expiry: u64) -> TransactionPa
))
}

/// update the bid using estimated net reward instead of the internal bid variables
pub fn proof_of_fee_pof_update_bid_net_reward(
net_reward: u64,
epoch_expiry: u64,
) -> TransactionPayload {
TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
AccountAddress::new([
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,
0, 0, 0, 1,
]),
ident_str!("proof_of_fee").to_owned(),
),
ident_str!("pof_update_bid_net_reward").to_owned(),
vec![],
vec![
bcs::to_bytes(&net_reward).unwrap(),
bcs::to_bytes(&epoch_expiry).unwrap(),
],
))
}

/// This function initiates governance for the multisig. It is called by the sponsor address, and is only callable once.
/// init_gov fails gracefully if the governance is already initialized.
/// init_type will throw errors if the type is already initialized.
Expand Down Expand Up @@ -3105,6 +3137,19 @@ mod decoder {
}
}

pub fn proof_of_fee_pof_update_bid_net_reward(
payload: &TransactionPayload,
) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::ProofOfFeePofUpdateBidNetReward {
net_reward: bcs::from_bytes(script.args().first()?).ok()?,
epoch_expiry: bcs::from_bytes(script.args().get(1)?).ok()?,
})
} else {
None
}
}

pub fn safe_init_payment_multisig(payload: &TransactionPayload) -> Option<EntryFunctionCall> {
if let TransactionPayload::EntryFunction(script) = payload {
Some(EntryFunctionCall::SafeInitPaymentMultisig {
Expand Down Expand Up @@ -3480,6 +3525,10 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy<EntryFunctionDecoderMa
"proof_of_fee_pof_update_bid".to_string(),
Box::new(decoder::proof_of_fee_pof_update_bid),
);
map.insert(
"proof_of_fee_pof_update_bid_net_reward".to_string(),
Box::new(decoder::proof_of_fee_pof_update_bid_net_reward),
);
map.insert(
"safe_init_payment_multisig".to_string(),
Box::new(decoder::safe_init_payment_multisig),
Expand Down
37 changes: 4 additions & 33 deletions framework/drop-user-tools/last_goodbye.move
Original file line number Diff line number Diff line change
Expand Up @@ -95,26 +95,15 @@ module ol_framework::last_goodbye {
return
};

// print(&2000);

// dangling state in receipts could allow user to participate in community
// wallets
// print(&2002);

receipts::hard_fork_sanitize(vm, user);
// print(&2003);

jail::garbage_collection(user);
// print(&2004);

vouch::hard_fork_sanitize(vm, user);
// print(&2005);

let locked = slow_wallet::hard_fork_sanitize(vm, user);
if (locked > 0) {
print(&user_addr);
print(&locked);
};

let _locked = slow_wallet::hard_fork_sanitize(vm, user);


// remove a pledge account if there is one, so that coins there are
// not dangling
Expand All @@ -138,20 +127,11 @@ module ol_framework::last_goodbye {
let good_capital = option::extract(&mut all_coins_opt);
burn::burn_and_track(good_capital);
};
// print(&2001);

option::destroy_none(all_coins_opt);


// if (coin_val > 0) {
// print(&user_addr);
// print(&coin_val);
// };


let auth_key = b"Oh, is it too late now to say sorry?";
vector::trim(&mut auth_key, 32);
// print(&2008);

// Oh, is it too late now to say sorry?
// Yeah, I know that I let you down
Expand All @@ -161,22 +141,17 @@ module ol_framework::last_goodbye {
// another function can be called to drop the account::Account completely
// and then the offline db tools can safely remove the key from db.
account::rotate_authentication_key_internal(user, auth_key);
// print(&2009);

}

fun last_goodbye(vm: &signer, user: &signer) {
// print(&10000);
let addr = signer::address_of(user);
if (!account::exists_at(addr)) {
// print(&addr);
return
};

let auth_orig = account::get_authentication_key(addr);
// print(&10001);
dont_think_twice_its_alright(vm, user);
// print(&10002);

let new_auth = account::get_authentication_key(addr);
// if the account is a validator they stay on ark a
Expand All @@ -189,12 +164,8 @@ module ol_framework::last_goodbye {
// Just hear this and then I'll go
// You gave me more to live for
// More than you'll ever know
// print(&10003);
account::hard_fork_drop(vm, user);
// print(&10004);


// print(&@0xDEAD);
account::hard_fork_drop(vm, user);
}

#[test_only]
Expand Down
4 changes: 2 additions & 2 deletions framework/drop-user-tools/last_goodbye.test.move
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module ol_framework::test_last_goodbye {

let _vals = mock::genesis_n_vals(framework, 1);
// we are at epoch 0
let epoch = reconfiguration::get_current_epoch();
let epoch = reconfiguration::current_epoch();
assert!(epoch == 0, 7357001);

last_goodbye::danger_test_last_goodby(vm, bob);
Expand All @@ -23,7 +23,7 @@ module ol_framework::test_last_goodbye {
last_goodbye::danger_user_gc(vm, bob);

mock::trigger_epoch(framework); // epoch 1
let epoch = reconfiguration::get_current_epoch();
let epoch = reconfiguration::current_epoch();
assert!(epoch == 1, 7357002);

let vals = stake::get_current_validators();
Expand Down
9 changes: 0 additions & 9 deletions framework/drop-user-tools/pledge_accounts_with_gc.move
Original file line number Diff line number Diff line change
Expand Up @@ -336,11 +336,7 @@

fun garbage_collection(pledge_account: &address): u64 acquires MyPledges,
BeneficiaryPolicy {
// print(&5000);
let pledge_list = get_user_pledges(pledge_account);
// print(&pledge_list);
// print(&5001);
// print(pledge_account);
let coins = 0;
let i = 0;
while (i < vector::length(&pledge_list)) {
Expand All @@ -349,14 +345,10 @@
let hundred_pct = fixed_point64::create_from_rational(1,1);
let c = withdraw_pct_from_one_pledge_account(bene,
pledge_account, &hundred_pct);
// print(&c);

if (option::is_some(&c)) {
// print(&5002);

let coin = option::extract(&mut c);
coins = coins + coin::value(&coin);
// print(&coin);
burn::burn_and_track(coin);
};
option::destroy_none(c);
Expand All @@ -367,7 +359,6 @@
pledge_account);

if (is_found) {
// print(&5006);
vector::remove(&mut bene_state.pledgers, idx);
};
i = i + 1;
Expand Down
23 changes: 9 additions & 14 deletions framework/libra-framework/sources/block.move
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ module diem_framework::block {
system_addresses::assert_diem_framework(diem_framework);
assert!(epoch_interval_microsecs > 0, error::invalid_argument(EZERO_EPOCH_INTERVAL));

reconfiguration::set_epoch_interval(diem_framework, epoch_interval_microsecs);

move_to<BlockResource>(
diem_framework,
BlockResource {
Expand All @@ -81,28 +83,24 @@ module diem_framework::block {
/// Update the epoch interval.
/// Can only be called as part of the Diem governance proposal process established by the DiemGovernance module.
public(friend) fun update_epoch_interval_microsecs(
_diem_framework: &signer,
diem_framework: &signer,
new_epoch_interval: u64,
) acquires BlockResource {
//system_addresses::assert_vm(diem_framework); //TODO: remove after testing fork
system_addresses::assert_diem_framework(diem_framework); //TODO: remove after testing fork
assert!(new_epoch_interval > 0, error::invalid_argument(EZERO_EPOCH_INTERVAL));

let block_resource = borrow_global_mut<BlockResource>(@diem_framework);
let old_epoch_interval = block_resource.epoch_interval;
block_resource.epoch_interval = new_epoch_interval;

reconfiguration::set_epoch_interval(diem_framework, new_epoch_interval);

event::emit_event<UpdateEpochIntervalEvent>(
&mut block_resource.update_epoch_interval_events,
UpdateEpochIntervalEvent { old_epoch_interval, new_epoch_interval },
);
}

#[view]
/// Return epoch interval in seconds.
public fun get_epoch_interval_secs(): u64 acquires BlockResource {
borrow_global<BlockResource>(@diem_framework).epoch_interval / 1000000
}

/// Set the metadata for the current block.
/// The runtime always runs this before executing the transactions in a block.
fun block_prologue(
Expand Down Expand Up @@ -244,16 +242,14 @@ module diem_framework::block {
};

if (timestamp - reconfiguration::last_reconfiguration_time() >= block_metadata_ref.epoch_interval) {
// if (!features::epoch_trigger_enabled() ||
// testnet::is_testnet()) {
if (testnet::is_testnet()) {
epoch_boundary::epoch_boundary(
vm,
reconfiguration::get_current_epoch(),
reconfiguration::current_epoch(),
round
);
} else {
epoch_boundary::enable_epoch_trigger(vm, reconfiguration::get_current_epoch());
epoch_boundary::enable_epoch_trigger(vm, reconfiguration::current_epoch());
}
}
}
Expand Down Expand Up @@ -284,8 +280,7 @@ module diem_framework::block {
}

#[test(diem_framework = @diem_framework, account = @0x123)]
//#[expected_failure(abort_code = 0x50003, location = diem_framework::system_addresses)] //TODO: remove after testing fork
#[ignore] //TODO: remove after testing fork
#[expected_failure(abort_code = 0x50003, location = diem_framework::system_addresses)]
public entry fun test_update_epoch_interval_unauthorized_should_fail(
diem_framework: signer,
account: signer,
Expand Down
4 changes: 0 additions & 4 deletions framework/libra-framework/sources/block.spec.move
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@ spec diem_framework::block {
ensures block_resource.epoch_interval == new_epoch_interval;
}

spec get_epoch_interval_secs(): u64 {
aborts_if !exists<BlockResource>(@diem_framework);
}

spec get_current_block_height(): u64 {
aborts_if !exists<BlockResource>(@diem_framework);
}
Expand Down
5 changes: 4 additions & 1 deletion framework/libra-framework/sources/genesis.move
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ module diem_framework::genesis {
use ol_framework::ol_account;
use ol_framework::musical_chairs;
use ol_framework::proof_of_fee;
use ol_framework::secret_bid;
use ol_framework::slow_wallet;
use ol_framework::libra_coin;
use ol_framework::infra_escrow;
Expand Down Expand Up @@ -256,7 +257,9 @@ module diem_framework::genesis {
// default 90% to align with thermostatic rule in the PoF paper.
// otherwise the thermostatic rule starts kicking-in immediately
let sig = create_signer(validator.validator_config.owner_address);
proof_of_fee::pof_update_bid(&sig, 0900, 1000); // make the genesis

// genesis validators need a bid struct
secret_bid::genesis_helper(diem_framework, &sig, 100);

if (testnet::is_not_mainnet()) {
// TODO: this is for testnet purposes only
Expand Down
2 changes: 2 additions & 0 deletions framework/libra-framework/sources/ol_sources/burn.move
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ module ol_framework::burn {
friend ol_framework::pledge_accounts;
friend ol_framework::make_whole;

#[test_only]
friend ol_framework::mock;
#[test_only]
friend ol_framework::test_burn;
#[test_only]
Expand Down
Loading
Loading