Solux Docs

Program reference#

Source: programs/solux/src/lib.rs.

Program id B8MCmdQhqXmasf75YdSCBMTgUqeSwbqaHc27ryWL4v8a (reserved; not deployed on a public cluster yet)
Size 47,624 bytes of SBF
Dependencies solana-program, the rv32 core, the lz decoder

Accounts#

A machine is two accounts, both owned by the program and created by the client with the System program's CreateAccount:

Account Size Holds
Machine 5,376 bytes Header, CPU state, console, keyboard buffer
RAM up to 10 MiB The guest's physical memory, from 0x8000_0000

Every instruction takes machine (writable) and ram (writable) first.

Instructions#

The first byte of the instruction data is the tag. Integers are little-endian.

Tag Name Data after the tag Extra accounts Who
0 Init entry: u32, dtb: u32 authority (signer) anyone, once
1 Write offset: u32, bytes authority (signer) authority, before the first Step
4 WriteLz offset: u32, out_len: u32, compressed bytes authority (signer) authority, before the first Step
2 Step instructions: u32, then anything (a nonce) none anyone
5 Type the keys authority (signer) authority
3 Close nothing authority (signer), recipient (writable) authority
  • Init records the authority and the RAM account, and writes the CPU's reset state: pc = entry, a0 = 0, a1 = dtb.
  • Write and WriteLz fill RAM. A WriteLz chunk decodes to out_len bytes at offset; its back-references may reach anything already in RAM. Once the first Step has run, memory belongs to the machine and both fail with AlreadyRunning.
  • Step runs min(instructions, 1_000_000) guest instructions, fewer if the guest powers off, reboots or gets stuck. Set the transaction's compute-unit limit to 1,400,000.
  • Type appends keys to the 248-byte keyboard buffer. The guest reads them during later Steps.
  • Close moves both accounts' lamports to the recipient and empties them.

Machine account layout#

Offset Size Field
0 8 Magic LNXSOL01
8 32 Authority
40 32 RAM account
72 4 Status: 0 loading, 1 running, 2 powered off, 3 rebooted, 4 stuck
76 8 Steps executed
84 8 Console bytes ever printed
96 204 CPU state
304 4 Length of the unfinished console line
308 700 The unfinished line, carried to the next Step
1024 4096 Console ring: the last 4,096 bytes printed
5120 4 Keys in the keyboard buffer
5124 4 Keys already read by the guest
5128 248 Keyboard buffer

The CPU state is x0 to x31 (32 × u32), then pc, mstatus, mie, mip, mtvec, mscratch, mepc, mcause, mtval, privilege, wfi, reservation, uart_lcr (u32 each), then mtime, mtimecmp, instret (u64 each).

Logs#

Each Step logs every console line the guest finished during it, then one summary line:

Program log: Total 19.75 (2 items)
Program log: solux: step 2 ran 2205 instructions, total 15205, pc 0x80000488, PowerOff

The exit is Budget (more to run), PowerOff, Reboot or Stuck. A line still being printed when the Step ends waits in the account and is logged by the Step that finishes it.

Errors#

Custom program errors (ProgramError::Custom):

Code Name When
0x100 BadInstruction Unknown tag or data too short
0x101 NotInitialized No Init yet
0x102 AlreadyInitialized Init twice
0x103 WrongRamAccount The RAM account is not the one recorded at Init
0x104 NotAuthority The signer is not the machine's authority
0x105 AlreadyRunning Write or WriteLz after the first Step
0x106 Halted Step or Type on a machine that powered off, rebooted or got stuck
0x107 OutOfBounds Write past the end of RAM
0x108 BadCompressedData WriteLz data does not decode
0x109 InputFull More than 248 keys waiting

Compressed upload format#

LZ77 with LZ4-like sequences: a token byte (high nibble: literal count; low nibble: match length minus 4; 15 means extension bytes follow, 255 = add and continue), the literals, then, unless the chunk is complete, the match distance as a LEB128 varint and the match-length extension. Distances count back from the write position across the whole RAM, so a chunk can copy from earlier waves. Source: crates/lz.