Skip to content

Commit 9db3bea

Browse files
stevenjkukkok3
andauthored
feat: Cap Nonce to Slot# of the transaction. | NPG-000 (#712)
# Description Prevents an extraordinarily large Nonce from eclipsing other later registrations. ## Checklist - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] Any dependent changes have been merged and published in downstream modules --------- Co-authored-by: kukkok3 <[email protected]>
1 parent 1b24d56 commit 9db3bea

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/voting-tools-rs/src/data/mod.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,15 @@ impl RawRegistration {
225225
&self,
226226
cddl_config: &CddlConfig,
227227
network_id: NetworkId,
228+
slot_no: SlotNo,
228229
) -> Result<SignedRegistration, Box<dyn Error>> {
229230
// validate cddl: 61284
230231
validate_reg_cddl(&self.bin_reg, cddl_config)?;
231232

232233
// validate cddl: 61285
233234
validate_sig_cddl(&self.bin_sig, cddl_config)?;
234235

235-
let registration = self.raw_reg_conversion(network_id)?;
236+
let registration = self.raw_reg_conversion(network_id, slot_no)?;
236237

237238
let signature = self.raw_sig_conversion()?;
238239

@@ -245,7 +246,11 @@ impl RawRegistration {
245246
})
246247
}
247248

248-
fn raw_reg_conversion(&self, network_id: NetworkId) -> Result<Registration, Box<dyn Error>> {
249+
fn raw_reg_conversion(
250+
&self,
251+
network_id: NetworkId,
252+
slot_no: SlotNo,
253+
) -> Result<Registration, Box<dyn Error>> {
249254
let decoded: ciborium::value::Value =
250255
ciborium::de::from_reader(Cursor::new(&self.bin_reg))?;
251256

@@ -283,7 +288,14 @@ impl RawRegistration {
283288

284289
// A nonce that identifies that most recent delegation
285290
let nonce = match inspect_nonce(metamap) {
286-
Ok(value) => value,
291+
Ok(value) => {
292+
if value.0 < slot_no.0 {
293+
// Don't allow nonce > slot number
294+
value
295+
} else {
296+
Nonce(slot_no.0)
297+
}
298+
}
287299
Err(value) => return value,
288300
};
289301

src/voting-tools-rs/src/verification/verify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub fn filter_registrations(
100100
};
101101

102102
// deserialize the raw Binary CBOR.
103-
let reg = match rawreg.to_signed(&cddl, network_id) {
103+
let reg = match rawreg.to_signed(&cddl, network_id, SlotNo(slot as u64)) {
104104
Err(err) => {
105105
invalids.push(InvalidRegistration {
106106
spec_61284: Some(prefix_hex(&rawreg.bin_reg)),

0 commit comments

Comments
 (0)