-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
When a script is executed, it should return a receipt with its status and used gas. However, if there is a halt-error defined in `InterpreterError::is_panic`, then the VM should be interrupted, no gas should be consumed, and no new state/receipt should be returned.
- Loading branch information
Showing
45 changed files
with
1,323 additions
and
713 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
//! Backtrace implementation to track script errors. | ||
//! | ||
//! As of the moment, doesn't support predicates. | ||
use crate::call::CallFrame; | ||
use crate::consts::*; | ||
use crate::interpreter::Interpreter; | ||
|
||
use fuel_asm::InstructionResult; | ||
use fuel_tx::Transaction; | ||
use fuel_types::{ContractId, Word}; | ||
|
||
#[derive(Debug)] | ||
/// Runtime description derived from a VM error. | ||
pub struct Backtrace { | ||
call_stack: Vec<CallFrame>, | ||
contract: ContractId, | ||
registers: [Word; VM_REGISTER_COUNT], | ||
memory: Vec<u8>, | ||
result: InstructionResult, | ||
tx: Transaction, | ||
} | ||
|
||
impl Backtrace { | ||
/// Create a backtrace from a vm instance and instruction result. | ||
/// | ||
/// This isn't copy-free and shouldn't be provided by default. | ||
pub fn from_vm_error<S>(vm: &Interpreter<S>, result: InstructionResult) -> Self { | ||
let call_stack = vm.call_stack().to_owned(); | ||
let contract = vm.internal_contract_or_default(); | ||
let memory = vm.memory().to_owned(); | ||
let tx = vm.transaction().clone(); | ||
let mut registers = [0; VM_REGISTER_COUNT]; | ||
|
||
registers.copy_from_slice(vm.registers()); | ||
|
||
Self { | ||
call_stack, | ||
contract, | ||
registers, | ||
memory, | ||
result, | ||
tx, | ||
} | ||
} | ||
|
||
/// Call stack of the VM when the error occurred. | ||
pub fn call_stack(&self) -> &[CallFrame] { | ||
self.call_stack.as_slice() | ||
} | ||
|
||
/// Last contract of the context when the error occurred. | ||
pub const fn contract(&self) -> &ContractId { | ||
&self.contract | ||
} | ||
|
||
/// Register set when the error occurred. | ||
pub const fn registers(&self) -> &[Word] { | ||
&self.registers | ||
} | ||
|
||
/// Memory of the VM when the error occurred. | ||
pub fn memory(&self) -> &[u8] { | ||
self.memory.as_slice() | ||
} | ||
|
||
/// [`InstructionResult`] of the error that caused this backtrace. | ||
pub const fn result(&self) -> &InstructionResult { | ||
&self.result | ||
} | ||
|
||
/// [`Transaction`] state when the error occurred. | ||
pub const fn tx(&self) -> &Transaction { | ||
&self.tx | ||
} | ||
|
||
/// Expose the internal attributes of the backtrace. | ||
pub fn into_inner( | ||
self, | ||
) -> ( | ||
Vec<CallFrame>, | ||
ContractId, | ||
[Word; VM_REGISTER_COUNT], | ||
Vec<u8>, | ||
InstructionResult, | ||
Transaction, | ||
) { | ||
let Self { | ||
call_stack, | ||
contract, | ||
registers, | ||
memory, | ||
result, | ||
tx, | ||
} = self; | ||
|
||
(call_stack, contract, registers, memory, result, tx) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.