-
Notifications
You must be signed in to change notification settings - Fork 84
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: implement 0x20 - SHA3 Opcode #115
Comments
Can I have this one please ? |
EDIT : Here is a corrected version of my first solution. This function returns the exact same hash than the EVM playground for many cases. I hope not forgetting some. The test cases I'm thinking about are ;
|
Here are my thoughts about either implementing Herodotus keccak or use the one suggested above. TL;DR : Herodotus keccak seems to be a little bit more gas efficient but the fact of having to format the u256 read from memory into a Span.u8 that will itself be formated into a Span.u64 may acutally "compenstate the gain from Herodotus' keccak". |
Putting here the content of the word file for @Quentash: I pulled Herodotus' keccak and added several test cases to be able to test some additional edge cases and compare them with my own implementation. I noticed that the tests consume slightly less gas in Herodotus than in my own implementation, but I think it's important to consider that Kakarot's tests set up a context and manipulate the stack/memory, while Herodotus' tests only test the hashing function. So, I also ran each test by isolating the hash function admitting that test_complete_cost - test_without_hash_cost = hash_cost. Use case 1: "Kakarot" implementation: Use case 2: "Kakarot" implementation: I have highlighted in green the differences (gas-consuming) between the two algorithms. I think that having to format the memory inputs into the type created by Herodotus (Bytes), which will then format this type into Span for carrio_keccak, may make the process more gas-consuming than the current one. Please let me know if I'm wrong or if I've missed something. |
Could we check |
I have taken the Herodotus impl and tried it as explained above. Using the sames use cases, here are the results ; Using this code :
I got those results ; Use case 1: Herodotus into "Kakarot" implementation: Which represent 1 617 354 more gas used compared to the 'Kakarot' impl. Use case 2: "Kakarot" implementation: Which represent 152,000,506 more gas used compared to the 'Kakarot' impl. I even tried to take a shorcut for the 32 bytes sized test doing this :
But it still consumed 2,274,852 gas which is only ~300k less than without the shorcut. |
I have analysed tests found at https://github.com/ethereum/tests/blob/develop/src/GeneralStateTestsFiller/VMTests/vmTests/sha3Filler.yml#L52 .
Beside that, all the other tests pass and return the correct values. |
Important update: we are gathering some bugs in the Kakarot v0 codebase, we need to make sure each issue and each PR in Kakarot-ssj is aware of the lists of known bugs. Look at this link everytime you take an issue and check your issue isn't targeted by a known bug. |
Important update: we are gathering some bugs in the Kakarot v0 codebase, we need to make sure each issue and each PR in Kakarot-ssj is aware of the lists of known bugs. Look at this tracking issue everytime you take an issue and check your issue isn't targeted by a known bug. Will add this reminder in many places to make sure we keep track of known bugs. |
Index 1 is top of the stack. See PUSH.
Stack input
offset
: byte offset in the memory.size
: byte size to read in the memory.Stack output
hash
: Keccak-256 hash of the given data in memory.Example
0xFFFFFFFF
1
0
0x29045A592007D0C246EF02C2223570DA9522D0CF0F73282C79A1BC8F0BB2C238
2
4
Reproduce in playground.
Error cases
The state changes done by the current context are reverted in those cases:
Gas
The memory expansion cost explanation can be found here.
Estimate your gas cost
The text was updated successfully, but these errors were encountered: