-
Notifications
You must be signed in to change notification settings - Fork 212
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
WiP: Double Publish and double Marry Malfeasance Proofs for ATX v2 #6043
Closed
Closed
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
1cdba4d
Double Publish malfeasance proof
fasmat df8c57c
Double marry malfeasance proof
fasmat 1b6910f
Add more tests and implement double marry proof
fasmat 28eb9d9
Tests for double marry
fasmat 9086798
Cleanup
fasmat e5e9dad
Add more comments
fasmat 06f1f34
Use types.Hash32 for leafs
fasmat 3103cd7
First draft activation malfeasance service
fasmat 8a547b1
make generate
fasmat d6053ad
Change double marry to new atx certificates structure
fasmat 1acf8b4
Merge remote-tracking branch 'origin/develop' into malfeasance-v2
fasmat d2d1612
Fix a few issues with malfeasance handling
fasmat a8968a3
Add more comments
fasmat 937294e
Cleanup
fasmat da9db77
Merge remote-tracking branch 'origin/develop' into malfeasance-v2
fasmat bc47352
Merge remote-tracking branch 'origin/develop' into malfeasance-v2
fasmat 188d372
Merge remote-tracking branch 'origin/develop' into malfeasance-v2
fasmat 02447ab
Merge remote-tracking branch 'origin/develop' into malfeasance-v2
fasmat 7a64494
Merge remote-tracking branch 'origin/develop' into malfeasance-v2
fasmat 4c93d60
Merge remote-tracking branch 'origin/develop' into malfeasance-v2
fasmat 8ecce30
Fix issue after merge
fasmat ff552a5
Merge remote-tracking branch 'origin/develop' into malfeasance-v2
fasmat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package activation | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"go.uber.org/zap" | ||
|
||
"github.com/spacemeshos/go-spacemesh/activation/wire" | ||
"github.com/spacemeshos/go-spacemesh/codec" | ||
"github.com/spacemeshos/go-spacemesh/common/types" | ||
"github.com/spacemeshos/go-spacemesh/signing" | ||
) | ||
|
||
type MalfeasanceService struct { | ||
logger *zap.Logger | ||
edVerifier *signing.EdVerifier | ||
} | ||
|
||
func NewMalfeasanceService(logger *zap.Logger, edVerifier *signing.EdVerifier) *MalfeasanceService { | ||
return &MalfeasanceService{ | ||
logger: logger, | ||
edVerifier: edVerifier, | ||
} | ||
} | ||
|
||
func (ms *MalfeasanceService) Validate(ctx context.Context, data []byte) ([]types.NodeID, error) { | ||
var decoded wire.ATXProof | ||
if err := codec.Decode(data, &decoded); err != nil { | ||
return nil, fmt.Errorf("decoding ATX malfeasance proof: %w", err) | ||
} | ||
|
||
var proof wire.Proof | ||
switch decoded.ProofType { | ||
case wire.DoublePublish: | ||
var p wire.ProofDoublePublish | ||
if err := codec.Decode(decoded.Proof, &p); err != nil { | ||
return nil, fmt.Errorf("decoding ATX double publish proof: %w", err) | ||
} | ||
proof = p | ||
case wire.DoubleMarry: | ||
var p wire.ProofDoubleMarry | ||
if err := codec.Decode(decoded.Proof, &p); err != nil { | ||
return nil, fmt.Errorf("decoding ATX double marry proof: %w", err) | ||
} | ||
proof = p | ||
default: | ||
return nil, fmt.Errorf("unknown ATX malfeasance proof type: %d", decoded.ProofType) | ||
} | ||
|
||
id, err := proof.Valid(ms.edVerifier) | ||
if err != nil { | ||
return nil, fmt.Errorf("validating ATX malfeasance proof: %w", err) | ||
} | ||
|
||
validIDs := make([]types.NodeID, 0, len(decoded.Certificates)+1) | ||
validIDs = append(validIDs, id) // id has already been proven to be malfeasant | ||
|
||
// check certificates provided with the proof | ||
// TODO(mafa): this only works if the main identity becomes malfeasant - try different approach with merkle proofs | ||
for _, cert := range decoded.Certificates { | ||
if id != cert.Target { | ||
continue | ||
} | ||
if !ms.edVerifier.Verify(signing.MARRIAGE, cert.Target, cert.ID.Bytes(), cert.Signature) { | ||
continue | ||
} | ||
validIDs = append(validIDs, cert.ID) | ||
} | ||
return validIDs, nil | ||
} | ||
|
||
func (ms *MalfeasanceService) Publish(ctx context.Context, proof wire.ATXProof) error { | ||
// TODO(mafa): this is called by the ATX handler in the activation package | ||
// | ||
// encode proof to []byte | ||
// bubble up to malfeasance handler to encode as `MalfeasanceProofV2` and publish | ||
return errors.New("not implemented") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package activation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package wire | ||
|
||
import ( | ||
"github.com/spacemeshos/go-spacemesh/common/types" | ||
"github.com/spacemeshos/go-spacemesh/signing" | ||
) | ||
|
||
//go:generate scalegen | ||
|
||
// ProofType is an identifier for the type of proof that is encoded in the ATXProof. | ||
type ProofType byte | ||
|
||
const ( | ||
DoublePublish ProofType = iota + 1 | ||
DoubleMarry | ||
) | ||
|
||
type ATXProof struct { | ||
// ProofType is the type of proof that is being provided. | ||
ProofType ProofType | ||
// Certificates is a slice of marriage certificates showing which identities belong to the same marriage set as | ||
// the one proven to be malfeasant. Up to 1024 can be put into a single proof, since by repeatedly marrying other | ||
// identities there can be much more than 256 in a malfeasant marriage set. Beyond that a second proof could be | ||
// provided to show that additional identities are part of the same malfeasant marriage set. | ||
Certificates []ProofCertificate `scale:"max=1024"` | ||
// Proof is the actual proof. Its type depends on the ProofType. | ||
Proof []byte `scale:"max=1048576"` // max size of proof is 1MiB | ||
} | ||
|
||
// ProofCertificate proofs that two identities are part of the same marriage set. | ||
type ProofCertificate struct { | ||
// Target of the certificate, i.e. the identity that signed the ATX containing the original certificate. | ||
Target types.NodeID | ||
// ID is the identity that signed the certificate. | ||
ID types.NodeID | ||
// Signature is the signature of the certificate, i.e. ID signed with the key of SmesherID. | ||
Signature types.EdSignature | ||
} | ||
Comment on lines
+31
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. Having type MarriageCertificates {
Target types.NodeID
Certificates []MarriageCertificate `scale:"max=256"`
}
type ATXProof struct {
ProofType ProofType
Certificates []MarriageCertificates `scale:"max=2"`
Proof []byte `scale:"max=1048576"`
} |
||
|
||
// Proof is an interface for all types of proofs that can be provided in an ATXProof. | ||
// Generally the proof should be able to validate itself. | ||
type Proof interface { | ||
Valid(edVerifier *signing.EdVerifier) (types.NodeID, error) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Maybe name it
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.
MarriageCertificate
already exists as a type in thewire
package (for v2 ATXs) but this is a different type it not only contains the signature and the payload but also the signer (which isn't needed for ATXs).