vm_stack.rs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. //! VM stack type abstractions
  2. use halo2_gadgets::ecc::{chip::EccChip, FixedPoint, FixedPointBaseField, FixedPointShort, Point};
  3. use halo2_proofs::circuit::AssignedCell;
  4. use pasta_curves::{pallas, EpAffine};
  5. use crate::crypto::{constants::OrchardFixedBases, merkle_node::MerkleNode};
  6. /// These represent the witness types outside of the circuit
  7. #[allow(clippy::large_enum_variant)]
  8. #[derive(Clone)]
  9. pub enum Witness {
  10. EcPoint(Option<pallas::Point>),
  11. EcFixedPoint(Option<pallas::Point>),
  12. Base(Option<pallas::Base>),
  13. Scalar(Option<pallas::Scalar>),
  14. MerklePath(Option<[MerkleNode; 32]>),
  15. Uint32(Option<u32>),
  16. Uint64(Option<u64>),
  17. }
  18. /// These represent the witness types inside the circuit
  19. #[allow(clippy::large_enum_variant)]
  20. #[derive(Clone)]
  21. pub enum StackVar {
  22. EcPoint(Point<pallas::Affine, EccChip<OrchardFixedBases>>),
  23. EcFixedPoint(FixedPoint<pallas::Affine, EccChip<OrchardFixedBases>>),
  24. EcFixedPointBase(FixedPointBaseField<pallas::Affine, EccChip<OrchardFixedBases>>),
  25. Base(AssignedCell<pallas::Base, pallas::Base>),
  26. Scalar(Option<pallas::Scalar>),
  27. MerklePath(Option<[pallas::Base; 32]>),
  28. Uint32(Option<u32>),
  29. Uint64(Option<u64>),
  30. FixedPointShort(FixedPointShort<EpAffine, EccChip<OrchardFixedBases>>),
  31. }
  32. impl From<StackVar> for Point<pallas::Affine, EccChip<OrchardFixedBases>> {
  33. fn from(value: StackVar) -> Self {
  34. match value {
  35. StackVar::EcPoint(v) => v,
  36. _ => unimplemented!(),
  37. }
  38. }
  39. }
  40. impl From<StackVar> for FixedPoint<pallas::Affine, EccChip<OrchardFixedBases>> {
  41. fn from(value: StackVar) -> Self {
  42. match value {
  43. StackVar::EcFixedPoint(v) => v,
  44. _ => unimplemented!(),
  45. }
  46. }
  47. }
  48. impl From<StackVar> for std::option::Option<pallas::Scalar> {
  49. fn from(value: StackVar) -> Self {
  50. match value {
  51. StackVar::Scalar(v) => v,
  52. _ => unimplemented!(),
  53. }
  54. }
  55. }
  56. impl From<StackVar> for AssignedCell<pallas::Base, pallas::Base> {
  57. fn from(value: StackVar) -> Self {
  58. match value {
  59. StackVar::Base(v) => v,
  60. _ => unimplemented!(),
  61. }
  62. }
  63. }
  64. impl From<StackVar> for std::option::Option<u32> {
  65. fn from(value: StackVar) -> Self {
  66. match value {
  67. StackVar::Uint32(v) => v,
  68. _ => unimplemented!(),
  69. }
  70. }
  71. }
  72. impl From<StackVar> for std::option::Option<[pallas::Base; 32]> {
  73. fn from(value: StackVar) -> Self {
  74. match value {
  75. StackVar::MerklePath(v) => v,
  76. _ => unimplemented!(),
  77. }
  78. }
  79. }
  80. impl From<StackVar> for FixedPointShort<EpAffine, EccChip<OrchardFixedBases>> {
  81. fn from(value: StackVar) -> Self {
  82. match value {
  83. StackVar::FixedPointShort(v) => v,
  84. _ => unimplemented!(),
  85. }
  86. }
  87. }