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

Final Blake2b PR. Merge this and close others. #2136

Closed
wants to merge 74 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
230647f
Start new EIP
tjade273 Jun 30, 2016
585958c
Add abstract and specification
tjade273 Jun 30, 2016
ae2a9ef
Add specification and rationale
tjade273 Jul 11, 2016
2fed08b
Add rationale
tjade273 Jul 11, 2016
9044f99
Spelling fixes
tjade273 Jul 11, 2016
57f2504
Remove EIP number until assignment
tjade273 Jul 11, 2016
1649ded
Fix gas calculation
tjade273 Jul 11, 2016
bb26ea7
Remove INSIZE parameter, as it is unnecessary
tjade273 Jul 12, 2016
ebea49b
Start new EIP
tjade273 Jun 30, 2016
9c45bf9
Add abstract and specification
tjade273 Jun 30, 2016
f33bbe1
Add specification and rationale
tjade273 Jul 11, 2016
34f649e
Add rationale
tjade273 Jul 11, 2016
10004d4
Spelling fixes
tjade273 Jul 11, 2016
00da725
Remove EIP number until assignment
tjade273 Jul 11, 2016
8e59a8d
Fix gas calculation
tjade273 Jul 11, 2016
5798cb7
Remove INSIZE parameter, as it is unnecessary
tjade273 Jul 12, 2016
db85771
Expand motivation section, typo fixes
Sep 27, 2017
f4e2fd8
Add implementations in various languages
Oct 3, 2017
2d4ea31
Edit wording
Oct 4, 2017
e8117c6
Merge branch 'blake2b' of https://github.com/arcalinea/EIPs into arca…
tjade273 Oct 4, 2017
0afe99a
Merge branch 'arcalinea-blake2b'
tjade273 Oct 4, 2017
39f7c3f
Create eip-Funding-eth-1x.md
MadeofTin May 13, 2019
6003de7
Delete eip-Funding-eth-1x.md
MadeofTin May 13, 2019
ef115c1
Created initial File
MadeofTin May 13, 2019
36a7845
Renamed to eip-blake2b.md
MadeofTin May 13, 2019
ef02974
updated authors
MadeofTin May 13, 2019
0d659c3
Updated to Historic EIP Number
MadeofTin May 13, 2019
7354cb4
Number 2024
MadeofTin May 13, 2019
601cc35
Update eip-Blake2b.md
MadeofTin May 13, 2019
46babcb
Rename eip-Blake2b.md to eip-2024.md
MadeofTin May 13, 2019
c260a55
Update eip-2024.md
MadeofTin May 13, 2019
f592757
Update eip-2024.md
MadeofTin May 14, 2019
ebe1d11
Update eip-2024.md
MadeofTin May 14, 2019
719318b
Update eip-2024.md
MadeofTin May 14, 2019
072efb9
Update eip-2024.md
MadeofTin May 14, 2019
e403a10
Update eip-2024.md
MadeofTin May 14, 2019
e774c44
Update and rename eip-2024.md to eip-131.md
MadeofTin May 14, 2019
b4fcd68
Update eip-131.md
MadeofTin May 14, 2019
3671f14
Merge pull request #1 from tjade273/master
MadeofTin May 14, 2019
5e745da
Updated Formatting to current standards
MadeofTin May 14, 2019
9258414
Delete eip-131.md
MadeofTin May 14, 2019
8613c50
Rename eip-9.md to eip-131.md
MadeofTin May 14, 2019
ceaa653
Update eip-131.md
MadeofTin May 14, 2019
5fa430f
Update eip-131.md
MadeofTin May 14, 2019
e79b430
Update eip-131.md
MadeofTin May 14, 2019
285c6f7
Added a Gitter room in the "discussions to" field
MadeofTin May 14, 2019
9ac83ee
Update eip-131.md
MadeofTin May 16, 2019
9d73b0b
updated backwards compatibility
MadeofTin May 16, 2019
9f5008e
Added References and carterpy as an Author
MadeofTin May 16, 2019
495062d
Added to EIP-1679 for Istanbul
MadeofTin May 17, 2019
d428749
Added additional references
MadeofTin May 21, 2019
ae038c8
Update eip-1679.md
MadeofTin May 24, 2019
fc56b06
updated authors formating
MadeofTin May 24, 2019
3f181cb
Updated Formating
MadeofTin May 24, 2019
186c1db
Clarified Specification
MadeofTin May 31, 2019
9084f86
Spelling
MadeofTin May 31, 2019
5b3345b
Removed metropolis block number from params
MadeofTin May 31, 2019
89a8794
Brought issue #152 into the repo as a draft EIP.
mhluongo Jun 16, 2019
843d377
Make the draft EIP consistent with the template
mhluongo Jun 16, 2019
3bcce1d
Break backwards compatibility into its own section
mhluongo Jun 16, 2019
c3f4c68
Added notes about the in-progress implementation
mhluongo Jun 16, 2019
92916e1
Specify EIP-2046 as a requirement
mhluongo Jun 16, 2019
764ff73
Don't use ABI encoding for precompile
mhluongo Jun 20, 2019
15c3352
Add @pdyraga to the EIP authors.
mhluongo Jun 20, 2019
552e602
Remove less relevant EIP rationale
mhluongo Jun 20, 2019
5a29338
Use 0x09 as the precompile address
mhluongo Jun 20, 2019
5d203c4
Choosing an EIP number
mhluongo Jun 21, 2019
ad01be2
Merge branch 'Blake2b' into blake2b-f-precompile
MadeofTin Jun 24, 2019
02568c4
Merge branch 'Blake2b' of https://github.com/madeoftin/EIPs into Blake2b
MadeofTin Jun 24, 2019
487aea3
Added References
MadeofTin Jun 24, 2019
2785b0a
Removing old draft
MadeofTin Jun 24, 2019
edb7d66
Update and rename eip-152.md to eip-131.md
MadeofTin Jun 24, 2019
e13d0ab
Spelling Updates
MadeofTin Jun 24, 2019
cab3f25
Update eip-131.md
nicksavers Jul 8, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 146 additions & 0 deletions EIPS/eip-131.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
---
eip: 131
title: Add Blake2 compression function `F` precompile
author: Tjaden Hess <tah83@cornell.edu>, Matt Luongo (@mhluongo), Piotr Dyraga (@pdyraga), James Hancock (@madeoftin)
discussions-to: https://ethereum-magicians.org/t/blake2b-f-precompile/3157
status: Draft
type: Standards Track
category: Core
created: 2016-10-04
---

