mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-14 11:15:51 +00:00
Fix arrayMatch.
It would incorrectly return true if just part of the subArray was at the end of the script.
This commit is contained in:
parent
c36d605404
commit
5ad1659660
@ -423,12 +423,13 @@ public class AuxPoW extends ChildMessage {
|
|||||||
* @return true if the shorter array is present at the offset, false otherwise.
|
* @return true if the shorter array is present at the offset, false otherwise.
|
||||||
*/
|
*/
|
||||||
static boolean arrayMatch(byte[] script, int offset, byte[] subArray) {
|
static boolean arrayMatch(byte[] script, int offset, byte[] subArray) {
|
||||||
for (int matchIdx = 0; matchIdx + offset < script.length && matchIdx < subArray.length; matchIdx++) {
|
int matchIdx;
|
||||||
|
for (matchIdx = 0; matchIdx + offset < script.length && matchIdx < subArray.length; matchIdx++) {
|
||||||
if (script[offset + matchIdx] != subArray[matchIdx]) {
|
if (script[offset + matchIdx] != subArray[matchIdx]) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return matchIdx == subArray.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -12,11 +12,8 @@ import org.libdohj.params.DogecoinMainNetParams;
|
|||||||
|
|
||||||
import static org.bitcoinj.core.Util.getBytes;
|
import static org.bitcoinj.core.Util.getBytes;
|
||||||
import static org.bitcoinj.core.Utils.reverseBytes;
|
import static org.bitcoinj.core.Utils.reverseBytes;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import static org.junit.Assert.assertArrayEquals;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -392,4 +389,21 @@ public class AuxPoWTest {
|
|||||||
final int result = AuxPoW.getExpectedIndex(nonce, chainId, merkleHeight);
|
final int result = AuxPoW.getExpectedIndex(nonce, chainId, merkleHeight);
|
||||||
assertEquals(expResult, result);
|
assertEquals(expResult, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the array matching algorithm for not accepting part of the array when it is in the end of the script.
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testArrayMatch() {
|
||||||
|
byte[] script = Utils.HEX.decode("089b911f5e471c0e1800f3384281ebec5b372fbb6f358790a92747ade271ccdf");
|
||||||
|
byte[] prefix = Utils.HEX.decode("089b911f");
|
||||||
|
byte[] suffix = Utils.HEX.decode("e271ccdf");
|
||||||
|
byte[] anywhere = Utils.HEX.decode("384281eb");
|
||||||
|
byte[] overTheEnd = Utils.HEX.decode("e271ccdf000000");
|
||||||
|
|
||||||
|
assertTrue(AuxPoW.arrayMatch(script, 0, prefix));
|
||||||
|
assertTrue(AuxPoW.arrayMatch(script, 28, suffix));
|
||||||
|
assertTrue(AuxPoW.arrayMatch(script, 11, anywhere));
|
||||||
|
assertFalse(AuxPoW.arrayMatch(script, 28, overTheEnd));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user