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

add version to coin-generator #4007

Merged
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions crypto/stateproof/coinGenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
// the index of the coin to reveal as part of the state proof.
type coinChoiceSeed struct {
// the ToBeHashed function should be updated when fields are added to this structure

version byte
partCommitment crypto.GenericDigest
lnProvenWeight uint64
sigCommitment crypto.GenericDigest
Expand All @@ -48,7 +48,8 @@ func (cc *coinChoiceSeed) ToBeHashed() (protocol.HashID, []byte) {
lnProvenWtAsBytes := make([]byte, 8)
binary.LittleEndian.PutUint64(lnProvenWtAsBytes, cc.lnProvenWeight)

coinChoiceBytes := make([]byte, 0, len(cc.partCommitment)+len(lnProvenWtAsBytes)+len(cc.sigCommitment)+len(signedWtAsBytes)+len(cc.data))
coinChoiceBytes := make([]byte, 0, 1+len(cc.partCommitment)+len(lnProvenWtAsBytes)+len(cc.sigCommitment)+len(signedWtAsBytes)+len(cc.data))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you use len(cc.version) instead of 1+?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately , len(cc.version) does not compile

coinChoiceBytes = append(coinChoiceBytes, cc.version)
coinChoiceBytes = append(coinChoiceBytes, cc.partCommitment...)
coinChoiceBytes = append(coinChoiceBytes, lnProvenWtAsBytes...)
coinChoiceBytes = append(coinChoiceBytes, cc.sigCommitment...)
Expand All @@ -71,6 +72,7 @@ type coinGenerator struct {
// Shake(coinChoiceSeed)
// we extract 64 bits from shake for each coin flip and divide it by signedWeight
func makeCoinGenerator(choice *coinChoiceSeed) coinGenerator {
choice.version = VersionForCoinGenerator
rep := crypto.HashRep(choice)
shk := sha3.NewShake256()
shk.Write(rep)
Expand Down
2 changes: 1 addition & 1 deletion crypto/stateproof/coinGenerator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestCoinFixedLengthHash(t *testing.T) {
}

rep := crypto.HashRep(&choice)
a.Equal(179, len(rep))
a.Equal(180, len(rep))
}

func TestHashCoin(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions crypto/stateproof/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ const (
precisionBits = uint8(16) // number of bits used for log approximation. This should not exceed 63
ln2IntApproximation = uint64(45427) // the value of the ln(2) with 16 bits of precision (i.e ln2IntApproximation = ceil( 2^precisionBits * ln(2) ))
MaxReveals = 1024 // MaxReveals is a bound on allocation and on numReveals to limit log computation
// VersionForCoinGenerator is used as part of the seed for Fiat-Shamir. We would change this
// value if the state proof verifier algorithm changes. This will allow us to make different coins for different state proof verification algorithms
VersionForCoinGenerator = byte(0)
)