Search in sources :

Example 1 with SnowPowProof

use of snowblossom.proto.SnowPowProof in project snowblossom by snowblossomcoin.

the class SnowMerkleProofTest method testProofMany.

private void testProofMany(int mb_size, String seed, int count) throws Exception {
    File tmp_dir = testFolder.newFolder();
    long byte_len = mb_size * 1048576L;
    File deck = new File(tmp_dir, "test.deck.a");
    File snow = new File(tmp_dir, "test.snow");
    new SnowFall(snow.getAbsolutePath(), seed, byte_len);
    ByteString root_hash = new SnowMerkle(tmp_dir, "test", true).getRootHash();
    SnowMerkleProof proofGen = new SnowMerkleProof(tmp_dir, "test");
    int words = (int) (byte_len / SnowMerkle.HASH_LEN_LONG);
    Random rnd = new Random(byte_len);
    for (int i = 0; i < count; i++) {
        long location = rnd.nextInt(words);
        SnowPowProof proof = proofGen.getProof(location);
        Assert.assertEquals(location, proof.getWordIdx());
        Assert.assertTrue(Validation.checkProof(proof, root_hash, byte_len));
    }
}
Also used : SnowMerkleProof(snowblossom.miner.SnowMerkleProof) SnowMerkle(snowblossom.lib.SnowMerkle) Random(java.util.Random) ByteString(com.google.protobuf.ByteString) SnowFall(snowblossom.lib.SnowFall) SnowPowProof(snowblossom.proto.SnowPowProof) File(java.io.File)

Example 2 with SnowPowProof

use of snowblossom.proto.SnowPowProof in project snowblossom by snowblossomcoin.

the class FieldScan method checkField.

private void checkField(int field_number, SnowMerkleProof proof) throws java.io.IOException {
    SplittableRandom rnd = new SplittableRandom();
    long max = proof.getTotalWords();
    long check = rnd.nextLong(max);
    SnowPowProof p = proof.getProof(check);
    SnowFieldInfo info = params.getSnowFieldInfo(field_number);
    if (!Validation.checkProof(p, info.getMerkleRootHash(), info.getLength())) {
        throw new RuntimeException("proof check failed");
    }
}
Also used : SnowFieldInfo(snowblossom.lib.SnowFieldInfo) SnowPowProof(snowblossom.proto.SnowPowProof) SplittableRandom(java.util.SplittableRandom)

Example 3 with SnowPowProof

use of snowblossom.proto.SnowPowProof in project snowblossom by snowblossomcoin.

the class SnowMerkleProof method getProof.

public SnowPowProof getProof(long word_index) throws java.io.IOException {
    try (TimeRecordAuto tra = TimeRecord.openAuto("SnowMerkleProof.getProof")) {
        LinkedList<ByteString> partners = new LinkedList<ByteString>();
        MessageDigest md;
        try {
            md = MessageDigest.getInstance(Globals.SNOW_MERKLE_HASH_ALGO);
        } catch (java.security.NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
        getInnerProof(md, partners, word_index, 0, total_words);
        SnowPowProof.Builder builder = SnowPowProof.newBuilder();
        builder.setWordIdx(word_index);
        builder.addAllMerkleComponent(partners);
        return builder.build();
    }
}
Also used : TimeRecordAuto(duckutil.TimeRecordAuto) ByteString(com.google.protobuf.ByteString) SnowPowProof(snowblossom.proto.SnowPowProof) MessageDigest(java.security.MessageDigest) LinkedList(java.util.LinkedList)

Example 4 with SnowPowProof

use of snowblossom.proto.SnowPowProof in project snowblossom by snowblossomcoin.

the class SnowMerkleProofTest method testProofSingle.

private void testProofSingle(int mb_size, String seed, long location) throws Exception {
    File tmp_dir = testFolder.newFolder();
    long byte_len = mb_size * 1048576L;
    File deck = new File(tmp_dir, "test.deck.a");
    File snow = new File(tmp_dir, "test.snow");
    new SnowFall(snow.getAbsolutePath(), seed, byte_len);
    ByteString root_hash = new SnowMerkle(tmp_dir, "test", true).getRootHash();
    SnowMerkleProof proofGen = new SnowMerkleProof(tmp_dir, "test");
    SnowPowProof proof = proofGen.getProof(location);
    Assert.assertEquals(location, proof.getWordIdx());
    System.out.println(proof);
    Assert.assertTrue(Validation.checkProof(proof, root_hash, byte_len));
}
Also used : SnowMerkleProof(snowblossom.miner.SnowMerkleProof) SnowMerkle(snowblossom.lib.SnowMerkle) ByteString(com.google.protobuf.ByteString) SnowFall(snowblossom.lib.SnowFall) SnowPowProof(snowblossom.proto.SnowPowProof) File(java.io.File)

Example 5 with SnowPowProof

use of snowblossom.proto.SnowPowProof in project snowblossom by snowblossomcoin.

the class SnowMerkleProofTest method testProofShortStack.

@Test
public void testProofShortStack() throws Exception {
    long location = 0;
    int mb_size = 1;
    String seed = "zing";
    File tmp_dir = testFolder.newFolder();
    long byte_len = mb_size * 1048576L;
    File deck = new File(tmp_dir, "test.deck.a");
    File snow = new File(tmp_dir, "test.snow");
    new SnowFall(snow.getAbsolutePath(), seed, byte_len);
    ByteString root_hash = new SnowMerkle(tmp_dir, "test", true).getRootHash();
    SnowMerkleProof proofGen = new SnowMerkleProof(tmp_dir, "test");
    SnowPowProof real_proof = proofGen.getProof(location);
    SnowPowProof.Builder fake_proof = SnowPowProof.newBuilder();
    fake_proof.setWordIdx(location);
    LinkedList<ByteString> fiends = new LinkedList<ByteString>();
    fiends.addAll(real_proof.getMerkleComponentList());
    MessageDigest md = MessageDigest.getInstance(Globals.SNOW_MERKLE_HASH_ALGO);
    md.update(fiends.poll().toByteArray());
    md.update(fiends.poll().toByteArray());
    fiends.push(ByteString.copyFrom(md.digest()));
    fake_proof.addAllMerkleComponent(fiends);
    Assert.assertFalse(Validation.checkProof(fake_proof.build(), root_hash, byte_len));
}
Also used : SnowMerkle(snowblossom.lib.SnowMerkle) ByteString(com.google.protobuf.ByteString) ByteString(com.google.protobuf.ByteString) SnowPowProof(snowblossom.proto.SnowPowProof) LinkedList(java.util.LinkedList) SnowMerkleProof(snowblossom.miner.SnowMerkleProof) SnowFall(snowblossom.lib.SnowFall) MessageDigest(java.security.MessageDigest) File(java.io.File) Test(org.junit.Test)

Aggregations

SnowPowProof (snowblossom.proto.SnowPowProof)5 ByteString (com.google.protobuf.ByteString)4 File (java.io.File)3 SnowFall (snowblossom.lib.SnowFall)3 SnowMerkle (snowblossom.lib.SnowMerkle)3 SnowMerkleProof (snowblossom.miner.SnowMerkleProof)3 MessageDigest (java.security.MessageDigest)2 LinkedList (java.util.LinkedList)2 TimeRecordAuto (duckutil.TimeRecordAuto)1 Random (java.util.Random)1 SplittableRandom (java.util.SplittableRandom)1 Test (org.junit.Test)1 SnowFieldInfo (snowblossom.lib.SnowFieldInfo)1