Skip to content
Open
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ lint-smart-contracts:

.PHONY: audit-rs
audit-rs:
$(CARGO) audit --ignore RUSTSEC-2024-0437 --ignore RUSTSEC-2025-0022 --ignore RUSTSEC-2025-0055 --ignore RUSTSEC-2026-0001
$(CARGO) audit --ignore RUSTSEC-2024-0437 --ignore RUSTSEC-2025-0022 --ignore RUSTSEC-2025-0055 --ignore RUSTSEC-2026-0001 --ignore RUSTSEC-2026-0007

.PHONY: audit
audit: audit-rs
Expand Down
16 changes: 13 additions & 3 deletions execution_engine/src/engine_state/engine_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use num_rational::Ratio;
use num_traits::One;

use casper_types::{
account::AccountHash, FeeHandling, ProtocolVersion, PublicKey, RefundHandling, StorageCosts,
SystemConfig, TimeDiff, WasmConfig, DEFAULT_FEE_HANDLING, DEFAULT_MINIMUM_BID_AMOUNT,
DEFAULT_REFUND_HANDLING,
account::AccountHash, FeeHandling, ProtocolVersion, PublicKey, RefundHandling, RewardsHandling,
StorageCosts, SystemConfig, TimeDiff, WasmConfig, DEFAULT_FEE_HANDLING,
DEFAULT_MINIMUM_BID_AMOUNT, DEFAULT_REFUND_HANDLING,
};

/// Default value for a maximum query depth configuration option.
Expand Down Expand Up @@ -93,6 +93,7 @@ pub struct EngineConfig {
pub(crate) compute_rewards: bool,
pub(crate) enable_entity: bool,
pub(crate) trap_on_ambiguous_entity_version: bool,
pub(crate) rewards_handling: RewardsHandling,
storage_costs: StorageCosts,
}

Expand All @@ -118,6 +119,7 @@ impl Default for EngineConfig {
protocol_version: DEFAULT_PROTOCOL_VERSION,
enable_entity: DEFAULT_ENABLE_ENTITY,
trap_on_ambiguous_entity_version: DEFAULT_TRAP_ON_AMBIGUOUS_ENTITY_VERSION,
rewards_handling: RewardsHandling::Standard,
storage_costs: Default::default(),
}
}
Expand Down Expand Up @@ -224,6 +226,11 @@ impl EngineConfig {
self.trap_on_ambiguous_entity_version
}

/// Returns the current configuration for rewards handling.
pub fn rewards_handling(&self) -> RewardsHandling {
self.rewards_handling.clone()
}

/// Sets the protocol version of the config.
///
/// NOTE: This is only useful to the WasmTestBuilder for emulating a network upgrade, and hence
Expand Down Expand Up @@ -267,6 +274,7 @@ pub struct EngineConfigBuilder {
balance_hold_interval: Option<TimeDiff>,
enable_entity: Option<bool>,
trap_on_ambiguous_entity_version: Option<bool>,
rewards_handling: Option<RewardsHandling>,
storage_costs: Option<StorageCosts>,
}

