-
Notifications
You must be signed in to change notification settings - Fork 0
feat(arbiter): Implement Byzantine Swarm Protection #705
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,38 @@ type Payoff struct { | |
| // PayoffMatrix for a 2x2 game | ||
| type PayoffMatrix [][]Payoff | ||
|
|
||
| // Node represents a participant in the swarm | ||
| type Node struct { | ||
| ID string | ||
| Reputation float64 | ||
| Authorized bool | ||
| } | ||
|
|
||
| // Arbiter handles quorum and reputation | ||
| type Arbiter struct { | ||
| Nodes []Node | ||
| QuorumThreshold float64 | ||
| } | ||
|
Comment on lines
+15
to
+26
|
||
|
|
||
| // CalculateQuorum validates quorum based on reputation | ||
| func (a *Arbiter) CalculateQuorum(votes map[string]bool) bool { | ||
| var totalReputation float64 | ||
| var positiveReputation float64 | ||
| for _, node := range a.Nodes { | ||
| if !node.Authorized { | ||
| continue | ||
| } | ||
| totalReputation += node.Reputation | ||
| if vote, ok := votes[node.ID]; ok && vote { | ||
| positiveReputation += node.Reputation | ||
|
Comment on lines
+36
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The quorum calculation sums raw Useful? React with 👍 / 👎.
Comment on lines
+32
to
+38
|
||
| } | ||
| } | ||
| if totalReputation == 0 { | ||
| return false | ||
| } | ||
| return (positiveReputation / totalReputation) >= a.QuorumThreshold | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎. |
||
| } | ||
|
Comment on lines
+41
to
+45
|
||
|
|
||
| func SolveMiniMax(m PayoffMatrix) int { | ||
| // Simple pure strategy minimax for demonstration | ||
| bestDefenderAction := 0 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,38 @@ | ||
| package main | ||
|
|
||
| import "testing" | ||
| import ( | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestMiniMax(t *testing.T) { | ||
| matrix := PayoffMatrix{ | ||
| {{10, -10}, {0, 0}}, | ||
| {{0, 0}, {5, -5}}, | ||
| func TestCalculateQuorum(t *testing.T) { | ||
| arbiter := Arbiter{ | ||
| Nodes: []Node{ | ||
| {"node1", 1.0, true}, | ||
| {"node2", 2.0, true}, | ||
| {"node3", 1.0, false}, | ||
| }, | ||
| QuorumThreshold: 0.6, | ||
| } | ||
|
Comment on lines
+7
to
15
|
||
| action := SolveMiniMax(matrix) | ||
| if action != 1 { | ||
| t.Errorf("Expected action 1, got %d", action) | ||
|
|
||
| votes := map[string]bool{ | ||
| "node1": true, | ||
| "node2": false, | ||
| "node3": true, | ||
| } | ||
|
|
||
| // Reputation: node1=1, node2=2, total=3 | ||
| // Positive: node1=1, node2=0, total=1 | ||
| // 1/3 = 0.33 < 0.6 => false | ||
| if arbiter.CalculateQuorum(votes) { | ||
| t.Errorf("Expected false for 0.33 threshold") | ||
| } | ||
|
|
||
| votes2 := map[string]bool{ | ||
| "node1": true, | ||
| "node2": true, | ||
| } | ||
| // (1+2)/3 = 1.0 >= 0.6 => true | ||
| if !arbiter.CalculateQuorum(votes2) { | ||
| t.Errorf("Expected true for 1.0 threshold") | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (bug_risk): Validate or constrain QuorumThreshold to avoid surprising behavior
If QuorumThreshold is set <= 0 or > 1, quorum checks could effectively always fail or always pass. Please either clamp this to [0,1] or enforce validation (e.g., in a constructor/setter) so invalid thresholds are rejected early.
Suggested implementation:
fmtis imported at the top ofphoenix_os/arbiter/src/arbiter.go, e.g.:import "fmt", or added to the existing import block.Arbitervia struct literals to instead callNewArbiter(or, if you must keep struct literals, make sure they always set a validQuorumThreshold).Arbiterelsewhere in the file, align them with the same validation logic soQuorumThresholdis always constrained to(0,1].