Skip to content
This repository has been archived by the owner on Jan 6, 2025. It is now read-only.

Prevent slash before start_dynasty #167

Merged
merged 2 commits into from
Jun 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions casper/contracts/simple_casper.v.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
60 changes: 40 additions & 20 deletions tests/test_slashing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down