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

[secp256r1] Add CU costs #3826

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions builtins-default-costs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ solana-frozen-abi = { workspace = true, optional = true, features = [
] }
solana-loader-v4-program = { workspace = true }
solana-sdk = { workspace = true }
solana-sdk-ids = { workspace = true }
solana-stake-program = { workspace = true }
solana-system-program = { workspace = true }
solana-vote-program = { workspace = true }
Expand Down
8 changes: 8 additions & 0 deletions builtins-default-costs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use {
pubkey::Pubkey,
secp256k1_program,
},
solana_sdk_ids::secp256r1_program,
};

/// DEVELOPER: when a builtin is migrated to sbpf, please add its corresponding
Expand Down Expand Up @@ -122,6 +123,13 @@ lazy_static! {
core_bpf_migration_feature: None,
},
),
(
secp256r1_program::id(),
BuiltinCost {
native_cost: 0,
core_bpf_migration_feature: None,
}
)
// DO NOT ADD MORE ENTRIES TO THIS MAP
]
.iter()
Expand Down
2 changes: 2 additions & 0 deletions cost-model/src/block_cost_limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ pub const SECP256K1_VERIFY_COST: u64 = COMPUTE_UNIT_TO_US_RATIO * 223;
pub const ED25519_VERIFY_COST: u64 = COMPUTE_UNIT_TO_US_RATIO * 76;
/// Number of compute units for one ed25519 strict signature verification.
pub const ED25519_VERIFY_STRICT_COST: u64 = COMPUTE_UNIT_TO_US_RATIO * 80;
/// Number of compute units for one secp256r1 signature verification.
pub const SECP256R1_VERIFY_COST: u64 = COMPUTE_UNIT_TO_US_RATIO * 160;
/// Number of compute units for one write lock
pub const WRITE_LOCK_UNITS: u64 = COMPUTE_UNIT_TO_US_RATIO * 10;
/// Number of data bytes per compute units
Expand Down
5 changes: 5 additions & 0 deletions cost-model/src/cost_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ impl CostModel {
.num_ed25519_instruction_signatures()
.saturating_mul(ed25519_verify_cost),
)
.saturating_add(
signatures_count_detail
.num_secp256r1_instruction_signatures()
.saturating_mul(SECP256R1_VERIFY_COST),
)
}

fn get_writable_accounts(message: &impl SVMMessage) -> impl Iterator<Item = &Pubkey> {
Expand Down
14 changes: 14 additions & 0 deletions cost-model/src/cost_tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub struct CostTracker {
/// the tracker, but are still waiting for an update with actual usage or
/// removal if the transaction does not end up getting committed.
in_flight_transaction_count: usize,
secp256r1_instruction_signature_count: u64,
}

impl Default for CostTracker {
Expand All @@ -102,6 +103,7 @@ impl Default for CostTracker {
secp256k1_instruction_signature_count: 0,
ed25519_instruction_signature_count: 0,
in_flight_transaction_count: 0,
secp256r1_instruction_signature_count: 0,
}
}
}
Expand Down Expand Up @@ -256,6 +258,11 @@ impl CostTracker {
self.in_flight_transaction_count,
i64
),
(
"secp256r1_instruction_signature_count",
self.secp256r1_instruction_signature_count,
i64
)
);
}

Expand Down Expand Up @@ -334,6 +341,10 @@ impl CostTracker {
self.ed25519_instruction_signature_count,
tx_cost.num_ed25519_instruction_signatures()
);
saturating_add_assign!(
self.secp256r1_instruction_signature_count,
tx_cost.num_secp256r1_instruction_signatures()
);
self.add_transaction_execution_cost(tx_cost, tx_cost.sum())
}

Expand All @@ -353,6 +364,9 @@ impl CostTracker {
self.ed25519_instruction_signature_count = self
.ed25519_instruction_signature_count
.saturating_sub(tx_cost.num_ed25519_instruction_signatures());
self.secp256r1_instruction_signature_count = self
.secp256r1_instruction_signature_count
.saturating_sub(tx_cost.num_secp256r1_instruction_signatures());
}

/// Apply additional actual execution units to cost_tracker
Expand Down
10 changes: 10 additions & 0 deletions cost-model/src/transaction_cost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ impl<'a, Tx: TransactionWithMeta> TransactionCost<'a, Tx> {
.num_ed25519_instruction_signatures(),
}
}

pub fn num_secp256r1_instruction_signatures(&self) -> u64 {
match self {
Self::SimpleVote { .. } => 0,
Self::Transaction(usage_cost) => usage_cost
.transaction
.signature_details()
.num_secp256r1_instruction_signatures(),
}
}
}

// costs are stored in number of 'compute unit's
Expand Down
1 change: 1 addition & 0 deletions programs/sbf/Cargo.lock

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

1 change: 1 addition & 0 deletions svm/examples/Cargo.lock

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

Loading