Skip to content

Commit

Permalink
Implements pre-mining time verification verification
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashy5000 committed Apr 9, 2024
1 parent 9b47c7f commit 60ed130
Show file tree
Hide file tree
Showing 13 changed files with 23 additions and 11 deletions.
Binary file modified builds/node/node_darwin-amd64
Binary file not shown.
Binary file modified builds/node/node_darwin-arm64
Binary file not shown.
Binary file modified builds/node/node_linux-386
Binary file not shown.
Binary file modified builds/node/node_linux-amd64
Binary file not shown.
Binary file modified builds/node/node_linux-arm
Binary file not shown.
Binary file modified builds/node/node_linux-arm64
Binary file not shown.
Binary file modified builds/node/node_windows-386
Binary file not shown.
Binary file modified builds/node/node_windows-amd64
Binary file not shown.
Binary file modified builds/node/node_windows-arm
Binary file not shown.
Binary file modified builds/node/node_windows-arm64
Binary file not shown.
2 changes: 1 addition & 1 deletion create_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func RequestTimeVerification(block Block) ([]Signature, []dsa.PublicKey) {
panic(err)
}
for _, peer := range GetPeers() {
if int64(len(block.TimeVerifiers)) >= GetMinerCount(len(blockchain))/5 && VerifyTimeVerifiers(block, block.TimeVerifiers, block.TimeVerifierSignatures) {
if int64(len(block.TimeVerifiers)) >= GetMinerCount(len(blockchain))/5 {
break
}
// Verify that the peer has mined a block (only miners can be time verifiers)
Expand Down
3 changes: 1 addition & 2 deletions peers.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
http://192.168.4.87:8080
http://192.168.4.23:8080
http://127.0.0.1:8080
29 changes: 21 additions & 8 deletions verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,24 +120,37 @@ func VerifyBlock(block Block) bool {
fmt.Println("Timestamp is in the future.")
return false
}
if !VerifyTimeVerifiers(block, block.TimeVerifiers, block.TimeVerifierSignatures) {
if !VerifyTimeVerifiers(block, block.TimeVerifiers, block.TimeVerifierSignatures, false) {
fmt.Println("Block has invalid time verifiers. Ignoring block request.")
return false
}
if !VerifyTimeVerifiers(block, block.PreMiningTimeVerifiers, block.PreMiningTimeVerifierSignatures, true) {
fmt.Println("Block has invalid time verifiers. Ignoring block request.")
return false
}
return true
}

func VerifyTimeVerifiers(block Block, verifiers []dsa.PublicKey, signatures []Signature) bool {
func VerifyTimeVerifiers(block Block, verifiers []dsa.PublicKey, signatures []Signature, premining bool) bool {
if len(verifiers) != len(signatures) {
fmt.Println("Signature count does not match verifier count.")
return false
}
for i, verifier := range verifiers {
if !dsa.Verify(&verifier, []byte(fmt.Sprintf("%d", block.Timestamp.Add(block.MiningTime).UnixNano())), &signatures[i].R, &signatures[i].S) {
fmt.Println("Time verifier signature is not valid.")
return false
}
}
if premining {
for i, verifier := range verifiers {
if !dsa.Verify(&verifier, []byte(fmt.Sprintf("%d", block.Timestamp.UnixNano())), &signatures[i].R, &signatures[i].S) {
fmt.Println("Time verifier signature is not valid.")
return false
}
}
} else {
for i, verifier := range verifiers {
if !dsa.Verify(&verifier, []byte(fmt.Sprintf("%d", block.Timestamp.Add(block.MiningTime).UnixNano())), &signatures[i].R, &signatures[i].S) {
fmt.Println("Time verifier signature is not valid.")
return false
}
}
}
// Ensure all verifiers are unique
verifierMap := make(map[string]bool)
for _, verifier := range verifiers {
Expand Down

0 comments on commit 60ed130

Please sign in to comment.