Skip to content

Commit

Permalink
address issue #1580 (#1600)
Browse files Browse the repository at this point in the history
* address issue #1580

* Update beacon_chain/spec/beaconstate.nim

Co-authored-by: Jacek Sieka <jacek@status.im>
  • Loading branch information
tersec and arnetheduck authored Sep 2, 2020
1 parent d9f9949 commit e4a43f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions beacon_chain/eth2_processor.nim
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ proc attestationValidator*(

logScope: wallSlot

# Potential under/overflows are fine; would just create odd metrics and logs
let delay = wallTime - attestation.data.slot.toBeaconTime
debug "Attestation received", delay
let v = self.attestationPool[].validateAttestation(
Expand Down Expand Up @@ -339,6 +340,7 @@ proc aggregateValidator*(

logScope: wallSlot

# Potential under/overflows are fine; would just create odd logs
let delay =
wallTime - signedAggregateAndProof.message.aggregate.data.slot.toBeaconTime
debug "Aggregate received", delay
Expand Down
10 changes: 10 additions & 0 deletions beacon_chain/spec/beaconstate.nim
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ func get_block_root_at_slot*(state: BeaconState,
slot: Slot): Eth2Digest =
# Return the block root at a recent ``slot``.

# Potential overflow/wrap shouldn't occur, as get_block_root_at_slot() called
# from internally controlled sources, but flag this explicitly, in case.
doAssert slot + SLOTS_PER_HISTORICAL_ROOT > slot

doAssert state.slot <= slot + SLOTS_PER_HISTORICAL_ROOT
doAssert slot < state.slot
state.block_roots[slot mod SLOTS_PER_HISTORICAL_ROOT]
Expand Down Expand Up @@ -538,6 +542,12 @@ func check_attestation_target_epoch*(

func check_attestation_inclusion*(data: AttestationData,
current_slot: Slot): Result[void, cstring] =
# Check for overflow
static:
doAssert SLOTS_PER_EPOCH >= MIN_ATTESTATION_INCLUSION_DELAY
if data.slot + SLOTS_PER_EPOCH <= data.slot:
return err("attestation data.slot overflow, malicious?")

if not (data.slot + MIN_ATTESTATION_INCLUSION_DELAY <= current_slot):
return err("Attestation too new")

Expand Down

0 comments on commit e4a43f7

Please sign in to comment.