Skip to content

Commit 2631ff3

Browse files
committed
fix(voting-tools-rs): Cap Registration Nonce at the Slot# of the Registration Transaction to fix Yoroi nonce eclipsing issue.
1 parent bd29fee commit 2631ff3

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

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

Lines changed: 8 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,7 @@ impl RawRegistration {
245246
})
246247
}
247248

248-
fn raw_reg_conversion(&self, network_id: NetworkId) -> Result<Registration, Box<dyn Error>> {
249+
fn raw_reg_conversion(&self, network_id: NetworkId, slot_no: SlotNo) -> Result<Registration, Box<dyn Error>> {
249250
let decoded: ciborium::value::Value =
250251
ciborium::de::from_reader(Cursor::new(&self.bin_reg))?;
251252

@@ -283,7 +284,11 @@ impl RawRegistration {
283284

284285
// A nonce that identifies that most recent delegation
285286
let nonce = match inspect_nonce(metamap) {
286-
Ok(value) => value,
287+
Ok(value) => if value.0 < slot_no.0 { // Don't allow nonce > slot number
288+
value
289+
} else {
290+
Nonce(slot_no.0)
291+
},
287292
Err(value) => return value,
288293
};
289294

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)