Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace H256 with the one in rust-numext #15

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

joii2020
Copy link
Contributor

I replaced the native H256 with the one in Rust-numext。

Copy link
Collaborator

@XuJiandong XuJiandong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

modify according to xuejie's comments: using numext H256 directly.

src/h256.rs Outdated
/// Represent 256 bits
#[derive(Eq, PartialEq, Debug, Default, Hash, Clone, Copy)]
pub struct H256([u8; 32]);
pub type H256 = numext_fixed_hash::H256;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shall be a private type declaration, or at least crate-level public. We don't want to confuse the users of this library with yet another H256 definition.


type SMT = SparseMerkleTree<Blake2bHasher, H256, DefaultStore<H256>>;

#[derive(Eq, PartialEq, Debug, Default, Hash, Clone)]
pub struct H256OrdTest {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we reuse H256Ord structure instead of defining a new one?

src/tree.rs Outdated
@@ -51,6 +44,23 @@ pub struct SparseMerkleTree<H, V, S> {
phantom: PhantomData<(H, V)>,
}

#[derive(Eq, PartialEq, Debug, Default, Hash, Clone)]
struct H256OrdTree {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing as the above, can we define only one H256Ord, possibly in h256.rs?

@xxuejie xxuejie requested a review from jjyr September 1, 2021 03:10
@xxuejie

This comment has been minimized.

pub fn compute_root<H: Hasher + Default>(&self, leaves: Vec<(H256, H256)>) -> Result<H256> {
let mut leaves_ord: Vec<(H256Ord, H256)> = leaves
.iter()
.take(leaves.len())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we just do an into_iter here?

src/h256.rs Show resolved Hide resolved
src/tree.rs Show resolved Hide resolved
@@ -18,6 +18,7 @@ blake2b = ["blake2b-rs"]
[dependencies]
cfg-if = "0.1"
blake2b-rs = { version = "0.1", optional = true }
numext-fixed-hash = "0.1.6"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

numext-fixed-hash breaks the no-std feature. We should introduce it as optional, if user choose feature=std then enable the numext_fixed_hash::H256, otherwise we use the H256([u8; 32]).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we had agreed earlier, that no_std feature here does not make any sense, it's best we remove it and we should only leverage C based verifier in smart contract? Has anything changed since then?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we decided to remove no_std support, we should actually remove the std feature from features section.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With #16 coming I do suggest we remove no_std support. @joii2020 can you make the change per @jjyr's suggestion?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@joii2020 joii2020 requested a review from jjyr September 8, 2021 04:16
src/error.rs Outdated
@@ -1,4 +1,5 @@
use crate::{string, H256};
extern crate std;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to mark std as external crate

@xxuejie
Copy link
Contributor

xxuejie commented Sep 15, 2021

#![cfg_attr(not(feature = "std"), no_std)]
There is still code left dealing with no_std

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants