Skip to content

Commit

Permalink
bus-mapping: fix return_data (privacy-scaling-explorations#874)
Browse files Browse the repository at this point in the history
* bus-mapping: fix return_data

* add zero check

Co-authored-by: adria0.eth <[email protected]>
Co-authored-by: Han <[email protected]>
  • Loading branch information
3 people authored Nov 4, 2022
1 parent a7efd0d commit b87a9d2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
23 changes: 23 additions & 0 deletions bus-mapping/src/circuit_input_builder/input_state_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,29 @@ impl<'a> CircuitInputStateRef<'a> {
/// Handle a return step caused by any opcode that causes a return to the
/// previous call context.
pub fn handle_return(&mut self, step: &GethExecStep) -> Result<(), Error> {
// handle return_data
if !self.call()?.is_root {
match step.op {
OpcodeId::RETURN | OpcodeId::REVERT => {
let offset = step.stack.nth_last(0)?.as_usize();
let length = step.stack.nth_last(1)?.as_usize();
// TODO: Try to get rid of clone.
// At the moment it conflicts with `call_ctx` and `caller_ctx`.
let callee_memory = self.call_ctx()?.memory.clone();
let caller_ctx = self.caller_ctx_mut()?;
caller_ctx.return_data.resize(length, 0);
if length != 0 {
caller_ctx.return_data[0..length]
.copy_from_slice(&callee_memory.0[offset..offset + length]);
}
}
_ => {
let caller_ctx = self.caller_ctx_mut()?;
caller_ctx.return_data.truncate(0);
}
}
}

let call = self.call()?.clone();
let call_ctx = self.call_ctx()?;

Expand Down
3 changes: 0 additions & 3 deletions bus-mapping/src/evm/opcodes/return.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ impl Opcode for Return {

caller_ctx.memory.0[return_offset..return_offset + copy_length]
.copy_from_slice(&callee_memory.0[offset..offset + copy_length]);
caller_ctx.return_data.resize(length, 0);
caller_ctx.return_data[0..copy_length]
.copy_from_slice(&callee_memory.0[offset..offset + copy_length]);

handle_copy(
state,
Expand Down

0 comments on commit b87a9d2

Please sign in to comment.