Expand Down Expand Up @@ -487,6 +495,7 @@ impl EngineConfigBuilder {
.trap_on_ambiguous_entity_version
.unwrap_or(DEFAULT_TRAP_ON_AMBIGUOUS_ENTITY_VERSION);
let storage_costs = self.storage_costs.unwrap_or_default();
let rewards_handling = self.rewards_handling.unwrap_or(RewardsHandling::Standard);

EngineConfig {
max_associated_keys,
Expand All @@ -508,6 +517,7 @@ impl EngineConfigBuilder {
compute_rewards,
enable_entity,
trap_on_ambiguous_entity_version,
rewards_handling,
storage_costs,
}
}
Expand Down
38 changes: 33 additions & 5 deletions execution_engine/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,18 @@ use casper_types::{
system::{
self,
auction::{self, DelegatorKind, EraInfo},
handle_payment, mint, CallStackElement, Caller, CallerInfo, SystemEntityType, AUCTION,
HANDLE_PAYMENT, MINT, STANDARD_PAYMENT,
handle_payment, mint,
mint::MINT_SUSTAIN_PURSE_KEY,
CallStackElement, Caller, CallerInfo, SystemEntityType, AUCTION, HANDLE_PAYMENT, MINT,
STANDARD_PAYMENT,
},
AccessRights, ApiError, BlockGlobalAddr, BlockTime, ByteCode, ByteCodeAddr, ByteCodeHash,
ByteCodeKind, CLTyped, CLValue, ContextAccessRights, Contract, ContractWasm, EntityAddr,
EntityKind, EntityVersion, EntityVersionKey, EntityVersions, Gas, GrantedAccess, Group, Groups,
HashAddr, HostFunction, HostFunctionCost, InitiatorAddr, Key, NamedArg, Package, PackageHash,
PackageStatus, Phase, PublicKey, RuntimeArgs, RuntimeFootprint, StoredValue, Transfer,
TransferResult, TransferV2, TransferredTo, URef, DICTIONARY_ITEM_KEY_MAX_LENGTH, U512,
PackageStatus, Phase, PublicKey, RewardsHandling, RuntimeArgs, RuntimeFootprint, StoredValue,
Transfer, TransferResult, TransferV2, TransferredTo, URef, DICTIONARY_ITEM_KEY_MAX_LENGTH,
U512,
};

use crate::{
Expand Down Expand Up @@ -1254,8 +1257,33 @@ where
// ExecError>`
auction::METHOD_DISTRIBUTE => (|| {
runtime.charge_system_contract_call(auction_costs.distribute)?;
let rewards_handling = self.context().engine_config().rewards_handling();
let rewards = Self::get_named_argument(runtime_args, auction::ARG_REWARDS_MAP)?;
runtime.distribute(rewards).map_err(Self::reverter)?;

let sustain_purse = match rewards_handling {
RewardsHandling::Standard => None,
RewardsHandling::Sustain { .. } => {
let sustain_purse = {
let mint_hash = self.context.get_system_contract(AUCTION)?;
match self
.context
.state()
.borrow_mut()
.get_named_keys(EntityAddr::System(mint_hash.value()))?
.get(MINT_SUSTAIN_PURSE_KEY)
{
Some(Key::URef(uref)) => Some(*uref),
Some(_) | None => None,
}
};

sustain_purse
}
};

runtime
.distribute(rewards, sustain_purse, rewards_handling)
.map_err(Self::reverter)?;
CLValue::from_t(()).map_err(Self::reverter)
})(),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct GenesisConfigBuilder {
gas_hold_balance_handling: Option<HoldBalanceHandling>,
gas_hold_interval_millis: Option<u64>,
enable_addressable_entity: Option<bool>,
rewards_ratio: Option<Ratio<u64>>,
storage_costs: Option<StorageCosts>,
}

Expand Down Expand Up @@ -98,6 +99,12 @@ impl GenesisConfigBuilder {
self
}

/// Sets the rewards ratio.
pub fn with_rewards_ratio(mut self, rewards_ratio: Ratio<u64>) -> Self {
self.rewards_ratio = Some(rewards_ratio);
self
}

/// Sets the storage_costs handling.
pub fn with_storage_costs(mut self, storage_costs: StorageCosts) -> Self {
self.storage_costs = Some(storage_costs);
Expand Down Expand Up @@ -125,6 +132,7 @@ impl GenesisConfigBuilder {
.unwrap_or(DEFAULT_GAS_HOLD_INTERVAL_MILLIS),
self.enable_addressable_entity
.unwrap_or(DEFAULT_ENABLE_ENTITY),
self.rewards_ratio,
self.storage_costs.unwrap_or_default(),
)
}
Expand Down
7 changes: 7 additions & 0 deletions execution_engine_testing/test_support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ pub static DEFAULT_PROPOSER_PUBLIC_KEY: Lazy<PublicKey> = Lazy::new(|| {
/// Default proposer address.
pub static DEFAULT_PROPOSER_ADDR: Lazy<AccountHash> =
Lazy::new(|| AccountHash::from(&*DEFAULT_PROPOSER_PUBLIC_KEY));

/// Default public key to associate with the sustain purse.
pub static DEFAULT_SUSTAIN_PUBLIC_KEY: Lazy<PublicKey> = Lazy::new(|| {
let secret_key = SecretKey::ed25519_from_bytes([207; SecretKey::ED25519_LENGTH]).unwrap();
PublicKey::from(&secret_key)
});

/// Default accounts.
pub static DEFAULT_ACCOUNTS: Lazy<Vec<GenesisAccount>> = Lazy::new(|| {
let mut ret = Vec::new();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use casper_types::{
bytesrepr::ToBytes,
system::mint::{ARG_AMOUNT, ARG_ID, ARG_SOURCE, ARG_TARGET},
BlockTime, CLValue, Digest, FeeHandling, Gas, InitiatorAddr, ProtocolVersion, RefundHandling,
RuntimeArgs, TransactionHash, TransactionV1Hash, TransferTarget, URef,
RewardsHandling, RuntimeArgs, TransactionHash, TransactionV1Hash, TransferTarget, URef,
DEFAULT_GAS_HOLD_INTERVAL, U512,
};

Expand Down Expand Up @@ -61,6 +61,7 @@ impl TransferRequestBuilder {
Ratio::new_raw(U512::zero(), U512::zero()),
DEFAULT_ENABLE_ENTITY,
2_500_000_000,
RewardsHandling::Standard,
);
/// The default value used for `TransferRequest::state_hash`.
pub const DEFAULT_STATE_HASH: Digest = Digest::from_raw([1; 32]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use num_rational::Ratio;

use casper_types::{
ChainspecRegistry, Digest, EraId, FeeHandling, HoldBalanceHandling, Key, ProtocolUpgradeConfig,
ProtocolVersion, StoredValue,
ProtocolVersion, RewardsHandling, StoredValue,
};

/// Builds an `UpgradeConfig`.
Expand All @@ -27,6 +27,7 @@ pub struct UpgradeRequestBuilder {
maximum_delegation_amount: u64,
minimum_delegation_amount: u64,
enable_addressable_entity: bool,
rewards_handling: RewardsHandling,
}

impl UpgradeRequestBuilder {
Expand Down Expand Up @@ -170,6 +171,7 @@ impl UpgradeRequestBuilder {
self.maximum_delegation_amount,
self.minimum_delegation_amount,
self.enable_addressable_entity,
self.rewards_handling,
)
}
}
Expand All @@ -195,6 +197,7 @@ impl Default for UpgradeRequestBuilder {
maximum_delegation_amount: u64::MAX,
minimum_delegation_amount: 0,
enable_addressable_entity: false,
rewards_handling: RewardsHandling::Standard,
}
}
}
71 changes: 69 additions & 2 deletions execution_engine_testing/test_support/src/wasm_test_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ use casper_types::{
BlockTime, ByteCode, ByteCodeAddr, ByteCodeHash, CLTyped, CLValue, Contract, Digest,
EntityAddr, EntryPoints, EraId, FeeHandling, Gas, HandlePaymentCosts, HoldBalanceHandling,
InitiatorAddr, Key, KeyTag, MintCosts, Motes, Package, PackageHash, Phase,
ProtocolUpgradeConfig, ProtocolVersion, PublicKey, RefundHandling, StoredValue,
SystemHashRegistry, TransactionHash, TransactionV1Hash, URef, OS_PAGE_SIZE, U512,
ProtocolUpgradeConfig, ProtocolVersion, PublicKey, RefundHandling, RewardsHandling,
StoredValue, SystemHashRegistry, TransactionHash, TransactionV1Hash, URef, OS_PAGE_SIZE, U512,
};

use crate::{
Expand Down Expand Up @@ -848,6 +848,7 @@ where
credit_cap,
enable_addressable_entity,
config.system_costs_config.mint_costs().transfer,
config.core_config.rewards_handling.clone(),
);

let bidding_req = BiddingRequest::new(
Expand Down Expand Up @@ -1018,6 +1019,7 @@ where
credit_cap,
self.chainspec.core_config.enable_addressable_entity,
self.chainspec.system_costs_config.mint_costs().transfer,
self.chainspec.core_config.rewards_handling.clone(),
)
}

Expand Down Expand Up @@ -1080,6 +1082,71 @@ where
distribute_block_rewards_result
}

/// Distributes the rewards.
pub fn distribute_with_rewards_handling(
&mut self,
pre_state_hash: Option<Digest>,
protocol_version: ProtocolVersion,
rewards: BTreeMap<PublicKey, Vec<U512>>,
block_time: u64,
rewards_handling: RewardsHandling,
) -> BlockRewardsResult {
let pre_state_hash = pre_state_hash.or(self.post_state_hash).unwrap();
let administrators: BTreeSet<AccountHash> = self
.chainspec
.core_config
.administrators
.iter()
.map(|x| x.to_account_hash())
.collect();
let allow_unrestricted = self.chainspec.core_config.allow_unrestricted_transfers;
let transfer_config = TransferConfig::new(administrators, allow_unrestricted);
let include_credits = self.chainspec.core_config.fee_handling == FeeHandling::NoFee;
let credit_cap = Ratio::new_raw(
U512::from(*self.chainspec.core_config.validator_credit_cap.numer()),
U512::from(*self.chainspec.core_config.validator_credit_cap.denom()),
);

let native_runtime_config = NativeRuntimeConfig::new(
transfer_config,
self.chainspec.core_config.fee_handling,
self.chainspec.core_config.refund_handling,
self.chainspec.core_config.vesting_schedule_period.millis(),
self.chainspec.core_config.allow_auction_bids,
self.chainspec.core_config.compute_rewards,
self.chainspec.core_config.max_delegators_per_validator,
self.chainspec.core_config.minimum_bid_amount,
self.chainspec.core_config.minimum_delegation_amount,
self.chainspec.core_config.maximum_delegation_amount,
self.chainspec.core_config.gas_hold_interval.millis(),
include_credits,
credit_cap,
self.chainspec.core_config.enable_addressable_entity,
self.chainspec.system_costs_config.mint_costs().transfer,
rewards_handling,
);

let distribute_req = BlockRewardsRequest::new(
native_runtime_config,
pre_state_hash,
protocol_version,
BlockTime::new(block_time),
rewards,
);
let distribute_block_rewards_result = self
.data_access_layer
.distribute_block_rewards(distribute_req);

if let BlockRewardsResult::Success {
post_state_hash, ..
} = distribute_block_rewards_result
{
self.post_state_hash = Some(post_state_hash);
}

distribute_block_rewards_result
}

/// Finalizes payment for a transaction
pub fn handle_fee(
&mut self,
Expand Down
8 changes: 4 additions & 4 deletions execution_engine_testing/tests/src/test/explorer/faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -663,14 +663,14 @@ fn faucet_costs() {
// This test will fail if execution costs vary. The expected costs should not be updated
// without understanding why the cost has changed. If the costs do change, it should be
// reflected in the "Costs by Entry Point" section of the faucet crate's README.md.
const EXPECTED_FAUCET_INSTALL_COST: u64 = 160_503_972_212;
const EXPECTED_FAUCET_INSTALL_COST: u64 = 149_263_295_166;
const EXPECTED_FAUCET_INSTALL_COST_ALT: u64 = 149_230_872_143;

const EXPECTED_FAUCET_SET_VARIABLES_COST: u64 = 79_455_975;
const EXPECTED_FAUCET_SET_VARIABLES_COST: u64 = 79_463_750;

const EXPECTED_FAUCET_CALL_BY_INSTALLER_COST: u64 = 2_652_626_533;
const EXPECTED_FAUCET_CALL_BY_INSTALLER_COST: u64 = 2_652_633_308;

const EXPECTED_FAUCET_CALL_BY_USER_COST: u64 = 2_558_318_531;
const EXPECTED_FAUCET_CALL_BY_USER_COST: u64 = 2_558_333_326;

let installer_account = AccountHash::new([1u8; 32]);
let user_account: AccountHash = AccountHash::new([2u8; 32]);
Expand Down
Loading