-
Notifications
You must be signed in to change notification settings - Fork 493
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
AVM: SHA3-256 hash function opcode #3544
Conversation
Matt-Ryley
commented
Feb 1, 2022
- Implemented the SHA3-256 hash function required for interoperability of Algorand with the ICON blockchain.
- Added the OPCode 0x96 for this functionality.
- Updated documentation and unit tests to include the new SHA3-256 hashing function.
Added SHA3-256 hashing function as an OP code
Made required changes to pass the unit tests. -- Changed testAccepts version from 1 to 6 -- Added sha3_256 to the Opgroups
From code review suggestion renamed opSHA3256 to opSHA3_256 in the eval.go and opcodes.go file
data/transactions/logic/opcodes.go
Outdated
@@ -294,6 +294,9 @@ var OpSpecs = []OpSpec{ | |||
{0x94, "exp", opExp, asmDefault, disDefault, twoInts, oneInt, 4, modeAny, opDefault}, | |||
{0x95, "expw", opExpw, asmDefault, disDefault, twoInts, twoInts, 4, modeAny, costly(10)}, | |||
|
|||
//More Hash Functions | |||
{0x96, "sha3_256", opSHA3_256, asmDefault, disDefault, oneBytes, oneBytes, 6, modeAny, costly(130)}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did you derive the cost?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't sure how to derive the cost. The cost of the SHA3-256 should be roughly the same as the Keccak256 as they are very similar algorithms, except the padding in the SHA3-256 adds up to 4 additional bits. Im open to any suggestions of how to derive this cost more accurately?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is some benchmarking code in eval_test.go. But hold off for a couple days. We're in the middle of a merge that will change it slightly. But once that merge happens, you'll find
func BenchmarkBase64Decode(b *testing.B)
that was used to compare base64 decode to the costs of various hashes. By adding sha3_256 in there, we should be able to get a feel for relative costs.
(The function may already be in master, if you want to look now.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the information! Which merge should I be looking out for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feature/contract-to-contract going into master #3397
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @Matt-Ryley, just FYI the aforementioned merge happened.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the heads up @algoanne! Ill get on this as soon as possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have just ran the sha3_256 through the suggested function and here is the output, comparing keccak256 and sha3_256
BenchmarkBase64Decode/keccak256_small-8 518492 2221 ns/op
BenchmarkBase64Decode/sha3_256_small-8 525247 1957 ns/op
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me they are in the same ball park as one another and thus should have the same cost, as the eqv for other hashes like
BenchmarkBase64Decode/sha256_small-8 1260788 1003 ns/op
BenchmarkBase64Decode/sha512_256_small-8 1695235 715.2 ns/op
Are very different
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it sounds like it should have the same cost as keccak. I think we can take this as soon as CI passes. I'll be making a pass over it once that happens as I have changed the opcode interface a bit. But I think your work is done! Thanks for the contribution.
Spelling mistake rectified
Sorry, it looks like one thing you'll have to do to make CI happy is run |
Didnt mean to push them!
accidentally pushed all local changes!
Codecov Report
@@ Coverage Diff @@
## master #3544 +/- ##
==========================================
+ Coverage 49.57% 49.60% +0.02%
==========================================
Files 392 392
Lines 68590 68596 +6
==========================================
+ Hits 34006 34024 +18
+ Misses 30845 30836 -9
+ Partials 3739 3736 -3
Continue to review full report at Codecov.
|
@jannotti after upstream merge the arm64 test is now failing in one of the tests for the ledger. As I haven't modified any code in that directory I am confused to why this test fails. Do you know of any reason? My local machine is amd64 architecture and those tests run successfully in the CI pipeline and also on my local machine, so I can't really debug to find the cause of the error. |
I'm not sure, but I'll be looking at it more closely today.
I used a new PR, so I would be able to tweak it (to handle merge conflicts).
#3762
I believe I merged your commits in properly so you will retain credit.
Thanks again.
…On Mon, Mar 14, 2022 at 7:04 AM Matt-Ryley ***@***.***> wrote:
@jannotti <https://github.com/jannotti> after upstream merge the arm64
test is now failing in one of the tests for the ledger. As I haven't
modified any code in that directory I am confused to why this test fails.
Do you know of any reason? My local machine is amd64 architecture and those
tests run successfully in the CI pipeline and also on my local machine, so
I can't really debug to find the cause of the error.
—
Reply to this email directly, view it on GitHub
<#3544 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADL7T6MTB7OTAMTHE5ESADU74MMHANCNFSM5NIXB5AQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Closed in favor of #3762 |