<!--You can leave these HTML comments in your merged EIP and delete the visible duplicate text guides, they will not appear and may be helpful to refer to if you edit it again. This is the suggested template for new EIPs. Note that an EIP number will be assigned by an editor. When opening a pull request to submit your EIP, please use an abbreviated title in the filename, `eip-draft_title_abbrev.md`. The title should be 44 characters or less.-->

## Simple Summary
<!--"If you can't explain it simply, you don't understand it well enough." Provide a simplified and layman-accessible explanation of the EIP.-->

This EIP will enable the Blake2b hash function to run cheaply on the EVM, allowing easier interoperability between Ethereum and Zcash as well as other Equihash-based PoW coins.

## Abstract
<!--A short (~200 word) description of the technical issue being addressed.-->

This EIP introduces a new precompiled contract which implements the compression function `F` used in the BLAKE2b cryptographic hashing algorithm, for the purpose of allowing interoperability between the EVM and Zcash, as well as introducing more flexible cryptographic hash primitives to the EVM.

## Motivation
<!--The motivation is critical for EIPs that want to change the Ethereum protocol. It should clearly explain why the existing protocol specification is inadequate to address the problem that the EIP solves. EIP submissions without sufficient motivation may be rejected outright.-->

Besides being a useful cryptographic hash function and SHA3 finalist, BLAKE2b allows for efficient verification of the Equihash PoW used in Zcash, making a BTC Relay - style SPV client possible on Ethereum. A single verification of an Equihash PoW verification requires 512 iterations of the hash function, making verification of Zcash block headers prohibitively expensive if a Solidity implementation of BLAKE2b is used.

