Skip to content

Commit 325c029

Browse files
committed
add feature-gated higher gas costs for SLH-DSA-SHA128s transactions
1 parent 34117c1 commit 325c029

File tree

15 files changed

+107
-8
lines changed

15 files changed

+107
-8
lines changed

aptos-move/aptos-gas-meter/src/meter.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,16 @@ where
617617
.charge_execution(KEYLESS_BASE_COST)
618618
.map_err(|e| e.finish(Location::Undefined))
619619
}
620+
621+
fn charge_slh_dsa_sha2_128s(&mut self) -> VMResult<()> {
622+
if self.feature_version() < RELEASE_V1_41 {
623+
return Ok(());
624+
}
625+
626+
self.algebra
627+
.charge_execution(SLH_DSA_SHA2_128S_BASE_COST)
628+
.map_err(|e| e.finish(Location::Undefined))
629+
}
620630
}
621631

622632
impl<A> CacheValueSizes for StandardGasMeter<A>

aptos-move/aptos-gas-meter/src/traits.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ pub trait AptosGasMeter: MoveGasMeter {
128128
/// expensive computation required.
129129
fn charge_keyless(&mut self) -> VMResult<()>;
130130

131+
/// Charges an additional cost for SLH-DSA signature verification to compensate for the
132+
/// expensive computation required (5x more expensive than ed25519).
133+
fn charge_slh_dsa_sha2_128s(&mut self) -> VMResult<()>;
134+
131135
/// Charges IO gas for the transaction itself.
132136
fn charge_io_gas_for_transaction(&mut self, txn_size: NumBytes) -> VMResult<()>;
133137

aptos-move/aptos-gas-profiling/src/erased.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ impl ExecutionAndIOCosts {
230230

231231
nodes.push(Node::new("keyless", self.keyless_cost));
232232

233+
nodes.push(Node::new("slh_dsa_sha2_128s", self.slh_dsa_sha2_128s_cost));
234+
233235
if !self.dependencies.is_empty() {
234236
let deps = Node::new_with_children(
235237
"dependencies",

aptos-move/aptos-gas-profiling/src/flamegraph.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ impl ExecutionAndIOCosts {
106106

107107
lines.push("keyless", self.keyless_cost);
108108

109+
lines.push("slh_dsa_sha2_128s", self.slh_dsa_sha2_128s_cost);
110+
109111
let mut path = vec![];
110112

111113
struct Rec<'a> {

aptos-move/aptos-gas-profiling/src/log.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ pub struct ExecutionAndIOCosts {
133133

134134
pub intrinsic_cost: InternalGas,
135135
pub keyless_cost: InternalGas,
136+
pub slh_dsa_sha2_128s_cost: InternalGas,
136137
pub dependencies: Vec<Dependency>,
137138
pub call_graph: CallFrame,
138139
pub transaction_transient: Option<InternalGas>,
@@ -265,6 +266,7 @@ impl ExecutionAndIOCosts {
265266

266267
total += self.intrinsic_cost;
267268
total += self.keyless_cost;
269+
total += self.slh_dsa_sha2_128s_cost;
268270

269271
for dep in &self.dependencies {
270272
total += dep.cost;

aptos-move/aptos-gas-profiling/src/profiler.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub struct GasProfiler<G> {
3737

3838
intrinsic_cost: Option<InternalGas>,
3939
keyless_cost: Option<InternalGas>,
40+
slh_dsa_sha2_128s_cost: Option<InternalGas>,
4041
dependencies: Vec<Dependency>,
4142
frames: Vec<CallFrame>,
4243
transaction_transient: Option<InternalGas>,
@@ -94,6 +95,7 @@ impl<G> GasProfiler<G> {
9495

9596
intrinsic_cost: None,
9697
keyless_cost: None,
98+
slh_dsa_sha2_128s_cost: None,
9799
dependencies: vec![],
98100
frames: vec![CallFrame::new_script()],
99101
transaction_transient: None,
@@ -114,6 +116,7 @@ impl<G> GasProfiler<G> {
114116

115117
intrinsic_cost: None,
116118
keyless_cost: None,
119+
slh_dsa_sha2_128s_cost: None,
117120
dependencies: vec![],
118121
frames: vec![CallFrame::new_function(module_id, func_name, ty_args)],
119122
transaction_transient: None,
@@ -702,9 +705,24 @@ where
702705
}
703706

704707
fn charge_keyless(&mut self) -> VMResult<()> {
705-
let (_cost, res) = self.delegate_charge(|base| base.charge_keyless());
708+
let (cost, res) = self.delegate_charge(|base| base.charge_keyless());
706709

707-
// TODO: add keyless
710+
// TODO: Is this right? (Do not understand the semantics here.)
711+
if res.is_ok() {
712+
self.keyless_cost = Some(self.keyless_cost.unwrap_or_else(|| 0.into()) + cost);
713+
}
714+
715+
res
716+
}
717+
718+
fn charge_slh_dsa_sha2_128s(&mut self) -> VMResult<()> {
719+
let (cost, res) = self.delegate_charge(|base| base.charge_slh_dsa_sha2_128s());
720+
721+
// TODO: Is this right? (Do not understand the semantics here.)
722+
if res.is_ok() {
723+
self.slh_dsa_sha2_128s_cost =
724+
Some(self.slh_dsa_sha2_128s_cost.unwrap_or_else(|| 0.into()) + cost);
725+
}
708726

709727
res
710728
}
@@ -726,6 +744,7 @@ where
726744
total: self.algebra().execution_gas_used() + self.algebra().io_gas_used(),
727745
intrinsic_cost: self.intrinsic_cost.unwrap_or_else(|| 0.into()),
728746
keyless_cost: self.keyless_cost.unwrap_or_else(|| 0.into()),
747+
slh_dsa_sha2_128s_cost: self.slh_dsa_sha2_128s_cost.unwrap_or_else(|| 0.into()),
729748
dependencies: self.dependencies,
730749
call_graph: self.frames.pop().expect("frame must exist"),
731750
transaction_transient: self.transaction_transient,

aptos-move/aptos-gas-profiling/src/report.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,23 @@ impl TransactionGasLog {
135135
data.insert("keyless-percentage".to_string(), json!(percentage));
136136
}
137137

138+
// SLH-DSA-SHA2-128s cost
139+
if !self.exec_io.slh_dsa_sha2_128s_cost.is_zero() {
140+
let cost_scaled = format!(
141+
"{:.8}",
142+
(u64::from(self.exec_io.slh_dsa_sha2_128s_cost) as f64 / scaling_factor)
143+
);
144+
let percentage = format!(
145+
"{:.2}%",
146+
u64::from(self.exec_io.slh_dsa_sha2_128s_cost) as f64 / total_exec_io * 100.0
147+
);
148+
data.insert("slh_dsa_sha2_128s".to_string(), json!(cost_scaled));
149+
data.insert(
150+
"slh_dsa_sha2_128s-percentage".to_string(),
151+
json!(percentage),
152+
);
153+
}
154+
138155
let mut deps = self.exec_io.dependencies.clone();
139156
deps.sort_by(|lhs, rhs| rhs.cost.cmp(&lhs.cost));
140157
data.insert(

aptos-move/aptos-gas-profiling/src/unique_stack.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ impl ExecutionAndIOCosts {
8181
total: self.total + other.total,
8282
intrinsic_cost: self.intrinsic_cost + other.intrinsic_cost,
8383
keyless_cost: self.keyless_cost + other.keyless_cost,
84+
slh_dsa_sha2_128s_cost: self.slh_dsa_sha2_128s_cost + other.slh_dsa_sha2_128s_cost,
8485
dependencies: dependencies
8586
.into_iter()
8687
.map(|((kind, id, size), cost)| Dependency {

aptos-move/aptos-gas-profiling/templates/index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ <h4>Keyless Cost</h4>
8888
{{keyless}} gas units, {{keyless-percentage}} of the total cost for execution & IO.
8989
{{/if}}
9090

91+
{{#if slh_dsa_sha2_128s}}
92+
<h4>SLH-DSA-SHA2-128s Cost</h4>
93+
{{slh_dsa_sha2_128s}} gas units, {{slh_dsa_sha2_128s-percentage}} of the total cost for execution & IO.
94+
{{/if}}
95+
9196
<h4>Dependencies</h4>
9297
{{#if deps}}
9398
<table>

aptos-move/aptos-gas-schedule/src/gas_schedule/transaction.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::{
88
gas_schedule::VMGasParameters,
99
ver::gas_feature_versions::{
1010
RELEASE_V1_10, RELEASE_V1_11, RELEASE_V1_12, RELEASE_V1_13, RELEASE_V1_15, RELEASE_V1_26,
11+
RELEASE_V1_41,
1112
},
1213
};
1314
use aptos_gas_algebra::{
@@ -275,7 +276,12 @@ crate::gas_schedule::macros::define_gas_parameters!(
275276
max_aa_gas: Gas,
276277
{ RELEASE_V1_26.. => "max_aa_gas" },
277278
60,
278-
]
279+
],
280+
[
281+
slh_dsa_sha2_128s_base_cost: InternalGas,
282+
{ RELEASE_V1_41.. => "slh_dsa_sha2_128s.base" },
283+
13_800_000,
284+
],
279285
]
280286
);
281287

0 commit comments

Comments
 (0)