-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #155 from 0xPolygonMiden/greenhat/i144-stdlib
[3/x] Miden stdlib functions transformation
- Loading branch information
Showing
35 changed files
with
3,923 additions
and
444 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
//! Function types and lowered signatures for the Miden stdlib API functions | ||
use std::sync::OnceLock; | ||
|
||
use super::ModuleFunctionTypeMap; | ||
|
||
pub(crate) mod crypto; | ||
pub(crate) mod mem; | ||
|
||
pub(crate) fn signatures() -> &'static ModuleFunctionTypeMap { | ||
static TYPES: OnceLock<ModuleFunctionTypeMap> = OnceLock::new(); | ||
TYPES.get_or_init(|| { | ||
let mut m: ModuleFunctionTypeMap = Default::default(); | ||
m.extend(crypto::hashes::signatures()); | ||
m.extend(crypto::dsa::signatures()); | ||
m.extend(mem::signatures()); | ||
m | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub(crate) mod dsa; | ||
pub(crate) mod hashes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use miden_hir::FunctionType; | ||
use miden_hir_type::Type::*; | ||
|
||
use crate::miden_abi::{FunctionTypeMap, ModuleFunctionTypeMap}; | ||
|
||
pub(crate) const RPO_FALCON512_VERIFY: &str = "rpo_falcon512_verify"; | ||
|
||
pub(crate) fn signatures() -> ModuleFunctionTypeMap { | ||
let mut m: ModuleFunctionTypeMap = Default::default(); | ||
let mut funcs: FunctionTypeMap = Default::default(); | ||
funcs.insert( | ||
RPO_FALCON512_VERIFY, | ||
FunctionType::new([Felt, Felt, Felt, Felt, Felt, Felt, Felt, Felt], []), | ||
); | ||
m.insert("miden:prelude/std_crypto_dsa", funcs); | ||
m | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use miden_hir::FunctionType; | ||
use miden_hir_type::Type::*; | ||
|
||
use crate::miden_abi::{FunctionTypeMap, ModuleFunctionTypeMap}; | ||
|
||
pub(crate) const BLAKE3_HASH_1TO1: &str = "blake3_hash_1to1"; | ||
pub(crate) const BLAKE3_HASH_2TO1: &str = "blake3_hash_2to1"; | ||
|
||
pub(crate) fn signatures() -> ModuleFunctionTypeMap { | ||
let mut m: ModuleFunctionTypeMap = Default::default(); | ||
let mut crypto: FunctionTypeMap = Default::default(); | ||
crypto.insert( | ||
BLAKE3_HASH_1TO1, | ||
//Accepts and returns a 8 Felt elements | ||
FunctionType::new( | ||
[Felt, Felt, Felt, Felt, Felt, Felt, Felt, Felt], | ||
[Felt, Felt, Felt, Felt, Felt, Felt, Felt, Felt], | ||
), | ||
); | ||
crypto.insert( | ||
BLAKE3_HASH_2TO1, | ||
// Accepts 16 and returns a 8 Felt elements | ||
FunctionType::new( | ||
[ | ||
Felt, Felt, Felt, Felt, Felt, Felt, Felt, Felt, Felt, Felt, Felt, Felt, Felt, Felt, | ||
Felt, Felt, | ||
], | ||
[Felt, Felt, Felt, Felt, Felt, Felt, Felt, Felt], | ||
), | ||
); | ||
m.insert("miden:prelude/std_crypto_hashes", crypto); | ||
m | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use miden_hir::FunctionType; | ||
use miden_hir_type::Type::*; | ||
|
||
use crate::miden_abi::{FunctionTypeMap, ModuleFunctionTypeMap}; | ||
|
||
pub(crate) const PIPE_WORDS_TO_MEMORY: &str = "pipe_words_to_memory"; | ||
pub(crate) const PIPE_DOUBLE_WORDS_TO_MEMORY: &str = "pipe_double_words_to_memory"; | ||
|
||
pub(crate) fn signatures() -> ModuleFunctionTypeMap { | ||
let mut m: ModuleFunctionTypeMap = Default::default(); | ||
let mut funcs: FunctionTypeMap = Default::default(); | ||
funcs.insert( | ||
PIPE_WORDS_TO_MEMORY, | ||
FunctionType::new( | ||
[ | ||
Felt, // num_words | ||
Felt, // write_ptr | ||
], | ||
[ | ||
Felt, Felt, Felt, Felt, // HASH | ||
Felt, // write_ptr' | ||
], | ||
), | ||
); | ||
funcs.insert( | ||
PIPE_DOUBLE_WORDS_TO_MEMORY, | ||
FunctionType::new( | ||
[ | ||
Felt, Felt, Felt, Felt, // C | ||
Felt, Felt, Felt, Felt, // B | ||
Felt, Felt, Felt, Felt, // A | ||
Felt, // write_ptr | ||
Felt, // end_ptr | ||
], | ||
[ | ||
Felt, Felt, Felt, Felt, // C | ||
Felt, Felt, Felt, Felt, // B | ||
Felt, Felt, Felt, Felt, // A | ||
Felt, // write_ptr | ||
], | ||
), | ||
); | ||
m.insert("miden:prelude/std_mem", funcs); | ||
m | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.