Explorar o código

zkas/compiler: Prepend magic bytes to binary and remove STACK_INDEX from contract.

parazyd %!s(int64=4) %!d(string=hai) anos
pai
achega
c999e20cc4
Modificáronse 1 ficheiros con 8 adicións e 1 borrados
  1. 8 1
      zkas/src/compiler.rs

+ 8 - 1
zkas/src/compiler.rs

@@ -4,6 +4,11 @@ use termion::{color, style};
 
 
 use crate::ast::{Constants, StatementType, Statements, Witnesses};
 use crate::ast::{Constants, StatementType, Statements, Witnesses};
 
 
+/// Version of the binary
+pub const BINARY_VERSION: u8 = 1;
+/// Magic bytes prepended to the binary
+pub const MAGIC_BYTES: [u8; 4] = [0xf3, 0x42, 0x69, BINARY_VERSION];
+
 pub struct Compiler {
 pub struct Compiler {
     file: String,
     file: String,
     lines: Vec<String>,
     lines: Vec<String>,
@@ -32,6 +37,9 @@ impl Compiler {
     pub fn compile(&self) -> Vec<u8> {
     pub fn compile(&self) -> Vec<u8> {
         let mut bincode = vec![];
         let mut bincode = vec![];
 
 
+        // Write the magic bytes
+        bincode.extend_from_slice(&MAGIC_BYTES);
+
         let mut stack_idx: u64 = 0;
         let mut stack_idx: u64 = 0;
 
 
         // Temporary stack vector for lookups
         // Temporary stack vector for lookups
@@ -50,7 +58,6 @@ impl Compiler {
         for i in &self.witnesses {
         for i in &self.witnesses {
             tmp_stack.push(i.name.as_str());
             tmp_stack.push(i.name.as_str());
             bincode.push(i.typ as u8);
             bincode.push(i.typ as u8);
-            bincode.extend_from_slice(&stack_idx.to_le_bytes());
             stack_idx += 1;
             stack_idx += 1;
         }
         }