The BLAKE2b algorithm is highly optimized for 64-bit CPUs, and is faster than MD5 on modern processors.

Interoperability with Zcash could enable contracts like trustless atomic swaps between the chains, which could provide a much needed aspect of privacy to the very public Ethereum blockchain.

## Specification
<!--The technical specification should describe the syntax and semantics of any new feature. The specification should be detailed enough to allow competing, interoperable implementations for any of the current Ethereum platforms (go-ethereum, parity, cpp-ethereum, ethereumj, ethereumjs, and [others](https://github.com/ethereum/wiki/wiki/Clients)).-->

We propose adding a precompiled contract at address `0x09` wrapping the [BLAkE2b `F` compression function](https://tools.ietf.org/html/rfc7693#section-3.2). Rather than the ABI-encoded call structure proposed in [#152](https://github.com/ethereum/EIPs/issues/152), this design better matches other precompiles and works well with a standard `staticcall`.

The precompile requires 6 inputs, corresponding to the inputs specified in the [BLAKE2b RFC](https://tools.ietf.org/html/rfc7693#section-3.2)

- `h` - the state vector
- `m` - the message block vector
- `t_0, t_1` - offset counters
- `f` - the final block indicator flag
- `rounds` - the number of rounds

Loosely packing the data in equal 32-byte slots means an easier job for app developers, and also appears to be compatible with how other precompiles accept input data.

```
[ bytes32[0] | bytes32[1] ][ bytes32[2] | bytes32[3] | bytes32[4] | bytes32[5] ]
[ 64 bytes for h ][ 128 bytes for m ]

[ bytes32[6] ][ bytes32[7] ]
[ 24 bytes padding | 8 bytes for t_0 ][ 24 bytes padding | 8 bytes for t_1 ]

[ bytes32[8] ][ bytes32[9] ]
[ 31 bytes padding | 1 byte for f ][ 28 bytes padding | 4 bytes for rounds]
```

The precompile can be wrapped easily in Solidity to provide a more development-friendly interface to `F`.

```solidity
function F(bytes32[2] memory h, bytes32[4] memory m, uint64[2] memory t, bool f, uint32 rounds) public view returns (bytes32[2] memory) {
bytes32[2] memory output;

bytes32 _t0 = bytes32(uint256(t[0]));
bytes32 _t1 = bytes32(uint256(t[1]));

bytes32 _f;
if (f) {
_f = hex"0000000000000000000000000000000000000000000000000000000000000001";
}

bytes32 _rounds = bytes32(uint256(rounds));

bytes32[10] memory args = [ h[0], h[1], m[0], m[1], m[2], m[3], _t0, _t1, _f, _rounds ];

assembly {
if iszero(staticcall(not(0), 0x09, args, 0x140, output, 0x40)) {
revert(0, 0)
}
}
return output;
}

function callF() public view returns (bytes32[2] memory) {
bytes32[2] memory h;
h[0] = hex"6a09e627f3bcc909bb67ae8484caa73b3c6ef372fe94b82ba54ff53a5f1d36f1";
h[1] = hex"510e527fade682d19b05688c2b3e6c1f1f83d9abfb41bd6b5be0cd19137e2179";

bytes32[4] memory m;
m[0] = hex"278400340e6b05c5752592c52c4f121292eafc51cc01a997b4aed13409298fad";
m[1] = hex"0d99ccc8f76453d9b3661e5c4d325d7751147db17489046d1682d50eefa4a1da";
m[2] = hex"0000000000000000000000000000000000000000000000000000000000000000";
m[3] = hex"0000000000000000000000000000000000000000000000000000000000000000";

uint64[2] memory t;
t[0] = 18446744073709551552;
t[1] = 18446744073709551615;

bool f = true;

uint32 rounds = 12;

return F(h, m, t, f, rounds);
}
```

### Gas costs and benchmarks

Each operation will cost `GFROUND * rounds`.

## Rationale
<!--The rationale fleshes out the specification by describing what motivated the design and why particular design decisions were made. It should describe alternate designs that were considered and related work, e.g. how the feature is supported in other languages. The rationale may also provide evidence of consensus within the community, and should discuss important objections or concerns raised during discussion.-->

BLAKE2b is an excellent candidate for precompilation. It exhibits an extremely asymmetric efficiency. BLAKE2b is heavily optimized for modern 64-bit CPUs, specifically utilizing 24 and 63-bit rotations to allow parallelism through SIMD instructions and little-endian arithmetic. These characteristics provide exceptional speed on native CPUs: 3.08 cycles per byte, or 1 gibibyte per second on an Intel i5.

In contrast, the big-endian 32 byte semantics of the EVM are not conducive to efficient implementation of BLAKE2, and thus the gas cost associated with computing the hash on the EVM is disproportionate to the true cost of computing the function natively.

Implementation of only the core F compression function allows substantial flexibility and extensibility while keeping changes at the protocol level to a minimum. This will allow functions like tree hashing, incremental hashing, and keyed, salted, and personalized hashing as well as variable length digests, none of which are currently available on the EVM.

## Backwards Compatibility
<!--All EIPs that introduce backwards incompatibilities must include a section describing these incompatibilities and their severity. The EIP must explain how the author proposes to deal with these incompatibilities. EIP submissions without a sufficient backwards compatibility treatise may be rejected outright.-->

There is very little risk of breaking backwards-compatibility with this EIP, the sole issue being if someone were to build a contract relying on the address at `0x09` being empty. The likelihood of this is low, and should specific instances arise, the address could be chosen to be any arbitrary value with negligible risk of collision.

## Test Cases

<!--Test cases for an implementation are mandatory for EIPs that are affecting consensus changes. Other EIPs can choose to include links to test cases if applicable.-->

Test cases are in progress, and can be followed along in our [Golang Blake2 library fork](https://github.com/keep-network/blake2-f) as well as our fork of [go-ethereum](https://github.com/keep-network/go-ethereum).

## Implementation
<!--The implementations must be completed before any EIP is given status "Final", but it need not be completed before the EIP is accepted. While there is merit to the approach of reaching consensus on the specification and rationale before writing code, the principle of "rough consensus and running code" is still useful when it comes to resolving many discussions of API details.-->

Implementations are in progress, and can be followed along in our [Golang Blake2 library fork](https://github.com/keep-network/blake2-f) as well as our fork of [go-ethereum](https://github.com/keep-network/go-ethereum).

## References

For historic purposes discussion on this EIP also occurred in the following PRs.

* [Original Issue](https://github.com/ethereum/EIPs/issues/152)
* [PR 2129](https://github.com/ethereum/EIPs/pull/2129)

## Copyright

Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).
1 change: 1 addition & 0 deletions EIPS/eip-1679.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ This meta-EIP specifies the changes included in the Ethereum hardfork named Ista

### Proposed EIPs

- [EIP-131](https://eips.ethereum.org/EIPS/eip-131): Add Precompiled BLAKE2b Contract
- [EIP-615](https://eips.ethereum.org/EIPS/eip-615): Subroutines and Static Jumps for the EVM
- [EIP-663](https://eips.ethereum.org/EIPS/eip-663): Unlimited SWAP and DUP instructions
- [EIP-1057](https://eips.ethereum.org/EIPS/eip-1057): ProgPoW, a Programmatic
Expand Down