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

zkas: Document opcodes and types.

parazyd 4 лет назад
Родитель
Сommit
dac6bab2cd
2 измененных файлов с 21 добавлено и 0 удалено
  1. 12 0
      zkas/src/opcode.rs
  2. 9 0
      zkas/src/types.rs

+ 12 - 0
zkas/src/opcode.rs

@@ -4,24 +4,36 @@ use crate::types::Type;
 #[derive(Copy, Clone, Debug)]
 #[derive(Copy, Clone, Debug)]
 #[repr(u8)]
 #[repr(u8)]
 pub enum Opcode {
 pub enum Opcode {
+    /// Elliptic curve addition
     EcAdd = 0x00,
     EcAdd = 0x00,
+    /// Elliptic curve multiplication
     EcMul = 0x01,
     EcMul = 0x01,
+    /// Elliptic curve multiplication with a Base field element
     EcMulBase = 0x02,
     EcMulBase = 0x02,
+    /// Elliptic curve multiplication with a u64 wrapped in a Scalar element
     EcMulShort = 0x03,
     EcMulShort = 0x03,
 
 
+    /// Get the x coordinate of an elliptic curve point
     EcGetX = 0x08,
     EcGetX = 0x08,
+    /// Get the y coordinate of an elliptic curve point
     EcGetY = 0x09,
     EcGetY = 0x09,
 
 
+    /// Poseidon hash of N elements
     PoseidonHash = 0x10,
     PoseidonHash = 0x10,
 
 
+    /// Calculate merkle root given given a position, Merkle path, and an element
     CalculateMerkleRoot = 0x20,
     CalculateMerkleRoot = 0x20,
 
 
+    /// Constrain a Base field element to a circuit's public input
     ConstrainInstance = 0xf0,
     ConstrainInstance = 0xf0,
 
 
+    /// Intermediate opcode for the compiler, should never appear in the result
     Noop = 0xff,
     Noop = 0xff,
 }
 }
 
 
 impl Opcode {
 impl Opcode {
+    /// Return a tuple of vectors of types that are accepted by a specific opcode
+    /// `r.0` is the return type(s) and `r.1` is the argument type(s).
     pub fn arg_types(&self) -> (Vec<Type>, Vec<Type>) {
     pub fn arg_types(&self) -> (Vec<Type>, Vec<Type>) {
         match self {
         match self {
             // (return_type, opcode_arg_types)
             // (return_type, opcode_arg_types)

+ 9 - 0
zkas/src/types.rs

@@ -2,19 +2,28 @@
 #[derive(Copy, Clone, PartialEq, Debug)]
 #[derive(Copy, Clone, PartialEq, Debug)]
 #[repr(u8)]
 #[repr(u8)]
 pub enum Type {
 pub enum Type {
+    /// Elliptic curve point
     EcPoint = 0x00,
     EcPoint = 0x00,
 
 
+    /// Elliptic curve fixed point (a constant)
     EcFixedPoint = 0x01,
     EcFixedPoint = 0x01,
 
 
+    /// Base field element
     Base = 0x10,
     Base = 0x10,
+    /// Array of Base field elements
     BaseArray = 0x11,
     BaseArray = 0x11,
 
 
+    /// Scalar field element
     Scalar = 0x12,
     Scalar = 0x12,
+    /// Array of Scalar field elements
     ScalarArray = 0x13,
     ScalarArray = 0x13,
 
 
+    /// A Merkle path
     MerklePath = 0x20,
     MerklePath = 0x20,
 
 
+    /// Unsigned 32-bit integer
     Uint32 = 0x30,
     Uint32 = 0x30,
 
 
+    /// Intermediate type, should never appear in the result
     Dummy = 0xff,
     Dummy = 0xff,
 }
 }