opcode.rs 1.1 KB

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