Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(firewall): remove decoding bundle for expired message #1682

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
29 changes: 7 additions & 22 deletions sync/firewall/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,35 +217,20 @@
return true
}

// TODO: we remove on the version v1.8.0
consensusHeightExtracted := false
var consensusHeight uint32
// Validate the format before extracting consensusHeight
consensusHeightBytes := msgData[msgLen-6:]
// Check if consensus height is set. Refer to the bundle encoding for more details.
if consensusHeightBytes[0] == 0x04 && consensusHeightBytes[1] == 0x1a {
consensusHeight = binary.BigEndian.Uint32(consensusHeightBytes[2:])
if consensusHeightBytes[0] != 0x04 || consensusHeightBytes[1] != 0x1a {
f.logger.Warn("firewall: invalid message format")

Check warning on line 223 in sync/firewall/firewall.go

View check run for this annotation

Codecov / codecov/patch

sync/firewall/firewall.go#L223

Added line #L223 was not covered by tests

if consensusHeight > 2_900_000 {
consensusHeightExtracted = true
}
return true

Check warning on line 225 in sync/firewall/firewall.go

View check run for this annotation

Codecov / codecov/patch

sync/firewall/firewall.go#L225

Added line #L225 was not covered by tests
}
if !consensusHeightExtracted {
// Decoding the message at this level is costly, and we should avoid it.
// In future versions, this code can be removed.
// However, at the time of writing this code, we need it to prevent replay attacks.
bdl := new(bundle.Bundle)
_, err := bdl.Decode(bytes.NewReader(msgData))
if err != nil {
return true
}

consensusHeight = bdl.Message.ConsensusHeight()
}
consensusHeight := binary.BigEndian.Uint32(consensusHeightBytes[2:])

// The message is expired, or the consensus height is behind the network's current height.
// In either case, the message is dropped and won't be propagated.
if f.state.LastBlockHeight() > 0 && consensusHeight < f.state.LastBlockHeight()-1 {
f.logger.Warn("firewall: expired message", "message height", consensusHeight, "our height", f.state.LastBlockHeight())
f.logger.Warn("firewall: expired message", "message height", consensusHeight,
"our height", f.state.LastBlockHeight())

return true
}
Expand Down
Loading