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
/// Task #107 — Emit the canonical EVM `Panic(uint256)` revert envelope for a
/// given panic code and THROW it.
///
/// The envelope shape is:
/// `keccak256("Panic(uint256)")[0..4] || abi.encode(uint256 code)`
/// = `0x4e487b71` (4 bytes) || `<32-byte big-endian code>`
///
/// This matches the shape consumed by `catch Panic(uint code)` in
/// `src/ir/statements/dispatch/try_catch.rs` and by the observe() helper
/// in `tests/fuzz_tests.rs`, so migrated call sites all route through the
/// same canonical path.
///
/// Before Task #103 / #107, sites emitted a raw `PushLiteral(ByteString("Panic: 0xNN")) ; Throw`
/// which the runtime surfaced only as an exception-message string and made
/// `catch Panic(uint code)` fail to bind. This helper replaces that shape
/// everywhere it was used (assert false, div/mod zero, arith over/under-flow,
/// unary negation, enum range cast, abi.decode short buffer, array pop from
/// empty) with the canonical envelope.
///
/// Stack contract: pushes the envelope ByteString then emits `Throw`. No
/// items are popped.
///
/// Emitted instructions:
/// ```text
/// PushLiteral ByteArray([0x4e, 0x48, 0x7b, 0x71]) ; selector
/// PushLiteral ByteArray([0x00 * 31, code]) ; 32-byte BE payload
/// CallBuiltin BytesConcat 2 ; selector || payload
/// Throw
/// ```