Skip to content

Commit

Permalink
Skip the panic reason from canonical serialization (#826)
Browse files Browse the repository at this point in the history
* Skip the panic reason from canonical serialization

* Updated CHANGELOG.md
  • Loading branch information
xgreenx authored Sep 16, 2024
1 parent bd97218 commit e75f4e8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed

#### Breaking
- [#826](https://github.com/FuelLabs/fuel-vm/pull/826): Skip the panic reason from canonical serialization of the panic receipt.
- [#821](https://github.com/FuelLabs/fuel-vm/pull/821): Added `block_transaction_size_limit` to `ConsensusParameters`. It adds a new `ConensusParametersV2` as a variant of the `ConsensusParameters`.
- [#670](https://github.com/FuelLabs/fuel-vm/pull/670): The `predicate` field of `fuel_tx::input::Coin` is now a wrapper struct `PredicateCode`.

Expand Down
20 changes: 20 additions & 0 deletions fuel-asm/src/panic_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::{
#[derive(fuel_types::canonical::Deserialize, fuel_types::canonical::Serialize)]
/// Describe a panic reason with the instruction that generated it
pub struct PanicInstruction {
#[canonical(skip)]
reason: PanicReason,
instruction: RawInstruction,
}
Expand Down Expand Up @@ -114,3 +115,22 @@ impl From<Word> for PanicInstruction {
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::op;
use fuel_types::canonical::Serialize;

#[test]
fn canonical_serialization_ignores_panic_reason() {
let revert_panic_instruction =
PanicInstruction::error(PanicReason::Revert, op::noop().into());
let out_of_gas_panic_instruction =
PanicInstruction::error(PanicReason::OutOfGas, op::noop().into());
assert_eq!(
revert_panic_instruction.to_bytes(),
out_of_gas_panic_instruction.to_bytes()
);
}
}
4 changes: 2 additions & 2 deletions fuel-asm/src/panic_reason.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ macro_rules! enum_from {
}

enum_from! {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, strum::EnumIter)]
#[derive(Default, Debug, Clone, Copy, PartialEq, Eq, Hash, strum::EnumIter)]
#[cfg_attr(feature = "typescript", wasm_bindgen::prelude::wasm_bindgen)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(fuel_types::canonical::Serialize, fuel_types::canonical::Deserialize)]
#[repr(u8)]
#[non_exhaustive]
/// Panic reason representation for the interpreter.
pub enum PanicReason {
#[default]
/// The byte can't be mapped to any known `PanicReason`.
UnknownPanicReason = 0x00,
/// Found `RVRT` instruction.
Expand Down
17 changes: 2 additions & 15 deletions fuel-tx/src/tests/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use rand::{
SeedableRng,
};
use std::fmt;
use strum::IntoEnumIterator;

pub fn assert_encoding_correct<T>(data: &[T])
where
Expand Down Expand Up @@ -158,7 +157,7 @@ fn output() {
fn receipt() {
let rng = &mut StdRng::seed_from_u64(8586);

let mut receipts = vec![
let receipts = vec![
Receipt::call(
rng.gen(),
rng.gen(),
Expand Down Expand Up @@ -216,7 +215,7 @@ fn receipt() {
Receipt::panic(
rng.gen(),
PanicInstruction::error(
PanicReason::ContractNotInInputs,
PanicReason::UnknownPanicReason,
op::ji(rng.gen::<Immediate24>() & 0xffffff).into(),
),
rng.gen(),
Expand All @@ -242,18 +241,6 @@ fn receipt() {
Receipt::burn(rng.gen(), rng.gen(), rng.gen(), rng.gen(), rng.gen()),
];

for panic_reason in PanicReason::iter() {
receipts.push(Receipt::panic(
rng.gen(),
PanicInstruction::error(
panic_reason,
op::ji(rng.gen::<Immediate24>() & 0xffffff).into(),
),
rng.gen(),
rng.gen(),
));
}

assert_encoding_correct(&receipts);
}

Expand Down

0 comments on commit e75f4e8

Please sign in to comment.