Skip to content
This repository has been archived by the owner on Jan 8, 2025. It is now read-only.

Commit

Permalink
propagate returndata of revert/success call, not exceptional fail
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Sep 4, 2024
1 parent 4ee074c commit 508b823
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
18 changes: 14 additions & 4 deletions crates/evm/src/call_helpers.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,20 @@ impl CallHelpersImpl of CallHelpers {
let result = EVMTrait::process_message(message, ref self.env);
self.merge_child(@result);

if result.is_success() {
self.stack.push(1)?;
} else {
self.stack.push(0)?;
match result.status {
ExecutionResultStatus::Success => {
self.return_data = result.return_data;
self.stack.push(1)?;
},
ExecutionResultStatus::Revert => {
self.return_data = result.return_data;
self.stack.push(0)?;
},
ExecutionResultStatus::Exception => {
// If the call has halted exceptionnaly, the return_data is emptied.
self.return_data = [].span();
self.stack.push(0)?;
},
}

// Get the min between len(return_data) and call_ctx.ret_size.
Expand Down
1 change: 1 addition & 0 deletions crates/evm/src/create_helpers.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ impl CreateHelpersImpl of CreateHelpers {
self.stack.push(0)?;
},
ExecutionResultStatus::Exception => {
// returndata is emptied in case of exception
self.return_data = [].span();
self.stack.push(0)?;
},
Expand Down
1 change: 1 addition & 0 deletions crates/evm/src/model/vm.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ impl VMImpl of VMTrait {
self.return_data = *child.return_data;
},
ExecutionResultStatus::Revert => { self.gas_left += *child.gas_left; },
// If the call has halted exceptionnaly, the gas is not returned.
ExecutionResultStatus::Exception => {}
};
}
Expand Down

0 comments on commit 508b823

Please sign in to comment.