-
Notifications
You must be signed in to change notification settings - Fork 8
fix: handle oracle messages as a tlv #131
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
base: master
Are you sure you want to change the base?
Conversation
b27508d to
8a7ce23
Compare
| oracle_public_key: crate::ser_impls::read_schnorr_pubkey(reader)?, | ||
| signatures: { | ||
| let len: u16 = Readable::read(reader)?; | ||
| let mut signatures = Vec::with_capacity(len as usize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No validation on len before allocating capacity?
| impl Readable for OracleAnnouncement { | ||
| fn read<R: bitcoin::io::Read>(reader: &mut R) -> Result<Self, DecodeError> { | ||
| let _type_id: u64 = BigSize::read(reader)?.0; | ||
| let _length: u64 = BigSize::read(reader)?.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On lines 252, 257, 502 the _length field is read but never validated?
| let _type_id: u64 = BigSize::read(reader)?.0; | ||
| let _length: u64 = BigSize::read(reader)?.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is TLV header read twice?
| let event_size = self.oracle_event.serialized_length(); | ||
| BigSize(self.oracle_event.type_id() as u64).serialized_length() + | ||
| BigSize(event_size as u64).serialized_length() + | ||
| event_size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calculating the size manually could lead to buffer overflows.
| let mut cursor = Cursor::new(bytes); | ||
| let announcement = OracleAnnouncement::read(&mut cursor); | ||
| println!("{:?}", announcement); | ||
| assert!(announcement.is_ok()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add validation on whether the parsed content matches the expected values?
| // fn read_oracle_message<T: Readable>(msg: MagnoliaResponse) -> Result<T, Error> { | ||
| // let bytes = hex::decode(msg.hex).map_err(|e| Error::OracleError(e.to_string()))?; | ||
| // let mut cursor = Cursor::new(bytes); | ||
| // let _type_id: u64 = lightning::util::ser::BigSize::read(&mut cursor).unwrap().0; | ||
| // let _length: u64 = lightning::util::ser::BigSize::read(&mut cursor).unwrap().0; | ||
| // T::read(&mut cursor).map_err(|e| Error::OracleError(e.to_string())) | ||
| // } | ||
| // impl_dlc_writeable!(OracleAnnouncement, { | ||
| // (announcement_signature, {cb_writeable, write_schnorrsig, read_schnorrsig}), | ||
| // (oracle_public_key, {cb_writeable, write_schnorr_pubkey, read_schnorr_pubkey}), | ||
| // (oracle_event, {cb_writeable, write_as_tlv, read_as_tlv}) | ||
| // }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this worth keeping commented out versus deleting entirely?
No description provided.