This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Blake2b f compression precompile test vectors
- Loading branch information
Showing
2 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...in/java/tech/pegasys/pantheon/ethereum/mainnet/precompiles/BLAKE2fPrecompileContract.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.pantheon.ethereum.mainnet.precompiles; | ||
|
||
import tech.pegasys.pantheon.ethereum.core.Gas; | ||
import tech.pegasys.pantheon.ethereum.mainnet.AbstractPrecompiledContract; | ||
import tech.pegasys.pantheon.ethereum.vm.GasCalculator; | ||
import tech.pegasys.pantheon.ethereum.vm.MessageFrame; | ||
import tech.pegasys.pantheon.util.bytes.BytesValue; | ||
|
||
public class BLAKE2fPrecompileContract extends AbstractPrecompiledContract { | ||
public BLAKE2fPrecompileContract(final GasCalculator gasCalculator) { | ||
super("BLAKE2b", gasCalculator); | ||
} | ||
|
||
@Override | ||
public Gas gasRequirement(final BytesValue input) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public BytesValue compute(final BytesValue input, final MessageFrame messageFrame) { | ||
if (input.size() != 213) { | ||
throw new IllegalArgumentException( | ||
"input length for Blake2 F precompile should be exactly 213 bytes"); | ||
} | ||
|
||
return null; | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
...ava/tech/pegasys/pantheon/ethereum/mainnet/precompiles/BLAKE2fPrecompileContractTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* Copyright 2019 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package tech.pegasys.pantheon.ethereum.mainnet.precompiles; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import tech.pegasys.pantheon.ethereum.mainnet.ConstantinopleFixGasCalculator; | ||
import tech.pegasys.pantheon.ethereum.vm.MessageFrame; | ||
import tech.pegasys.pantheon.util.bytes.BytesValue; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
@RunWith(Parameterized.class) | ||
public class BLAKE2fPrecompileContractTest { | ||
private final BLAKE2fPrecompileContract contract = | ||
new BLAKE2fPrecompileContract(new ConstantinopleFixGasCalculator()); | ||
|
||
public BLAKE2fPrecompileContractTest() {} | ||
|
||
private MessageFrame messageFrame = mock(MessageFrame.class); | ||
|
||
@Parameterized.Parameters | ||
public static Object[][] parameters() { | ||
return new Object[][] { | ||
{ | ||
"6a09e667f2bd8948bb67ae8484caa73b3c6ef372fe94f82ba54ff53a5f1d36f1510e527fade682d19b05688c2b3e6c1f1f83d9abfb41bd6b5be0cd19137e2179000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c", | ||
"63b3654623b9ca0757a1474a529433186257ba9deee206e9572365bbce31cea6d3e6d6901c014e1be3c5854bdbbef6de8ccfe917f2bb6643c72c02911aecadad" | ||
}, | ||
{ | ||
"6a09e627f3bcc909bb67ae8484caa73b3c6ef372fe94b82ba54ff53a5f1d36f1510e527fade682d19b05688c2b3e6c1f1f83d9abfb41bd6b5be0cd19137e2179278400340e6b05c5752592c52c4f121292eafc51cc01a997b4aed13409298fad0d99ccc8f76453d9b3661e5c4d325d7751147db17489046d1682d50eefa4a1da00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffc0ffffffffffffffff010000000c", | ||
"d618d21e4ccdda64b147dcca5687459fbf24145ea9091c33416e45229d0972282ea8b80ff6ca078d180efb0a36b08042c068f0ae9ce69f4a7098c8215ee61773" | ||
}, | ||
{ | ||
"2b536b65aae1d6731671813c2841a6146b8927a455d1f805ed650cdc3d38b03decbeb55e397687eb59650053fa515f5c817b4cedb190759a7f24f6ba1fc97300808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff00000000000001000000000000000000010000000c", | ||
"913105d263890354d07b7868b36d287c2391f54f2d43099882adae97a0345a253672600754921d844010f12d6e9455d383bb247343b1372dbb58369fbc9b2bdf" | ||
}, | ||
{ | ||
"6a09e667f2bd8948bb67aea184caa73b3c6ef372fe94f82ba54ff53a5f1d36f1510e527fade682d19b05688c2b3e6c1f1f83d9abfb41bd6b5be0cd19137e2179000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c", | ||
"138f26ca8e8b5088415879a35a2c2d7dd95e0929ba0bfe9c8b0ce25db7bce94cdbf1e30c89a2c099ea0da3e8e9ff135368f769a0eaae54da630d9b2ce7272703" | ||
}, | ||
{ | ||
"456d45a3841d8a19f16ed318dc09cb4a225593e559ecd4e1c57032c0316e2f08239531a59702945cb52b3fba2f3aa61e55e133554d2f4fd4fc252af7327e80e3808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff00000000000001000000000000000000010000000c", | ||
"164a65d708f5ee940fffc9ac7d1ca30083dbe67dfc6623e36b7d5ffd9aa8edca89e32143550f1d81b3297a7dba3ed6097d246f9e82ba2a93d5b908dbaef1384c" | ||
}, | ||
{ | ||
"6a09e627f3bcc901bb67aecc84caa73a3c6ef372fe94b82ba54ff53a5f1d36f1510e527fade682d19b05688c2b3e6c1f1f83d9abfb41bd6b5be0cd19137e2179d817fa064689494877e43d757ab1285b4b2a1899cde490442a90071c439a224e7070d3be04b6370df09c77018cf9d989afe1e208a9a35ce951330f210d56364a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffc0ffffffffffffffff010000000c", | ||
"089c3ff02e0c9e934a01d4631722ffbbb1f5d4cc508cdb5510ebbbab022e58b50e585dcd7dbfb1c7a9a01d51a9523d54ec60d2a1a96c1f6690b407054e4d00e3" | ||
}, | ||
{ | ||
"6a09e627f3bcc91fbb67aed284caa73a3c6ef372fe94b82ba54ff53a5f1d36f1510e527fade682d19b05688c2b3e6c1f1f83d9abfb41bd6b5be0cd19137e2179a11a4843ebc5ebc5e402d0f0ecf997957a5a01b2bfa6715e67130c95562c6f4d84c64d4bd0fb03698fbb0103aa31c4c1daeb4d727b46074d23756f961141685a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffc0ffffffffffffffff010000000c", | ||
"d38f3c045427b0ff87160b670ad983c7611cfe54558be69c7a8890fd94186323e43ce133de436abdea320274298acd2eef70be64c3277a60a902da3fd06af78e" | ||
}, | ||
{ | ||
"6a09e627f3bcc92dbb67aee084caa73a3c6ef372fe94b82ba54ff53a5f1d36f1510e527fade682d19b05688c2b3e6c1f1f83d9abfb41bd6b5be0cd19137e217928cdecc6e7e3f0e93591c75513aa862e44adae0a40ce7b8e6c72ea4b47b7c88b832a34cca4d8dbc6f112373f1e82e1d26a58498cfa1ed290e872149667cb2b9100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffc0ffffffffffffffff010000000c", | ||
"f1639feeaad03b7ea99e85889b6f7407a26a4095687dbc027d3256ad0c481f1661564b3628ba5b0a8117ea73be040036921ce3b64849a70db05bbaec2ba82c15" | ||
}, | ||
{ | ||
"6a09e627f3bcc93bbb67aef684caa73a3c6ef372fe94b82ba54ff53a5f1d36f1510e527fade682d19b05688c2b3e6c1f1f83d9abfb41bd6b5be0cd19137e21795f88c38e13dd036e0b6907218d2236f47bfc9ad7ad4478e69c11a4dd69109a5045de7154839b33f604c0f5907ab5e9a916abd7bedaba1dd6635f2850f42038b500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffc0ffffffffffffffff010000000c", | ||
"4c0fa0b3fa95a5ef7eb0ee4c662f9aef6b96582d211917c640cba8d7a7009fcaccfbb7ba7664cf24b2e2f5c3e7d45fee8b459c6581a25a97af1d6e71fd67a709" | ||
}, | ||
{ | ||
"6a09e627f3bcc948bb67ae0484caa73a3c6ef372fe94b82ba54ff53a5f1d36f1510e527fade682d19b05688c2b3e6c1f1f83d9abfb41bd6b5be0cd19137e21790bc009514bdad0c0331a29252f923da6137d6fd4ba14cb0e9c7cbb0bb1a666d5597d4d8c44612f5a2b12e8e39fa134d96b1d53fa08e48a1ad915bc44040c22ed00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffc0ffffffffffffffff010000000c", | ||
"272539bb30107dea7bf9ef9e3ed75db2c8a0ddb9f37c39ea06c012ed70c8a917e00040c6684905cc1b627d7d9b4e87daa03e2412698679068fe944138ab3c796" | ||
}, | ||
}; | ||
} | ||
|
||
@Parameterized.Parameter public String input; | ||
|
||
@Parameterized.Parameter(1) | ||
public String expectedResult; | ||
|
||
@Test | ||
public void shouldRecoverAddress() { | ||
final BytesValue input = BytesValue.fromHexString(this.input); | ||
final BytesValue expected = | ||
expectedResult == null ? BytesValue.EMPTY : BytesValue.fromHexString(expectedResult); | ||
assertThat(contract.compute(input, messageFrame)).isEqualTo(expected); | ||
} | ||
} |