types.rs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /// Types supported by the VM
  2. #[derive(Copy, Clone, PartialEq, Eq, Debug)]
  3. #[repr(u8)]
  4. pub enum Type {
  5. /// Elliptic curve point
  6. EcPoint = 0x00,
  7. /// Elliptic curve fixed point (a constant)
  8. EcFixedPoint = 0x01,
  9. /// Elliptic curve fixed point short
  10. EcFixedPointShort = 0x02,
  11. /// Elliptic curve fixed point in base field
  12. EcFixedPointBase = 0x03,
  13. /// Base field element
  14. Base = 0x10,
  15. /// Array of Base field elements
  16. BaseArray = 0x11,
  17. /// Scalar field element
  18. Scalar = 0x12,
  19. /// Array of Scalar field elements
  20. ScalarArray = 0x13,
  21. /// A Merkle path
  22. MerklePath = 0x20,
  23. /// Unsigned 32-bit integer
  24. Uint32 = 0x30,
  25. /// Unsigned 64-bit integer
  26. Uint64 = 0x31,
  27. /// Intermediate type, should never appear in the result
  28. Dummy = 0xff,
  29. }
  30. impl Type {
  31. pub fn from_repr(b: u8) -> Self {
  32. match b {
  33. 0x00 => Self::EcPoint,
  34. 0x01 => Self::EcFixedPoint,
  35. 0x02 => Self::EcFixedPointShort,
  36. 0x03 => Self::EcFixedPointBase,
  37. 0x10 => Self::Base,
  38. 0x11 => Self::BaseArray,
  39. 0x12 => Self::Scalar,
  40. 0x13 => Self::ScalarArray,
  41. 0x20 => Self::MerklePath,
  42. 0x30 => Self::Uint32,
  43. 0x31 => Self::Uint64,
  44. _ => unimplemented!(),
  45. }
  46. }
  47. }