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

feat: Cap Nonce to Slot# of the transaction. | NPG-000 #712

Merged
merged 4 commits into from
Sep 13, 2024
Merged
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
18 changes: 15 additions & 3 deletions src/voting-tools-rs/src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,15 @@ impl RawRegistration {
&self,
cddl_config: &CddlConfig,
network_id: NetworkId,
slot_no: SlotNo,
) -> Result<SignedRegistration, Box<dyn Error>> {
// validate cddl: 61284
validate_reg_cddl(&self.bin_reg, cddl_config)?;

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

let registration = self.raw_reg_conversion(network_id)?;
let registration = self.raw_reg_conversion(network_id, slot_no)?;

let signature = self.raw_sig_conversion()?;

Expand All @@ -245,7 +246,11 @@ impl RawRegistration {
})
}

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

Expand Down Expand Up @@ -283,7 +288,14 @@ impl RawRegistration {

// A nonce that identifies that most recent delegation
let nonce = match inspect_nonce(metamap) {
Ok(value) => value,
Ok(value) => {
if value.0 < slot_no.0 {
// Don't allow nonce > slot number
value
} else {
Nonce(slot_no.0)
}
}
Err(value) => return value,
};

Expand Down
2 changes: 1 addition & 1 deletion src/voting-tools-rs/src/verification/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub fn filter_registrations(
};

// deserialize the raw Binary CBOR.
let reg = match rawreg.to_signed(&cddl, network_id) {
let reg = match rawreg.to_signed(&cddl, network_id, SlotNo(slot as u64)) {
Err(err) => {
invalids.push(InvalidRegistration {
spec_61284: Some(prefix_hex(&rawreg.bin_reg)),
Expand Down
Loading