Documentation
¶
Overview ¶
Package protocol defines the session protocol types and operations. This includes attestation domains, oracle operations, and receipt handling.
Index ¶
- func ComputeAttestationID(domain Domain, subjectID, commitRoot core.ID, epoch uint64) core.ID
- func ComputeMerkleRoot(records []*OracleRecord) core.ID
- func ComputeReceiptID(sessionID core.ID, stepIndex uint32, messageHash, senderID, receiverID core.ID) core.ID
- func ComputeReceiptsRoot(receipts []*SignedReceipt) core.ID
- func DomainSeparator(d Domain) []byte
- func ValidateAttestationForStep(step *core.Step, attestation *Attestation) error
- func ValidateDomainForStep(domain Domain, kind core.StepKind) bool
- func VerifyMerkleProof(root, leaf core.ID, proof *MerkleProof) bool
- func VerifyReceiptProof(root core.ID, proof *ReceiptProof) bool
- type Attestation
- type Domain
- type EpochBeaconAttestation
- type EquivocationEvidence
- type MerkleProof
- type OracleCommit
- type OracleCommitAttestation
- type OracleRecord
- type OracleRequest
- type Receipt
- type ReceiptCommit
- type ReceiptProof
- type RequestKind
- type RequestStatus
- type SessionCompleteAttestation
- type SignedReceipt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ComputeAttestationID ¶
ComputeAttestationID computes a deterministic attestation ID.
func ComputeMerkleRoot ¶
func ComputeMerkleRoot(records []*OracleRecord) core.ID
ComputeMerkleRoot computes the Merkle root of a set of records. Uses a simple binary Merkle tree construction.
func ComputeReceiptID ¶
func ComputeReceiptID(sessionID core.ID, stepIndex uint32, messageHash, senderID, receiverID core.ID) core.ID
ComputeReceiptID computes a deterministic receipt ID.
func ComputeReceiptsRoot ¶
func ComputeReceiptsRoot(receipts []*SignedReceipt) core.ID
ComputeReceiptsRoot computes the Merkle root of a set of receipts.
func DomainSeparator ¶
DomainSeparator returns the cryptographic domain separator for an attestation domain. This is prefixed to all data before signing to prevent cross-domain replay attacks.
func ValidateAttestationForStep ¶
func ValidateAttestationForStep(step *core.Step, attestation *Attestation) error
ValidateAttestationForStep validates that an attestation is valid for completing a step.
func ValidateDomainForStep ¶
ValidateDomainForStep validates that an attestation domain matches the step kind.
func VerifyMerkleProof ¶
func VerifyMerkleProof(root, leaf core.ID, proof *MerkleProof) bool
VerifyMerkleProof verifies a Merkle inclusion proof.
func VerifyReceiptProof ¶
func VerifyReceiptProof(root core.ID, proof *ReceiptProof) bool
VerifyReceiptProof verifies that a receipt is included in the receipts root.
Types ¶
type Attestation ¶
type Attestation struct {
// ID is the unique attestation identifier
ID core.ID `json:"id"`
// Domain specifies what is being attested
Domain Domain `json:"domain"`
// SubjectID is what is being attested (request_id, session_id, or epoch)
SubjectID core.ID `json:"subjectId"`
// CommitRoot is the Merkle root being attested
CommitRoot core.ID `json:"commitRoot"`
// Epoch when attestation was created
Epoch uint64 `json:"epoch"`
// Signers are the node IDs that signed this attestation
Signers []core.ID `json:"signers"`
// Signature is the aggregated threshold signature
Signature []byte `json:"signature"`
// CreatedAt is when the attestation was created
CreatedAt time.Time `json:"createdAt"`
}
Attestation represents a threshold attestation from the QuantumVM committee. Attestations are the cryptographic proof that a quorum of nodes agree on a statement.
func NewAttestation ¶
func NewAttestation(domain Domain, subjectID, commitRoot core.ID, epoch uint64, signers []core.ID, signature []byte) *Attestation
NewAttestation creates a new attestation.
func (*Attestation) SigningPayload ¶
func (a *Attestation) SigningPayload() []byte
SigningPayload returns the payload that should be signed for this attestation.
type Domain ¶
type Domain string
Domain represents an attestation domain. Domains provide cryptographic separation between different attestation types.
const ( // DomainOracleWrite - attestation over oracle write commits DomainOracleWrite Domain = "oracle/write" // DomainOracleRead - attestation over oracle read commits DomainOracleRead Domain = "oracle/read" // DomainSessionComplete - attestation over session completion DomainSessionComplete Domain = "session/complete" // DomainEpochBeacon - attestation over epoch randomness beacon DomainEpochBeacon Domain = "epoch/beacon" )
func DomainForStepKind ¶
DomainForStepKind returns the appropriate attestation domain for a step kind.
type EpochBeaconAttestation ¶
type EpochBeaconAttestation struct {
*Attestation
Randomness core.ID `json:"randomness"`
}
EpochBeaconAttestation is an attestation over epoch randomness.
type EquivocationEvidence ¶
type EquivocationEvidence struct {
// NodeID of the equivocating node
NodeID core.ID `json:"nodeId"`
// First attestation
First *Attestation `json:"first"`
// Second conflicting attestation
Second *Attestation `json:"second"`
// DetectedAt is when the equivocation was detected
DetectedAt time.Time `json:"detectedAt"`
}
EquivocationEvidence represents evidence of a node signing conflicting attestations.
func DetectEquivocation ¶
func DetectEquivocation(a1, a2 *Attestation) *EquivocationEvidence
DetectEquivocation checks if two attestations represent equivocation by the same signer. Returns evidence if equivocation is detected.
type MerkleProof ¶
type MerkleProof struct {
// LeafIndex is the index of the leaf
LeafIndex uint32 `json:"leafIndex"`
// Siblings are the sibling hashes along the path
Siblings []core.ID `json:"siblings"`
// IsLeft indicates if the sibling is on the left at each level
IsLeft []bool `json:"isLeft"`
}
MerkleProof represents a Merkle inclusion proof.
type OracleCommit ¶
type OracleCommit struct {
// RequestID this commit is for
RequestID core.ID `json:"requestId"`
// MerkleRoot of all records
MerkleRoot core.ID `json:"merkleRoot"`
// RecordCount is the number of records
RecordCount uint32 `json:"recordCount"`
// Epoch when committed
Epoch uint64 `json:"epoch"`
// CommittedAt is when the commit was created
CommittedAt time.Time `json:"committedAt"`
}
OracleCommit represents a committed set of oracle records.
type OracleCommitAttestation ¶
type OracleCommitAttestation struct {
*Attestation
RequestID core.ID `json:"requestId"`
}
OracleCommitAttestation is an attestation over an oracle commit.
type OracleRecord ¶
type OracleRecord struct {
// RecordID is the unique record identifier
RecordID core.ID `json:"recordId"`
// RequestID this record belongs to
RequestID core.ID `json:"requestId"`
// SubmitterID is the node that submitted this record
SubmitterID core.ID `json:"submitterId"`
// Data is the record payload
Data []byte `json:"data"`
// DataHash is the hash of the data
DataHash core.ID `json:"dataHash"`
// Signature from the submitter
Signature []byte `json:"signature"`
// CreatedAt is when the record was created
CreatedAt time.Time `json:"createdAt"`
}
OracleRecord represents a single oracle observation.
func NewOracleRecord ¶
func NewOracleRecord(requestID, submitterID core.ID, data []byte, signature []byte) *OracleRecord
NewOracleRecord creates a new oracle record.
type OracleRequest ¶
type OracleRequest struct {
// ID is the deterministic request identifier
// H("LUX:OracleRequest:v1" || service_id || session_id || step || retry || tx_id)
ID core.ID `json:"id"`
// ServiceID identifies the service
ServiceID core.ID `json:"serviceId"`
// SessionID identifies the session
SessionID core.ID `json:"sessionId"`
// StepIndex is the step number
StepIndex uint32 `json:"stepIndex"`
// RetryIndex for retry attempts
RetryIndex uint32 `json:"retryIndex"`
// TxID that triggered this request
TxID core.ID `json:"txId"`
// Kind of request (read or write)
Kind RequestKind `json:"kind"`
// Status of the request
Status RequestStatus `json:"status"`
// InputHash is the hash of request inputs
InputHash core.ID `json:"inputHash"`
// Records collected for this request
Records []*OracleRecord `json:"records,omitempty"`
// CommitRoot is the Merkle root of committed records
CommitRoot core.ID `json:"commitRoot,omitempty"`
// AttestationID is the attestation over the commit
AttestationID core.ID `json:"attestationId,omitempty"`
// CreatedAt is when the request was created
CreatedAt time.Time `json:"createdAt"`
// CommittedAt is when records were committed
CommittedAt time.Time `json:"committedAt,omitempty"`
}
OracleRequest represents a request for external I/O.
func NewOracleRequest ¶
func NewOracleRequest(serviceID, sessionID, txID, inputHash core.ID, step, retry uint32, kind RequestKind) *OracleRequest
NewOracleRequest creates a new oracle request.
type Receipt ¶
type Receipt struct {
// ID is the unique receipt identifier
ID core.ID `json:"id"`
// SessionID this receipt belongs to
SessionID core.ID `json:"sessionId"`
// StepIndex is the step that generated this message
StepIndex uint32 `json:"stepIndex"`
// MessageHash is the hash of the relayed message
MessageHash core.ID `json:"messageHash"`
// SenderID is the sending node
SenderID core.ID `json:"senderId"`
// ReceiverID is the receiving node
ReceiverID core.ID `json:"receiverId"`
// Timestamp of relay
Timestamp time.Time `json:"timestamp"`
// Signature from the relay node
Signature []byte `json:"signature"`
}
Receipt represents a relay receipt for message delivery.
type ReceiptCommit ¶
type ReceiptCommit struct {
// SessionID this commit is for
SessionID core.ID `json:"sessionId"`
// MerkleRoot of all receipts
MerkleRoot core.ID `json:"merkleRoot"`
// ReceiptCount is the number of receipts
ReceiptCount uint32 `json:"receiptCount"`
// Epoch when committed
Epoch uint64 `json:"epoch"`
// CommittedAt is when the commit was created
CommittedAt time.Time `json:"committedAt"`
}
ReceiptCommit represents a committed set of receipts for a session.
type ReceiptProof ¶
type ReceiptProof struct {
*MerkleProof
Receipt *SignedReceipt `json:"receipt"`
}
ReceiptProof represents a Merkle inclusion proof for a receipt.
type RequestKind ¶
type RequestKind uint8
RequestKind indicates the type of oracle request.
const ( // RequestKindWrite - external write request RequestKindWrite RequestKind = iota // RequestKindRead - external read request RequestKindRead )
func (RequestKind) String ¶
func (k RequestKind) String() string
type RequestStatus ¶
type RequestStatus uint8
RequestStatus indicates the status of an oracle request.
const ( RequestStatusPending RequestStatus = iota // Waiting for records RequestStatusCommitted // Records committed RequestStatusAttested // Attestation received )
func (RequestStatus) String ¶
func (s RequestStatus) String() string
type SessionCompleteAttestation ¶
type SessionCompleteAttestation struct {
*Attestation
SessionID core.ID `json:"sessionId"`
OutputHash core.ID `json:"outputHash"`
OracleRoot core.ID `json:"oracleRoot"`
ReceiptsRoot core.ID `json:"receiptsRoot"`
}
SessionCompleteAttestation is an attestation over session completion.
type SignedReceipt ¶
type SignedReceipt struct {
*Receipt
// RelayNodeID is the node that relayed the message
RelayNodeID core.ID `json:"relayNodeId"`
// RelaySignature is the signature from the relay node
RelaySignature []byte `json:"relaySignature"`
}
SignedReceipt is a receipt with additional verification data.