From f6ed68e13e36bc215506e497165180d5894f5c27 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 10 Sep 2018 20:15:20 +0800 Subject: [PATCH] =?UTF-8?q?I=20found=20a=20problem=20with=20clique:=20if?= =?UTF-8?q?=20there=20is=20only=20one=20last=20signer=20in=20the=20whole?= =?UTF-8?q?=20network,=20it=20can=20vote=20to=20set=20its=20own=20permissi?= =?UTF-8?q?on=20to=20false.=20After=20the=20resolution=20is=20passed,=20le?= =?UTF-8?q?n(signers)=20will=20be=20equal=20to=200,=20which=20will=20cause?= =?UTF-8?q?=20this=20code=20to=20crash=20in=20this=20line.=E2=80=99(number?= =?UTF-8?q?=20%=20uint64(len(signers)))=20=3D=3D=20uint64(offset)=E2=80=99?= =?UTF-8?q?.=20Crash=20information:=20panic:=20runtime=20error:=20integer?= =?UTF-8?q?=20divide=20by=20zero?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- consensus/clique/snapshot.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/consensus/clique/snapshot.go b/consensus/clique/snapshot.go index 2333d69247..1dc7932534 100644 --- a/consensus/clique/snapshot.go +++ b/consensus/clique/snapshot.go @@ -24,6 +24,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/ethdb" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" lru "github.com/hashicorp/golang-lru" ) @@ -308,5 +309,11 @@ func (s *Snapshot) inturn(number uint64, signer common.Address) bool { for offset < len(signers) && signers[offset] != signer { offset++ } + + if len(signers) == 0 { + log.Warn("no signer. len(signers)==0") + return false + } + return (number % uint64(len(signers))) == uint64(offset) }