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

EE-1221: Increase create purse / mint entry point cost #1326

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions execution_engine/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file. The format

### Changed
* Support building and testing using stable Rust.
* Changed price of `create_purse` to 2.5CSPR to discourage people from creating purses in the payment code.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "in the payment code" is confusing b/c it increases the price across the whole execution, including session code. Is that correct @mpapierski ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, but it was increased specifically to disallow creating those in the payment code.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the comment makes it sound as if the cost is increased only in the payment code. I don't think the last part needs to be included in the changelog.




Expand Down
2 changes: 1 addition & 1 deletion execution_engine/src/shared/host_function_costs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const DEFAULT_ADD_COST: u32 = 5_800;
const DEFAULT_CALL_CONTRACT_COST: u32 = 4_500;
const DEFAULT_CALL_CONTRACT_ARGS_SIZE_WEIGHT: u32 = 420;

const DEFAULT_CREATE_PURSE_COST: u32 = 170_000;
const DEFAULT_CREATE_PURSE_COST: u32 = 2_500_000_000;
const DEFAULT_GET_BALANCE_COST: u32 = 3_800;
const DEFAULT_GET_BLOCKTIME_COST: u32 = 330;
const DEFAULT_GET_CALLER_COST: u32 = 380;
Expand Down
4 changes: 2 additions & 2 deletions execution_engine/src/shared/system_config/mint_costs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use datasize::DataSize;
use rand::{distributions::Standard, prelude::*, Rng};
use serde::{Deserialize, Serialize};

pub const DEFAULT_MINT_COST: u32 = 10_000;
pub const DEFAULT_MINT_COST: u32 = 2_500_000_000;
pub const DEFAULT_REDUCE_TOTAL_SUPPLY_COST: u32 = 10_000;
pub const DEFAULT_CREATE_COST: u32 = 10_000;
pub const DEFAULT_CREATE_COST: u32 = 2_500_000_000;
pub const DEFAULT_BALANCE_COST: u32 = 10_000;
pub const DEFAULT_TRANSFER_COST: u32 = 10_000;
pub const DEFAULT_READ_BASE_ROUND_REWARD_COST: u32 = 10_000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const CONTRACT_TRANSFER_PURSE_TO_ACCOUNT: &str = "transfer_purse_to_account.wasm
const FINALIZE_PAYMENT: &str = "finalize_payment.wasm";
const LOCAL_REFUND_PURSE: &str = "local_refund_purse";

const CREATE_PURSE_01: &str = "create_purse_01.wasm";
const ARG_PURSE_NAME: &str = "purse_name";

const ACCOUNT_ADDR: AccountHash = AccountHash::new([1u8; 32]);
pub const ARG_AMOUNT: &str = "amount";
pub const ARG_AMOUNT_SPENT: &str = "amount_spent";
Expand Down Expand Up @@ -94,11 +97,26 @@ fn finalize_payment_should_refund_to_specified_purse() {
ARG_REFUND_FLAG => refund_purse_flag,
ARG_AMOUNT_SPENT => Option::<U512>::None,
ARG_ACCOUNT_KEY => Option::<AccountHash>::None,
ARG_PURSE_NAME => LOCAL_REFUND_PURSE,
};

builder.run_genesis(&DEFAULT_RUN_GENESIS_REQUEST);

let create_purse_request = {
ExecuteRequestBuilder::standard(
*DEFAULT_ACCOUNT_ADDR,
CREATE_PURSE_01,
runtime_args! {
ARG_PURSE_NAME => LOCAL_REFUND_PURSE,
},
)
.build()
};

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

let rewards_pre_balance = builder.get_proposer_purse_balance();

