Skip to content

Commit

Permalink
WIP debugging supply overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Oct 26, 2023
1 parent 2c5e0ba commit 738359c
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 11 deletions.
8 changes: 7 additions & 1 deletion framework/libra-framework/sources/ol_sources/libra_coin.move
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ module ol_framework::gas_coin {
use std::signer;
use std::vector;
use std::option::{Self, Option};
// use diem_std::debug::print;

use diem_framework::coin::{Self, MintCapability, BurnCapability};
use diem_framework::system_addresses;
Expand All @@ -129,12 +130,16 @@ module ol_framework::gas_coin {
friend diem_framework::genesis;
friend ol_framework::genesis_migration;

const MAX_U64: u128 = 18446744073709551615;

/// Account does not have mint capability
const ENO_CAPABILITIES: u64 = 1;
/// Mint capability has already been delegated to this specified address
const EALREADY_DELEGATED: u64 = 2;
/// Cannot find delegation of mint capability to this account
const EDELEGATION_NOT_FOUND: u64 = 3;
/// Supply somehow above MAX_U64
const ESUPPLY_OVERFLOW: u64 = 4;

struct LibraCoin has key {}

Expand Down Expand Up @@ -258,7 +263,7 @@ module ol_framework::gas_coin {
let supply_opt = coin::supply<LibraCoin>();
if (option::is_some(&supply_opt)) {
let value = *option::borrow(&supply_opt);
if (value == 0) return 0u64;
assert!(value <= MAX_U64, ESUPPLY_OVERFLOW);
return (value as u64)
};
0
Expand Down Expand Up @@ -332,6 +337,7 @@ module ol_framework::gas_coin {
dst_addr: address,
amount: u64,
) acquires MintCapStore {
let _s = supply(); // check we didn't overflow supply

let account_addr = signer::address_of(root);

Expand Down
11 changes: 5 additions & 6 deletions framework/libra-framework/sources/ol_sources/mock.move
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ module ol_framework::mock {
use ol_framework::musical_chairs;
use ol_framework::globals;
use diem_framework::block;
// use diem_framework::chain_status;

use diem_std::debug::print;

const ENO_GENESIS_END_MARKER: u64 = 1;
const EDID_NOT_ADVANCE_EPOCH: u64 = 1;
const EDID_NOT_ADVANCE_EPOCH: u64 = 2;
/// coin supply does not match expected
const ESUPPLY_MISMATCH: u64 = 3;

#[test_only]
public fun reset_val_perf_one(vm: &signer, addr: address) {
Expand Down Expand Up @@ -203,14 +205,13 @@ module ol_framework::mock {
let (burn_cap, mint_cap) = gas_coin::initialize_for_test_without_aggregator_factory(root);
coin::destroy_burn_cap(burn_cap);


transaction_fee::initialize_fee_collection_and_distribution(root, 0);

let initial_fees = 1000000 * 100; // coin scaling * 100 coins
let tx_fees = coin::test_mint(initial_fees, &mint_cap);
transaction_fee::vm_pay_fee(root, @ol_framework, tx_fees);
let supply_pre = gas_coin::supply();
assert!(supply_pre == initial_fees, 666);
assert!(supply_pre == initial_fees, ESUPPLY_MISMATCH);
gas_coin::test_set_final_supply(root, initial_fees);

mint_cap
Expand Down Expand Up @@ -311,7 +312,6 @@ module ol_framework::mock {
// genesis();

let set = genesis_n_vals(&root, 4);
print(&set);
assert!(vector::length(&set) == 4, 7357001);

let addr = vector::borrow(&set, 0);
Expand Down Expand Up @@ -362,5 +362,4 @@ module ol_framework::mock {
assert!(entry_fee == 999, 73570003);
assert!(median_bid == 3, 73570004);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ module ol_framework::ol_account {
if (exists<BurnTracker>(addr)) return;

let (_, total_balance) = balance(addr);

move_to(sig, BurnTracker {
prev_supply: gas_coin::supply(),
prev_balance: total_balance,
Expand Down
Binary file modified framework/releases/head.mrb
Binary file not shown.
4 changes: 2 additions & 2 deletions smoke-tests/src/libra_smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ impl LibraSmoke {
// the genesis does NOT mint by default to genesis validators
// 10,000 coins with 6 decimals precision
let mut pub_info = swarm.diem_public_info();
helpers::mint_libra(&mut pub_info, addr, 100_000_000_000).await.context("could not mint to account")?;
helpers::mint_libra(&mut pub_info, addr, 10_000_000).await.context("could not mint to account")?;

helpers::unlock_libra(&mut pub_info, addr, 100_000_000_000).await.context("could not unlock coins")?;
helpers::unlock_libra(&mut pub_info, addr, 10_000_000).await.context("could not unlock coins")?;

Ok(Self {
swarm,
Expand Down
3 changes: 2 additions & 1 deletion tools/tower/tests/tower_newbie.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anyhow::Context;
use libra_smoke_tests::libra_smoke::LibraSmoke;

use libra_txs::submit_transaction::Sender;
Expand Down Expand Up @@ -25,7 +26,7 @@ async fn tower_newbie() -> anyhow::Result<()> {
let mut s = Sender::from_app_cfg(&val_app_cfg, None).await?;
let res = s
.transfer(alice.child_0_owner.account, 10_000.0, false)
.await?
.await.context("could not create account")?
.unwrap();
assert!(res.info.status().is_success());

Expand Down
2 changes: 1 addition & 1 deletion tools/txs/tests/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async fn smoke_transfer_estimate() {
config_path: Some(d.path().to_owned().join("libra.yaml")),
url: Some(s.api_endpoint.clone()),
tx_profile: None,
tx_cost: Some(TxCost::default_baseline_cost()),
tx_cost: Some(TxCost::default_cheap_txs_cost()),
estimate_only: true,
};

Expand Down

0 comments on commit 738359c

Please sign in to comment.