-
Notifications
You must be signed in to change notification settings - Fork 107
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 native #1354
add keccak256 native #1354
Conversation
@@ -461,7 +461,7 @@ Return ID if called during current pact execution, failing if not. | |||
Obtain current pact build version. | |||
```lisp | |||
pact> (pact-version) | |||
"4.10" | |||
"4.11" |
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 do not think the docs have been regenerated in a while - there are some changes that are not related to what I have touched.
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.
In general: The readthedocs website is deprecated, and we need to manually PR changes for docs.kadena.io, is this right @sstraatemans ?
@@ -461,7 +461,7 @@ Return ID if called during current pact execution, failing if not. | |||
Obtain current pact build version. | |||
```lisp | |||
pact> (pact-version) | |||
"4.10" | |||
"4.11" |
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.
In general: The readthedocs website is deprecated, and we need to manually PR changes for docs.kadena.io, is this right @sstraatemans ?
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.
Cannot be merged until we remove the unsafe lens access
I thought the lens access was safe because I was under the impression that natives were typechecked, but I was wrong |
b71af95
to
332702e
Compare
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.
@chessai, I've updated the FV translation but what I've noticed is, that the output has changed.
I.e., in the initial version 332702e, the output of (keccak256 [])
was: xdJGAYb3IzySfn2y3McDwOUAtlPKgic7e/rYBF2FpHA=
(see
pact/src-tool/Pact/Analyze/Eval/Core.hs
Line 320 in 8687946
let h = "xdJGAYb3IzySfn2y3McDwOUAtlPKgic7e/rYBF2FpHA=" |
xdJGAYb3IzySfn2y3McDwOUAtlPKgic7e_rYBF2FpHA
I've updated the FV branch with the recent changes, but we should look at the correct behaviour.
9c09175
to
4264ec4
Compare
329c428
to
b78f703
Compare
b78f703
to
4db0ad1
Compare
Co-authored-by: rsoeldner <r.soeldner@gmail.com>
4db0ad1
to
9bf3f05
Compare
Tests
Unit tests, Haskell:
tests/Keccak256Spec.hs
Repl tests, Pact:
tests/pact/keccak256.repl
Blocked on Pact 4.12 fork
Gas Benchmark
Gas Benchmark Code
Gas Benchmark Results
Findings
Linear regression of single-blob points only:

Linear regression of chunked points only:

From the single blob regression, the cost of
keccak256
could be computed (in milligas) roughly as:From the chunked regression, the cost of
keccak256
could be computed (in milligas) roughly as:This seems to suggest that for smaller inputs, the number of chunks matters more. This corroborates the story the benchmarks tell, as you can see that the difference between chunked and non-chunked input gets smaller as the total number of bytes grows larger. In practice, this convergence takes so long that we should charge per chunk.
I propose that the cost be this, per chunk:
To avoid rounding errors due to the small cost per bytes, we can cost this per 100 bytes:
With ceiling to avoid chunks of 99 bytes going ungassed:
And because
defaultGasTable
contains the base cost for a single call tokeccak256
, I believe the entry should be1 gas
, because any call does some work (evenkeccak256 []
), but the rest is gassed per chunk.