diff --git a/coins/monero/src/ringct.rs b/coins/monero/src/ringct.rs index 72cc1c2d..d564fe9f 100644 --- a/coins/monero/src/ringct.rs +++ b/coins/monero/src/ringct.rs @@ -194,9 +194,17 @@ impl RctBase { } /// Read a RctBase. - pub fn read(inputs: usize, outputs: usize, r: &mut R) -> io::Result<(RctBase, RctType)> { + pub fn read( + inputs: usize, + outputs: usize, + r: &mut R, + ) -> io::Result> { + let rct_type = read_byte(r)?; + if rct_type == 0 { + return Ok(None); + } let rct_type = - RctType::try_from(read_byte(r)?).map_err(|()| io::Error::other("invalid RCT type"))?; + RctType::try_from(rct_type).map_err(|()| io::Error::other("invalid RCT type"))?; match rct_type { RctType::AggregateMlsagBorromean | RctType::MlsagBorromean => {} @@ -215,7 +223,8 @@ impl RctBase { } } - Ok(( + Ok(Some(( + rct_type, RctBase { fee: read_varint(r)?, // Only read pseudo_outs if they have yet to be moved to RctPrunable @@ -232,8 +241,7 @@ impl RctBase { .collect::>()?, commitments: read_raw_vec(read_point, outputs, r)?, }, - rct_type, - )) + ))) } } @@ -469,11 +477,11 @@ impl RctProofs { inputs: usize, outputs: usize, r: &mut R, - ) -> io::Result { - let base = RctBase::read(inputs, outputs, r)?; - Ok(RctProofs { - base: base.0, - prunable: RctPrunable::read(base.1, ring_length, inputs, outputs, r)?, - }) + ) -> io::Result> { + let Some((rct_type, base)) = RctBase::read(inputs, outputs, r)? else { return Ok(None) }; + Ok(Some(RctProofs { + base, + prunable: RctPrunable::read(rct_type, ring_length, inputs, outputs, r)?, + })) } } diff --git a/coins/monero/src/transaction.rs b/coins/monero/src/transaction.rs index b365cfe4..9d683b65 100644 --- a/coins/monero/src/transaction.rs +++ b/coins/monero/src/transaction.rs @@ -395,7 +395,7 @@ impl Transaction { Ok(Transaction::V1 { prefix, signatures }) } else if version == 2 { - let proofs = Some(RctProofs::read( + let proofs = RctProofs::read( prefix.inputs.first().map_or(0, |input| match input { Input::Gen(_) => 0, Input::ToKey { key_offsets, .. } => key_offsets.len(), @@ -403,7 +403,7 @@ impl Transaction { prefix.inputs.len(), prefix.outputs.len(), r, - )?); + )?; Ok(Transaction::V2 { prefix, proofs }) } else {