Skip to content

Commit

Permalink
shielded-pool: use typed Nullifier in EventSpend
Browse files Browse the repository at this point in the history
This is technically a breaking change but I think we should pretend it isn't, since it only affects events, and we never parse the events. So cleaning it up now is an opportunity to do a fix with minimal breakage.
  • Loading branch information
hdevalence authored and erwanor committed Dec 15, 2023
1 parent 50103f2 commit 4e6a169
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 261 deletions.
Binary file modified crates/cnidarium/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.
2 changes: 1 addition & 1 deletion crates/core/component/shielded-pool/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::NotePayload;

pub fn spend(nullifier: &Nullifier) -> EventSpend {
EventSpend {
nullifier: nullifier.to_bytes().to_vec(),
nullifier: Some((*nullifier).into()),
}
}

Expand Down
13 changes: 8 additions & 5 deletions crates/proto/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,17 @@ mod tests {
#[test]
fn event_round_trip() {
use super::*;
use crate::core::component::sct::v1alpha1::Nullifier;
use crate::core::component::shielded_pool::v1alpha1::{EventOutput, EventSpend};
use crate::crypto::tct::v1alpha1::StateCommitment;

let proto_spend = EventSpend {
nullifier: vec![
148, 190, 149, 23, 86, 113, 152, 145, 104, 242, 142, 162, 233, 239, 137, 141, 140,
164, 180, 98, 154, 55, 168, 255, 163, 228, 179, 176, 26, 25, 219, 211,
],
nullifier: Some(Nullifier {
inner: vec![
148, 190, 149, 23, 86, 113, 152, 145, 104, 242, 142, 162, 233, 239, 137, 141,
140, 164, 180, 98, 154, 55, 168, 255, 163, 228, 179, 176, 26, 25, 219, 211,
],
}),
};

let abci_spend = proto_spend.into_event();
Expand All @@ -80,7 +83,7 @@ mod tests {
"penumbra.core.component.shielded_pool.v1alpha1.EventSpend",
vec![abci::EventAttribute {
key: "nullifier".to_string(),
value: "\"lL6VF1ZxmJFo8o6i6e+JjYyktGKaN6j/o+SzsBoZ29M=\"".to_string(),
value: "{\"inner\":\"lL6VF1ZxmJFo8o6i6e+JjYyktGKaN6j/o+SzsBoZ29M=\"}".to_string(),
index: true,
}],
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ impl ::prost::Name for Spend {
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct EventSpend {
#[prost(bytes = "vec", tag = "1")]
pub nullifier: ::prost::alloc::vec::Vec<u8>,
#[prost(message, optional, tag = "1")]
pub nullifier: ::core::option::Option<super::super::sct::v1alpha1::Nullifier>,
}
impl ::prost::Name for EventSpend {
const NAME: &'static str = "EventSpend";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,12 @@ impl serde::Serialize for EventSpend {
{
use serde::ser::SerializeStruct;
let mut len = 0;
if !self.nullifier.is_empty() {
if self.nullifier.is_some() {
len += 1;
}
let mut struct_ser = serializer.serialize_struct("penumbra.core.component.shielded_pool.v1alpha1.EventSpend", len)?;
if !self.nullifier.is_empty() {
#[allow(clippy::needless_borrow)]
struct_ser.serialize_field("nullifier", pbjson::private::base64::encode(&self.nullifier).as_str())?;
if let Some(v) = self.nullifier.as_ref() {
struct_ser.serialize_field("nullifier", v)?;
}
struct_ser.end()
}
Expand Down Expand Up @@ -372,14 +371,12 @@ impl<'de> serde::Deserialize<'de> for EventSpend {
if nullifier__.is_some() {
return Err(serde::de::Error::duplicate_field("nullifier"));
}
nullifier__ =
Some(map_.next_value::<::pbjson::private::BytesDeserialize<_>>()?.0)
;
nullifier__ = map_.next_value()?;
}
}
}
Ok(EventSpend {
nullifier: nullifier__.unwrap_or_default(),
nullifier: nullifier__,
})
}
}
Expand Down
Binary file modified crates/proto/src/gen/proto_descriptor.bin.no_lfs
Binary file not shown.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "penumbra/core/keys/v1alpha1/keys.proto";
import "penumbra/core/num/v1alpha1/num.proto";
import "penumbra/crypto/decaf377_rdsa/v1alpha1/decaf377_rdsa.proto";
import "penumbra/crypto/tct/v1alpha1/tct.proto";
import "penumbra/core/component/sct/v1alpha1/sct.proto";

message Note {
asset.v1alpha1.Value value = 1;
Expand Down Expand Up @@ -64,7 +65,7 @@ message Spend {

// ABCI Event recording a spend.
message EventSpend {
bytes nullifier = 1;
core.component.sct.v1alpha1.Nullifier nullifier = 1;
}

// ABCI Event recording an output.
Expand Down

0 comments on commit 4e6a169

Please sign in to comment.