opcode.rs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. use crate::types::Type;
  2. /// Opcodes supported by the VM
  3. #[derive(Copy, Clone, Debug)]
  4. #[repr(u8)]
  5. pub enum Opcode {
  6. EcAdd = 0x00,
  7. EcMul = 0x01,
  8. EcMulBase = 0x02,
  9. EcMulShort = 0x03,
  10. EcGetX = 0x08,
  11. EcGetY = 0x09,
  12. PoseidonHash = 0x10,
  13. CalculateMerkleRoot = 0x20,
  14. ConstrainInstance = 0xf0,
  15. Noop = 0xff,
  16. }
  17. impl Opcode {
  18. pub fn arg_types(&self) -> (Vec<Type>, Vec<Type>) {
  19. match self {
  20. // (return_type, opcode_arg_types)
  21. Opcode::EcAdd => (vec![Type::EcPoint], vec![Type::EcPoint, Type::EcPoint]),
  22. Opcode::EcMul => (vec![Type::EcPoint], vec![Type::Scalar, Type::EcFixedPoint]),
  23. Opcode::EcMulBase => (vec![Type::EcPoint], vec![Type::Base, Type::EcFixedPoint]),
  24. Opcode::EcMulShort => (vec![Type::EcPoint], vec![Type::Base, Type::EcFixedPoint]),
  25. Opcode::EcGetX => (vec![Type::Base], vec![Type::EcPoint]),
  26. Opcode::EcGetY => (vec![Type::Base], vec![Type::EcPoint]),
  27. Opcode::PoseidonHash => (vec![Type::Base], vec![Type::BaseArray]),
  28. Opcode::CalculateMerkleRoot => (vec![Type::Base], vec![Type::MerklePath, Type::Base]),
  29. Opcode::ConstrainInstance => (vec![], vec![Type::Base]),
  30. Opcode::Noop => (vec![], vec![]),
  31. }
  32. }
  33. }