mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-18 14:31:31 +03:00
core circuit wip
This commit is contained in:
parent
993b86e8c7
commit
26f04e2eaf
42
compiler/core/src/algorithms/bhp.rs
Normal file
42
compiler/core/src/algorithms/bhp.rs
Normal file
@ -0,0 +1,42 @@
|
||||
// Copyright (C) 2019-2021 Aleo Systems Inc.
|
||||
// This file is part of the Leo library.
|
||||
|
||||
// The Leo library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// The Leo library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use leo_ast::{Circuit, CircuitMember, Function, Identifier};
|
||||
use leo_span::sym;
|
||||
|
||||
pub struct BHP256(Circuit);
|
||||
|
||||
impl BHP256 {
|
||||
pub fn new() -> Self {
|
||||
Self(Circuit {
|
||||
circuit_name: Identifier::new(sym::bhp256),
|
||||
members: vec![
|
||||
CircuitMember::CircuitFunction(Box::new(
|
||||
Function {
|
||||
identifier: Identifier {},
|
||||
input: vec![],
|
||||
output: Type::Address,
|
||||
core_mapping: Cell::new(None),
|
||||
block: Block {},
|
||||
span: Default::default()
|
||||
}
|
||||
))
|
||||
]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BHP512(Circuit);
|
@ -15,10 +15,42 @@
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::Types;
|
||||
use leo_span::{sym, Symbol};
|
||||
|
||||
use indexmap::IndexSet;
|
||||
use leo_span::Symbol;
|
||||
|
||||
/// A core library circuit
|
||||
#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum CoreCircuit {
|
||||
BHP256,
|
||||
BHP512,
|
||||
BHP768,
|
||||
BHP1024,
|
||||
Pedersen64,
|
||||
Pedersen128,
|
||||
Poseidon2,
|
||||
Poseidon4,
|
||||
Poseidon8,
|
||||
}
|
||||
|
||||
impl CoreCircuit {
|
||||
/// Returns a `CoreCircuit` from the given `Symbol`.
|
||||
pub fn from_symbol(symbol: Symbol) -> Option<Self> {
|
||||
Some(match symbol {
|
||||
sym::bhp256 => Self::BHP256,
|
||||
sym::bhp512 => Self::BHP512,
|
||||
sym::bhp1024 => Self::BHP1024,
|
||||
sym::ped64 => Self::Pedersen64,
|
||||
sym::ped128 => Self::Pedersen128,
|
||||
sym::psd2 => Self::Poseidon2,
|
||||
sym::psd4 => Self::Poseidon4,
|
||||
sym::psd8 => Self::Poseidon8,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// todo (collin): deprecate this code
|
||||
pub struct Algorithms;
|
||||
|
||||
impl Types for Algorithms {
|
||||
|
@ -55,6 +55,7 @@ impl<'a> ProgramVisitorDirector<'a> for Director<'a> {
|
||||
}
|
||||
|
||||
fn visit_circuit(&mut self, input: &'a Circuit) {
|
||||
// circuit Foo { x: u8, y: u8 };
|
||||
todo!()
|
||||
// if let VisitResult::VisitChildren = self.visitor_ref().visit_function(input) {
|
||||
// self.
|
||||
|
@ -138,18 +138,18 @@ symbols! {
|
||||
xor,
|
||||
|
||||
// algorithm operator names 33-44
|
||||
bhp256,
|
||||
bhp512,
|
||||
bhp768,
|
||||
bhp1024,
|
||||
bhp256: "BHP256",
|
||||
bhp512: "BHP512",
|
||||
bhp768: "BHP768",
|
||||
bhp1024: "BHP1024",
|
||||
commit,
|
||||
hash,
|
||||
ped64,
|
||||
ped128,
|
||||
ped64: "Pedersen64",
|
||||
ped128: "Pedersen128",
|
||||
prf,
|
||||
psd2,
|
||||
psd4,
|
||||
psd8,
|
||||
psd2: "Poseidon2",
|
||||
psd4: "Poseidon4",
|
||||
psd8: "Poseidon8",
|
||||
|
||||
// types
|
||||
address,
|
||||
|
Loading…
Reference in New Issue
Block a user