parazyd 3 лет назад
Родитель
Сommit
0ed1d62b4b
6 измененных файлов с 10 добавлено и 66 удалено
  1. 0 2
      src/lib.rs
  2. 1 1
      src/sdk/src/crypto/coin.rs
  3. 1 11
      src/sdk/src/crypto/mod.rs
  4. 1 3
      src/sdk/src/crypto/schnorr.rs
  5. 7 2
      src/sdk/src/merkle.rs
  6. 0 47
      src/sdk/src/util.rs

+ 0 - 2
src/lib.rs

@@ -16,8 +16,6 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-//#![feature(cursor_remaining)]
-
 pub mod error;
 pub use error::{ClientFailed, ClientResult, Error, Result, VerifyFailed, VerifyResult};
 

+ 1 - 1
src/sdk/src/crypto/coin.rs

@@ -22,7 +22,7 @@ use std::io;
 use darkfi_serial::{SerialDecodable, SerialEncodable};
 use pasta_curves::{group::ff::PrimeField, pallas};
 
-/// The `Coin` is represented as a base field element.
+/// `Coin` is represented as a base field element.
 #[repr(C)]
 #[derive(Debug, Clone, Copy, Eq, PartialEq, SerialEncodable, SerialDecodable)]
 pub struct Coin(pub pallas::Base);

+ 1 - 11
src/sdk/src/crypto/mod.rs

@@ -16,17 +16,6 @@
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
-//! This module contains a bit more minimal implementations of the
-//! objects and types that can be found in `darkfi::crypto`.
-//! This is done so we can have a lot less dependencies in this SDK,
-//! and therefore make compilation of smart contracts faster in a sense.
-//!
-//! Eventually, we should strive to somehow migrate the types from
-//! `darkfi::crypto` into here, and then implement certain functionality
-//! in the library using traits.
-//! If you feel like trying, please help out with this migration, but do
-//! it properly, with care, and write documentation while you're at it.
-
 /// Cryptographic constants
 pub mod constants;
 
@@ -81,6 +70,7 @@ pub mod mimc_vdf;
 
 pub use incrementalmerkletree;
 pub use pasta_curves::{pallas, vesta};
+
 /// Convenience module to import all the pasta traits.
 /// You still have to import the curves.
 pub mod pasta_prelude {

+ 1 - 3
src/sdk/src/crypto/schnorr.rs

@@ -56,9 +56,7 @@ pub trait SchnorrPublic {
     fn verify(&self, message: &[u8], signature: &Signature) -> bool;
 }
 
-// ===================================================================
-// Schnorr signature trait implementations for the stuff in keypair.rs
-// ===================================================================
+/// Schnorr signature trait implementations for the stuff in `keypair.rs`
 impl SchnorrSecret for SecretKey {
     fn sign(&self, rng: &mut (impl CryptoRng + RngCore), message: &[u8]) -> Signature {
         let mask = pallas::Scalar::random(rng);

+ 7 - 2
src/sdk/src/merkle.rs

@@ -24,18 +24,23 @@ use super::{
     error::{ContractError, GenericResult},
 };
 
+/// Add given elements into a Merkle tree.
+/// * `db_info` is a handle for a database where the Merkle tree is stored.
+/// * `db_roots` is a handle for a database where all the new Merkle roots are stored.
+/// * `key` is the serialized key for `db_info`.
+/// * `elements` are the items we want to add to the Merkle tree.
 pub fn merkle_add(
     db_info: DbHandle,
     db_roots: DbHandle,
     key: &[u8],
-    coins: &[MerkleNode],
+    elements: &[MerkleNode],
 ) -> GenericResult<()> {
     let mut buf = vec![];
     let mut len = 0;
     len += db_info.encode(&mut buf)?;
     len += db_roots.encode(&mut buf)?;
     len += key.to_vec().encode(&mut buf)?;
-    len += coins.to_vec().encode(&mut buf)?;
+    len += elements.to_vec().encode(&mut buf)?;
 
     match unsafe { merkle_add_(buf.as_ptr(), len as u32) } {
         0 => Ok(()),

+ 0 - 47
src/sdk/src/util.rs

@@ -1,47 +0,0 @@
-/* This file is part of DarkFi (https://dark.fi)
- *
- * Copyright (C) 2020-2023 Dyne.org foundation
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program 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 Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <https://www.gnu.org/licenses/>.
- */
-
-use super::error::ContractError;
-
-pub fn set_return_data(data: &[u8]) -> Result<(), ContractError> {
-    unsafe {
-        match set_return_data_(data.as_ptr(), data.len() as u32) {
-            0 => Ok(()),
-            errcode => Err(ContractError::from(errcode)),
-        }
-    }
-}
-
-pub fn put_object_bytes(data: &[u8]) -> i64 {
-    unsafe { put_object_bytes_(data.as_ptr(), data.len() as u32) }
-}
-
-pub fn get_object_bytes(data: &mut [u8], object_index: u32) -> i64 {
-    unsafe { get_object_bytes_(data.as_mut_ptr(), object_index as u32) }
-}
-
-pub fn get_object_size(object_index: u32) -> i64 {
-    unsafe { get_object_size_(object_index as u32) }
-}
-
-extern "C" {
-    fn set_return_data_(ptr: *const u8, len: u32) -> i64;
-    fn put_object_bytes_(ptr: *const u8, len: u32) -> i64;
-    fn get_object_bytes_(ptr: *mut u8, len: u32) -> i64;
-    fn get_object_size_(len: u32) -> i64;
-}