Skip to content

Commit

Permalink
fix: advance buffer during 2718 decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr committed Sep 25, 2024
1 parent 6ff6a9d commit 406b1e1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 3 additions & 1 deletion crates/consensus/src/transaction/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,9 +636,11 @@ mod tests {
let tx_signed = tx.into_signed(signature);
let tx_envelope: TxEnvelope = tx_signed.into();
let encoded = tx_envelope.encoded_2718();
let decoded = TxEnvelope::decode_2718(&mut encoded.as_ref()).unwrap();
let mut slice = encoded.as_slice();
let decoded = TxEnvelope::decode_2718(&mut slice).unwrap();
assert_eq!(encoded.len(), tx_envelope.encode_2718_len());
assert_eq!(decoded, tx_envelope);
assert_eq!(slice.len(), 0);
}

#[test]
Expand Down
5 changes: 4 additions & 1 deletion crates/eips/src/eip2718.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ pub trait Decodable2718: Sized {
/// [EIP-2718]: https://eips.ethereum.org/EIPS/eip-2718
fn decode_2718(buf: &mut &[u8]) -> Eip2718Result<Self> {
Self::extract_type_byte(buf)
.map(|ty| Self::typed_decode(ty, &mut &buf[1..]))
.map(|ty| {
buf.advance(1);
Self::typed_decode(ty, buf)
})
.unwrap_or_else(|| Self::fallback_decode(buf))
}

Expand Down

0 comments on commit 406b1e1

Please sign in to comment.