fix: add check for block number (#2199)
* fix: add check for block number * fix review comments * fix review comments
This commit is contained in:
parent
d7e7f73718
commit
e7cd04b38e
@ -1398,16 +1398,20 @@ func (c *verifyDoubleSignEvidence) RequiredGas(input []byte) uint64 {
|
||||
return params.DoubleSignEvidenceVerifyGas
|
||||
}
|
||||
|
||||
var (
|
||||
extraSeal = 65
|
||||
)
|
||||
|
||||
type DoubleSignEvidence struct {
|
||||
ChainId *big.Int
|
||||
HeaderBytes1 []byte
|
||||
HeaderBytes2 []byte
|
||||
}
|
||||
|
||||
const (
|
||||
extraSeal = 65
|
||||
)
|
||||
|
||||
var (
|
||||
errInvalidEvidence = errors.New("invalid double sign evidence")
|
||||
)
|
||||
|
||||
// Run input: rlp encoded DoubleSignEvidence
|
||||
// return:
|
||||
// signer address| evidence height|
|
||||
@ -1432,27 +1436,30 @@ func (c *verifyDoubleSignEvidence) Run(input []byte) ([]byte, error) {
|
||||
}
|
||||
|
||||
// basic check
|
||||
if len(header1.Number.Bytes()) > 32 || len(header2.Number.Bytes()) > 32 { // block number should be less than 2^256
|
||||
return nil, errInvalidEvidence
|
||||
}
|
||||
if header1.Number.Cmp(header2.Number) != 0 {
|
||||
return nil, ErrExecutionReverted
|
||||
return nil, errInvalidEvidence
|
||||
}
|
||||
if header1.ParentHash != header2.ParentHash {
|
||||
return nil, ErrExecutionReverted
|
||||
return nil, errInvalidEvidence
|
||||
}
|
||||
|
||||
if len(header1.Extra) < extraSeal || len(header2.Extra) < extraSeal {
|
||||
return nil, ErrExecutionReverted
|
||||
return nil, errInvalidEvidence
|
||||
}
|
||||
sig1 := header1.Extra[len(header1.Extra)-extraSeal:]
|
||||
sig2 := header2.Extra[len(header2.Extra)-extraSeal:]
|
||||
if bytes.Equal(sig1, sig2) {
|
||||
return nil, ErrExecutionReverted
|
||||
return nil, errInvalidEvidence
|
||||
}
|
||||
|
||||
// check sig
|
||||
msgHash1 := types.SealHash(header1, evidence.ChainId)
|
||||
msgHash2 := types.SealHash(header2, evidence.ChainId)
|
||||
if bytes.Equal(msgHash1.Bytes(), msgHash2.Bytes()) {
|
||||
return nil, ErrExecutionReverted
|
||||
return nil, errInvalidEvidence
|
||||
}
|
||||
pubkey1, err := secp256k1.RecoverPubkey(msgHash1.Bytes(), sig1)
|
||||
if err != nil {
|
||||
@ -1463,7 +1470,7 @@ func (c *verifyDoubleSignEvidence) Run(input []byte) ([]byte, error) {
|
||||
return nil, ErrExecutionReverted
|
||||
}
|
||||
if !bytes.Equal(pubkey1, pubkey2) {
|
||||
return nil, ErrExecutionReverted
|
||||
return nil, errInvalidEvidence
|
||||
}
|
||||
|
||||
returnBz := make([]byte, 52) // 20 + 32
|
||||
|
@ -417,3 +417,13 @@ func TestDoubleSignSlash(t *testing.T) {
|
||||
|
||||
testPrecompiled("68", tc, t)
|
||||
}
|
||||
|
||||
func TestDoubleSignSlashFailure(t *testing.T) {
|
||||
tc := precompiledFailureTest{
|
||||
Input: "f9066b38b90332f9032fa01062d3d5015b9242bc193a9b0769f3d3780ecb55f97f40a752ae26d0b68cd0d8a0fae1a05fcb14bfd9b8a9f2b65007a9b6c2000de0627a73be644dd993d32342c494df87f0e2b8519ea2dd4abd8b639cdd628497ed25a0f385cc58ed297ff0d66eb5580b02853d3478ba418b1819ac659ee05df49b9794a0bf88464af369ed6b8cf02db00f0b9556ffa8d49cd491b00952a7f83431446638a00a6d0870e586a76278fbfdcedf76ef6679af18fc1f9137cfad495f434974ea81b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001a1010000000000000000000000000000000000000000000000000000000000000000830f4240830f42408465bc6996b90115d983010306846765746889676f312e32302e3131856c696e7578000053474aa9f8b25fb860b0844a5082bfaa2299d2a23f076e2f6b17b15f839cc3e7d5a875656f6733fd4b87ba3401f906d15f3dea263cd9a6076107c7db620a4630dd3832c4a4b57eb8f497e28a3d69e5c03b30205c4b45675747d513e1accd66329770f3c35b18c9d023f84c84023a5ad6a086a28d985d9a6c8e7f9a4feadd5ace0adba9818e1e1727edca755fcc0bd8344684023a5ad7a0bc3492196b2e68b8e6ceea87cfa7588b4d590089eb885c4f2c1e9d9fb450f7b980988e1b9d0beb91dab063e04879a24c43d33baae3759dee41fd62ffa83c77fd202bea27a829b49e8025bdd198393526dd12b223ab16052fd26a43f3aabf63e76901a0232c9ba2d41b40d36ed794c306747bcbc49bf61a0f37409c18bfe2b5bef26a2d880000000000000000b90332f9032fa01062d3d5015b9242bc193a9b0769f3d3780ecb55f97f40a752ae26d0b68cd0d8a0b2789a5357827ed838335283e15c4dcc42b9bebcbf2919a18613246787e2f96094df87f0e2b8519ea2dd4abd8b639cdd628497ed25a071ce4c09ee275206013f0063761bc19c93c13990582f918cc57333634c94ce89a00e095703e5c9b149f253fe89697230029e32484a410b4b1f2c61442d73c3095aa0d317ae19ede7c8a2d3ac9ef98735b049bcb7278d12f48c42b924538b60a25e12b901000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001a1010000000000000000000000000000000000000000000000000000000000000000830f4240830f42408465bc6996b90115d983010306846765746889676f312e32302e3131856c696e7578000053474aa9f8b25fb860b0844a5082bfaa2299d2a23f076e2f6b17b15f839cc3e7d5a875656f6733fd4b87ba3401f906d15f3dea263cd9a6076107c7db620a4630dd3832c4a4b57eb8f497e28a3d69e5c03b30205c4b45675747d513e1accd66329770f3c35b18c9d023f84c84023a5ad6a086a28d985d9a6c8e7f9a4feadd5ace0adba9818e1e1727edca755fcc0bd8344684023a5ad7a0bc3492196b2e68b8e6ceea87cfa7588b4d590089eb885c4f2c1e9d9fb450f7b9804c71ed015dd0c5c2d7393b68c2927f83f0a5da4c66f761f09e2f950cc610832c7876144599368404096ddef0eadacfde57717e2c7d23982b927285b797d41bfa00a0b56228685be711834d0f154292d07826dea42a0fad3e4f56c31470b7fbfbea26880000000000000000",
|
||||
ExpectedError: errInvalidEvidence.Error(),
|
||||
Name: "",
|
||||
}
|
||||
|
||||
testPrecompiledFailure("68", tc, t)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user