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

add Keccak256 hash to cadence #1327

Merged
merged 7 commits into from
Jan 14, 2022
Merged

Conversation

zhiqiangxu
Copy link
Contributor

@zhiqiangxu zhiqiangxu commented Dec 28, 2021

This is a PR for #537 .

I'll make another PR to the prefixedHashing in flow-go repo once this is merged (in order to reference to the newly added runtime.HashAlgorithmKECCAK_256).

Basically the PR for flow-go will be this commit:

zhiqiangxu/flow-go@317a094

@turbolent
Copy link
Member

Thank you for contributing @zhiqiangxu! This looks good 👍

From what I can see, this is all that is needed to be changed. However, after adding the new "enum case" to HashAlgorithm, hashalgorithm_string.go must be updated. You can update it by running make generate.

@turbolent
Copy link
Member

@tarakby Could you please have a look?

@turbolent turbolent requested a review from tarakby January 5, 2022 19:33
Copy link
Contributor

@tarakby tarakby left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution!
This looks good. I just left minor comments about the doc, but I let the Cadence team approve the rest of the Cadence related PR.
Looking forward to the flow-go PR :)

@@ -27,6 +27,9 @@ pub enum HashAlgorithm: UInt8 {
/// used in BLS signatures.
pub case KMAC128_BLS_BLS12_381 = 5

/// KECCAK_256 is ethereum-compatible Keccak-256 hash
Copy link
Contributor

@tarakby tarakby Jan 6, 2022

Choose a reason for hiding this comment

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

It is preferable not to define the cryptographic algorithms based on its blockchain application, but using its original definition. I'd suggest something like:

Suggested change
/// KECCAK_256 is ethereum-compatible Keccak-256 hash
/// KECCAK_256 is the legacy Keccak algorithm with a 256-bits digest, as per the original submission to the NIST SHA3 competition.
/// KECCAK_256 is different than SHA3 and is used by Ethereum.

Copy link

Choose a reason for hiding this comment

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

Let's not remove Ethereum entirely from that description, perhaps? My suggestion:

/// KECCAK_256 is the 256-bit legacy Keccak algorithm (NIST SHA3 candidate submission), as used by Ethereum and others

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ethereum is not removed entirely, it's on the 2nd line:)

Comment on lines 333 to 335
const HashAlgorithmDocStringKECCAK_256 = `
This is a specific function for calculating the Keccak256 hash of arbitrary data.
`
Copy link
Contributor

@tarakby tarakby Jan 6, 2022

Choose a reason for hiding this comment

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

The text of the above algorithms seems to be a copy of the doc text, in that case I suggest to do the same for Keccak.

Suggested change
const HashAlgorithmDocStringKECCAK_256 = `
This is a specific function for calculating the Keccak256 hash of arbitrary data.
`
const HashAlgorithmDocStringKECCAK_256 = `
KECCAK_256 is the legacy Keccak algorithm with a 256-bits digest, as per the original submission to the NIST SHA3 competition.
KECCAK_256 is different than SHA3 and is used by Ethereum.
`

@turbolent turbolent self-assigned this Jan 7, 2022
Copy link
Contributor

@ramtinms ramtinms left a comment

Choose a reason for hiding this comment

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

Looks good to me

@turbolent
Copy link
Member

@zhiqiangxu I investigated the CI test failures. The addition of the new enum case causes a different iteration order, so the assertions in the failing tests need to be updated. Is it OK to commit the fixes to your branch?

@zhiqiangxu
Copy link
Contributor Author

@zhiqiangxu I investigated the CI test failures. The addition of the new enum case causes a different iteration order, so the assertions in the failing tests need to be updated. Is it OK to commit the fixes to your branch?

Sure, please do it, thanks! I haven't got time to look into the CI issue yet..

atree iteration order is now different, as the new built-in
HashAlgorithm enum case is constructed before the test values
@codecov-commenter
Copy link

Codecov Report

Merging #1327 (d2d8228) into master (95aea4a) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1327   +/-   ##
=======================================
  Coverage   75.78%   75.78%           
=======================================
  Files         280      280           
  Lines       38779    38785    +6     
=======================================
+ Hits        29390    29395    +5     
- Misses       8039     8040    +1     
  Partials     1350     1350           
Flag Coverage Δ
unittests 75.78% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
runtime/sema/hashalgorithm_string.go 0.00% <ø> (ø)
runtime/sema/crypto_algorithm_types.go 83.92% <100.00%> (+0.90%) ⬆️
runtime/sema/simple_type.go 92.85% <0.00%> (-3.58%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 95aea4a...d2d8228. Read the comment docs.

Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution! 👍

@turbolent turbolent merged commit 4d392ad into onflow:master Jan 14, 2022
@tarakby
Copy link
Contributor

tarakby commented Jan 14, 2022

FYI, @ramtinms and I will be adding Keccak-256 to Flow-go next week, for both the crypto and FVM side.
@zhiqiangxu, letting you know so we don't duplicate the work.

@zhiqiangxu
Copy link
Contributor Author

FYI, @ramtinms and I will be adding Keccak-256 to Flow-go next week, for both the crypto and FVM side. @zhiqiangxu, letting you know so we don't duplicate the work.

ok, but seems that CI is still not happy?

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

Successfully merging this pull request may close these issues.

6 participants