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 network sharding eclipse attack #1201

Merged

Conversation

iulianpascalau
Copy link
Contributor

No description provided.

@iulianpascalau iulianpascalau self-assigned this Mar 10, 2020
@iulianpascalau iulianpascalau added type:bug Something isn't working type:feature New feature or request labels Mar 10, 2020
@AdoAdoAdo AdoAdoAdo self-requested a review March 10, 2020 13:42
@sasurobert sasurobert self-requested a review March 10, 2020 13:42
@@ -227,16 +227,29 @@
Size = 75000
Type = "LRU"

[PublicKeyShardId]
#PublicKeyShardId represents the main cache used to map Elrond block signing public keys to their associated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PublicKeyShardId -> PublicKeyPeerID
The long explanation of the logic behind this parameter is unnecessary here, please keep it simple

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

func (pq *pidQueue) pop() p2p.PeerID {
evicted := pq.data[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no len check, this could give index out of bounds

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in order to keep this unexported struct as simple as possible, the check has been introduced before calling pop (UpdatePeerIdPublicKey function, L179)

@@ -76,6 +90,7 @@ func (psm *PeerShardMapper) byIDWithNodesCoordinator(pid p2p.PeerID) (shardId ui

pkBuff, ok := pkObj.([]byte)
if !ok {
psm.peerIdPk.Remove([]byte(pid))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this getter doing a remove?
please don't change values in getters.

this change is also done without acquiring the mutex which will lead to race conditions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed, added log.Warn as it is a programming error

@@ -99,6 +114,7 @@ func (psm *PeerShardMapper) byIDSearchingPkInFallbackCache(pkBuff []byte) (shard

shard, ok := shardObj.(uint32)
if !ok {
psm.fallbackPkShard.Remove(pkBuff)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as previous comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed, added log.Warn as it is a programming error

@@ -113,15 +129,86 @@ func (psm *PeerShardMapper) byIDSearchingPidInFallbackCache(pid p2p.PeerID) (sha

shard, ok := shardObj.(uint32)
if !ok {
psm.fallbackPidShard.Remove([]byte(pid))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as previous comment, please do not remove on getter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed, added log.Warn as it is a programming error

}

idxPid := pq.indexOf(pid)
if idxPid > -1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please create a constant for -1 e.g idxNotFound and check against that ( != idxNotFound ).
you can also use maxint and make the type unsigned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, added const

Copy link
Contributor

@sasurobert sasurobert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only what Adi said.

@iulianpascalau iulianpascalau merged commit 6899eb5 into feat/network-sharding Mar 11, 2020
@iulianpascalau iulianpascalau deleted the fix-network-sharding-eclipse-attack branch March 11, 2020 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Something isn't working type:feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants