Skip to content

Commit

Permalink
move protocol version inside final hash
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaSripal committed Nov 14, 2024
1 parent 1269ed6 commit 9005362
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions spec/core/v2/ics-004-packet-semantics/PACKET.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func commitPayload(payload: Payload): bytes {
// Note: SourceChannel and the sequence are omitted since they will be included in the key
// Every other field of the packet is committed to in the packet which will be stored in the
// packet commitment value
// The final hash will be prepended by the byte 0x02 in order to clearly define the protocol version
// The final preimage will be prepended by the byte 0x02 before hashing in order to clearly define the protocol version
// and allow for future upgradability
func commitV2Packet(packet: Packet) {
timeoutBytes = LittleEndian(packet.timeout)
Expand All @@ -96,7 +96,8 @@ func commitV2Packet(packet: Packet) {
buffer = sha256.Hash(packet.destChannel)
buffer = append(buffer, sha256.hash(timeoutBytes))
buffer = append(buffer, sha256.hash(appBytes))
return append([]byte{0x02}, sha256.Hash(buffer))
buffer = append([]byte{0x02}, buffer)
return sha256.Hash(buffer)
}
```

Expand All @@ -123,12 +124,16 @@ interface Acknowledgement {
All acknowledgements must be committed to and stored under the ICS24 acknowledgment path.

```typescript
// commitV2Acknowledgement hashes each app acknowledgment and hashes them together
// the final preimage is then prepended with the byte 0x02 in order to clearly define the protocol version
// and allow for future upgradability
func commitV2Acknowledgment(ack: Acknowledgement) {
var buffer: bytes
for appAck in ack.appAcknowledgement {
buffer = append(buffer, sha256.Hash(appAck))
}
return append([]byte{0x02}, sha256.Hash(buffer))
buffer = append([]byte{0x02}, buffer)
return sha256.Hash(buffer)
}
```

0 comments on commit 9005362

Please sign in to comment.