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

[framework] unify Rust and Move object ID derivation #143

Merged
merged 1 commit into from
Jan 10, 2022

Conversation

sblackshear
Copy link
Collaborator

Previously, there were two incompatible implementations of ObjectID derivation. This PR:

  • Eliminates the ObjectID derivation inside Move and replaces it with a native function that invokes the Rust ObjectID derivation. This ensures that Rust and Move agree on how ID's are generated, and should also be more efficient than the previous approach.
  • Introduces a harness for invoking Move unit tests and a unit test for TxContext that shows the ID generation working as expected.

Copy link
Collaborator

@gdanezis gdanezis left a comment

Choose a reason for hiding this comment

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

Nice, one and this unblocks #58 .

let ids_created = pop_arg!(args, u64);
let inputs_hash = pop_arg!(args, Vec<u8>);

// unwrap safe because digest length is checked in Move
Copy link
Collaborator

Choose a reason for hiding this comment

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

Now that we do not have to keep rust and move in sync, we can address Issue #58 . We need to define a ObjectIDPreimage struct that holds (transaction_id, new_obj_sequence), then make it BcsSignable and use sha3_hash to get the digest. This ensures that we have one way to derive hashes (incl. for what we sign) and therefore domain separation is ensured uniformly.

Lets add a todo here, and add the above to issue #58 .

// TODO(https://github.com/MystenLabs/fastnft/issues/58):
// audit ID derivation: do we want/need domain separation, different hash function, truncation ...

let mut hasher = Sha3_256::default();
Copy link
Collaborator

Choose a reason for hiding this comment

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

See my comment above on how to derive this in a uniform way in relation to all other hashes we derive.

#[test_only]
/// Create a `Signer` from `bytes` for testing
public fun new_signer(bytes: vector<u8>): Signer {
Signer { inner: new(bytes) }
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I have a feeling a length check here would not go amiss.

Previously, there were two incompatible implementations of ObjectID derivation. This PR:

- Eliminates the `ObjectID` derivation inside Move and replaces it with a native function that invokes the Rust `ObjectID` derivation. This ensures that Rust and Move agree on how ID's are generated, and should also be more efficient than the previous approach.
- Introduces a harness for invoking Move unit tests and a unit tests for `TxContext` that shows the ID generation working as expected.
@sblackshear sblackshear merged commit 1af0d37 into MystenLabs:main Jan 10, 2022
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.

3 participants