Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Add blake2_f precompile #11017

Merged
merged 40 commits into from
Sep 9, 2019
Merged

Conversation

dvdplm
Copy link
Collaborator

@dvdplm dvdplm commented Sep 2, 2019

As per EIP 152, adds a new precompile at 0x09 to expose the Blake2 compression function, aka the "F function".

Spec: https://tools.ietf.org/html/rfc7693#section-3.2
EIP-152: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-152.md

Closes #10994

Note: the F compression function in this PR is not optimised (or rather, it's optimised for readability ;). This will be addressed in a separate PR as the intention here is to be 1. spec compliant and 2. get the precompile plumbing in place.

Note-2: The chainspecs are not yet updated a part from foundation.json. Would appreciate a review of the format used there and I'll replicate it elsewhere.

@dvdplm dvdplm requested a review from sorpaas September 2, 2019 20:20
@dvdplm dvdplm self-assigned this Sep 2, 2019
@dvdplm dvdplm added the A3-inprogress ⏳ Pull request is in progress. No review needed at this stage. label Sep 2, 2019
@dvdplm dvdplm requested review from seunlanlege and removed request for sorpaas September 2, 2019 20:20
* master:
  EIP 1108: Reduce alt_bn128 precompile gas costs (#11008)
  Fix deadlock in `network-devp2p` (#11013)
  Implement EIP-1283 reenable transition, EIP-1706 and EIP-2200 (#10191)
Add remaining test vectors
Copy link
Member

@seunlanlege seunlanlege left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good 😎

ethcore/builtin/src/lib.rs Outdated Show resolved Hide resolved
ethcore/builtin/src/lib.rs Outdated Show resolved Hide resolved
ethcore/builtin/src/lib.rs Outdated Show resolved Hide resolved
ethcore/builtin/src/lib.rs Outdated Show resolved Hide resolved
json/src/spec/builtin.rs Outdated Show resolved Hide resolved
dvdplm and others added 3 commits September 3, 2019 12:12
* master:
  Extract snapshot to own crate (#11010)
  Edit publish-onchain.sh to use https (#11016)
Co-Authored-By: Andronik Ordian <write@reusable.software>
Co-Authored-By: Andronik Ordian <write@reusable.software>
@ordian ordian added this to the 2.7 milestone Sep 3, 2019
@ordian ordian added B0-patch-stable 🕷 Pull request should also be back-ported to the stable branch. B1-patch-beta 🕷🕷 M4-core ⛓ Core client code / Rust. labels Sep 3, 2019
Return a cost of u32::MAX if conversion fails
Fix docs and todos
dvdplm and others added 5 commits September 4, 2019 11:25
Co-Authored-By: Niklas Adolfsson <niklasadolfsson1@gmail.com>
Co-Authored-By: Andronik Ordian <write@reusable.software>
Co-Authored-By: Andronik Ordian <write@reusable.software>
…:paritytech/parity-ethereum into dp/feature/eip-152-add-blake2-precompile

* 'dp/feature/eip-152-add-blake2-precompile' of github.com:paritytech/parity-ethereum:
  Update json/src/spec/builtin.rs
  Update json/src/spec/builtin.rs
  Update util/EIP-152/src/lib.rs
@niklasad1
Copy link
Collaborator

niklasad1 commented Sep 4, 2019

@dvdplm do we got any benches for this?

Would be nice but maybe it is intended to be part of #11020?

EDIT: nvm, didn't read the issue properly sorry

Copy link
Collaborator

@niklasad1 niklasad1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@dvdplm
Copy link
Collaborator Author

dvdplm commented Sep 4, 2019

Let's not merge this PR before I say so. There are problems with the EIP being discussed in the gitter and until we know what is going to happen we're better off not merging this.

@ordian ordian added the A1-onice 🌨 Pull request is reviewed well, but should not yet be merged. label Sep 4, 2019
@holiman
Copy link
Contributor

holiman commented Sep 9, 2019

Let's not merge this PR before I say so. There are problems with the EIP being discussed in the gitter and until we know what is going to happen we're better off not merging this.

It was decided on ACD on friday that nothing changes on the implementation: ethereum/EIPs#152 (comment) .

  • There seems to be some work going on in the background to make use of a BLAKE2b-variant with non-standard rounds. Unfortunately @mhluongo could not divulge further details.
  • It is unknown what would be a reasonable upper bound for rounds for such a non-standard BLAKE2b. As a result the rounds parameter seemed to be left at 32-bit.
  • It was agreed that the EIP should be updated to reflect it describes a very specific superset of BLAKE2b, but still a subset of BLAKE2. The EIP also should include the actual compression function and parameters (SIGMA, IV) – and not leave it as a reference to the RFC.
  • There was no agreement about introducing the m_len field, which is a devex improvement and gas saving. It would make sense for client implementers to judge the complexity and decide upon that.

Please get this merged so we can kick off cross-client testing. Btw: did you guys implement Istanbul in state tests yet?

* master:
  fix: remove unused error-chain (#11028)
  fix: remove needless use of itertools (#11029)
  Convert `std::test` benchmarks to use Criterion (#10999)
  Fix block detail updating (#11015)
  [trace] introduce trace failed to Ext (#11019)
  cli: update usage and version headers (#10924)
  [private-tx] remove unused rand (#11024)
@ordian ordian removed the A1-onice 🌨 Pull request is reviewed well, but should not yet be merged. label Sep 9, 2019
// 1. immutable,
// 2. comprised of `u64`
// …and because we're using the (known) length of `h`
slice::from_raw_parts(h.as_ptr() as *const u8, h.len() * size_of::<u64>())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to remove this unsafe. What I worry is someone compiling parity-ethereum to a big endian platform. There may not be many, but once people do that it breaks consensus. We may want to just specify the exact encoding how conversion from u64 array to bytearray happens.

Copy link
Collaborator

@ordian ordian Sep 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There could be other problems with big endian, e.g. with ethash https://github.com/paritytech/parity-ethereum/blob/5baa7e8fb50512b0de11b0994fa1b136de289831/ethash/src/compute.rs#L273-L276

but in this case it should work with big endian if I'm not mistaken

@sorpaas sorpaas added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Sep 9, 2019
@sorpaas sorpaas merged commit d8d7abc into master Sep 9, 2019
@sorpaas sorpaas deleted the dp/feature/eip-152-add-blake2-precompile branch September 9, 2019 22:26
dvdplm added a commit that referenced this pull request Sep 10, 2019
…he-right-place

* master:
  cleanup json crate (#11027)
  [spec] add istanbul test spec (#11033)
  [json-spec] make blake2 pricing spec more readable (#11034)
  Add blake2_f precompile (#11017)
  Add new line after writing block to hex file. (#10984)
  fix: remove unused error-chain (#11028)
  fix: remove needless use of itertools (#11029)
  Convert `std::test` benchmarks to use Criterion (#10999)
  Fix block detail updating (#11015)
  [trace] introduce trace failed to Ext (#11019)
  cli: update usage and version headers (#10924)
  [private-tx] remove unused rand (#11024)
dvdplm added a commit that referenced this pull request Sep 11, 2019
* feat: implement eip1108

* doc nit: price per point pair

Co-Authored-By: David <dvdplm@gmail.com>

* fix: test-build

* fix: update chain specs

* fix: basic_authority.json chain spec

* fix: change `eip_transition == 0x7fffffffffffff`

* Merge na-eip1108

* Pre-compile plumbing

* Use type alias instead of struct

* Extract the data from incoming EVM call and forward it to blake2_f

* Fetch parity-common from git for now

* Fix broken cost impl
Add remaining test vectors

* cleanup

* Trailing comma in json spec

* Update ethcore/builtin/src/lib.rs

Co-Authored-By: Andronik Ordian <write@reusable.software>

* Update ethcore/builtin/src/lib.rs

Co-Authored-By: Andronik Ordian <write@reusable.software>

* Rename pricer to be Blake2-specific
Return a cost of u32::MAX if conversion fails
Fix docs and todos

* Fix error handling in cost()

* fix chainspec

* EIP-152 crate

* Update ethcore/builtin/src/lib.rs

Co-Authored-By: Seun LanLege <seunlanlege@gmail.com>

* Address grumbles

* Update ethcore/builtin/src/lib.rs

Co-Authored-By: Niklas Adolfsson <niklasadolfsson1@gmail.com>

* Switch tests to use hex!

* remove parity-crypto from git

* Sort out the SIGMA

* Prefer arrays to vecs

* Update util/EIP-152/src/lib.rs

Co-Authored-By: Niklas Adolfsson <niklasadolfsson1@gmail.com>

* Update json/src/spec/builtin.rs

Co-Authored-By: Andronik Ordian <write@reusable.software>

* Update json/src/spec/builtin.rs

Co-Authored-By: Andronik Ordian <write@reusable.software>

* Review feedback

* Do not change chainspecs yet

* Do not assume endianess: precompile output is LE
dvdplm added a commit that referenced this pull request Sep 11, 2019
* feat: implement eip1108

* doc nit: price per point pair

Co-Authored-By: David <dvdplm@gmail.com>

* fix: test-build

* fix: update chain specs

* fix: basic_authority.json chain spec

* fix: change `eip_transition == 0x7fffffffffffff`

* Merge na-eip1108

* Pre-compile plumbing

* Use type alias instead of struct

* Extract the data from incoming EVM call and forward it to blake2_f

* Fetch parity-common from git for now

* Fix broken cost impl
Add remaining test vectors

* cleanup

* Trailing comma in json spec

* Update ethcore/builtin/src/lib.rs

Co-Authored-By: Andronik Ordian <write@reusable.software>

* Update ethcore/builtin/src/lib.rs

Co-Authored-By: Andronik Ordian <write@reusable.software>

* Rename pricer to be Blake2-specific
Return a cost of u32::MAX if conversion fails
Fix docs and todos

* Fix error handling in cost()

* fix chainspec

* EIP-152 crate

* Update ethcore/builtin/src/lib.rs

Co-Authored-By: Seun LanLege <seunlanlege@gmail.com>

* Address grumbles

* Update ethcore/builtin/src/lib.rs

Co-Authored-By: Niklas Adolfsson <niklasadolfsson1@gmail.com>

* Switch tests to use hex!

* remove parity-crypto from git

* Sort out the SIGMA

* Prefer arrays to vecs

* Update util/EIP-152/src/lib.rs

Co-Authored-By: Niklas Adolfsson <niklasadolfsson1@gmail.com>

* Update json/src/spec/builtin.rs

Co-Authored-By: Andronik Ordian <write@reusable.software>

* Update json/src/spec/builtin.rs

Co-Authored-By: Andronik Ordian <write@reusable.software>

* Review feedback

* Do not change chainspecs yet

* Do not assume endianess: precompile output is LE
This was referenced Sep 12, 2019
s3krit added a commit that referenced this pull request Sep 12, 2019
* add more tx tests (#11038)
* Fix parallel transactions race-condition (#10995)
* Add blake2_f precompile (#11017)
* [trace] introduce trace failed to Ext (#11019)
* Edit publish-onchain.sh to use https (#11016)
* Fix deadlock in network-devp2p (#11013)
* EIP 1108: Reduce alt_bn128 precompile gas costs (#11008)
* xDai chain support and nodes list update (#10989)
* EIP 2028: transaction gas lowered from 68 to 16 (#10987)
* EIP-1344 Add CHAINID op-code (#10983)
* manual publish jobs for releases, no changes for nightlies (#10977)
* [blooms-db] Fix benchmarks (#10974)
* Verify transaction against its block during import (#10954)
* Better error message for rpc gas price errors (#10931)
* Fix fork choice (#10837)
* Fix compilation on recent nightlies (#10991)
s3krit added a commit that referenced this pull request Sep 12, 2019
* add more tx tests (#11038)
* Fix parallel transactions race-condition (#10995)
* Add blake2_f precompile (#11017)
* [trace] introduce trace failed to Ext (#11019)
* Edit publish-onchain.sh to use https (#11016)
* Fix deadlock in network-devp2p (#11013)
* EIP 1108: Reduce alt_bn128 precompile gas costs (#11008)
* xDai chain support and nodes list update (#10989)
* EIP 2028: transaction gas lowered from 68 to 16 (#10987)
* EIP-1344 Add CHAINID op-code (#10983)
* manual publish jobs for releases, no changes for nightlies (#10977)
* [blooms-db] Fix benchmarks (#10974)
* Verify transaction against its block during import (#10954)
* Better error message for rpc gas price errors (#10931)
* tx-pool: accept local tx with higher gas price when pool full (#10901)
* Fix fork choice (#10837)
* Cleanup unused vm dependencies (#10787)
* Fix compilation on recent nightlies (#10991)
dvdplm added a commit that referenced this pull request Sep 13, 2019
* master: (70 commits)
  ethcore: remove `test-helper feat` from build (#11047)
  Include test-helpers from ethjson (#11045)
  [ethcore]: cleanup dependencies (#11043)
  add more tx tests (#11038)
  Fix parallel transactions race-condition (#10995)
  [ethcore]: make it compile without `test-helpers` feature (#11036)
  Benchmarks for block verification (#11035)
  Move snapshot related traits to their proper place (#11012)
  cleanup json crate (#11027)
  [spec] add istanbul test spec (#11033)
  [json-spec] make blake2 pricing spec more readable (#11034)
  Add blake2_f precompile (#11017)
  Add new line after writing block to hex file. (#10984)
  fix: remove unused error-chain (#11028)
  fix: remove needless use of itertools (#11029)
  Convert `std::test` benchmarks to use Criterion (#10999)
  Fix block detail updating (#11015)
  [trace] introduce trace failed to Ext (#11019)
  cli: update usage and version headers (#10924)
  [private-tx] remove unused rand (#11024)
  ...
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. B0-patch-stable 🕷 Pull request should also be back-ported to the stable branch. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EIP-152
6 participants