Search in sources :

Example 1 with EquiUtils

use of org.aion.equihash.EquiUtils in project aion by aionnetwork.

the class EquihashSolutionRuleTest method testProperSolution.

// perhaps we should generate a solution by hand
@Test
public void testProperSolution() {
    // given that all our inputs are deterministic, for given nonce, there should always
    // be a valid output solution
    final int n = 210;
    final int k = 9;
    final BigInteger givenNonce = new BigInteger("21");
    // assume a 32-byte nonce (fixed)
    byte[] unpaddedNonceBytes = givenNonce.toByteArray();
    byte[] nonceBytes = new byte[32];
    System.arraycopy(unpaddedNonceBytes, 0, nonceBytes, 32 - unpaddedNonceBytes.length, unpaddedNonceBytes.length);
    System.out.println(new ByteArrayWrapper(nonceBytes));
    A0BlockHeader header = new A0BlockHeader.Builder().build();
    header.setNonce(nonceBytes);
    byte[] headerBytes = header.getHeaderBytes(true);
    Equihash equihash = new Equihash(n, k);
    int[][] solutions = equihash.getSolutionsForNonce(headerBytes, header.getNonce());
    byte[] compressedSolution = (new EquiUtils()).getMinimalFromIndices(solutions[0], n / (k + 1));
    header.setSolution(compressedSolution);
// EquihashSolutionRule rule = new EquihashSolutionRule(new OptimizedEquiValidator(n, k));
// boolean result = rule.validate(header);
// assertThat(result).isTrue();
// assertThat(rule.getErrors()).isEmpty();
}
Also used : A0BlockHeader(org.aion.zero.types.A0BlockHeader) EquiUtils(org.aion.equihash.EquiUtils) ByteArrayWrapper(org.aion.base.util.ByteArrayWrapper) BigInteger(java.math.BigInteger) Equihash(org.aion.equihash.Equihash) Test(org.junit.Test)

Aggregations

BigInteger (java.math.BigInteger)1 ByteArrayWrapper (org.aion.base.util.ByteArrayWrapper)1 EquiUtils (org.aion.equihash.EquiUtils)1 Equihash (org.aion.equihash.Equihash)1 A0BlockHeader (org.aion.zero.types.A0BlockHeader)1 Test (org.junit.Test)1