-
Notifications
You must be signed in to change notification settings - Fork 13
/
peaceRelay.js
178 lines (123 loc) · 16.2 KB
/
peaceRelay.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
var PeaceRelay = artifacts.require("./PeaceRelay.sol");
EthProof = require('../merkle-patricia-proof/lib/ethProof.js')
EthVerify = require('../merkle-patricia-proof/lib/ethVerify.js')
ethProof = new EthProof(new Web3.providers.HttpProvider("https://mainnet.infura.io"))
var tx1
var tx2
var tx3
var tx4
var tx5
ethProof.getTxProof('0xb53f752216120e8cbe18783f41c6d960254ad59fac16229d4eaec5f7591319de', function(error,result){
tx1 = result
console.log(1)
})
ethProof.getTxProof('0xc55e2b90168af6972193c1f86fa4d7d7b31a29c156665d15b9cd48618b5177ef', function(error,result){
tx2 = result
console.log(2)
})
ethProof.getTxProof('0x299a93acf5b100336455ef6ecda39e22329fb750e6264c8ee44f579947349de9', function(error,result){
tx3 = result
console.log(3)
})
ethProof.getTxProof('0x4e4b9cd37d9b5bb38941983a34d1539e4930572bdaf41d1aa54ddc738630b1bb', function(error,result){
tx4 = result
console.log(4)
})
ethProof.getTxProof('0x74bdf5450025b8806d55cfbb9b393dce630232f5bf87832ae6b675db9d286ac3', function(error,result){
tx5 = result
console.log(5)
})
contract('PeaceRelay', function(accounts) {
//So sorry for this work around.
//In the process of moving library to promises, but haven't gotten to it yet :~)
before(() => {
new Promise(resolve => setTimeout(resolve, 1000000)).then()
})
console.log("AHAHAHAHAH")
var peaceRelay
it("Should allow for blocks to be submitted, correctly grabbing tx root", function () {
var blockHash = "0xf82990de9b368d810ce4b858c45717737245aa965771565f8a41df4c75acc171"
var rlpBlockHeader = "0xf90217a005e37f4ea28008554ea6f332e70e556d994c7fe14854563a811e58131dcb36e8a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347941e9939daaad6924ad004c2560e90804164900341a04914025aa9ea9f274b174205adde3243eec74589bef9a0e78a433763b2f8caa3a076de858022a0904dbc0d6ed58f42423abe3b3ced468f81636d52c74d2186efa3a0ba4f6879d2ccd6eec8351435f78d3da607b33d82bac26583ecc79a74a7485299b9010080080000008000000000000000000002000000014400008000100400002001080000800004000100008000040080410008000000400000000000000000008080800008400008000000000008000010000001000000000000080000000000000000000030000000000000104000000000000004000004080000001010000004600000020080000200080000000000000000000000000c0000000000200000010000400000200000000040000000010000000c04800000800000100001000040000004000204000000200000000020000000800004000c20002000000000040001010000080010000004000000000000000000000044400000000002000080400087037b56173c36b2833c5e8683666c488310bfad845957394e96706f6f6c2e657468666"
+ "16e732e6f726720284d4e3729a0673c72b485df4da9e90a0101fa664792b10b3e7086f31737e87e6810a2608a1088f326a04006c213c0"
var txRoot = "0x76de858022a0904dbc0d6ed58f42423abe3b3ced468f81636d52c74d2186efa3"
return PeaceRelay.new().then(instance => {
peaceRelay = instance
return peaceRelay.submitBlock(rlpBlockHeader, blockHash)
}).then(() => {
return peaceRelay.getTxRoot(blockHash)
}).then(parsedTxRoot => {
assert.equal(parsedTxRoot, txRoot, "txRoots should match")
})
})
describe("transaction verification", function () {
beforeEach(function () {
return PeaceRelay.new().then(instance => {
peaceRelay = instance
})
})
it("Should allow for verification with 2 nodes", function () {
var txRoot = "0x76de858022a0904dbc0d6ed58f42423abe3b3ced468f81636d52c74d2186efa3"
var rlpStack = "0xf90106f891a0e689a95524285e09f8ecc6b54109f1b8bacf8f3620a27bbb5f8a423be160e343a0f58ed79964e37302cf24967ee7177f1b8f703eb3adbc6f50fa42e56c12db8caca052d1f0f14af906e982f194b621f4cd8e6b8a78199e9489ff2e45bdfc5ec988258080808080a01e51b4181e4ab8bbb9b0807d875c8d9113443595334f34b773b6b3c2128d1ac28080808080808080f87130b86ef86c80850df847580082520894b56d622ddf60ec532b5f43b4ff9b0e7b1ff92db3883782dace9d9000008025a03c76c52993d9519cbcff2abeed7c1a62f81d83072fd0b6c245e6138e6088d313a0674e59dd82cfe38e1ae326796060df3fb776e890508a80343b1d98f3a70dab41"
var rlpTransaction = "0xb86ef86c80850df847580082520894b56d622ddf60ec532b5f43b4ff9b0e7b1ff92db3883782dace9d9000008025a03c76c52993d9519cbcff2abeed7c1a62f81d83072fd0b6c245e6138e6088d313a0674e59dd82cfe38e1ae326796060df3fb776e890508a80343b1d98f3a70dab41"
var path = [8]
return peaceRelay.checkProof.call(txRoot, rlpStack, path, rlpTransaction).then(res => {
assert.isTrue(res, "Should have verified correct stuff. ")
})
})
it("Should not allow verification with a mistake is stack", function () {
var txRoot = "0x76de858022a0904dbc0d6ed58f42423abe3b3ced468f81636d52c74d2186efa3"
var rlpStack = "0xf90106f891a0e689a95524285e09f8ecc6b5410" + "8" + "f1b8bacf8f3620a27bbb5f8a423be160e343a0f58ed79964e37302cf24967ee7177f1b8f703eb3adbc6f50fa42e56c12db8caca052d1f0f14af906e982f194b621f4cd8e6b8a78199e9489ff2e45bdfc5ec988258080808080a01e51b4181e4ab8bbb9b0807d875c8d9113443595334f34b773b6b3c2128d1ac28080808080808080f87130b86ef86c80850df847580082520894b56d622ddf60ec532b5f43b4ff9b0e7b1ff92db3883782dace9d9000008025a03c76c52993d9519cbcff2abeed7c1a62f81d83072fd0b6c245e6138e6088d313a0674e59dd82cfe38e1ae326796060df3fb776e890508a80343b1d98f3a70dab41"
//used to be a 9
var rlpTransaction = "0xb86ef86c80850df847580082520894b56d622ddf60ec532b5f43b4ff9b0e7b1ff92db3883782dace9d9000008025a03c76c52993d9519cbcff2abeed7c1a62f81d83072fd0b6c245e6138e6088d313a0674e59dd82cfe38e1ae326796060df3fb776e890508a80343b1d98f3a70dab4" + "2" //Actually ends w/ a 2
var path = [8]
return peaceRelay.checkProof.call(txRoot, rlpStack, path, rlpTransaction).then(res => {
assert.isFalse(res, "Should not have verified with fake stack")
})
})
it("Should not allow verification with a fake transaction", function () {
var txRoot = "0x76de858022a0904dbc0d6ed58f42423abe3b3ced468f81636d52c74d2186efa3"
var rlpStack = "0xf90106f891a0e689a95524285e09f8ecc6b54109f1b8bacf8f3620a27bbb5f8a423be160e343a0f58ed79964e37302cf24967ee7177f1b8f703eb3adbc6f50fa42e56c12db8caca052d1f0f14af906e982f194b621f4cd8e6b8a78199e9489ff2e45bdfc5ec988258080808080a01e51b4181e4ab8bbb9b0807d875c8d9113443595334f34b773b6b3c2128d1ac28080808080808080f87130b86ef86c80850df847580082520894b56d622ddf60ec532b5f43b4ff9b0e7b1ff92db3883782dace9d9000008025a03c76c52993d9519cbcff2abeed7c1a62f81d83072fd0b6c245e6138e6088d313a0674e59dd82cfe38e1ae326796060df3fb776e890508a80343b1d98f3a70dab41"
var rlpTransaction = "0xb86ef86c80850df847580082520894b56d622ddf60ec532b5f43b4ff9b0e7b1ff92db3883782dace9d9000008025a03c76c52993d9519cbcff2abeed7c1a62f81d83072fd0b6c245e6138e6088d313a0674e59dd82cfe38e1ae326796060df3fb776e890508a80343b1d98f3a70dab4" + "2" //Actually ends w/ a 2
var path = [8]
return peaceRelay.checkProof.call(txRoot, rlpStack, path, rlpTransaction).then(res => {
assert.isFalse(res, "Should not have verified fake transaction")
})
})
it("Should allow for verification with more nodes", function () {
var txRoot = "0xb31f174d27b99cdae8e746bd138a01ce60d8dd7b224f7c60845914def05ecc58"
var rlpStack = "0xf87af878822080b873f8718301efc58506fc23ac008305161594104994f45d9d697ca104e5704a7b77d7fec3537c890821878651a4d70000801ba051222d91a379452395d0abaff981af4cfcc242f25cfaf947dea8245a477731f9a03a997c910b4701cca5d933fb26064ee5af7fe3236ff0ef2b58aa50b25aff8ca5"
var path = [1]
var rlpTransaction = "0xb873f8718301efc58506fc23ac008305161594104994f45d9d697ca104e5704a7b77d7fec3537c890821878651a4d70000801ba051222d91a379452395d0abaff981af4cfcc242f25cfaf947dea8245a477731f9a03a997c910b4701cca5d933fb26064ee5af7fe3236ff0ef2b58aa50b25aff8ca5"
return peaceRelay.checkProof.call(txRoot, rlpStack, path, rlpTransaction).then(res => {
assert.isTrue(res, "Should have verified correct stuff")
})
})
it("Should allow for verification with more nodes", function () {
var txRoot = "0x18f2a30bb2c4d0818a253d287ed8c1defd65d6d3bcf47cc355b4fcf6b17ecf46"
var rlpStack = "0xf902bcf851a03b336aa1f6c6cd88d2e78561a6e35b062f0d4faa8295b3dd4fd4082aae9be2de80808080808080a0d80e62fbbacd9b1a058d7262f1c5aac18694f4fb5fa3e79ee94305a166872af28080808080808080f901f180a091e4ed9ce5f63c94b54394f2e8fece56fb5440c21da2a799903b51ec04c120e1a010d1557be630665cf06036f489691157d8813cef4977e0939db3b961a942bc26a0680b47dfd75a4578d48cc3d4f1b7765963f41bafb80df5556d3c4d76798515b9a0867e5b6a34a7351d91dc0d197bc8737251b390b332baf52b99d3786c97c5a960a001e54bccc835f610cc38142020aab5a0dfc9022ccb740f19d3b5a24cfcb75ec0a01e6b5a6184e5b86ee2805a426794ec39785ee432f9b4b930e97979d67634e2cca06dcf843b88a8d3d7bf3589b53ff0f5d06151fac071dc8ecf8acb7f3be76ad0e6a0c8fa4fda40dff8a1e835a2a546ce4c3fedc0818f67715b73e9f7e20233d6cddca0a07e2d25e54d11c83efd869d20c090887f5257b57005d03a8ea005443d136dd6a0be3c61e0830713f157a019b126053c57224eb4328255a078306ead2c702efeefa0bae76624a2b82df6febd4e8b8d77f0b5ed56cb150abe7e2a9a62a9af77e4ef79a0d39cf188518803816c447fd4e30359d2cce588a28f7c8f5954f09c1e6cbff6eba06e94fc7fca3bff828b7084113ab468c9c232e5301dd20910efdb4e799786bc74a0001fefa4fdaa1cbaf4ebf977142c4135d75bc351593977fe65461e1a3f49d6b6a0e015753585040da47bc60e995a240f1ba05c4f800f847d0e4cb65ab9f87fe30f80f87320b870f86e8324102184ee6b280082c3509446ecb5055c82b399e0ccc2cb53e36db2b366727e8802cdf679294e1c608026a009604361a8c7575d40d4285cb74d342d2c7717942222f991adb82272039d21caa06254f7e45bfda5fd1cb3559dc56fb2c5e3d21de04c3012fea73eb4d4a714d159"
var path = [0, 15, 1]
var rlpTransaction = "0xb870f86e8324102184ee6b280082c3509446ecb5055c82b399e0ccc2cb53e36db2b366727e8802cdf679294e1c608026a009604361a8c7575d40d4285cb74d342d2c7717942222f991adb82272039d21caa06254f7e45bfda5fd1cb3559dc56fb2c5e3d21de04c3012fea73eb4d4a714d159"
return peaceRelay.checkProof.call(txRoot, rlpStack, path, rlpTransaction).then(res => {
assert.isTrue(res, "Should have verified correct stuff")
})
})
it("Should allow for verification with more nodes", function () {
var txRoot = "0xa4e60606f59a911abb9dfd8817e4269d8b7fdef3e729f3645b1f468c280ac68f"
var rlpStack = "0xf90603f90131a0f191d8985c7b637b955de4c8b81d7f7f15c97a92443c65966b2223bb239c6235a080687c8d07cf5b24b6810eb267b9d1c1aaeb4d66877437fbb5f9be3c92428140a060f73715291af5c3f9efa4bc35299e6b8fa0fda68278541ceda18c5566323091a0ddc7fb1c94ac13e70c64c814dcc11be5fc98658fc46c4d7dbe882f6f2ff87a86a0ccb3338686725f9ddb37c02071d5b4567766cc96df50708131f004b92bf54596a0b856c07461ce990380e4984f7a73e53be2470b8398c29d00516440d8114b90bfa097830f293f305c5eff72912d49f22f51962ea1d1b32d2252d0375e687961c912a07bd1976fe5d0211f0aebc3327f83c98a32f48010ab2707b8014c11723cc97469a03d0fd629cafad74c14c2c4772765b8d971e3392042d6d53998b7ea055e11f5958080808080808080f851a07024b4ed71cba8f63364888aa55d71e80a2d8500163275bc837cd7aa106e3930a05b4f5582651be3650721a438db5e53edd312c03dc8235186826367693994da85808080808080808080808080808080f8918080808080808080a0429483cf58e656f0911db74e7ce4858e46ebcdc847b0a4efa828611fc7ba198fa0cfa5e3201c1285d9dab793b2ad32c055c2ef8c396268eca6e3b237fa6a5c2541a07811542c83094051270c11846561b4da125badf0566c1cf62abbb52ee555bd7aa0802be6b46847237e2744333e1eede13b233f9805d1b168c875ef50b7c3ac95158080808080f90211a04ebc620f54969dd31bd30dbfdf6d8c85092135e91c86f82a9fe61bfa0a2e5650a0242566ef36639704fb47dcb44421bebefa5d1502f1dbd2c2086d4b6fe37fad65a044c56b84849a54fd27435e8bdeb672b020edbe5185ab6bce8fafcb26fd3031c3a0501ac7ad5872f36318a2d6fbbd17a5d332e065046b4296e452b195affd8e7012a0ef31b75830d830a43e16f87b7f15a8253ddc7410f1a6440c924417c557b8651ea0213edf40e16248dccbb90f6dfa5396bc5e4b44422ead0051f2277df4e8173808a0e2987df734c342104346d069713bc64fe33cdb2d586e3e6618a0aee982bcb87fa0e0fc5f0dc97913343db6f5e5c444e9008c61bb7030fef3379bdf7f3b23c7daf7a027e033df2dcd45a952722f71fa7173acd52e00212ef3f0bb42d79067e773a72fa03c2e9183bb2f2d14d72be18d916eb0955c7bb9f43d97e0e0a1205ab05e3b3a70a0ecb55922479d600a50cf027da649ba354f4e30a6ef8664705373ffb33b434b77a029ef54c181f550841aaab25968a12a5fa0a875dc7e2028c495e9ee7505a52c78a0e6379784c567240110a21acc2140a0cc616e6ae2cf79f9e3b65deda7a848cf2fa0c24c9a30896d5ac62c50cb1598013c8c11b1b0525f762349030e5962b70dfb8aa0b7bb6417b156ac0daf8b56176c28b30dd0c5e5cb90cece6ae61be2403c857602a0e437523c5f5e8a0fcc1454872da8ccfced0948a1195cc3c897f80d493f4d145280f901d220b901cef901cb818984ee6b28008303d090948d12a197cb00d4747a1fe03395095ce2a5cc681980b901640a19b14a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000053eecff4d190000000000000000000000000000d4fa1460f537bb9085d22c7bccb5dd450ef28e3a000000000000000000000000000000000000000000000000000000006b49d20000000000000000000000000000000000000000000000000000000000003d60600000000000000000000000000000000000000000000000000000000054829e730000000000000000000000005403921d72cbcda017a915863a57189d65ad52d1000000000000000000000000000000000000000000000000000000000000001b92d46219a426a277ed6c1abc01f49fe80d4460fe9473f058d821d207a3133b8753887e0d6897fd91448090f363a57f42ce2b3ac4bcb23f4f233c2733453144eb000000000000000000000000000000000000000000000000053eecff4d19000026a051f70c90daf5c7224cd777762274b1703778e02bdfb15a353b85f91de35c2652a01881ee92b94851db15dc374880f5155daa6889f6f9589f3319b8954bed33be83"
var path = [8, 1, 10, 10, 1]
var rlpTransaction = "0xb901cef901cb818984ee6b28008303d090948d12a197cb00d4747a1fe03395095ce2a5cc681980b901640a19b14a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000053eecff4d190000000000000000000000000000d4fa1460f537bb9085d22c7bccb5dd450ef28e3a000000000000000000000000000000000000000000000000000000006b49d20000000000000000000000000000000000000000000000000000000000003d60600000000000000000000000000000000000000000000000000000000054829e730000000000000000000000005403921d72cbcda017a915863a57189d65ad52d1000000000000000000000000000000000000000000000000000000000000001b92d46219a426a277ed6c1abc01f49fe80d4460fe9473f058d821d207a3133b8753887e0d6897fd91448090f363a57f42ce2b3ac4bcb23f4f233c2733453144eb000000000000000000000000000000000000000000000000053eecff4d19000026a051f70c90daf5c7224cd777762274b1703778e02bdfb15a353b85f91de35c2652a01881ee92b94851db15dc374880f5155daa6889f6f9589f3319b8954bed33be83"
return peaceRelay.checkProof.call(txRoot, rlpStack, path, rlpTransaction).then(res => {
assert.isTrue(res, "Should have verified correct stuff")
})
})
it("Should allow for verification with more nodes", function () {
var txRoot = "0xcbd33f19aa3c22fac0c085ed80c05aa52d1429240c20f2751a23ef8922664177"
var rlpStack = "0xf90320f90131a006dcde6bd003558b0e79e45bf5134f15187f6b3c1225e0d966e0f9920bd487aaa06c4b94e98b84dce9c1a74376a1540f37137be8b9a0f726a68a7739714b0a16b7a0a9a02fb73b6800b76df8dbd95eabf00bffaa5089272131c82460793b1a89fa6ca03670af2bce604504a2601c8650407302da388209ac03644f1a67cd05cdf4746ca0b4df7b48c2b5f2a4a7cc739124ced180d14d0115d3ed0ec77354eac3380a9770a0fe97d99da71de75568d97cfd58ad6a1528b8d5a1784e4b540f8ac3be7e86dfe4a07cd7fb78132f9e726e6b1e9c1e44a2ff9e0fb7b492d753a828e17efe2e96957ca02dddb2b58cdfeddad50654cfabad7bd77f638511fd76d73b5f6543a4eeef4531a05649803e27e22c01da15ecc41dd8c9ff30ef387f48f382cc9150471f979a704f8080808080808080f851a06fda95297d17e6cdd616e24a2e3c387f495a23b5d9d6ff82b591d1ddb317b39da0c149adc727f92c51a31d619f7a35d0b914292d68b0b2cbfed0981611d283b181808080808080808080808080808080f8b18080808080808080a0344cf71fcc29811b49f50c5b8191923a2b042660643034f390c7c07c2cd76990a0ffb7183f617efca44feb00284c1bf6daba433baefb8e16c8966cd24443b60917a016025224d2f782da624208506470f2688452c1c8cd510b7d95fddae8b2ebf573a0bd62e4f86cb17e4091d4dc78bc9c03a1c93ef17d1583ae15677681aeac15188da09d07f4272f5c963c5a4d97053a6fb3acbf542a44ee2b4360fdf11e58d9ca696580808080f871a08e4a3f2c87a9872867e8dd69b14d7f841e6a149d155bb78d2e4f8fd54e1c0179a0974ecca960d0b0d510b8b0873cff17190d2d7a38d2dd85968f3d147b4041d775a030f32691431fd4c8d98445627926e4bd09a90c5b83ba946e465106c9303c93e98080808080808080808080808080f87120b86ef86c0a8504a817c8008262709431e59a754f29fd9af7c44d63cda72fe0b849e4398806fb03d5c20580008025a039ceb86758daa5162c6cdd932b498e4605c960db71e66fa29631216f3aec605ea0124cc41f49c53b3dee0534cc322acfc51ba5a83bf1e86ac567c9b500df9dcb6f"
var path = [8, 1, 12, 0, 1]
var rlpTransaction = "0xb86ef86c0a8504a817c8008262709431e59a754f29fd9af7c44d63cda72fe0b849e4398806fb03d5c20580008025a039ceb86758daa5162c6cdd932b498e4605c960db71e66fa29631216f3aec605ea0124cc41f49c53b3dee0534cc322acfc51ba5a83bf1e86ac567c9b500df9dcb6f"
return peaceRelay.checkProof.call(txRoot, rlpStack, path, rlpTransaction).then(res => {
assert.isTrue(res, "Should have verified correct stuff")
})
})
})
})