Skip to content
This repository was archived by the owner on Jan 29, 2025. It is now read-only.
Merged
Changes from all 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
13 changes: 10 additions & 3 deletions zcash/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ var (
TestSpendingKey = [2]byte{0xAC, 0x08}
ProdAddress = [2]byte{0x16, 0x9A}
TestAddress = [2]byte{0x16, 0xB6}
ProdViewingKey = [2]byte{0, 0} // Not yet specified - WILL CHANGE
ProdViewingKey = [2]byte{0x0B, 0x1C}
TestViewingKey = [2]byte{0x0B, 0x2A}
)

var (
Expand Down Expand Up @@ -96,8 +97,14 @@ func KeyToViewingKey(key []byte) ([]byte, error) {
if len(key) != 32 || key[0]&0xf0 != 0 {
return nil, ErrInvalidKey
}
viewKey := make([]byte, 32)
prfAddr(viewKey, key, 1)
viewKey := make([]byte, 64)
prfAddr(viewKey, key, 0)
prfAddr(viewKey[32:], key, 1)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Per sections 4.2 and 5.4.6 of the Zcash spec, the output of prfAddr(_, key, 1) needs to be clamped to a valid Curve25519 secret key in order to match the definition of sk_enc. I'm guessing this was unnecessary in askToPKenc() because curve25519.ScalarBaseMult() performs clamping internally.

// Clamp PRF output to a valid Curve25519 secret key.
// (See sections 4.2 and 5.4.6 of the Zcash spec.)
viewKey[32] &= 248
viewKey[63] &= 127
viewKey[63] |= 64
return viewKey, nil
}

Expand Down