let payment_pre_balance = get_handle_payment_payment_purse_balance(&builder);
let refund_pre_balance =
get_named_account_balance(&builder, *DEFAULT_ACCOUNT_ADDR, LOCAL_REFUND_PURSE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ use casper_types::{account::AccountHash, runtime_args, RuntimeArgs, U512};
const CONTRACT_TRANSFER_PURSE_TO_ACCOUNT: &str = "transfer_purse_to_account.wasm";
const ACCOUNT_1_ADDR: AccountHash = AccountHash::new([1u8; 32]);
const ARG_PAYMENT_AMOUNT: &str = "payment_amount";
const CREATE_PURSE_01: &str = "create_purse_01.wasm";
const ARG_PURSE_NAME: &str = "purse_name";
const ARG_PURSE_NAME_1: &str = "purse_name_1";
const ARG_PURSE_NAME_2: &str = "purse_name_2";
const LOCAL_REFUND_PURSE_1: &str = "local_refund_purse_1";
const LOCAL_REFUND_PURSE_2: &str = "local_refund_purse_2";

#[ignore]
#[test]
Expand Down Expand Up @@ -55,20 +61,55 @@ fn transfer(builder: &mut InMemoryWasmTestBuilder, account_hash: AccountHash, am
}

fn refund_tests(builder: &mut InMemoryWasmTestBuilder, account_hash: AccountHash) {
let exec_request = {
let create_purse_request_1 = {
ExecuteRequestBuilder::standard(
account_hash,
CREATE_PURSE_01,
runtime_args! {
ARG_PURSE_NAME => LOCAL_REFUND_PURSE_1,
},
)
.build()
};

let create_purse_request_2 = {
ExecuteRequestBuilder::standard(
account_hash,
CREATE_PURSE_01,
runtime_args! {
ARG_PURSE_NAME => LOCAL_REFUND_PURSE_2,
},
)
.build()
};

builder
.exec(create_purse_request_1)
.expect_success()
.commit();
builder
.exec(create_purse_request_2)
.expect_success()
.commit();

let refund_purse_request = {
let deploy = DeployItemBuilder::new()
.with_address(account_hash)
.with_deploy_hash([2; 32])
.with_session_code("do_nothing.wasm", RuntimeArgs::default())
.with_payment_code(
"refund_purse.wasm",
runtime_args! { ARG_PAYMENT_AMOUNT => *DEFAULT_PAYMENT },
runtime_args! {
ARG_PAYMENT_AMOUNT => *DEFAULT_PAYMENT,
ARG_PURSE_NAME_1 => LOCAL_REFUND_PURSE_1,
ARG_PURSE_NAME_2 => LOCAL_REFUND_PURSE_2,
},
)
.with_authorization_keys(&[account_hash])
.build();

ExecuteRequestBuilder::new().push_deploy(deploy).build()
};

builder.exec(exec_request).expect_success().commit();
builder.exec(refund_purse_request).expect_success().commit();
}
6 changes: 3 additions & 3 deletions resources/local/chainspec.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ call_contract = { cost = 4_500, arguments = [0, 0, 0, 0, 0, 420, 0] }
call_versioned_contract = { cost = 200, arguments = [0, 0, 0, 0, 0, 0, 0, 0, 0] }
create_contract_package_at_hash = { cost = 200, arguments = [0, 0] }
create_contract_user_group = { cost = 200, arguments = [0, 0, 0, 0, 0, 0, 0, 0] }
create_purse = { cost = 170_000, arguments = [0, 0] }
create_purse = { cost = 2_500_000_000, arguments = [0, 0] }
disable_contract_version = { cost = 200, arguments = [0, 0, 0, 0] }
get_balance = { cost = 3_800, arguments = [0, 0, 0] }
get_blocktime = { cost = 330, arguments = [0] }
Expand Down Expand Up @@ -199,9 +199,9 @@ read_era_id = 10_000
activate_bid = 10_000

[system_costs.mint_costs]
mint = 10_000
mint = 2_500_000_000
reduce_total_supply = 10_000
create = 10_000
create = 2_500_000_000
balance = 10_000
transfer = 10_000
read_base_round_reward = 10_000
Expand Down
6 changes: 3 additions & 3 deletions resources/production/chainspec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ call_contract = { cost = 4_500, arguments = [0, 0, 0, 0, 0, 420, 0] }
call_versioned_contract = { cost = 200, arguments = [0, 0, 0, 0, 0, 0, 0, 0, 0] }
create_contract_package_at_hash = { cost = 200, arguments = [0, 0] }
create_contract_user_group = { cost = 200, arguments = [0, 0, 0, 0, 0, 0, 0, 0] }
create_purse = { cost = 170_000, arguments = [0, 0] }
create_purse = { cost = 2_500_000_000, arguments = [0, 0] }
disable_contract_version = { cost = 200, arguments = [0, 0, 0, 0] }
get_balance = { cost = 3_800, arguments = [0, 0, 0] }
get_blocktime = { cost = 330, arguments = [0] }
Expand Down Expand Up @@ -202,9 +202,9 @@ read_era_id = 10_000
activate_bid = 10_000

[system_costs.mint_costs]
mint = 10_000
mint = 2_500_000_000
reduce_total_supply = 10_000
create = 10_000
create = 2_500_000_000
balance = 10_000
transfer = 10_000
read_base_round_reward = 10_000
Expand Down
4 changes: 2 additions & 2 deletions resources/test/valid/0_9_0/chainspec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ read_era_id = 10_000
activate_bid = 10_000

[system_costs.mint_costs]
mint = 10_000
mint = 2_500_000_000
reduce_total_supply = 10_000
create = 10_000
create = 2_500_000_000
balance = 10_000
transfer = 10_000
read_base_round_reward = 10_000
Expand Down
4 changes: 2 additions & 2 deletions resources/test/valid/0_9_0_unordered/chainspec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ read_era_id = 10_000
activate_bid = 10_000

[system_costs.mint_costs]
mint = 10_000
mint = 2_500_000_000
reduce_total_supply = 10_000
create = 10_000
create = 2_500_000_000
balance = 10_000
transfer = 10_000
read_base_round_reward = 10_000
Expand Down
4 changes: 2 additions & 2 deletions resources/test/valid/1_0_0/chainspec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ read_era_id = 10_000
activate_bid = 10_000

[system_costs.mint_costs]
mint = 10_000
mint = 2_500_000_000
reduce_total_supply = 10_000
create = 10_000
create = 2_500_000_000
balance = 10_000
transfer = 10_000
read_base_round_reward = 10_000
Expand Down
12 changes: 10 additions & 2 deletions smart_contracts/contracts/test/finalize-payment/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#![no_std]
#![no_main]

extern crate alloc;

use alloc::string::String;

use casper_contract::{
contract_api::{account, runtime, system},
unwrap_or_revert::UnwrapOrRevert,
Expand All @@ -12,6 +16,7 @@ pub const ARG_AMOUNT_SPENT: &str = "amount_spent";
pub const ARG_REFUND_FLAG: &str = "refund";
pub const ARG_PURSE: &str = "purse";
pub const ARG_ACCOUNT_KEY: &str = "account";
pub const ARG_PURSE_NAME: &str = "purse_name";

fn set_refund_purse(contract_hash: ContractHash, purse: URef) {
runtime::call_contract(
Expand Down Expand Up @@ -52,12 +57,15 @@ pub extern "C" fn call() {
let refund_purse_flag: u8 = runtime::get_named_arg(ARG_REFUND_FLAG);
let maybe_amount_spent: Option<U512> = runtime::get_named_arg(ARG_AMOUNT_SPENT);
let maybe_account: Option<AccountHash> = runtime::get_named_arg(ARG_ACCOUNT_KEY);
let purse_name: String = runtime::get_named_arg(ARG_PURSE_NAME);

submit_payment(contract_hash, payment_amount);

if refund_purse_flag != 0 {
let refund_purse = system::create_purse();
runtime::put_key("local_refund_purse", refund_purse.into());
let refund_purse = {
let stored_purse_key = runtime::get_key(&purse_name).unwrap_or_revert();
stored_purse_key.into_uref().unwrap_or_revert()
};
set_refund_purse(contract_hash, refund_purse);
}

Expand Down
27 changes: 21 additions & 6 deletions smart_contracts/contracts/test/refund-purse/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#![no_std]
#![no_main]

extern crate alloc;

use alloc::string::String;

use casper_contract::{
contract_api::{account, runtime, system},
unwrap_or_revert::UnwrapOrRevert,
Expand All @@ -20,6 +24,8 @@ const ARG_PAYMENT_AMOUNT: &str = "payment_amount";
const SET_REFUND_PURSE: &str = "set_refund_purse";
const GET_REFUND_PURSE: &str = "get_refund_purse";
const GET_PAYMENT_PURSE: &str = "get_payment_purse";
const ARG_PURSE_NAME_1: &str = "purse_name_1";
const ARG_PURSE_NAME_2: &str = "purse_name_2";

fn set_refund_purse(contract_hash: ContractHash, p: &URef) {
runtime::call_contract(
Expand Down Expand Up @@ -49,7 +55,13 @@ fn submit_payment(handle_payment: ContractHash, amount: U512) {
pub extern "C" fn call() {
let handle_payment = system::get_handle_payment();

let refund_purse = system::create_purse();
let refund_purse_name_1: String = runtime::get_named_arg(ARG_PURSE_NAME_1);
let refund_purse_name_2: String = runtime::get_named_arg(ARG_PURSE_NAME_2);

let refund_purse_1 = runtime::get_key(&refund_purse_name_1)
.unwrap_or_revert()
.into_uref()
.unwrap_or_revert();
{
// get_refund_purse should return None before setting it
let refund_result = get_refund_purse(handle_payment);
Expand All @@ -58,10 +70,10 @@ pub extern "C" fn call() {
}

// it should return Some(x) after calling set_refund_purse(x)
set_refund_purse(handle_payment, &refund_purse);
set_refund_purse(handle_payment, &refund_purse_1);
let refund_purse = match get_refund_purse(handle_payment) {
None => runtime::revert(ApiError::User(Error::NotFound as u16)),
Some(x) if x.addr() == refund_purse.addr() => x,
Some(x) if x.addr() == refund_purse_1.addr() => x,
Some(_) => runtime::revert(ApiError::User(Error::Invalid as u16)),
};

Expand All @@ -71,12 +83,15 @@ pub extern "C" fn call() {
}
}
{
let refund_purse = system::create_purse();
let refund_purse_2 = runtime::get_key(&refund_purse_name_2)
.unwrap_or_revert()
.into_uref()
.unwrap_or_revert();
// get_refund_purse should return correct value after setting a second time
set_refund_purse(handle_payment, &refund_purse);
set_refund_purse(handle_payment, &refund_purse_2);
match get_refund_purse(handle_payment) {
None => runtime::revert(ApiError::User(Error::NotFound as u16)),
Some(uref) if uref.addr() == refund_purse.addr() => (),
Some(uref) if uref.addr() == refund_purse_2.addr() => (),
Some(_) => runtime::revert(ApiError::User(Error::Invalid as u16)),
}

Expand Down
6 changes: 3 additions & 3 deletions utils/nctl/sh/scenarios/chainspecs/bond_its.chainspec.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ call_contract = { cost = 4_500, arguments = [0, 0, 0, 0, 0, 420, 0] }
call_versioned_contract = { cost = 200, arguments = [0, 0, 0, 0, 0, 0, 0, 0, 0] }
create_contract_package_at_hash = { cost = 200, arguments = [0, 0] }
create_contract_user_group = { cost = 200, arguments = [0, 0, 0, 0, 0, 0, 0, 0] }
create_purse = { cost = 170_000, arguments = [0, 0] }
create_purse = { cost = 2_500_000_000, arguments = [0, 0] }
disable_contract_version = { cost = 200, arguments = [0, 0, 0, 0] }
get_balance = { cost = 3_800, arguments = [0, 0, 0] }
get_blocktime = { cost = 330, arguments = [0] }
Expand Down Expand Up @@ -198,9 +198,9 @@ read_era_id = 10_000
activate_bid = 10_000

[system_costs.mint_costs]
mint = 10_000
mint = 2_500_000_000
reduce_total_supply = 10_000
create = 10_000
create = 2_500_000_000
balance = 10_000
transfer = 10_000
read_base_round_reward = 10_000
Expand Down
6 changes: 3 additions & 3 deletions utils/nctl/sh/scenarios/chainspecs/itst13.chainspec.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ call_contract = { cost = 4_500, arguments = [0, 0, 0, 0, 0, 420, 0] }
call_versioned_contract = { cost = 200, arguments = [0, 0, 0, 0, 0, 0, 0, 0, 0] }
create_contract_package_at_hash = { cost = 200, arguments = [0, 0] }
create_contract_user_group = { cost = 200, arguments = [0, 0, 0, 0, 0, 0, 0, 0] }
create_purse = { cost = 170_000, arguments = [0, 0] }
create_purse = { cost = 2_500_000_000, arguments = [0, 0] }
disable_contract_version = { cost = 200, arguments = [0, 0, 0, 0] }
get_balance = { cost = 3_800, arguments = [0, 0, 0] }
get_blocktime = { cost = 330, arguments = [0] }
Expand Down Expand Up @@ -198,9 +198,9 @@ read_era_id = 10_000
activate_bid = 10_000

[system_costs.mint_costs]
mint = 10_000
mint = 2_500_000_000
reduce_total_supply = 10_000
create = 10_000
create = 2_500_000_000
balance = 10_000
transfer = 10_000
read_base_round_reward = 10_000
Expand Down
6 changes: 3 additions & 3 deletions utils/nctl/sh/scenarios/chainspecs/itst14.chainspec.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ call_contract = { cost = 4_500, arguments = [0, 0, 0, 0, 0, 420, 0] }
call_versioned_contract = { cost = 200, arguments = [0, 0, 0, 0, 0, 0, 0, 0, 0] }
create_contract_package_at_hash = { cost = 200, arguments = [0, 0] }
create_contract_user_group = { cost = 200, arguments = [0, 0, 0, 0, 0, 0, 0, 0] }
create_purse = { cost = 170_000, arguments = [0, 0] }
create_purse = { cost = 2_500_000_000, arguments = [0, 0] }
disable_contract_version = { cost = 200, arguments = [0, 0, 0, 0] }
get_balance = { cost = 3_800, arguments = [0, 0, 0] }
get_blocktime = { cost = 330, arguments = [0] }
Expand Down Expand Up @@ -198,9 +198,9 @@ read_era_id = 10_000
activate_bid = 10_000

[system_costs.mint_costs]
mint = 10_000
mint = 2_500_000_000
reduce_total_supply = 10_000
create = 10_000
create = 2_500_000_000
balance = 10_000
transfer = 10_000
read_base_round_reward = 10_000
Expand Down