From 1f5da2dd36b6bb837d036b155cc527b10ea6cddc Mon Sep 17 00:00:00 2001 From: Elichai Turkel Date: Tue, 28 May 2019 17:53:08 +0300 Subject: [PATCH] DOC: Fixed typos and requests from code review --- enigma-core/app/src/cli.rs | 2 +- enigma-core/app/src/esgx/ocalls_u.rs | 1 + enigma-crypto/src/asymmetric.rs | 16 +++++++++------- enigma-crypto/src/lib.rs | 2 +- enigma-tools-m/src/common/utils.rs | 2 +- .../src/attestation_service/service.rs | 8 ++++---- enigma-types/src/lib.rs | 2 +- enigma-types/src/types.rs | 10 +++++----- 8 files changed, 23 insertions(+), 20 deletions(-) diff --git a/enigma-core/app/src/cli.rs b/enigma-core/app/src/cli.rs index 2ba270c5..52c02ad9 100644 --- a/enigma-core/app/src/cli.rs +++ b/enigma-core/app/src/cli.rs @@ -2,7 +2,7 @@ //! //! We use `StructOpt` to easily generate the CLI https://github.com/TeXitoi/structopt
//! it uses rustdocs for the `--help` menu, and proc macros to get long/short and parsing methods.
-//! it is used by running `let opt: Opt = Opt::from_args();` and thn it will fill up the struct from the user inputs. +//! it is used by running `let opt: Opt = Opt::from_args();` and then it will fill up the struct from the user inputs. //! (and of course fail if needed) use std::path::PathBuf; diff --git a/enigma-core/app/src/esgx/ocalls_u.rs b/enigma-core/app/src/esgx/ocalls_u.rs index f94dd0df..5a32ad1c 100644 --- a/enigma-core/app/src/esgx/ocalls_u.rs +++ b/enigma-core/app/src/esgx/ocalls_u.rs @@ -1,6 +1,7 @@ #![allow(unused_attributes)] use crate::db::{CRUDInterface, DeltaKey, P2PCalls, ResultType, ResultTypeVec, Stype, DB}; use enigma_tools_m::utils::LockExpectMutex; +use enigma_crypto::hash::Sha256; use enigma_types::{ContractAddress, EnclaveReturn, Hash256, RawPointer}; use lru_cache::LruCache; use std::sync::Mutex; diff --git a/enigma-crypto/src/asymmetric.rs b/enigma-crypto/src/asymmetric.rs index 671cacbd..6602ee4f 100644 --- a/enigma-crypto/src/asymmetric.rs +++ b/enigma-crypto/src/asymmetric.rs @@ -3,11 +3,11 @@ //! Right now we use https://github.com/sorpaas/libsecp256k1-rs as a backend but this is a less common library, //! Meaning if we use this in testnet/mainnet we should audit that library ourself. //! otherwise we need to put effort into using the much audited library: https://github.com/bitcoin-core/secp256k1 -//! I put work into making the rust bindings for this library support SGX but the work isn't yet done: -//! https://github.com/rust-bitcoin/rust-secp256k1/pull/100 -//! https://github.com/bitcoin-core/secp256k1/pull/595 -//! https://github.com/bitcoin-core/secp256k1/pull/566 -//! After these PR I think it would be possible to swap that library in instead of the current one. +//! I put work into making the rust bindings for this library support SGX and after this PR it should be ready: +//! https://github.com/rust-bitcoin/rust-secp256k1/pull/115 +//! After this PR I think it would be possible to swap that library in instead of the current one. +//! +//! Here is a PoC of how it can be done easily (and the one problem with it) https://github.com/enigmampc/enigma-core/pull/167 use crate::error::CryptoError; use secp256k1::{PublicKey, SecretKey, SharedSecret, RecoveryId, Signature}; @@ -43,6 +43,8 @@ impl KeyPair { /// This function will create a Pair of keys from an array of 32 bytes. /// Please don't use it to generate a new key, if you want a new key use `KeyPair::new()` + /// Because `KeyPair::new()` will make sure it uses a good random source and will loop private keys until it's a good key. + /// (and it's best to isolate the generation of keys to one place) pub fn from_slice(privkey: &[u8; 32]) -> Result { let privkey = SecretKey::parse(&privkey) .map_err(|e| CryptoError::KeyError { key_type: "Private Key", err: Some(e) })?; @@ -74,7 +76,7 @@ impl KeyPair { /// Get the Public Key and slice the first byte /// The first byte represents if the key is compressed or not. - /// Because we always use Uncompressed Keys That's start with `0x04` we can slice it out. + /// Because we use uncompressed Keys That start with `0x04` we can slice it out. /// /// We should move to compressed keys in the future, this will save 31 bytes on each pubkey. /// @@ -118,7 +120,7 @@ impl KeyPair { let v: u8 = recovery.into(); let mut returnvalue = [0u8; 65]; returnvalue[..64].copy_from_slice(&sig.serialize()); - returnvalue[64] = v + 27; // + returnvalue[64] = v + 27; Ok(returnvalue) } diff --git a/enigma-crypto/src/lib.rs b/enigma-crypto/src/lib.rs index 96dee82a..dc13bd73 100644 --- a/enigma-crypto/src/lib.rs +++ b/enigma-crypto/src/lib.rs @@ -43,7 +43,7 @@ pub use crate::asymmetric::KeyPair; /// This trait is to encrypt/decrypt a struct, when implemented you should use `symmetric::encrypt`. -/// when you implement decrypt and encrypt_with_nonce you get `encrypt` for free. +/// when you implement decrypt and encrypt_with_nonce you get `encrypt` for free(don't need to implement manually). /// you should only use decrypt/encrypt. `encrypt_with_nonce` is for testing purposes only. pub trait Encryption where R: Sized, Self: Sized { diff --git a/enigma-tools-m/src/common/utils.rs b/enigma-tools-m/src/common/utils.rs index d0f93447..d36e02ad 100644 --- a/enigma-tools-m/src/common/utils.rs +++ b/enigma-tools-m/src/common/utils.rs @@ -29,7 +29,7 @@ pub trait EthereumAddress { /// This should convert the object(by hashing and slicing) into a String type 40 characters Ethereum address. fn address_string(&self) -> T where T: Sized; - /// This should convert the object(by hashing and slicing) int a 20 byte Ethereum address. + /// This should convert the object(by hashing and slicing) into a 20 byte Ethereum address. fn address(&self) -> P where P: Sized; } diff --git a/enigma-tools-u/src/attestation_service/service.rs b/enigma-tools-u/src/attestation_service/service.rs index a69ee833..edb5b3ab 100644 --- a/enigma-tools-u/src/attestation_service/service.rs +++ b/enigma-tools-u/src/attestation_service/service.rs @@ -234,7 +234,7 @@ impl QBody { /// This will read the data given to it and parse it byte by byte just like the API says /// The exact sizes of the field in `QBody` are extremley important. /// also the order in which `read_exact` is executed (filed by field just like the API) is also important - /// because it reads the bytes sequencially. + /// because it reads the bytes sequentially. /// if the Reader is shorter or longer then the size of QBody it will return an error. pub fn from_bytes_read(body: &mut R) -> Result { let mut result: QBody = Default::default(); @@ -256,7 +256,7 @@ impl QBody { impl Default for QBody { // Using `mem::zeroed()` here should be safe because all the fields are [u8] - // *But* this isn't good practice. because if you add a Box/Vec or any other complex type this *will* become UB. + // *But* this isn't good practice. because if you add a Box/Vec or any other complex type this *will* become UB(Undefined Behavior). fn default() -> QBody { unsafe { mem::zeroed() } } } @@ -264,7 +264,7 @@ impl QReportBody { /// This will read the data given to it and parse it byte by byte just like the API says /// The exact sizes of the field in `QBody` are extremley important. /// also the order in which `read_exact` is executed (filed by field just like the API) is also important - /// because it reads the bytes sequencially. + /// because it reads the bytes sequentially. /// if the Reader is shorter or longer then the size of QBody it will return an error. /// Overall Size: 384 pub fn from_bytes_read(body: &mut R) -> Result { @@ -292,7 +292,7 @@ impl QReportBody { impl Default for QReportBody { // Using `mem::zeroed()` here should be safe because all the fields are [u8] - // *But* this isn't good practice. because if you add a Box/Vec or any other complex type this *will* become UB. + // *But* this isn't good practice. because if you add a Box/Vec or any other complex type this *will* become UB(Undefined Behavior). fn default() -> QReportBody { unsafe { mem::zeroed() } } } diff --git a/enigma-types/src/lib.rs b/enigma-types/src/lib.rs index 719eae11..99b9a310 100644 --- a/enigma-types/src/lib.rs +++ b/enigma-types/src/lib.rs @@ -27,7 +27,7 @@ use crate::traits::SliceCPtr; pub use crate::types::*; /// This is a bit safer wrapper of [`core::ptr::copy_nonoverlapping`] -/// it checks that the src len is at least as bigger as `count` otherwise it will panic. +/// it checks that the src len is at least as big as `count` otherwise it will panic. /// *and* it uses [`SliceCPtr`](crate::traits::SliceCPtr) trait to pass a C compatible pointer. pub unsafe fn write_ptr(src: &[T], dst: *mut T, count: usize) { if src.len() > count { diff --git a/enigma-types/src/types.rs b/enigma-types/src/types.rs index e91e85d6..5a5e7450 100644 --- a/enigma-types/src/types.rs +++ b/enigma-types/src/types.rs @@ -45,7 +45,7 @@ pub enum EnclaveReturn { // TODO: Also don't think this is needed. /// RecoveringError, Something failed in recovering the public key. RecoveringError, - ///PermissionError, Received a permission error from an ocall, (i.e. opening the signing keys file or somethign like that) + ///PermissionError, Received a permission error from an ocall, (i.e. opening the signing keys file or something like that) PermissionError, /// SgxError, Error that came from the SGX specific stuff (i.e DRAND, Sealing etc.) SgxError, @@ -53,7 +53,7 @@ pub enum EnclaveReturn { StateError, /// OcallError, an error from an ocall. OcallError, - /// OcallDBError, an error from the Database in the untrusted part, could't get/save something. + /// OcallDBError, an error from the Database in the untrusted part, couldn't get/save something. OcallDBError, /// MessagingError, a message that received couldn't be processed (i.e. KM Message, User Key Exchange etc.) MessagingError, @@ -99,7 +99,7 @@ pub struct ExecuteResult { } /// This struct is a wrapper to a raw pointer. -/// when you pass a pointer through the SGX bridge(EDL) than the SGX Edger8r it copies the data that it's pointing to +/// when you pass a pointer through the SGX bridge(EDL) the SGX Edger8r will copy the data that it's pointing to /// using `memalloc` and `memset` to the other side of the bridge, then it changes the pointer to point to the new data. /// /// So this struct is needed if you want to pass a pointer from one side to the other while the pointer still points to the right locaiton. @@ -150,7 +150,7 @@ impl RawPointer { } /// This will unsafely cast the underlying pointer back into a mut pointer. - /// it will return a result and has the same rules as [`get_mut_ptr`] + /// it will return a result and have the same rules as [`get_mut_ptr`] /// /// [`get_mut_ptr`]: #method.get_mut_ptr pub unsafe fn get_mut_ref(&self) -> Result<&mut T, &'static str> { @@ -234,7 +234,7 @@ impl fmt::Display for EnclaveReturn { /// we want to convert [`enigma_tools_t::common::errors::EnclaveError`](../replace_me) into [`EnclaveReturn`] to return it back through the EDL. /// *but* in this module we can't impl [`From`](core::convert::From) from `EnclaveError` to `EnclaveReturn` because this crate is `std` pure /// so it doesn't have access to `enigma_tools_t`. -/// And we can't impelment this as `Into for Result<(), EnclaveError>` in `enigma_tools_t` +/// And we can't implement this as `Into for Result<(), EnclaveError>` in `enigma_tools_t` /// because in rust you can't implement an imported trait(`From`/`Into`) on a type you imported (`Result`). /// /// So my solution was to declare a new trait, and to implement [`core::convert::From`] on whatever implements my trait through generics.