Secondly, the idea of skipping the first Fork with checkpoints have some problems/issues:
1. bypassing the proof of work on that many blocks will leave the app vulnerable to getting on the wrong fork for any user that installed his app before the fork. There may be a way of getting around this by adding some hard coded checkpoints into vertcoinj (something I put in CoinDefinition.java). Even the checkpoints could end up on the wrong fork, since you are not validating any of the blocks. Additionally
2. For the people after the forks, they won't notice anything, assuming the checkpoints come out correctly.
3. Using native libraries may be a way around not having the java code, even for BuildCheckpoints.java - native libraries also speed up the execution of hashes and can decrease battery usage on the device. this something you should look into to make your app secure. This is how I would have done it if I were to do this project.
Thanks for your answer.
1. I'm sure the only user of this app right now is me only, because it's not working since Dec 2014 (fork from N-scrypt to unsupported Lyra2RE)...
2. Yes, that is exactly what I would like to do: to make some solid checkpoints after last fork, after block no. 347000
3. that is beyond my range now, I suppose. I just tried to be similar to your solution of darkcoinj:
https://github.com/HashEngineering/darkcoinj/blob/master/core/src/main/java/com/hashengineering/crypto/X11.javahttps://github.com/HashEngineering/darkcoinj/tree/master/core/src/main/java/fr/cryptohashSo now I'm stuck at block no 347952:
http://explorer.thisisvtc.com/block/c06c7a1a1c0424c18a197305c3cfea6c171ff80e60083fb2774d5eee0d86a96cI have switched on verification again, so my current Block.java:
BigInteger h = getScryptHash().toBigInteger();
if (h.compareTo(target) > 0) { //BLA
//if ( false ) {
// Proof of work check failed!
if (throwException)
throw new VerificationException("Hash is higher than target: " + getScryptHashAsString() + " vs "
+ target.toString(16));
else
return false;
}
return true;
and my Utils.java correction, in order to: lyra2re2_hash from:
https://github.com/vertcoin/vertcoin/blob/master/src/Lyra2RE/Lyra2RE.c public static byte[] scryptDigest(byte[] input) {
byte[] digestA;
byte[] digestB;
try {
//return SCrypt.scrypt(input, input, 2048, 1, 1, 32);
BLAKE256 blake256 = new BLAKE256();
digestA = blake256.digest(input);
Keccak256 keccak = new Keccak256();
digestB = keccak.digest(digestA);
CubeHash256 cubehash = new CubeHash256();
digestA = cubehash.digest(digestB);
Lyra2.LYRA2(digestB, digestA, digestA, 1, 4, 4);
Skein256 skein = new Skein256();
digestA = skein.digest(digestB);
CubeHash256 cubehash2 = new CubeHash256();
digestB = cubehash2.digest(digestA);
BMW256 bmw = new BMW256();
digestA = bmw.digest(digestB);
return digestA;
} catch (Exception e) {
return null;
}
}
Unfortunatelly, I'm getting "Hash is higher than target"...
I have some debug yet.
- first is manual test of Lyra2 function, with already known input digest (the result is fortunately the same like a DigestB after Lyra below)
- then there are: input array and all internal digest arrays
root@vps179585:~/jLyra2/src# cat Main.java | grep "_bytes\["
//password_bytes[0] = 0xFA;
password_bytes[0] = -6;
password_bytes[1] = 51;
password_bytes[2] = -23;
password_bytes[3] = 86;
password_bytes[4] = -50;
password_bytes[5] = -13;
password_bytes[6] = -92;
password_bytes[7] = 117;
password_bytes[8] = 121;
password_bytes[9] = 83;
password_bytes[10] = -73;
password_bytes[11] = -99;
password_bytes[12] = -70;
password_bytes[13] = -87;
password_bytes[14] = -12;
password_bytes[15] = -8;
password_bytes[16] = -118;
password_bytes[17] = -105;
password_bytes[18] = -33;
password_bytes[19] = -18;
password_bytes[20] = 11;
password_bytes[21] = 123;
password_bytes[22] = 100;
password_bytes[23] = -106;
password_bytes[24] = 2;
password_bytes[25] = -63;
password_bytes[26] = -77;
password_bytes[27] = 74;
password_bytes[28] = 122;
password_bytes[29] = 109;
password_bytes[30] = 104;
password_bytes[31] = 96;
salt_bytes[0] = -6;
salt_bytes[1] = 51;
salt_bytes[2] = -23;
salt_bytes[3] = 86;
salt_bytes[4] = -50;
salt_bytes[5] = -13;
salt_bytes[6] = -92;
salt_bytes[7] = 117;
salt_bytes[8] = 121;
salt_bytes[9] = 83;
salt_bytes[10] = -73;
salt_bytes[11] = -99;
salt_bytes[12] = -70;
salt_bytes[13] = -87;
salt_bytes[14] = -12;
salt_bytes[15] = -8;
salt_bytes[16] = -118;
salt_bytes[17] = -105;
salt_bytes[18] = -33;
salt_bytes[19] = -18;
salt_bytes[20] = 11;
salt_bytes[21] = 123;
salt_bytes[22] = 100;
salt_bytes[23] = -106;
salt_bytes[24] = 2;
salt_bytes[25] = -63;
salt_bytes[26] = -77;
salt_bytes[27] = 74;
salt_bytes[28] = 122;
salt_bytes[29] = 109;
salt_bytes[30] = 104;
salt_bytes[31] = 96;
root@vps179585:~/jLyra2/src#
root@vps179585:~/jLyra2/src# java -Djava.library.path=/root/jLyra2/src/ Main
[OK] Test initState
[OK] Test squeeze
[OK] Test reducedBlake2bLyra
[OK] Test reducedSqueezeRow0
[OK] Test absorbBlock
[OK] Test absorbBlockBlake2Safe
[OK] Test reducedDuplexRowSetup
[OK] Test reducedDuplexRow
[OK] Test reducedDuplexRow1
[OK] Test padding
[OK] -- Main LYRA2 Test --
Java: [-7, -26, 1, -68, 2, 29, 8, -45, 28, 80, 85, -82, -69, 49, 9, -108, 74, -39, 82, -123, -24, -40, 34, 33, 104, -92, 28, -122, -56, -26, -47, 46]
C:[-7, -26, 1, -68, 2, 29, 8, -45, 28, 80, 85, -82, -69, 49, 9, -108, 74, -39, 82, -123, -24, -40, 34, 33, 104, -92, 28, -122, -56, -26, -47, 46]
root@vps179585:~/jLyra2/src#
input:
0 = 4 (0x4)
1 = 0 (0x0)
2 = 0 (0x0)
3 = 0 (0x0)
4 = -50 (0xCE)
5 = 76 (0x4C)
6 = 18 (0x12)
7 = -38 (0xDA)
8 = -123 (0x85)
9 = -117 (0x8B)
10 = -5 (0xFB)
11 = -85 (0xAB)
12 = -78 (0xB2)
13 = -25 (0xE7)
14 = -109 (0x93)
15 = -113 (0x8F)
16 = -102 (0x9A)
17 = 88 (0x58)
18 = -1 (0xFF)
19 = 51 (0x33)
20 = 92 (0x5C)
21 = 102 (0x66)
22 = -39 (0xD9)
23 = 90 (0x5A)
24 = -103 (0x99)
25 = 26 (0x1A)
26 = -123 (0x85)
27 = -20 (0xEC)
28 = -124 (0x84)
29 = 43 (0x2B)
30 = 113 (0x71)
31 = -44 (0xD4)
32 = -118 (0x8A)
33 = -95 (0xA1)
34 = -13 (0xF3)
35 = 113 (0x71)
36 = -101 (0x9B)
37 = 35 (0x23)
38 = 9 (0x9)
39 = -94 (0xA2)
40 = -69 (0xBB)
41 = -106 (0x96)
42 = 80 (0x50)
43 = -128 (0x80)
44 = -24 (0xE8)
45 = 8 (0x8)
46 = 26 (0x1A)
47 = -62 (0xC2)
48 = -31 (0xE1)
49 = 58 (0x3A)
50 = 65 (0x41)
51 = -110 (0x92)
52 = 79 (0x4F)
53 = -82 (0xAE)
54 = 42 (0x2A)
55 = -111 (0x91)
56 = 27 (0x1B)
57 = -99 (0x9D)
58 = -70 (0xBA)
59 = 118 (0x76)
60 = 80 (0x50)
61 = 20 (0x14)
62 = -38 (0xDA)
63 = 103 (0x67)
64 = -13 (0xF3)
65 = -17 (0xEF)
66 = -110 (0x92)
67 = 57 (0x39)
68 = -126 (0x82)
69 = 100 (0x64)
70 = -54 (0xCA)
71 = 85 (0x55)
72 = -33 (0xDF)
73 = 92 (0x5C)
74 = 1 (0x1)
75 = 28 (0x1C)
76 = 9 (0x9)
77 = -1 (0xFF)
78 = -5 (0xFB)
79 = -19 (0xED)
digestA:
0 = 49 (0x31)
1 = -13 (0xF3)
2 = 96 (0x60)
3 = 95 (0x5F)
4 = -120 (0x88)
5 = 20 (0x14)
6 = 12 (0xC)
7 = -9 (0xF7)
8 = 91 (0x5B)
9 = -103 (0x99)
10 = -65 (0xBF)
11 = 83 (0x53)
12 = -93 (0xA3)
13 = -54 (0xCA)
14 = 112 (0x70)
15 = 118 (0x76)
16 = 98 (0x62)
17 = -30 (0xE2)
18 = 22 (0x16)
19 = -41 (0xD7)
20 = -96 (0xA0)
21 = -41 (0xD7)
22 = -122 (0x86)
23 = 85 (0x55)
24 = 83 (0x53)
25 = -89 (0xA7)
26 = -123 (0x85)
27 = -24 (0xE8)
28 = -43 (0xD5)
29 = -48 (0xD0)
30 = 86 (0x56)
31 = -87 (0xA9)
digestB:
0 = -116 (0x8C)
1 = -43 (0xD5)
2 = 32 (0x20)
3 = 89 (0x59)
4 = 118 (0x76)
5 = 100 (0x64)
6 = 34 (0x22)
7 = 61 (0x3D)
8 = 63 (0x3F)
9 = -88 (0xA8)
10 = -74 (0xB6)
11 = -32 (0xE0)
12 = -29 (0xE3)
13 = -107 (0x95)
14 = -58 (0xC6)
15 = -119 (0x89)
16 = 7 (0x7)
17 = 116 (0x74)
18 = -1 (0xFF)
19 = -74 (0xB6)
20 = -20 (0xEC)
21 = -67 (0xBD)
22 = 63 (0x3F)
23 = -79 (0xB1)
24 = 84 (0x54)
25 = -43 (0xD5)
26 = 103 (0x67)
27 = -88 (0xA8)
28 = -43 (0xD5)
29 = -115 (0x8D)
30 = -63 (0xC1)
31 = -98 (0x9E)
digestA:
0 = -6 (0xFA)
1 = 51 (0x33)
2 = -23 (0xE9)
3 = 86 (0x56)
4 = -50 (0xCE)
5 = -13 (0xF3)
6 = -92 (0xA4)
7 = 117 (0x75)
8 = 121 (0x79)
9 = 83 (0x53)
10 = -73 (0xB7)
11 = -99 (0x9D)
12 = -70 (0xBA)
13 = -87 (0xA9)
14 = -12 (0xF4)
15 = -8 (0xF8)
16 = -118 (0x8A)
17 = -105 (0x97)
18 = -33 (0xDF)
19 = -18 (0xEE)
20 = 11 (0xB)
21 = 123 (0x7B)
22 = 100 (0x64)
23 = -106 (0x96)
24 = 2 (0x2)
25 = -63 (0xC1)
26 = -77 (0xB3)
27 = 74 (0x4A)
28 = 122 (0x7A)
29 = 109 (0x6D)
30 = 104 (0x68)
31 = 96 (0x60)
digestB (after Lyra):
0 = -7 (0xF9)
1 = -26 (0xE6)
2 = 1 (0x1)
3 = -68 (0xBC)
4 = 2 (0x2)
5 = 29 (0x1D)
6 = 8 (0x8)
7 = -45 (0xD3)
8 = 28 (0x1C)
9 = 80 (0x50)
10 = 85 (0x55)
11 = -82 (0xAE)
12 = -69 (0xBB)
13 = 49 (0x31)
14 = 9 (0x9)
15 = -108 (0x94)
16 = 74 (0x4A)
17 = -39 (0xD9)
18 = 82 (0x52)
19 = -123 (0x85)
20 = -24 (0xE8)
21 = -40 (0xD8)
22 = 34 (0x22)
23 = 33 (0x21)
24 = 104 (0x68)
25 = -92 (0xA4)
26 = 28 (0x1C)
27 = -122 (0x86)
28 = -56 (0xC8)
29 = -26 (0xE6)
30 = -47 (0xD1)
31 = 46 (0x2E)
digestA:
0 = 76 (0x4C)
1 = -40 (0xD8)
2 = 86 (0x56)
3 = 73 (0x49)
4 = 41 (0x29)
5 = 58 (0x3A)
6 = 115 (0x73)
7 = -19 (0xED)
8 = 79 (0x4F)
9 = -17 (0xEF)
10 = -69 (0xBB)
11 = -66 (0xBE)
12 = 127 (0x7F)
13 = 30 (0x1E)
14 = -79 (0xB1)
15 = -32 (0xE0)
16 = -110 (0x92)
17 = 32 (0x20)
18 = -44 (0xD4)
19 = -106 (0x96)
20 = -107 (0x95)
21 = 109 (0x6D)
22 = 69 (0x45)
23 = 98 (0x62)
24 = -75 (0xB5)
25 = -120 (0x88)
26 = -39 (0xD9)
27 = 65 (0x41)
28 = 112 (0x70)
29 = -117 (0x8B)
30 = 93 (0x5D)
31 = 106 (0x6A)
digestB:
0 = -42 (0xD6)
1 = -55 (0xC9)
2 = -117 (0x8B)
3 = 22 (0x16)
4 = 41 (0x29)
5 = -79 (0xB1)
6 = 87 (0x57)
7 = -109 (0x93)
8 = 23 (0x17)
9 = -12 (0xF4)
10 = 103 (0x67)
11 = -12 (0xF4)
12 = -16 (0xF0)
13 = -99 (0x9D)
14 = 101 (0x65)
15 = -54 (0xCA)
16 = -72 (0xB8)
17 = 79 (0x4F)
18 = 2 (0x2)
19 = 25 (0x19)
20 = -33 (0xDF)
21 = -51 (0xCD)
22 = 62 (0x3E)
23 = 8 (0x8)
24 = -112 (0x90)
25 = 30 (0x1E)
26 = -89 (0xA7)
27 = -54 (0xCA)
28 = 56 (0x38)
29 = 97 (0x61)
30 = -45 (0xD3)
31 = 73 (0x49)
digestA (final value, after BMW):
0 = 124 (0x7C)
1 = -123 (0x85)
2 = -127 (0x81)
3 = 90 (0x5A)
4 = -31 (0xE1)
5 = -7 (0xF9)
6 = -40 (0xD8)
7 = -26 (0xE6)
8 = -13 (0xF3)
9 = -18 (0xEE)
10 = 119 (0x77)
11 = -127 (0x81)
12 = -84 (0xAC)
13 = 41 (0x29)
14 = 112 (0x70)
15 = -22 (0xEA)
16 = 59 (0x3B)
17 = 56 (0x38)
18 = -112 (0x90)
19 = -33 (0xDF)
20 = 34 (0x22)
21 = -68 (0xBC)
22 = 110 (0x6E)
23 = -47 (0xD1)
24 = -36 (0xDC)
25 = -5 (0xFB)
26 = -126 (0x82)
27 = -93 (0xA3)
28 = -91 (0xA5)
29 = -70 (0xBA)
30 = -21 (0xEB)
31 = -113 (0x8F)
it seems I'm close to make it working, but I'm a bit lost right now..
(is it necessary to reorder final bytes somehow ? )