Skip to content

Commit b39042d

Browse files
committed
core, miner: implemented canary
1 parent d1e93db commit b39042d

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

core/canary.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package core
2+
3+
import (
4+
"math/big"
5+
6+
"github.com/ethereum/go-ethereum/common"
7+
"github.com/ethereum/go-ethereum/core/state"
8+
)
9+
10+
var (
11+
jeff = common.HexToAddress("9d38997c624a71b21278389ea2fdc460d000e4b2")
12+
vitalik = common.HexToAddress("b1e570be07eaa673e4fd0c8265b64ef739385709")
13+
christoph = common.HexToAddress("529bc43a5d93789fa28de1961db6a07e752204ae")
14+
gav = common.HexToAddress("e3e942b2aa524293c84ff6c7f87a6635790ad5e4")
15+
)
16+
17+
// Canary will check the 0'd address of the 4 contracts above.
18+
// If two or more are set to anything other than a 0 the canary
19+
// dies a horrible death.
20+
func Canary(statedb *state.StateDB) bool {
21+
r := new(big.Int)
22+
r.Add(r, statedb.GetState(jeff, common.Hash{}).Big())
23+
r.Add(r, statedb.GetState(vitalik, common.Hash{}).Big())
24+
r.Add(r, statedb.GetState(christoph, common.Hash{}).Big())
25+
r.Add(r, statedb.GetState(gav, common.Hash{}).Big())
26+
27+
return r.Cmp(big.NewInt(1)) > 0
28+
}

miner/worker.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ func (self *worker) wait() {
267267

268268
func (self *worker) push() {
269269
if atomic.LoadInt32(&self.mining) == 1 {
270+
if core.Canary(self.current.state) {
271+
glog.Infoln("Toxicity levels rising to deadly levels. Your canary has died. You can go back or continue down the mineshaft --more--")
272+
glog.Infoln("You turn back and abort mining")
273+
return
274+
}
275+
270276
self.current.state.Sync()
271277
self.current.block.SetRoot(self.current.state.Root())
272278

0 commit comments

Comments
 (0)