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

Commit

Permalink
Merged Kerl Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul D Handy committed Aug 7, 2017
1 parent 3f1343b commit 539e413
Show file tree
Hide file tree
Showing 39 changed files with 5,466 additions and 4,734 deletions.
15 changes: 11 additions & 4 deletions src/main/java/com/iota/iri/BundleValidator.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.iota.iri;

import com.iota.iri.controllers.BundleViewModel;
import com.iota.iri.controllers.HashesViewModel;
import com.iota.iri.hash.Curl;
import com.iota.iri.hash.ISS;
import com.iota.iri.hash.SpongeFactory;
import com.iota.iri.model.Hash;
import com.iota.iri.controllers.TransactionViewModel;
import com.iota.iri.storage.Tangle;
Expand Down Expand Up @@ -44,12 +44,13 @@ public static List<List<TransactionViewModel>> validate(Tangle tangle, Hash hash

if (instanceTransactionViewModels.get(0).getValidity() == 0) {

final Curl bundleHash = new Curl();
final Curl bundleHash = SpongeFactory.create(SpongeFactory.Mode.KERL);
for (final TransactionViewModel transactionViewModel2 : instanceTransactionViewModels) {
bundleHash.absorb(transactionViewModel2.trits(), TransactionViewModel.ESSENCE_TRINARY_OFFSET, TransactionViewModel.ESSENCE_TRINARY_SIZE);
}
final int[] bundleHashTrits = new int[TransactionViewModel.BUNDLE_TRINARY_SIZE];
bundleHash.squeeze(bundleHashTrits, 0, bundleHashTrits.length);
Hash h = new Hash(bundleHashTrits);
if (instanceTransactionViewModels.get(0).getBundleHash().equals(new Hash(Converter.bytes(bundleHashTrits, 0, TransactionViewModel.BUNDLE_TRINARY_SIZE)))) {

final int[] normalizedBundle = ISS.normalizedBundle(bundleHashTrits);
Expand All @@ -58,13 +59,19 @@ public static List<List<TransactionViewModel>> validate(Tangle tangle, Hash hash

transactionViewModel = instanceTransactionViewModels.get(j);
if (transactionViewModel.value() < 0) { // let's recreate the address of the transactionViewModel.
final SpongeFactory.Mode addressMode;
if(Snapshot.initialState.containsKey(transactionViewModel.getAddressHash())) {
addressMode = SpongeFactory.Mode.CURL;
} else {
addressMode = SpongeFactory.Mode.KERL;
}

final Curl address = new Curl();
final Curl address = SpongeFactory.create(addressMode);
int offset = 0;
do {

address.absorb(
ISS.digest(Arrays.copyOfRange(normalizedBundle, offset % (Curl.HASH_LENGTH / Converter.NUMBER_OF_TRITS_IN_A_TRYTE), offset = (offset + ISS.NUMBER_OF_FRAGMENT_CHUNKS - 1) % (Curl.HASH_LENGTH / Converter.NUMBER_OF_TRITS_IN_A_TRYTE) + 1),
ISS.digest(addressMode, Arrays.copyOfRange(normalizedBundle, offset % (Curl.HASH_LENGTH / Converter.NUMBER_OF_TRITS_IN_A_TRYTE), offset = (offset + ISS.NUMBER_OF_FRAGMENT_CHUNKS - 1) % (Curl.HASH_LENGTH / Converter.NUMBER_OF_TRITS_IN_A_TRYTE) + 1),
Arrays.copyOfRange(instanceTransactionViewModels.get(j).trits(), TransactionViewModel.SIGNATURE_MESSAGE_FRAGMENT_TRINARY_OFFSET,
TransactionViewModel.SIGNATURE_MESSAGE_FRAGMENT_TRINARY_OFFSET + TransactionViewModel.SIGNATURE_MESSAGE_FRAGMENT_TRINARY_SIZE)),
0, Curl.HASH_LENGTH);
Expand Down
Loading

0 comments on commit 539e413

Please sign in to comment.