penumbra_transaction/gas.rs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653
use penumbra_auction::auction::dutch::actions::{
ActionDutchAuctionEnd, ActionDutchAuctionSchedule, ActionDutchAuctionWithdraw,
};
use penumbra_community_pool::{CommunityPoolDeposit, CommunityPoolOutput, CommunityPoolSpend};
use penumbra_dex::{PositionClose, PositionOpen, PositionWithdraw, Swap, SwapClaim};
use penumbra_fee::Gas;
use penumbra_ibc::IbcRelay;
use penumbra_shielded_pool::{Ics20Withdrawal, Output, Spend};
use penumbra_stake::{
validator::Definition as ValidatorDefinition, Delegate, Undelegate, UndelegateClaim,
};
use penumbra_governance::{
DelegatorVote, ProposalDepositClaim, ProposalSubmit, ProposalWithdraw, ValidatorVote,
};
use crate::{
plan::{ActionPlan, TransactionPlan},
Action, Transaction,
};
use penumbra_proto::DomainType;
const NULLIFIER_SIZE: u64 = 2 + 32;
const NOTEPAYLOAD_SIZE: u64 = 32 + 32 + 176;
const SWAPPAYLOAD_SIZE: u64 = 32 + 272;
const ZKPROOF_SIZE: u64 = 192;
// This is an approximation, the actual size is variable
const BSOD_SIZE: u64 = 16 + 16 + 0 + 4 + 64 + 4;
/// Allows [`Action`]s and [`Transaction`]s to statically indicate their relative resource consumption.
/// Since the gas cost needs to be multiplied by a price, the values returned
/// only need to be scaled relatively to each other.
pub trait GasCost {
fn gas_cost(&self) -> Gas;
}
// Where block space costs are hard-coded instead of calculated in the following functions, the values are based on the approximate byte size of the
// encoded action and ignore the protobuf framing overhead, because it makes only a small difference and simplifies accounting.
pub fn spend_gas_cost() -> Gas {
Gas {
// penumbra.core.asset.v1.BalanceCommitment `balance_commitment` = 32 bytes
// penumbra.core.component.sct.v1.Nullifier `nullifier` = 32 bytes
// penumbra.crypto.decaf377_rdsa.v1.SpendVerificationKey `rk` = 32 bytes
// penumbra.crypto.decaf377_rdsa.v1.SpendAuthSignature `auth_sig` = 64 bytes
// ZKSpendProof `proof` = 192 bytes
// The block space measured as the byte length of the encoded action.
block_space: 160 + ZKPROOF_SIZE, // 352 bytes
// The compact block space cost is based on the byte size of the data the [`Action`] adds
// to the compact block. For a `Spend`, this is the byte size of a `Nullifier`.
compact_block_space: NULLIFIER_SIZE,
// Includes a zk-SNARK proof, so we include a constant verification cost.
verification: 1000,
// Execution cost is currently hardcoded at 10 for all [`Action`] variants.
execution: 10,
}
}
pub fn output_gas_cost() -> Gas {
Gas {
// NotePayload `note_payload` = 32 + 32 + 176 = 240 bytes
// penumbra.core.asset.v1.BalanceCommitment `balance_commitment` = 32 bytes
// wrapped_memo_key `wrapped_memo_key` = 48 bytes
// ovk_wrapped_key `ovk_wrapped_key` = 48 bytes
// ZKOutputProof `proof` = 192 bytes
// The block space measured as the byte length of the encoded action.
block_space: 128 + NOTEPAYLOAD_SIZE + ZKPROOF_SIZE, // 560 bytes
// The compact block space cost is based on the byte size of the data the [`Action`] adds
// to the compact block.
compact_block_space: NOTEPAYLOAD_SIZE,
// Includes a zk-SNARK proof, so we include a constant verification cost.
verification: 1000,
// Execution cost is currently hardcoded at 10 for all [`Action`] variants.
execution: 10,
}
}
fn delegate_gas_cost(delegate: &Delegate) -> Gas {
Gas {
// The block space measured as the byte length of the encoded action.
block_space: delegate.encode_to_vec().len() as u64,
// The compact block space cost is based on the byte size of the data the [`Action`] adds
// to the compact block.
// For a Delegate, nothing is added to the compact block directly. The associated [`Action::Spend`]
// actions will add their costs, but there's nothing to add here.
compact_block_space: 0,
// Does not include a zk-SNARK proof, so there's no verification cost.
verification: 0,
// Execution cost is currently hardcoded at 10 for all Action variants.
execution: 10,
}
}
fn undelegate_gas_cost(undelegate: &Undelegate) -> Gas {
Gas {
// The block space measured as the byte length of the encoded action.
block_space: undelegate.encode_to_vec().len() as u64,
// The compact block space cost is based on the byte size of the data the [`Action`] adds
// to the compact block.
// For an Undelegate, nothing is added to the compact block directly. The associated [`Action::Spend`]
// actions will add their costs, but there's nothing to add here.
compact_block_space: 0,
// Does not include a zk-SNARK proof, so there's no verification cost.
verification: 0,
// Execution cost is currently hardcoded at 10 for all Action variants.
execution: 10,
}
}
fn undelegate_claim_gas_cost() -> Gas {
Gas {
// penumbra.core.keys.v1.IdentityKey `validator_identity` = 32 bytes
// uint64 `start_epoch_index` = 8 bytes
// Penalty `penalty` = 32 bytes
// penumbra.core.asset.v1.BalanceCommitment `balance_commitment` = 32 bytes
// uint64 `unbonding_start_height` = 8 bytes
// ZKSpendProof `proof` = 192 bytes
// The block space measured as the byte length of the encoded action.
block_space: 112 + ZKPROOF_SIZE, // 304 bytes
// The compact block space cost is based on the byte size of the data the [`Action`] adds
// to the compact block.
// For an `UndelegateClaim`, nothing is added to the compact block directly. The associated [`Action::Output`]
// actions will add their costs, but there's nothing to add here.
compact_block_space: 0,
// Includes a zk-SNARK proof, so we include a constant verification cost.
verification: 1000,
// Execution cost is currently hardcoded at 10 for all Action variants.
execution: 10,
}
}
fn validator_definition_gas_cost(validator_definition: &ValidatorDefinition) -> Gas {
Gas {
// The block space measured as the byte length of the encoded action.
block_space: validator_definition.encode_to_vec().len() as u64,
// The compact block space cost is based on the byte size of the data the [`Action`] adds
// to the compact block.
// For a ValidatorDefinition the compact block is not modified.
compact_block_space: 0,
// Includes a signature verification, so we include a small constant verification cost.
verification: 200,
// Execution cost is currently hardcoded at 10 for all Action variants.
execution: 10,
}
}
fn swap_gas_cost() -> Gas {
Gas {
// TradingPair `trading_pair` = 64 bytes
// penumbra.core.num.v1.Amount `delta_1_i` = 16 bytes
// penumbra.core.num.v1.Amount `delta_2_i` = 16 bytes
// penumbra.core.asset.v1.BalanceCommitment `fee_commitment` = 32 bytes
// SwapPayload `payload` = 304 bytes
// ZKSwapProof `proof` = 192 bytes
// Batch swap output data = 104 bytes
// The block space measured as the byte length of the encoded action.
block_space: 128 + ZKPROOF_SIZE + SWAPPAYLOAD_SIZE + BSOD_SIZE, // 728 bytes
// The compact block space cost is based on the byte size of the data the [`Action`] adds
// to the compact block.
// For a `Swap` this is the byte size of a [`StatePayload`] and a [`BatchSwapOutputData`].
// `Swap`s are batched so technically the cost of the `BatchSwapOutputData` is shared across
// multiple swaps, but if only one `swap` for a trading pair is performed in a block, that
// `swap` will add a `BatchSwapOutputData` all on its own.
// Note: the BSOD has variable size, we pick an approximation.
compact_block_space: SWAPPAYLOAD_SIZE + BSOD_SIZE,
// Includes a zk-SNARK proof, so we include a constant verification cost.
verification: 1000,
// Execution cost is currently hardcoded at 10 for all Action variants.
execution: 10,
}
}
pub fn swap_claim_gas_cost() -> Gas {
Gas {
// penumbra.core.component.sct.v1.Nullifier `nullifier` = 32 bytes
// penumbra.core.component.fee.v1.Fee `fee`` = 48 bytes
// penumbra.crypto.tct.v1.StateCommitment `output_1_commitment`` = 32 bytes
// penumbra.crypto.tct.v1.StateCommitment `output_2_commitment` = 32 bytes
// BatchSwapOutputData `output_data` = 176 bytes
// uint64 `epoch_duration` = 8 bytes
// ZKSwapClaimProof `proof` = 192 bytes
// Batch swap output data = 104 bytes
// The block space measured as the byte length of the encoded action.
block_space: 328 + ZKPROOF_SIZE + BSOD_SIZE, // 624 bytes
// The compact block space cost is based on the byte size of the data the [`Action`] adds
// to the compact block.
// For a `SwapClaim`, nothing is added to the compact block directly. The associated [`Action::Spend`]
// and [`Action::Output`] actions will add their costs, but there's nothing to add here.
compact_block_space: 0,
// Includes a zk-SNARK proof, so we include a constant verification cost.
verification: 1000,
// Execution cost is currently hardcoded at 10 for all Action variants.
execution: 10,
}
}
fn delegator_vote_gas_cost() -> Gas {
Gas {
// uint64 `proposal` = 8 bytes
// uint64 `start_position` = 8 bytes
// Vote `vote` = 1 byte
// penumbra.core.asset.v1.Value `value` = 48 bytes
// penumbra.core.num.v1.Amount `unbonded_amount` = 16 bytes
// penumbra.core.component.sct.v1.Nullifier `nullifier` = 32 bytes
// penumbra.crypto.decaf377_rdsa.v1.SpendVerificationKey `rk` = 32 bytes
// penumbra.crypto.decaf377_rdsa.v1.SpendAuthSignature `auth_sig` = 64 bytes
// ZKDelegatorVoteProof `proof` = 192 bytes
// The block space measured as the byte length of the encoded action.
block_space: 209 + ZKPROOF_SIZE, // 401 bytes
// The compact block space cost is based on the byte size of the data the [`Action`] adds
// to the compact block.
// For a DelegatorVote the compact block is not modified.
compact_block_space: 0,
// Includes a zk-SNARK proof, so we include a constant verification cost.
verification: 1000,
// Execution cost is currently hardcoded at 10 for all Action variants.
execution: 10,
}
}
fn position_withdraw_gas_cost() -> Gas {
Gas {
// PositionId `position_id` = 32 bytes
// penumbra.core.asset.v1.BalanceCommitment `reserves_commitment` = 32 bytes
// uint64 `sequence` = 8 bytes
// The block space measured as the byte length of the encoded action.
block_space: 72, // 72 bytes
// The compact block space cost is based on the byte size of the data the [`Action`] adds
// to the compact block.
// For a PositionWithdraw the compact block is not modified.
compact_block_space: 0,
// Does not include a zk-SNARK proof, so there's no verification cost.
verification: 0,
// Execution cost is currently hardcoded at 10 for all `Action`` variants.
// Reminder: Any change to this execution gas vector must also be reflected
// in updates to the dutch auction gas vectors.
execution: 10,
}
}
fn dutch_auction_schedule_gas_cost(dutch_action_schedule: &ActionDutchAuctionSchedule) -> Gas {
Gas {
// penumbra.core.asset.v1.Value `input` = 48 bytes
// penumbra.core.asset.v1.AssetId `output_id` = 32 bytes
// penumbra.core.num.v1.Amount `max_output` = 16 bytes
// penumbra.core.num.v1.Amount `min_output` = 16 bytes
// uint64 `start_height` = 8 bytes
// uint64 `end_height` = 8 bytes
// uint64 `step_count` = 8 bytes
// bytes `nonce` = 32 bytes
block_space: 168,
compact_block_space: 0,
verification: 50,
// Currently, we make the execution cost for DA actions proportional to the number of steps
// and costs of position open/close in dutch action. The gas cost is calculated by:
// 2 * step_count * (`PositionOpen`` + `PositionClose` cost).
execution: 2 * dutch_action_schedule.description.step_count * (10 + 10),
}
}
fn dutch_auction_end_gas_cost() -> Gas {
Gas {
// AuctionId `auction_id` = 32 bytes
block_space: 32, // 32 bytes
compact_block_space: 0,
verification: 0,
execution: 10,
}
}
fn dutch_auction_withdraw_gas_cost() -> Gas {
Gas {
// AuctionId `auction_id` = 32 bytes
// uint64 `seq`= 8 bytes
// penumbra.core.asset.v1.BalanceCommitment `reserves_commitment` = 32 bytes
block_space: 72, // 72 bytes
compact_block_space: 0,
verification: 0,
execution: 10,
}
}
impl GasCost for Transaction {
fn gas_cost(&self) -> Gas {
self.actions().map(GasCost::gas_cost).sum()
}
}
impl GasCost for TransactionPlan {
fn gas_cost(&self) -> Gas {
self.actions.iter().map(GasCost::gas_cost).sum()
}
}
// The planner also needs to be able to calculate gas costs,
// however until the transaction is finalized, the planner only
// has access to `ActionPlan` variants.
//
// IMPORTANT: The results produced by this impl should always
// match what the impl for the associated `Action` variant would
// produce, otherwise the planner will not include proper gas in
// transactions.
impl GasCost for ActionPlan {
fn gas_cost(&self) -> Gas {
match self {
// Some variants use separate `*Plan` inners and need their
// own implementations; others encapsulate an `Action` variant
// and can call the `GasCost` impl on that.
ActionPlan::Spend(_) => spend_gas_cost(),
ActionPlan::Output(_) => output_gas_cost(),
ActionPlan::UndelegateClaim(_) => undelegate_claim_gas_cost(),
ActionPlan::Swap(_) => swap_gas_cost(),
ActionPlan::SwapClaim(_) => swap_claim_gas_cost(),
ActionPlan::DelegatorVote(_) => delegator_vote_gas_cost(),
ActionPlan::PositionWithdraw(_) => position_withdraw_gas_cost(),
ActionPlan::ActionDutchAuctionSchedule(das) => das.gas_cost(),
ActionPlan::ActionDutchAuctionEnd(_) => dutch_auction_end_gas_cost(),
ActionPlan::ActionDutchAuctionWithdraw(_) => dutch_auction_withdraw_gas_cost(),
ActionPlan::Delegate(d) => d.gas_cost(),
ActionPlan::Undelegate(u) => u.gas_cost(),
ActionPlan::ValidatorDefinition(vd) => vd.gas_cost(),
ActionPlan::IbcAction(i) => i.gas_cost(),
ActionPlan::ProposalSubmit(ps) => ps.gas_cost(),
ActionPlan::ProposalWithdraw(pw) => pw.gas_cost(),
ActionPlan::ValidatorVote(v) => v.gas_cost(),
ActionPlan::ProposalDepositClaim(pdc) => pdc.gas_cost(),
ActionPlan::PositionOpen(po) => po.gas_cost(),
ActionPlan::PositionClose(pc) => pc.gas_cost(),
ActionPlan::CommunityPoolSpend(ds) => ds.gas_cost(),
ActionPlan::CommunityPoolOutput(d) => d.gas_cost(),
ActionPlan::CommunityPoolDeposit(dd) => dd.gas_cost(),
ActionPlan::Ics20Withdrawal(w) => w.gas_cost(),
}
}
}
impl GasCost for Action {
fn gas_cost(&self) -> Gas {
match self {
Action::Output(output) => output.gas_cost(),
Action::Spend(spend) => spend.gas_cost(),
Action::Delegate(delegate) => delegate.gas_cost(),
Action::Undelegate(undelegate) => undelegate.gas_cost(),
Action::UndelegateClaim(undelegate_claim) => undelegate_claim.gas_cost(),
Action::Swap(swap) => swap.gas_cost(),
Action::SwapClaim(swap_claim) => swap_claim.gas_cost(),
Action::ProposalSubmit(submit) => submit.gas_cost(),
Action::ProposalWithdraw(withdraw) => withdraw.gas_cost(),
Action::DelegatorVote(delegator_vote) => delegator_vote.gas_cost(),
Action::ValidatorVote(validator_vote) => validator_vote.gas_cost(),
Action::ProposalDepositClaim(p) => p.gas_cost(),
Action::PositionOpen(p) => p.gas_cost(),
Action::PositionClose(p) => p.gas_cost(),
Action::PositionWithdraw(p) => p.gas_cost(),
Action::Ics20Withdrawal(withdrawal) => withdrawal.gas_cost(),
Action::CommunityPoolDeposit(deposit) => deposit.gas_cost(),
Action::CommunityPoolSpend(spend) => spend.gas_cost(),
Action::CommunityPoolOutput(output) => output.gas_cost(),
Action::IbcRelay(x) => x.gas_cost(),
Action::ValidatorDefinition(x) => x.gas_cost(),
Action::ActionDutchAuctionSchedule(action_dutch_auction_schedule) => {
action_dutch_auction_schedule.gas_cost()
}
Action::ActionDutchAuctionEnd(action_dutch_auction_end) => {
action_dutch_auction_end.gas_cost()
}
Action::ActionDutchAuctionWithdraw(action_dutch_auction_withdraw) => {
action_dutch_auction_withdraw.gas_cost()
}
}
}
}
impl GasCost for Output {
fn gas_cost(&self) -> Gas {
output_gas_cost()
}
}
impl GasCost for Spend {
fn gas_cost(&self) -> Gas {
spend_gas_cost()
}
}
impl GasCost for Delegate {
fn gas_cost(&self) -> Gas {
delegate_gas_cost(&self)
}
}
impl GasCost for Undelegate {
fn gas_cost(&self) -> Gas {
undelegate_gas_cost(&self)
}
}
impl GasCost for UndelegateClaim {
fn gas_cost(&self) -> Gas {
undelegate_claim_gas_cost()
}
}
impl GasCost for Swap {
fn gas_cost(&self) -> Gas {
swap_gas_cost()
}
}
impl GasCost for SwapClaim {
fn gas_cost(&self) -> Gas {
swap_claim_gas_cost()
}
}
impl GasCost for ProposalSubmit {
fn gas_cost(&self) -> Gas {
Gas {
// The block space measured as the byte length of the encoded action.
block_space: self.encode_to_vec().len() as u64,
// In the case of a proposal submission, the compact block cost is zero.
// The compact block is only modified it the proposal is ratified.
// And when that's the case, the cost is mutualized.
compact_block_space: 0,
// There are some checks performed to validate the proposed state changes, so we include a constant verification cost,
// smaller than a zk-SNARK verification cost.
verification: 100,
// Execution cost is currently hardcoded at 10 for all Action variants.
execution: 10,
}
}
}
impl GasCost for ProposalWithdraw {
fn gas_cost(&self) -> Gas {
Gas {
// The block space measured as the byte length of the encoded action.
block_space: self.encode_to_vec().len() as u64,
// The compact block space cost is based on the byte size of the data the [`Action`] adds
// to the compact block.
// For a ProposalWithdraw the compact block is not modified.
compact_block_space: 0,
// Does not include a zk-SNARK proof, so there's no verification cost.
verification: 0,
// Execution cost is currently hardcoded at 10 for all Action variants.
execution: 10,
}
}
}
impl GasCost for DelegatorVote {
fn gas_cost(&self) -> Gas {
delegator_vote_gas_cost()
}
}
impl GasCost for ValidatorVote {
fn gas_cost(&self) -> Gas {
Gas {
// The block space measured as the byte length of the encoded action.
block_space: self.encode_to_vec().len() as u64,
// The compact block space cost is based on the byte size of the data the [`Action`] adds
// to the compact block.
// For a ValidatorVote the compact block is not modified.
compact_block_space: 0,
// Includes a signature verification, so we include a small constant verification cost.
verification: 200,
// Execution cost is currently hardcoded at 10 for all Action variants.
execution: 10,
}
}
}
impl GasCost for ProposalDepositClaim {
fn gas_cost(&self) -> Gas {
Gas {
// The block space measured as the byte length of the encoded action.
block_space: self.encode_to_vec().len() as u64,
// The compact block space cost is based on the byte size of the data the [`Action`] adds
// to the compact block.
// For a ProposalDepositClaim the compact block is not modified.
compact_block_space: 0,
// Does not include a zk-SNARK proof, so there's no verification cost.
verification: 0,
// Execution cost is currently hardcoded at 10 for all Action variants.
execution: 10,
}
}
}
impl GasCost for PositionOpen {
fn gas_cost(&self) -> Gas {
Gas {
// The block space measured as the byte length of the encoded action.
block_space: self.encode_to_vec().len() as u64,
// The compact block space cost is based on the byte size of the data the [`Action`] adds
// to the compact block.
// For a PositionOpen the compact block is not modified.
compact_block_space: 0,
// There are some small validations performed so a token amount of gas is charged.
verification: 50,
// Execution cost is currently hardcoded at 10 for all Action variants.
// Reminder: Any change to this execution gas vector must also be reflected
// in updates to the dutch auction gas vectors.
execution: 10,
}
}
}
impl GasCost for PositionClose {
fn gas_cost(&self) -> Gas {
Gas {
// The block space measured as the byte length of the encoded action.
block_space: self.encode_to_vec().len() as u64,
// The compact block space cost is based on the byte size of the data the [`Action`] adds
// to the compact block.
// For a PositionClose the compact block is not modified.
compact_block_space: 0,
// Does not include a zk-SNARK proof, so there's no verification cost.
verification: 0,
// Execution cost is currently hardcoded at 10 for all Action variants.
// Reminder: Any change to this execution gas vector must also be reflected
// in updates to the dutch auction gas vectors.
execution: 10,
}
}
}
impl GasCost for PositionWithdraw {
fn gas_cost(&self) -> Gas {
position_withdraw_gas_cost()
}
}
impl GasCost for Ics20Withdrawal {
fn gas_cost(&self) -> Gas {
Gas {
// The block space measured as the byte length of the encoded action.
block_space: self.encode_to_vec().len() as u64,
// The compact block space cost is based on the byte size of the data the [`Action`] adds
// to the compact block.
// For a Ics20Withdrawal the compact block is not modified.
compact_block_space: 0,
// Does not include a zk-SNARK proof, so there's no verification cost.
verification: 0,
// Execution cost is currently hardcoded at 10 for all Action variants.
execution: 10,
}
}
}
impl GasCost for CommunityPoolDeposit {
fn gas_cost(&self) -> Gas {
Gas {
// The block space measured as the byte length of the encoded action.
block_space: self.encode_to_vec().len() as u64,
// The compact block space cost is based on the byte size of the data the [`Action`] adds
// to the compact block.
// For a CommunityPoolDeposit the compact block is not modified.
compact_block_space: 0,
// Does not include a zk-SNARK proof, so there's no verification cost.
verification: 0,
// Execution cost is currently hardcoded at 10 for all Action variants.
execution: 10,
}
}
}
impl GasCost for CommunityPoolSpend {
fn gas_cost(&self) -> Gas {
Gas {
// The block space measured as the byte length of the encoded action.
block_space: self.encode_to_vec().len() as u64,
// The compact block space cost is based on the byte size of the data the [`Action`] adds
// to the compact block.
// For a CommunityPoolSpend the compact block is not modified.
compact_block_space: 0,
// Does not include a zk-SNARK proof, so there's no verification cost.
verification: 0,
// Execution cost is currently hardcoded at 10 for all Action variants.
execution: 10,
}
}
}
impl GasCost for CommunityPoolOutput {
fn gas_cost(&self) -> Gas {
// We hardcode the gas costs of a `CommunityPoolOutput` to 0, since it's a protocol action.
Gas {
block_space: 0,
compact_block_space: 0,
verification: 0,
execution: 0,
}
}
}
impl GasCost for IbcRelay {
fn gas_cost(&self) -> Gas {
Gas {
// The block space measured as the byte length of the encoded action.
block_space: self.encode_to_vec().len() as u64,
// The compact block space cost is based on the byte size of the data the [`Action`] adds
// to the compact block.
// For a IbcAction this is the byte size of a [`StatePayload`].
compact_block_space: match self {
// RecvPacket will mint a note if successful.
IbcRelay::RecvPacket(_) => NOTEPAYLOAD_SIZE,
_ => 0,
},
// Includes a proof in the execution for RecvPacket (TODO: check the other variants).
verification: match self {
IbcRelay::RecvPacket(_) => 1000,
_ => 0,
},
// Execution cost is currently hardcoded at 10 for all Action variants.
execution: 10,
}
}
}
impl GasCost for ValidatorDefinition {
fn gas_cost(&self) -> Gas {
validator_definition_gas_cost(&self)
}
}
impl GasCost for ActionDutchAuctionSchedule {
fn gas_cost(&self) -> Gas {
dutch_auction_schedule_gas_cost(&self)
}
}
impl GasCost for ActionDutchAuctionEnd {
fn gas_cost(&self) -> Gas {
dutch_auction_end_gas_cost()
}
}
impl GasCost for ActionDutchAuctionWithdraw {
fn gas_cost(&self) -> Gas {
dutch_auction_withdraw_gas_cost()
}
}