Spaces:
Sleeping
Sleeping
Update src/verifier.rs
Browse files- src/verifier.rs +10 -3
src/verifier.rs
CHANGED
|
@@ -1,19 +1,26 @@
|
|
| 1 |
use crate::opcode::Opcode;
|
| 2 |
|
| 3 |
pub fn verify_program(bytes: &[u8]) -> Result<(), String> {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
for chunk in bytes.chunks(8) {
|
| 5 |
let opcode = Opcode::from_byte(chunk[0])
|
| 6 |
.ok_or("Unknown opcode")?;
|
| 7 |
|
| 8 |
-
|
| 9 |
-
if (0xE0..=0xE5).contains(&(chunk[0])) {
|
| 10 |
return Err("Constitutional violation".into());
|
| 11 |
}
|
| 12 |
|
| 13 |
-
// Hard invariants
|
| 14 |
if opcode == Opcode::CISS && chunk[5] == 0 {
|
| 15 |
return Err("Zero credit issuance forbidden".into());
|
| 16 |
}
|
| 17 |
}
|
|
|
|
| 18 |
Ok(())
|
| 19 |
}
|
|
|
|
| 1 |
use crate::opcode::Opcode;
|
| 2 |
|
| 3 |
pub fn verify_program(bytes: &[u8]) -> Result<(), String> {
|
| 4 |
+
if bytes.len() % 8 != 0 {
|
| 5 |
+
return Err("Program length must be multiple of 8 bytes".into());
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
if bytes.len() > 8192 {
|
| 9 |
+
return Err("Program too large".into());
|
| 10 |
+
}
|
| 11 |
+
|
| 12 |
for chunk in bytes.chunks(8) {
|
| 13 |
let opcode = Opcode::from_byte(chunk[0])
|
| 14 |
.ok_or("Unknown opcode")?;
|
| 15 |
|
| 16 |
+
if (0xE0..=0xE5).contains(&chunk[0]) {
|
|
|
|
| 17 |
return Err("Constitutional violation".into());
|
| 18 |
}
|
| 19 |
|
|
|
|
| 20 |
if opcode == Opcode::CISS && chunk[5] == 0 {
|
| 21 |
return Err("Zero credit issuance forbidden".into());
|
| 22 |
}
|
| 23 |
}
|
| 24 |
+
|
| 25 |
Ok(())
|
| 26 |
}
|