diff --git a/casper/contracts/simple_casper.v.py b/casper/contracts/simple_casper.v.py index 766b752..df386e1 100644 --- a/casper/contracts/simple_casper.v.py +++ b/casper/contracts/simple_casper.v.py @@ -373,6 +373,7 @@ def validate_vote_signature(vote_msg: bytes[1024]) -> bool: return self.validate_signature(msg_hash, sig, validator_index) + @public # cannot be labeled @constant because of external call # even though the call is to a pure contract call @@ -405,6 +406,8 @@ def slashable(vote_msg_1: bytes[1024], vote_msg_2: bytes[1024]) -> bool: return False if validator_index_1 != validator_index_2: return False + if self.validators[validator_index_1].start_dynasty > self.dynasty: + return False if msg_hash_1 == msg_hash_2: return False if self.validators[validator_index_1].is_slashed: diff --git a/tests/test_slashing.py b/tests/test_slashing.py index 3b79dd4..e88fc20 100644 --- a/tests/test_slashing.py +++ b/tests/test_slashing.py @@ -4,16 +4,15 @@ from utils.utils import encode_int32 -def test_invalid_signature_fails( - casper, - concise_casper, - funded_account, - validation_key, - deposit_amount, - induct_validator, - mk_vote, - fake_hash, - assert_tx_failed): +def test_invalid_signature_fails(casper, + concise_casper, + funded_account, + validation_key, + deposit_amount, + induct_validator, + mk_vote, + fake_hash, + assert_tx_failed): validator_index = induct_validator(funded_account, validation_key, deposit_amount) # construct double votes but one has an invalid signature @@ -44,16 +43,15 @@ def test_invalid_signature_fails( ) -def test_different_validators_fails( - casper, - concise_casper, - funded_accounts, - validation_keys, - deposit_amount, - induct_validators, - mk_vote, - fake_hash, - assert_tx_failed): +def test_different_validators_fails(casper, + concise_casper, + funded_accounts, + validation_keys, + deposit_amount, + induct_validators, + mk_vote, + fake_hash, + assert_tx_failed): validator_indexes = induct_validators( funded_accounts, validation_keys, @@ -135,6 +133,28 @@ def test_double_slash_fails(casper, ) +def test_slash_before_start_dynasty_fails(casper, + concise_casper, + funded_account, + validation_key, + deposit_amount, + deposit_validator, + mk_slash_votes, + new_epoch, + assert_tx_failed): + new_epoch() + validator_index = deposit_validator(funded_account, validation_key, deposit_amount) + + vote_1, vote_2 = mk_slash_votes(validator_index, validation_key) + + assert concise_casper.validators__start_dynasty(validator_index) > concise_casper.dynasty() + + assert not concise_casper.slashable(vote_1, vote_2) + assert_tx_failed( + lambda: casper.functions.slash(vote_1, vote_2).transact() + ) + + def test_slash_no_dbl_prepare(casper, concise_casper, funded_account,