-
Notifications
You must be signed in to change notification settings - Fork 21.7k
all: use stateless keccak #33222
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
all: use stateless keccak #33222
Conversation
gballet
left a comment
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.
That reminds me of something I've done before for keeper, I'll have to check that this doesn't clash with those changes. I'm flying today, don't merge before I've had a deeper look.
|
The changes are not essential, we prefer to not include it. |
|
@rjl493456442 let me at least argument my motivation - when running geth within ZK VM it is highly beneficial to outsource heavy computation (like Keccak) to the dedicated VM precompiles; by removing all unnecessarily stateful hashing and reusing the |
Context
Keccak hashing algorithm can be used in two ways: (1) as a one-shot hash function (we are just interested in hash of the data that we already have in full) or (2) as a cryptographic sponge (for cases where we don't know all the data to be hashed yet, we need some intermediate hashes, etc.)
From the caller perspective, (1) is a completely stateless process, but (2) requires keeping some state.
The
cryptopackage exposesKeccak256Hash()andKeccak256()functions realizing (1) andNewKeccakState()for (2).Problem
There are ~20 places where we use stateful approach (2) for (1). In other words, we:
NewKeccakState()to create the sponge stateWrite(),Read(),Sum())whereas we could (and should) just use
Keccak256()utility.Proposed changes
spongeDbin some testing.Keccak256Hash()andKeccak256()KeccakStateinterface just extendio.Readerinstead of inliningio.Reader's method