Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
20 changes: 20 additions & 0 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@
- [PacketCommitmentData](#ibc.lightclients.solomachine.v2.PacketCommitmentData)
- [PacketReceiptAbsenceData](#ibc.lightclients.solomachine.v2.PacketReceiptAbsenceData)
- [SignBytes](#ibc.lightclients.solomachine.v2.SignBytes)
- [SignBytesV2](#ibc.lightclients.solomachine.v2.SignBytesV2)
- [SignatureAndData](#ibc.lightclients.solomachine.v2.SignatureAndData)
- [TimestampedSignatureData](#ibc.lightclients.solomachine.v2.TimestampedSignatureData)

Expand Down Expand Up @@ -4737,6 +4738,25 @@ SignBytes defines the signed bytes used for signature verification.



<a name="ibc.lightclients.solomachine.v2.SignBytesV2"></a>

### SignBytesV2
SignBytesV2 defines the signed bytes used for signature verification.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `sequence` | [uint64](#uint64) | | the sequence number |
| `timestamp` | [uint64](#uint64) | | the proof timestamp |
| `diversifier` | [string](#string) | | the public key diversifier |
| `path` | [bytes](#bytes) | | the standardised path bytes |
| `data` | [bytes](#bytes) | | the marshaled data bytes |






<a name="ibc.lightclients.solomachine.v2.SignatureAndData"></a>

### SignatureAndData
Expand Down
71 changes: 70 additions & 1 deletion modules/light-clients/06-solomachine/client_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,76 @@ func (cs *ClientState) VerifyMembership(
path []byte,
value []byte,
) error {
// TODO: Implement 06-solomachine VerifyMembership
// TODO: Attempt to refactor code to smaller function
if revision := height.GetRevisionNumber(); revision != 0 {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidHeight, "revision must be 0 for solomachine, got revision-number: %d", revision)
}

// sequence is encoded in the revision height of height struct
sequence := height.GetRevisionHeight()
latestSequence := cs.GetLatestHeight().GetRevisionHeight()
if latestSequence != sequence {
return sdkerrors.Wrapf(
sdkerrors.ErrInvalidHeight,
"client state sequence != proof sequence (%d != %d)", latestSequence, sequence,
)
}

var merklePath commitmenttypes.MerklePath
if err := cdc.Unmarshal(path, &merklePath); err != nil {
return sdkerrors.Wrap(commitmenttypes.ErrInvalidProof, "failed to unmarshal path into ICS 23 commitment merkle path")
}

var timestampedSigData TimestampedSignatureData
if err := cdc.Unmarshal(proof, &timestampedSigData); err != nil {
return sdkerrors.Wrapf(err, "failed to unmarshal proof into type %T", timestampedSigData)
}

timestamp := timestampedSigData.Timestamp

if len(timestampedSigData.SignatureData) == 0 {
return sdkerrors.Wrap(ErrInvalidProof, "signature data cannot be empty")
}

sigData, err := UnmarshalSignatureData(cdc, timestampedSigData.SignatureData)
if err != nil {
return err
}

if cs.ConsensusState == nil {
return sdkerrors.Wrap(clienttypes.ErrInvalidConsensus, "consensus state cannot be empty")
}

if cs.ConsensusState.GetTimestamp() > timestamp {
return sdkerrors.Wrapf(ErrInvalidProof, "the consensus state timestamp is greater than the signature timestamp (%d >= %d)", cs.ConsensusState.GetTimestamp(), timestamp)
}

publicKey, err := cs.ConsensusState.GetPubKey()
if err != nil {
return err
}

signBytes := &SignBytesV2{
Sequence: sequence,
Timestamp: timestamp,
Diversifier: cs.ConsensusState.Diversifier,
Path: []byte(merklePath.String()),
Data: value,
}

signBz, err := cdc.Marshal(signBytes)
if err != nil {
return err
}

if err := VerifySignature(publicKey, signBz, sigData); err != nil {
return err
}

cs.Sequence++
cs.ConsensusState.Timestamp = timestamp
setClientState(clientStore, cdc, cs)

return nil
}

Expand Down
Loading