Skip to content
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

Skip the panic reason from canonical serialization #826

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading