1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use super::*;
impl ExecutionContext {
pub(crate) fn execute_flow_exceptions(&mut self, opcode: u8) -> Result<bool, RuntimeError> {
match opcode {
0x38 => {
// ABORT
return Err(RuntimeError::ExecutionError {
message: "ABORT instruction executed".to_string(),
});
}
0x39 => {
// ASSERT
let condition = self.pop_stack()?;
if condition.is_truthy() {
self.instruction_pointer += 1;
} else {
return Err(RuntimeError::ExecutionError {
message: "ASSERT failed".to_string(),
});
}
}
0x3A => {
// THROW
//
// Task #27 (runtime slice) — preserve the raw stack-top bytes
// verbatim in `self.revert_payload` BEFORE lossy-decoding them
// into a UTF-8 String for the exception message. The bridge
// reads `revert_payload` on the error path and routes it into
// `ExecutionResult.return_data`, giving callers an EVM-style
// `return_data = selector || abi.encode(args)` surface when
// the compiler lowering pushes structured bytes (follow-up
// slice) or when users hand-roll the payload today.
let payload = Self::stack_item_to_bytes(self.pop_stack()?);
self.revert_payload = payload.clone();
let message = String::from_utf8_lossy(&payload);
let message = if message.is_empty() {
"THROW".to_string()
} else {
format!("THROW: {message}")
};
self.dispatch_exception(message)?;
}
_ => return Ok(false),
}
Ok(true)
}
}