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

fix(stack): pop with five items was not correct #1472

Merged
merged 1 commit into from
May 31, 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
4 changes: 2 additions & 2 deletions crates/interpreter/src/instructions/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ macro_rules! pop {
$crate::pop_ret!($interp, $x1, $x2, $x3, $x4, ())
};
($interp:expr, $x1:ident, $x2:ident, $x3:ident, $x4:ident, $x5:ident) => {
pop_ret!($interp, $x1, $x2, $x3, $x4, $x5, ())
$crate::pop_ret!($interp, $x1, $x2, $x3, $x4, $x5, ())
};
}

Expand Down Expand Up @@ -206,7 +206,7 @@ macro_rules! pop_ret {
let ($x1, $x2, $x3, $x4) = unsafe { $interp.stack.pop4_unsafe() };
};
($interp:expr, $x1:ident, $x2:ident, $x3:ident, $x4:ident, $x5:ident, $ret:expr) => {
if $interp.stack.len() < 4 {
if $interp.stack.len() < 5 {
$interp.instruction_result = $crate::InstructionResult::StackUnderflow;
return $ret;
}
Expand Down
7 changes: 7 additions & 0 deletions crates/interpreter/src/instructions/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,18 @@ pub fn returndataload<H: Host + ?Sized>(interpreter: &mut Interpreter, _host: &m
gas!(interpreter, gas::VERYLOW);
pop_top!(interpreter, offset);
let offset_usize = as_usize_or_fail!(interpreter, offset);
// TODO EOF needs to be padded with zeros, it is not correct to fail.
/*
if offset + 32 > len(returndata buffer) the result is zero-padded
(same behavior as CALLDATALOAD).see matching behavior of RETURNDATACOPY
in Modified Behavior section.
*/
if offset_usize.saturating_add(32) > interpreter.return_data_buffer.len() {
// TODO(EOF) proper error.
interpreter.instruction_result = InstructionResult::OutOfOffset;
return;
}

*offset =
B256::from_slice(&interpreter.return_data_buffer[offset_usize..offset_usize + 32]).into();
}
Expand Down