-
Notifications
You must be signed in to change notification settings - Fork 90
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
Panic on instructions with non-zero reserved part #737
Conversation
fuel-asm/src/encoding_tests.rs
Outdated
fn invalid_reserved_part() { | ||
// Args: 0 | ||
Instruction::try_from([Opcode::NOOP as u8, 0, 0, 0]).unwrap(); | ||
Instruction::try_from([Opcode::NOOP as u8, 0, 0, 1]) | ||
.expect_err("Reserved part is nonzero"); | ||
|
||
// Args: 1 | ||
Instruction::try_from([Opcode::RET as u8, 0, 0, 0]).unwrap(); | ||
Instruction::try_from([Opcode::RET as u8, 0, 0, 1]) | ||
.expect_err("Reserved part is nonzero"); | ||
|
||
// Args: 2 | ||
Instruction::try_from([Opcode::NOT as u8, 0, 0, 0]).unwrap(); | ||
Instruction::try_from([Opcode::NOT as u8, 0, 0, 1]) | ||
.expect_err("Reserved part is nonzero"); | ||
|
||
// Args: 3 | ||
Instruction::try_from([Opcode::XOR as u8, 0, 0, 0]).unwrap(); | ||
Instruction::try_from([Opcode::XOR as u8, 0, 0, 1]) | ||
.expect_err("Reserved part is nonzero"); | ||
} |
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.
While this behaviour is implemented as a macro, and all opcodes inherit this behaviour, it may be worth testing this for all opcodes. From an opcode-centric perspective, we want to show that each opcode fulfills the specification (regardless of implementation).
Maybe we could have a macro-generated test(s) that tests common behaviours for a given opcode, and maintain a list that invokes this test macro for all opcodes.
But that's up to you - it may be overkill here.
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.
Makes sense to me.
fuel-asm/src/encoding_tests.rs
Outdated
// Args: 1 | ||
Instruction::try_from([Opcode::RET as u8, 0, 0, 0]).unwrap(); | ||
Instruction::try_from([Opcode::RET as u8, 0, 0, 1]) | ||
.expect_err("Reserved part is nonzero"); | ||
|
||
// Args: 2 | ||
Instruction::try_from([Opcode::NOT as u8, 0, 0, 0]).unwrap(); | ||
Instruction::try_from([Opcode::NOT as u8, 0, 0, 1]) | ||
.expect_err("Reserved part is nonzero"); | ||
|
||
// Args: 3 | ||
Instruction::try_from([Opcode::XOR as u8, 0, 0, 0]).unwrap(); | ||
Instruction::try_from([Opcode::XOR as u8, 0, 0, 1]) | ||
.expect_err("Reserved part is nonzero"); |
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.
I don't see where are we using arg 2 and arg 3=)
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.
Let's discuss first regarding suggestion to move the check to unpack
level=)
…#583) VM PR: FuelLabs/fuel-vm#737 What is says on the tin. This is a small but breaking change. It's unlikely to cause any breakage, as no Sway code or code constructed using the fuel-asm helper functions is affected. This change is originating from an audit report that pointed out the likely unintentional behavior of the unused part of instruction is ignored. ### Before requesting review - [x] I have reviewed the code myself Co-authored-by: Green Baneling <XgreenX9999@gmail.com>
# Conflicts: # CHANGELOG.md
# Conflicts: # CHANGELOG.md
…f packed. Added tests to verify behaviour for the unreserved parts.
fuel-asm/src/lib.rs
Outdated
#[cfg_attr(feature = "typescript", wasm_bindgen::prelude::wasm_bindgen)] | ||
pub struct RegId(u8); | ||
|
||
/// Represents a 6-bit immediate value, guaranteed to be masked by construction. | ||
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] | ||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
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.
The derived Deserialize
impl allows constructing invalid values.
…`Instruction` takes 12(with aligment) bytes instead of 4
Spec PR: FuelLabs/fuel-specs#583
See spec pr for extended description.
Checklist
Before requesting review