mirror of
https://github.com/serai-dex/serai.git
synced 2025-12-08 12:19:24 +00:00
Initial documentation for the Monero libraries (#122)
* Document all features * Largely document the Monero libraries Relevant to https://github.com/serai-dex/serai/issues/103 and likely sufficient to get this removed from https://github.com/serai-dex/serai/issues/102.
This commit is contained in:
@@ -6,6 +6,9 @@ license = "MIT"
|
||||
authors = ["Luke Parker <lukeparker5132@gmail.com>"]
|
||||
edition = "2021"
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
|
||||
[dependencies]
|
||||
lazy_static = "1"
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ use dalek_ff_group::field::FieldElement;
|
||||
|
||||
use crate::hash;
|
||||
|
||||
#[allow(dead_code)]
|
||||
/// Monero's hash to point function, as named `ge_fromfe_frombytes_vartime`.
|
||||
pub fn hash_to_point(bytes: [u8; 32]) -> EdwardsPoint {
|
||||
#[allow(non_snake_case)]
|
||||
let A = FieldElement::from(486662u64);
|
||||
|
||||
@@ -25,6 +25,7 @@ fn hash(data: &[u8]) -> [u8; 32] {
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
/// Monero alternate generator `H`, used for amounts in Pedersen commitments.
|
||||
pub static ref H: DalekPoint =
|
||||
CompressedEdwardsY(hash(&ED25519_BASEPOINT_POINT.compress().to_bytes()))
|
||||
.decompress()
|
||||
@@ -36,20 +37,22 @@ const MAX_M: usize = 16;
|
||||
const N: usize = 64;
|
||||
const MAX_MN: usize = MAX_M * N;
|
||||
|
||||
/// Container struct for Bulletproofs(+) generators.
|
||||
#[allow(non_snake_case)]
|
||||
pub struct Generators {
|
||||
pub G: [EdwardsPoint; MAX_MN],
|
||||
pub H: [EdwardsPoint; MAX_MN],
|
||||
}
|
||||
|
||||
pub fn bulletproofs_generators(prefix: &'static [u8]) -> Generators {
|
||||
/// Generate generators as needed for Bulletproofs(+), as Monero does.
|
||||
pub fn bulletproofs_generators(dst: &'static [u8]) -> Generators {
|
||||
let mut res =
|
||||
Generators { G: [EdwardsPoint::identity(); MAX_MN], H: [EdwardsPoint::identity(); MAX_MN] };
|
||||
for i in 0 .. MAX_MN {
|
||||
let i = 2 * i;
|
||||
|
||||
let mut even = H.compress().to_bytes().to_vec();
|
||||
even.extend(prefix);
|
||||
even.extend(dst);
|
||||
let mut odd = even.clone();
|
||||
|
||||
write_varint(&i.try_into().unwrap(), &mut even).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user