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

state proofs: Initial commit for stateproofs model #1002

Merged
merged 24 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions api/converter_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ func signedTxnWithAdToTransaction(stxn *transactions.SignedTxnWithAD, extra rowD
var assetFreeze *generated.TransactionAssetFreeze
var assetTransfer *generated.TransactionAssetTransfer
var application *generated.TransactionApplication
var stateProof *generated.TransactionStateProof

switch stxn.Txn.Type {
case protocol.PaymentTx:
Expand Down Expand Up @@ -407,6 +408,101 @@ func signedTxnWithAdToTransaction(stxn *transactions.SignedTxnWithAD, extra rowD
}

application = &a
case protocol.StateProofTx:
partPath := make([][]byte, len(stxn.Txn.StateProof.PartProofs.Path))
for idx, part := range stxn.Txn.StateProof.PartProofs.Path {
digest := make([]byte, len(part))
copy(digest, part)
partPath[idx] = digest
}

sigProofPath := make([][]byte, len(stxn.Txn.StateProof.SigProofs.Path))
for idx, sigPart := range stxn.Txn.StateProof.SigProofs.Path {
digest := make([]byte, len(sigPart))
copy(digest, sigPart)
sigProofPath[idx] = digest
}

// We need to iterate through these in order, to make sure our responses are deterministic
keys := make([]uint64, len(stxn.Txn.StateProof.Reveals))
elems := 0
for key := range stxn.Txn.StateProof.Reveals {
keys[elems] = key
elems++
}
sort.Slice(keys, func(i, j int) bool { return keys[i] < keys[j] })
reveals := make([]generated.StateProofReveal, len(stxn.Txn.StateProof.Reveals))
for _, key := range keys {
revToConv := stxn.Txn.StateProof.Reveals[key]
commitment := revToConv.Part.PK.Commitment[:]
falconSig := []byte(revToConv.SigSlot.Sig.Signature)
verifyKey := revToConv.SigSlot.Sig.VerifyingKey.PublicKey[:]
proofPath := make([][]byte, len(revToConv.SigSlot.Sig.Proof.Path))
for idx, proofPart := range revToConv.SigSlot.Sig.Proof.Path {
proofPath[idx] = proofPart
}

reveals[key] = generated.StateProofReveal{
Participant: &generated.StateProofParticipant{
Verifier: &generated.StateProofVerifier{
Commitment: &commitment,
KeyLifetime: uint64Ptr(revToConv.Part.PK.KeyLifetime),
},
Weight: uint64Ptr(revToConv.Part.Weight),
},
Position: uint64Ptr(key),
SigSlot: &generated.StateProofSigSlot{
LowerSigWeight: uint64Ptr(revToConv.SigSlot.L),
Signature: &generated.StateProofSignature{
FalconSignature: &falconSig,
MerkleArrayIndex: uint64Ptr(revToConv.SigSlot.Sig.VectorCommitmentIndex),
Proof: &generated.MerkleArrayProof{
HashFactory: &generated.HashFactory{
HashType: uint64Ptr(uint64(revToConv.SigSlot.Sig.Proof.HashFactory.HashType)),
},
Path: &proofPath,
TreeDepth: uint64Ptr(uint64(revToConv.SigSlot.Sig.Proof.TreeDepth)),
},
VerifyingKey: &verifyKey,
},
},
}
}
proof := generated.StateProof{
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should also copy PositionsToReveal slice

Copy link
Contributor

Choose a reason for hiding this comment

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

@Eric-Warehime You can use byteSlicePtr to create a copy

PartProofs: &generated.MerkleArrayProof{
HashFactory: &generated.HashFactory{
HashType: uint64Ptr(uint64(stxn.Txn.StateProof.PartProofs.HashFactory.HashType)),
},
Path: &partPath,
TreeDepth: uint64Ptr(uint64(stxn.Txn.StateProof.PartProofs.TreeDepth)),
},
Reveals: &reveals,
SaltVersion: uint64Ptr(uint64(stxn.Txn.StateProof.MerkleSignatureSaltVersion)),
SigCommit: byteSliceOmitZeroPtr(stxn.Txn.StateProof.SigCommit),
SigProofs: &generated.MerkleArrayProof{
HashFactory: &generated.HashFactory{
HashType: uint64Ptr(uint64(stxn.Txn.StateProof.SigProofs.HashFactory.HashType)),
},
Path: &sigProofPath,
TreeDepth: uint64Ptr(uint64(stxn.Txn.StateProof.SigProofs.TreeDepth)),
},
SignedWeight: uint64Ptr(stxn.Txn.StateProof.SignedWeight),
}

message := generated.StateProofMessage{
BlockHeadersCommitment: &stxn.Txn.Message.BlockHeadersCommitment,
FirstAttestedRound: uint64Ptr(stxn.Txn.Message.FirstAttestedRound),
LatestAttestedRound: uint64Ptr(stxn.Txn.Message.LastAttestedRound),
LnProvenWeight: uint64Ptr(stxn.Txn.Message.LnProvenWeight),
VotersCommitment: &stxn.Txn.Message.VotersCommitment,
}

proofTxn := generated.TransactionStateProof{
Message: &message,
StateProof: &proof,
StateProofType: uint64Ptr(uint64(stxn.Txn.StateProofType)),
}
stateProof = &proofTxn
}

var localStateDelta *[]generated.AccountStateDelta
Expand Down Expand Up @@ -486,6 +582,7 @@ func signedTxnWithAdToTransaction(stxn *transactions.SignedTxnWithAD, extra rowD
AssetTransferTransaction: assetTransfer,
PaymentTransaction: payment,
KeyregTransaction: keyreg,
StateProofTransaction: stateProof,
ClosingAmount: uint64Ptr(stxn.ClosingAmount.Raw),
ConfirmedRound: uint64Ptr(extra.Round),
IntraRoundOffset: uint64Ptr(uint64(extra.Intra)),
Expand Down
Loading