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: add block hash to LightBlockHeader #5663

Merged
merged 3 commits into from
Nov 17, 2023
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
22 changes: 17 additions & 5 deletions config/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,11 @@
// their account balances.
StateProofExcludeTotalWeightWithRewards bool

// StateProofBlockHashInLightHeader specifies that the LightBlockHeader
// committed to by state proofs should contain the BlockHash of each
// block, instead of the seed.
StateProofBlockHashInLightHeader bool

// EnableAssetCloseAmount adds an extra field to the ApplyData. The field contains the amount of the remaining
// asset that were sent to the close-to address.
EnableAssetCloseAmount bool
Expand Down Expand Up @@ -759,15 +764,20 @@
return err
}
if newConsensus != nil {
Consensus = newConsensus
// Set allocation limits
for _, p := range Consensus {
checkSetAllocBounds(p)
}
SetConfigurableConsensusProtocols(newConsensus)

Check warning on line 767 in config/consensus.go

View check run for this annotation

Codecov / codecov/patch

config/consensus.go#L767

Added line #L767 was not covered by tests
}
return nil
}

// SetConfigurableConsensusProtocols sets the configurable protocols.
func SetConfigurableConsensusProtocols(newConsensus ConsensusProtocols) {
Consensus = newConsensus

Check warning on line 774 in config/consensus.go

View check run for this annotation

Codecov / codecov/patch

config/consensus.go#L773-L774

Added lines #L773 - L774 were not covered by tests
// Set allocation limits
for _, p := range Consensus {
checkSetAllocBounds(p)

Check warning on line 777 in config/consensus.go

View check run for this annotation

Codecov / codecov/patch

config/consensus.go#L776-L777

Added lines #L776 - L777 were not covered by tests
}
}

// PreloadConfigurableConsensusProtocols loads the configurable protocols from the data directory
// and merge it with a copy of the Consensus map. Then, it returns it to the caller.
func PreloadConfigurableConsensusProtocols(dataDirectory string) (ConsensusProtocols, error) {
Expand Down Expand Up @@ -1377,6 +1387,8 @@
vFuture.LogicSigVersion = 10 // When moving this to a release, put a new higher LogicSigVersion here
vFuture.EnableLogicSigCostPooling = true

vFuture.StateProofBlockHashInLightHeader = true

// Setting DynamicFilterTimeout in vFuture will impact e2e test performance
// by reducing round time. Hence, it is commented out for now.
// vFuture.DynamicFilterTimeout = true
Expand Down
20 changes: 18 additions & 2 deletions data/bookkeeping/lightBlockHeader.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package bookkeeping

import (
"github.com/algorand/go-algorand/config"
"github.com/algorand/go-algorand/crypto"
"github.com/algorand/go-algorand/data/basics"
"github.com/algorand/go-algorand/data/committee"
Expand All @@ -38,21 +39,36 @@
In addition, we make sure that the Seed (The unpredictable value) would be the first field that gets
hashed (give it the lowest codec value in the LightBlockHeader struct) to mitigate a collision attack
on the merkle damgard construction.

The BlockHash serves a similar role, in that it also depends on the seed and introduces some
uncontrollable input. It is slightly weaker, in the sense that an adversary can influence
the BlockHash to some degree (e.g., by including specific transactions in the payset), but
it comes with the added benefit of allowing to authenticate the entire blockchain based on
the BlockHash value.
*/
Seed committee.Seed `codec:"0"`
BlockHash BlockHash `codec:"1"`
Round basics.Round `codec:"r"`
GenesisHash crypto.Digest `codec:"gh"`
Sha256TxnCommitment crypto.GenericDigest `codec:"tc,allocbound=crypto.Sha256Size"`
}

// ToLightBlockHeader creates returns a LightBlockHeader from a given block header
func (bh *BlockHeader) ToLightBlockHeader() LightBlockHeader {
return LightBlockHeader{
Seed: bh.Seed,
res := LightBlockHeader{
GenesisHash: bh.GenesisHash,
Round: bh.Round,
Sha256TxnCommitment: bh.Sha256Commitment[:],
}

proto := config.Consensus[bh.CurrentProtocol]
if proto.StateProofBlockHashInLightHeader {
res.BlockHash = bh.Hash()

Check warning on line 66 in data/bookkeeping/lightBlockHeader.go

View check run for this annotation

Codecov / codecov/patch

data/bookkeeping/lightBlockHeader.go#L66

Added line #L66 was not covered by tests
} else {
res.Seed = bh.Seed
}

return res
}

// ToBeHashed implements the crypto.Hashable interface
Expand Down
45 changes: 34 additions & 11 deletions data/bookkeeping/msgp_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test/e2e-go/features/stateproofs/stateproofs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ func TestStateProofMessageCommitmentVerification(t *testing.T) {
consensusVersion := protocol.ConsensusVersion("test-fast-stateproofs")
consensusParams := getDefaultStateProofConsensusParams()
configurableConsensus[consensusVersion] = consensusParams
config.SetConfigurableConsensusProtocols(configurableConsensus)

var fixture fixtures.RestClientFixture
fixture.SetConsensus(configurableConsensus)
Expand Down
Loading