Просмотр исходного кода

zkas: Prepend magic AND version.

parazyd 4 лет назад
Родитель
Сommit
fe6c62f38a
2 измененных файлов с 12 добавлено и 10 удалено
  1. 9 8
      book/src/zkas/bincode.md
  2. 3 2
      zkas/src/compiler.rs

+ 9 - 8
book/src/zkas/bincode.md

@@ -18,6 +18,7 @@ The compiled binary blob has the following layout:
 
 ```
 MAGIC_BYTES
+BINARY_VERSION
 .constant
 CONSTANT_TYPE STACK_INDEX CONSTANT_NAME 
 CONSTANT_TYPE STACK_INDEX CONSTANT_NAME 
@@ -37,15 +38,17 @@ TBD
 ## `MAGIC_BYTES`
 
 The magic bytes are the file signature consisting of four bytes used
-to identify the zkas binary code. It also contains the binary version
-to allow parsing potential different formats in the future.
+to identify the zkas binary code. They consist of:
 
-They consist of:
+> `0x0b` `0xxx` `0xb1` `0x35`
 
-> `0xf3` `0x42` `0x69` `BINARY_VERSION`
 
-Where binary version is the byte representing the format version.
+## `BINARY_VERSION`
 
+The binary code also contains the binary version to allow parsing
+potential different formats in the future.
+
+> `0x01`
 
 ## `.constant`
 
@@ -70,9 +73,7 @@ The `.circuit` section holds the procedural logic of the ZK proof.
 In here we have statements with opcodes that are executed as
 understood by the VM. The statements are in the form of:
 
-```
-OPCODE ARG_NUM STACK_INDEX ... STACK_INDEX
-```
+> `OPCODE ARG_NUM STACK_INDEX ... STACK_INDEX`
 
 where:
 

+ 3 - 2
zkas/src/compiler.rs

@@ -7,7 +7,7 @@ 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 const MAGIC_BYTES: [u8; 4] = [0x0b, 0x00, 0xb1, 0x35];
 
 pub struct Compiler {
     file: String,
@@ -37,8 +37,9 @@ impl Compiler {
     pub fn compile(&self) -> Vec<u8> {
         let mut bincode = vec![];
 
-        // Write the magic bytes
+        // Write the magic bytes and version
         bincode.extend_from_slice(&MAGIC_BYTES);
+        bincode.push(BINARY_VERSION);
 
         let mut stack_idx: u64 = 0;