File size: 669 Bytes
ca43859
 
 
b5ac7c4
 
 
 
 
 
 
 
ca43859
 
 
 
b5ac7c4
ca43859
 
 
 
 
 
 
b5ac7c4
ca43859
 
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
use crate::opcode::Opcode;

pub fn verify_program(bytes: &[u8]) -> Result<(), String> {
    if bytes.len() % 8 != 0 {
        return Err("Program length must be multiple of 8 bytes".into());
    }

    if bytes.len() > 8192 {
        return Err("Program too large".into());
    }

    for chunk in bytes.chunks(8) {
        let opcode = Opcode::from_byte(chunk[0])
            .ok_or("Unknown opcode")?;

        if (0xE0..=0xE5).contains(&chunk[0]) {
            return Err("Constitutional violation".into());
        }

        if opcode == Opcode::CISS && chunk[5] == 0 {
            return Err("Zero credit issuance forbidden".into());
        }
    }

    Ok(())
}