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

SHA256 workaround #14

Closed
wants to merge 3 commits into from
Closed

SHA256 workaround #14

wants to merge 3 commits into from

Conversation

hwwhww
Copy link
Contributor

@hwwhww hwwhww commented Feb 26, 2019

ethereum/consensus-specs#612

Since Vyper doesn't support built-in function call to call precompile sha256, it's a workaround to call call the precompile with raw_call() function.

Gas cost

(Updated: 2019/03/07: rebased)

The first 10 deposit gas cost with sha3

tests/contracts/test_deposit.py::test_deposit_tree
deposit transaction consumes 171466 gas
deposit transaction consumes 142334 gas
deposit transaction consumes 141476 gas
deposit transaction consumes 143202 gas
deposit transaction consumes 141476 gas
deposit transaction consumes 142344 gas
deposit transaction consumes 141486 gas
deposit transaction consumes 144070 gas
deposit transaction consumes 141476 gas
deposit transaction consumes 142344 gas

The first 10 deposit gas cost with this PR (SHA256)

tests/contracts/test_deposit.py::test_deposit_tree
deposit transaction consumes 225808 gas
deposit transaction consumes 198311 gas
deposit transaction consumes 195818 gas
deposit transaction consumes 200814 gas
deposit transaction consumes 195818 gas
deposit transaction consumes 198321 gas
deposit transaction consumes 195828 gas
deposit transaction consumes 203317 gas
deposit transaction consumes 195818 gas
deposit transaction consumes 198321 gas

Rough calculation

Gas price

GAS_CALL = 700

GAS_SHA256 = 60
GAS_SHA256WORD = 12

GAS_SHA3 = 30
GAS_SHA3WORD = 6
Merkliezing two leaves (32 bytes * 2) * 64 times + hashing deposit data (528 bytes) 1 time
= 64 * ((GAS_SHA256 + (64 // 32) * GAS_SHA256WORD) / 2.0 + GAS_CALL) + ((GAS_SHA256 + (528 // 32 + 1) * GAS_SHA256WORD) / 2.0 + GAS_CALL)
= 64 * ((60 + ceil(64 / 32) * 12) / 2.0 + 700) + ((60 + ceil(528 / 32) * 12) / 2.0 + 700)
= 48320

Cute Animal Picture

🦙

@hwwhww
Copy link
Contributor Author

hwwhww commented Mar 14, 2019

closing via #19

@hwwhww hwwhww closed this Mar 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant