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

zkas: Use usize for stack indexes.

parazyd 4 лет назад
Родитель
Сommit
4b013f27ee
2 измененных файлов с 6 добавлено и 6 удалено
  1. 3 3
      src/zkas/compiler.rs
  2. 3 3
      src/zkas/decoder.rs

+ 3 - 3
src/zkas/compiler.rs

@@ -73,7 +73,7 @@ impl Compiler {
 
             for arg in &i.args {
                 if let Some(found) = Compiler::lookup_stack(&tmp_stack, &arg.name) {
-                    bincode.extend_from_slice(&serialize(&VarInt(found)));
+                    bincode.extend_from_slice(&serialize(&VarInt(found as u64)));
                     continue
                 }
 
@@ -95,10 +95,10 @@ impl Compiler {
         bincode
     }
 
-    fn lookup_stack(stack: &[&str], name: &str) -> Option<u64> {
+    fn lookup_stack(stack: &[&str], name: &str) -> Option<usize> {
         for (idx, n) in stack.iter().enumerate() {
             if n == &name {
-                return Some(idx.try_into().unwrap())
+                return Some(idx)
             }
         }
 

+ 3 - 3
src/zkas/decoder.rs

@@ -9,7 +9,7 @@ use crate::{
 pub struct ZkBinary {
     pub constants: Vec<(Type, String)>,
     pub witnesses: Vec<Type>,
-    pub opcodes: Vec<(Opcode, Vec<u64>)>,
+    pub opcodes: Vec<(Opcode, Vec<usize>)>,
 }
 
 impl ZkBinary {
@@ -95,7 +95,7 @@ impl ZkBinary {
         Ok(witnesses)
     }
 
-    fn parse_circuit(bytes: &[u8]) -> Result<Vec<(Opcode, Vec<u64>)>> {
+    fn parse_circuit(bytes: &[u8]) -> Result<Vec<(Opcode, Vec<usize>)>> {
         let mut opcodes = vec![];
 
         let mut iter_offset = 0;
@@ -110,7 +110,7 @@ impl ZkBinary {
             for _ in 0..arg_num.0 {
                 let (stack_index, offset) = deserialize_partial::<VarInt>(&bytes[iter_offset..])?;
                 iter_offset += offset;
-                args.push(stack_index.0);
+                args.push(stack_index.0 as usize); // FIXME
             }
 
             opcodes.push((opcode, args));