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

burn implemented #4640

Merged
merged 11 commits into from
May 6, 2024
8 changes: 8 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions execution_engine/src/runtime/mint_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ where
fn allow_unrestricted_transfers(&self) -> bool {
self.context.engine_config().allow_unrestricted_transfers()
}

/// Validate URef against context access rights.
fn is_valid_uref(&self, uref: &URef) -> bool {
self.context.access_rights().has_access_rights_to_uref(uref)
}
}

// TODO: update Mint + StorageProvider to better handle errors
Expand Down
8 changes: 8 additions & 0 deletions execution_engine/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,14 @@ where
let result: Result<(), mint::Error> = mint_runtime.reduce_total_supply(amount);
CLValue::from_t(result).map_err(Self::reverter)
})(),
mint::METHOD_BURN => (|| {
mint_runtime.charge_system_contract_call(mint_costs.burn)?;

let purse: URef = Self::get_named_argument(runtime_args, mint::ARG_PURSE)?;
let amount: U512 = Self::get_named_argument(runtime_args, mint::ARG_AMOUNT)?;
let result: Result<(), mint::Error> = mint_runtime.burn(purse, amount);
CLValue::from_t(result).map_err(Self::reverter)
})(),
// Type: `fn create() -> URef`
mint::METHOD_CREATE => (|| {
mint_runtime.charge_system_contract_call(mint_costs.create)?;
Expand Down
4 changes: 2 additions & 2 deletions execution_engine/src/runtime_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ where
}

/// Validates whether keys used in the `value` are not forged.
fn validate_value(&self, value: &StoredValue) -> Result<(), ExecError> {
pub(crate) fn validate_value(&self, value: &StoredValue) -> Result<(), ExecError> {
match value {
StoredValue::CLValue(cl_value) => self.validate_cl_value(cl_value),
StoredValue::NamedKey(named_key_value) => {
Expand Down Expand Up @@ -765,7 +765,7 @@ where
}

/// Validates if a [`Key`] refers to a [`URef`] and has a write bit set.
fn validate_writeable(&self, key: &Key) -> Result<(), ExecError> {
pub(crate) fn validate_writeable(&self, key: &Key) -> Result<(), ExecError> {
if self.is_writeable(key) {
Ok(())
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -705,8 +705,8 @@ where
/// Panics if the total supply can't be found.
pub fn total_supply(
&self,
maybe_post_state: Option<Digest>,
protocol_version: ProtocolVersion,
maybe_post_state: Option<Digest>,
) -> U512 {
let post_state = maybe_post_state
.or(self.post_state_hash)
Expand Down Expand Up @@ -759,7 +759,7 @@ where
let post_state = maybe_post_state
.or(self.post_state_hash)
.expect("builder must have a post-state hash");
let total_supply = self.total_supply(Some(post_state), protocol_version);
let total_supply = self.total_supply(protocol_version, Some(post_state));
let rate = self.round_seigniorage_rate(Some(post_state), protocol_version);
rate.checked_mul(&Ratio::from(total_supply))
.map(|ratio| ratio.to_integer())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn test_burning_fees(
.expect("should have rewards purse");
let rewards_purse_uref = rewards_purse_key.into_uref().expect("should be uref");
assert_eq!(builder.get_purse_balance(rewards_purse_uref), U512::zero());
let total_supply_before = builder.total_supply(None, protocol_version);
let total_supply_before = builder.total_supply(protocol_version, None);
// TODO: reevaluate this test, considering fee / refund / pricing modes
// let exec_request_1 = ExecuteRequestBuilder::module_bytes(
// *DEFAULT_ADMIN_ACCOUNT_ADDR,
Expand All @@ -139,7 +139,7 @@ fn test_burning_fees(
// U512::zero(),
// "proposer should not receive anything",
// );
let total_supply_after = builder.total_supply(None, protocol_version);
let total_supply_after = builder.total_supply(protocol_version, None);
assert_eq!(
total_supply_before - total_supply_after,
expected_burn_amount,
Expand All @@ -149,11 +149,11 @@ fn test_burning_fees(
TransferRequestBuilder::new(MINIMUM_ACCOUNT_CREATION_BALANCE, *ACCOUNT_1_ADDR)
.with_initiator(*DEFAULT_ADMIN_ACCOUNT_ADDR)
.build();
let total_supply_before = builder.total_supply(None, protocol_version);
let total_supply_before = builder.total_supply(protocol_version, None);
builder
.transfer_and_commit(transfer_request)
.expect_success();
let total_supply_after = builder.total_supply(None, protocol_version);
let total_supply_after = builder.total_supply(protocol_version, None);

match fee_handling {
FeeHandling::PayToProposer | FeeHandling::Accumulate | FeeHandling::NoFee => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn should_not_distribute_rewards_but_compute_next_set() {

let protocol_version = DEFAULT_PROTOCOL_VERSION;
// initial token supply
let initial_supply = builder.total_supply(None, protocol_version);
let initial_supply = builder.total_supply(protocol_version, None);

for _ in 0..3 {
builder.distribute(
Expand Down Expand Up @@ -101,7 +101,7 @@ fn should_not_distribute_rewards_but_compute_next_set() {
era_info
);

let total_supply_after_distribution = builder.total_supply(None, protocol_version);
let total_supply_after_distribution = builder.total_supply(protocol_version, None);
assert_eq!(
initial_supply, total_supply_after_distribution,
"total supply of tokens should not increase after an auction is ran"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ fn withdraw_bid(
) {
let auction = builder.get_auction_contract_hash();
let withdraw_bid_args = runtime_args! {
auction::ARG_PUBLIC_KEY => validator,
auction::ARG_AMOUNT => amount,
ARG_PUBLIC_KEY => validator,
ARG_AMOUNT => amount,
};
let withdraw_bid_request = ExecuteRequestBuilder::contract_call_by_hash(
sender,
Expand All @@ -118,9 +118,9 @@ fn undelegate(
) {
let auction = builder.get_auction_contract_hash();
let undelegate_args = runtime_args! {
auction::ARG_DELEGATOR => delegator,
auction::ARG_VALIDATOR => validator,
auction::ARG_AMOUNT => amount,
ARG_DELEGATOR => delegator,
ARG_VALIDATOR => validator,
ARG_AMOUNT => amount,
};
let undelegate_request = ExecuteRequestBuilder::contract_call_by_hash(
sender,
Expand Down Expand Up @@ -256,7 +256,7 @@ fn should_distribute_delegation_rate_zero() {

let protocol_version = DEFAULT_PROTOCOL_VERSION;
// initial token supply
let initial_supply = builder.total_supply(None, protocol_version);
let initial_supply = builder.total_supply(protocol_version, None);
let total_payout = builder.base_round_reward(None, protocol_version);
let expected_total_reward = *GENESIS_ROUND_SEIGNIORAGE_RATE * initial_supply;
let expected_total_reward_integer = expected_total_reward.to_integer();
Expand Down Expand Up @@ -524,7 +524,7 @@ fn should_withdraw_bids_after_distribute() {
let total_payout = builder.base_round_reward(None, protocol_version);

// initial token supply
let initial_supply = builder.total_supply(None, protocol_version);
let initial_supply = builder.total_supply(protocol_version, None);
let rate = builder.round_seigniorage_rate(None, protocol_version);

let expected_total_reward = rate * initial_supply;
Expand Down Expand Up @@ -830,7 +830,7 @@ fn should_distribute_rewards_after_restaking_delegated_funds() {

let protocol_version = DEFAULT_PROTOCOL_VERSION;
// initial token supply
let initial_supply = builder.total_supply(None, protocol_version);
let initial_supply = builder.total_supply(protocol_version, None);
let initial_rate = builder.round_seigniorage_rate(None, protocol_version);
let initial_round_reward = builder.base_round_reward(None, protocol_version);

Expand Down Expand Up @@ -978,7 +978,7 @@ fn should_distribute_rewards_after_restaking_delegated_funds() {
));

// Next round of rewards
let updated_supply = builder.total_supply(None, protocol_version);
let updated_supply = builder.total_supply(protocol_version, None);
assert!(updated_supply > total_supply);
total_supply = updated_supply;

Expand Down Expand Up @@ -1151,7 +1151,7 @@ fn should_distribute_delegation_rate_half() {

let protocol_version = DEFAULT_PROTOCOL_VERSION;
// initial token supply
let initial_supply = builder.total_supply(None, protocol_version);
let initial_supply = builder.total_supply(protocol_version, None);
let total_payout = builder.base_round_reward(None, protocol_version);
let expected_total_reward = *GENESIS_ROUND_SEIGNIORAGE_RATE * initial_supply;
let expected_total_reward_integer = expected_total_reward.to_integer();
Expand Down Expand Up @@ -1383,7 +1383,7 @@ fn should_distribute_delegation_rate_full() {

let protocol_version = DEFAULT_PROTOCOL_VERSION;
// initial token supply
let initial_supply = builder.total_supply(None, protocol_version);
let initial_supply = builder.total_supply(protocol_version, None);
let expected_total_reward = *GENESIS_ROUND_SEIGNIORAGE_RATE * initial_supply;
let expected_total_reward_integer = expected_total_reward.to_integer();

Expand Down Expand Up @@ -1565,7 +1565,7 @@ fn should_distribute_uneven_delegation_rate_zero() {

let protocol_version = DEFAULT_PROTOCOL_VERSION;
// initial token supply
let initial_supply = builder.total_supply(None, protocol_version);
let initial_supply = builder.total_supply(protocol_version, None);
let total_payout = builder.base_round_reward(None, protocol_version);
let expected_total_reward = *GENESIS_ROUND_SEIGNIORAGE_RATE * initial_supply;
let expected_total_reward_integer = expected_total_reward.to_integer();
Expand Down Expand Up @@ -1868,7 +1868,7 @@ fn should_distribute_with_multiple_validators_and_delegators() {

let protocol_version = DEFAULT_PROTOCOL_VERSION;
// initial token supply
let initial_supply = builder.total_supply(None, protocol_version);
let initial_supply = builder.total_supply(protocol_version, None);
let total_payout = builder.base_round_reward(None, protocol_version);
let expected_total_reward = *GENESIS_ROUND_SEIGNIORAGE_RATE * initial_supply;
let expected_total_reward_integer = expected_total_reward.to_integer();
Expand Down Expand Up @@ -2200,7 +2200,7 @@ fn should_distribute_with_multiple_validators_and_shared_delegator() {

let protocol_version = DEFAULT_PROTOCOL_VERSION;
// initial token supply
let initial_supply = builder.total_supply(None, protocol_version);
let initial_supply = builder.total_supply(protocol_version, None);
let total_payout = builder.base_round_reward(None, protocol_version);
let expected_total_reward = *GENESIS_ROUND_SEIGNIORAGE_RATE * initial_supply;
let expected_total_reward_integer = expected_total_reward.to_integer();
Expand Down Expand Up @@ -2557,13 +2557,13 @@ fn should_increase_total_supply_after_distribute() {

let protocol_version = DEFAULT_PROTOCOL_VERSION;
// initial token supply
let initial_supply = builder.total_supply(None, protocol_version);
let initial_supply = builder.total_supply(protocol_version, None);

for request in post_genesis_requests {
builder.exec(request).commit().expect_success();
}

let post_genesis_supply = builder.total_supply(None, protocol_version);
let post_genesis_supply = builder.total_supply(protocol_version, None);

assert_eq!(
initial_supply, post_genesis_supply,
Expand All @@ -2576,7 +2576,7 @@ fn should_increase_total_supply_after_distribute() {
timestamp_millis += TIMESTAMP_MILLIS_INCREMENT;
}

let post_auction_supply = builder.total_supply(None, protocol_version);
let post_auction_supply = builder.total_supply(protocol_version, None);
assert_eq!(
initial_supply, post_auction_supply,
"total supply should remain unchanged regardless of auction"
Expand All @@ -2603,7 +2603,7 @@ fn should_increase_total_supply_after_distribute() {

builder.exec(distribute_request).expect_success().commit();

let post_distribute_supply = builder.total_supply(None, protocol_version);
let post_distribute_supply = builder.total_supply(protocol_version, None);
assert!(
initial_supply < post_distribute_supply,
"total supply should increase after distribute ({} >= {})",
Expand Down Expand Up @@ -2737,13 +2737,13 @@ fn should_not_create_purses_during_distribute() {

let protocol_version = DEFAULT_PROTOCOL_VERSION;
// initial token supply
let initial_supply = builder.total_supply(None, protocol_version);
let initial_supply = builder.total_supply(protocol_version, None);

for request in post_genesis_requests {
builder.exec(request).commit().expect_success();
}

let post_genesis_supply = builder.total_supply(None, protocol_version);
let post_genesis_supply = builder.total_supply(protocol_version, None);

assert_eq!(
initial_supply, post_genesis_supply,
Expand All @@ -2756,7 +2756,7 @@ fn should_not_create_purses_during_distribute() {
timestamp_millis += TIMESTAMP_MILLIS_INCREMENT;
}

let post_auction_supply = builder.total_supply(None, protocol_version);
let post_auction_supply = builder.total_supply(protocol_version, None);
assert_eq!(
initial_supply, post_auction_supply,
"total supply should remain unchanged regardless of auction"
Expand Down Expand Up @@ -2789,7 +2789,7 @@ fn should_not_create_purses_during_distribute() {
number_of_purses_before_distribute
);

let post_distribute_supply = builder.total_supply(None, protocol_version);
let post_distribute_supply = builder.total_supply(protocol_version, None);
assert!(
initial_supply < post_distribute_supply,
"total supply should increase after distribute ({} >= {})",
Expand Down Expand Up @@ -2899,7 +2899,7 @@ fn should_distribute_delegation_rate_full_after_upgrading() {

let protocol_version = DEFAULT_PROTOCOL_VERSION;
// initial token supply
let initial_supply = builder.total_supply(None, protocol_version);
let initial_supply = builder.total_supply(protocol_version, None);
let expected_total_reward_before = *GENESIS_ROUND_SEIGNIORAGE_RATE * initial_supply;
let expected_total_reward_integer = expected_total_reward_before.to_integer();

Expand Down Expand Up @@ -2985,7 +2985,7 @@ fn should_distribute_delegation_rate_full_after_upgrading() {

builder.upgrade(&mut upgrade_request);

let initial_supply = builder.total_supply(None, protocol_version);
let initial_supply = builder.total_supply(protocol_version, None);

for _ in 0..5 {
builder.advance_era();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ fn should_track_total_token_supply_in_mint() {

builder.run_genesis(genesis_request);

let total_supply = builder.total_supply(None, protocol_version);
let total_supply = builder.total_supply(protocol_version, None);

let expected_balance: U512 = accounts.iter().map(|item| item.balance().value()).sum();
let expected_staked_amount: U512 = accounts
Expand Down
Loading
Loading