-
Notifications
You must be signed in to change notification settings - Fork 86
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
Fix ldc opcode in internal contexts #736
Conversation
Word::from_be_bytes(self.memory.read_bytes(code_size_ptr)?); | ||
let old_code_size = padded_len_word(old_code_size) | ||
.expect("Code size cannot overflow with padding"); |
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 would assume the size should already be padded when written in memory. Is it really correct to just compute padding 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.
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.
Yep. Shouldn't CallFrame
use the padded value?
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.
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'll ask the team, but a quick search from Sway codebase seems like they don't use this for anything. Time to remove? :D
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.
Doesnt "word-aligned" mean the same thing as padding 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.
Yep.
Moved to use padded size in 7335f9f.
… into dento/fix-ldc-frame-size-update
fuel-vm/src/interpreter/flow.rs
Outdated
let frame_end = | ||
(*self.registers.system_registers.fp) + CallFrame::serialized_size() as Word; |
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 frame_end = | |
(*self.registers.system_registers.fp) + CallFrame::serialized_size() as Word; | |
let frame_end = | |
(*self.registers.system_registers.fp) + total_size_in_stack as Word; |
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 name was wrong but the math correct. I've fixed this in 27ef70c
Could ou also update the Specification to specify this behaviour explicitly, please?=) |
|
let code_start = | ||
(*self.registers.system_registers.fp) + CallFrame::serialized_size() as Word; | ||
|
||
*self.registers.system_registers.pc = code_start; |
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.
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.
No? Essentially it was before like this:
content_size = len - frame_len_with_padding
frame_end = fp + content_size # return value
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.
Ohh, there is saturating_sub
, I missed that=D
@@ -2047,3 +2047,180 @@ fn coinbase_works() { | |||
|
|||
assert_eq!(data.as_ref().unwrap(), &*expected); | |||
} | |||
|
|||
#[test] | |||
fn various_ldc_issues_poc() { |
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.
Is there any way to break this down in to more granular && specific tests? Tests like this are hard to maintain as it's not clear what behavior they are defining.
Introduced here: FuelLabs/fuel-vm#736 ### Before requesting review - [x] I have reviewed the code myself
LDC opcode was behaving incorrectly in internal contexts, i.e. when called from within a contract.
FuelLabs/fuel-specs#584
Checklist
Before requesting review