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

feat: support Uuid type and sha1_calculate API #145

Merged
merged 21 commits into from
Dec 7, 2021

Conversation

brew0722
Copy link
Contributor

@brew0722 brew0722 commented Nov 26, 2021

Description

Closes #141

  • Support Uuid for a clear unique id type.
    Usually, Uuidv4 is used the most, but v4 is based on random.
    So Use internally Uuidv5 and NAMESPACE_OID.
    The name is combined with contract address, block height, and increase-sequential(u16).

  • Add sha1 crypto native API.
    Uuidv5 uses internally sha1.
    However, crypto-related calls in the contract usually cost expensive gas.
    And As crypto function code is compiled into wasm code, there is a performance degradation compared to native.

    • So I Change gas to be configurable by adding native like other crypto-related apis.
    • The set gas is based on benchmark results. It runs significantly faster than other existing crypto APIs (nano sec(ns) vs micro sec(us)), so the gas value is much lower than existed api.
    • About the larger the hash input, the more overhead it may have than expected.
      So put a limit on the hash input, we can relax this later as needed.
  • Add the example contract 'voting-with-uuid' for usage examples and gas consumption measurement.
    As per the table, the gas consumption increased by the using hash function.
    This even includes the cost of uuid.to_string() in attributes. Excluding this, the actual cost of uuid is lower.

optimize by rust-optimizer make seq-id msg make uuid msg(sha1 via wasm) make uuid msg(sha1 via native) make uuid msg without to_string (sha1 via native)
X 35626 52338 49210 44954
O 30885 46475 42848 39030

Types of changes

  • Bug fix (changes which fixes an issue)
  • New feature (changes which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • ETC (build, ci, docs, perf, refactor, style, test)

Checklist

@brew0722 brew0722 changed the title Support UUID feat: support Uuid type Dec 1, 2021
@brew0722 brew0722 marked this pull request as ready for review December 1, 2021 03:10
@brew0722 brew0722 self-assigned this Dec 1, 2021
Copy link
Contributor

@loloicci loloicci left a comment

Choose a reason for hiding this comment

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

In general, LGTM!

I added some comments about the code.

@brew0722
Copy link
Contributor Author

brew0722 commented Dec 6, 2021

Changed the input limit from 40bytes to 80bytes as needed.(avg 266ns -> 270ns)
The benchmark results show no significant change in the execution speed of sha1.

So the gas cost is similar.

@brew0722 brew0722 requested a review from loloicci December 6, 2021 03:11
Copy link
Contributor

@shiki-tak shiki-tak left a comment

Choose a reason for hiding this comment

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

LGTM

@brew0722 brew0722 changed the title feat: support Uuid type feat: support Uuid type and native sha1 API Dec 7, 2021
@brew0722 brew0722 changed the title feat: support Uuid type and native sha1 API feat: support Uuid type and sha1_calculate API Dec 7, 2021
Copy link
Contributor

@loloicci loloicci left a comment

Choose a reason for hiding this comment

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

LGTM!

@brew0722 brew0722 merged commit f2f3692 into Finschia:main Dec 7, 2021
@brew0722 brew0722 deleted the support-uuid branch December 7, 2021 08:37
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.

Support UUID
3 participants