Skip to content

Commit 5f2f196

Browse files
author
wanderer
committed
should throw on invalid stateRoots
1 parent cb3acc5 commit 5f2f196

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,10 @@ module.exports = class Hypervisor {
149149
async setStateRoot (stateRoot) {
150150
this.tree.root = stateRoot
151151
const node = await this.tree.get(Buffer.from([0]))
152-
this.nonce = node.value || 0
152+
if (!node.value) {
153+
throw new Error('invalid state root')
154+
}
155+
this.nonce = node.value
153156
}
154157

155158
/**

tests/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ tape('three communicating actors, with tick counting', async t => {
266266
})
267267

268268
tape('errors', async t => {
269-
t.plan(3)
269+
t.plan(4)
270270
const expectedState = Buffer.from('25bc7e81511bfded44a1846f4bca1acc99f24273', 'hex')
271271
const tree = new RadixTree({
272272
db
@@ -306,6 +306,12 @@ tape('errors', async t => {
306306
hypervisor.send(message)
307307
const stateRoot = await hypervisor.createStateRoot()
308308
t.deepEquals(stateRoot, expectedState, 'expected root!')
309+
310+
try {
311+
await hypervisor.setStateRoot(Buffer.from([0]))
312+
} catch (e) {
313+
t.pass('should catch invalid state roots')
314+
}
309315
})
310316

311317
tape('out-of-gas', async t => {

0 commit comments

Comments
 (0)