Assessment reports>Brevis>Discussion>Consistent usage of named constants

Consistent usage of named constants

In some cases, we noticed that named constants were replaced by literal constants with the same value in some places. Using the named constants everywhere would make the code more robust by preventing changes that lead to inconsistencies. In this section, we collect instances of this type.

Maximum number of hash rounds for the fabric's header circuit

In the zk-bridge file circuits/fabric/headers/circuit.go, a constant CHUNK_HEADER_MAX_HASH_ROUNDS is used for the maximum number of hash rounds, and this is what is used with regards to what the length of the Headers field of the Circuit struct should be:

! const CHUNK_HEADER_MAX_HASH_ROUNDS = 5

type Circuit struct {
	ChunkRoot     [2]frontend.Variable `gnark:",public"`
	PrevHash      [2]frontend.Variable `gnark:",public"`
	EndHash       [2]frontend.Variable `gnark:",public"`
	StartBlockNum frontend.Variable    `gnark:",public"`
	EndBlockNum   frontend.Variable    `gnark:",public"`

!	// RLP encoded header bits, pre-padded with 10..1 for keccak, additional zeros are padded in the end
!	// to fill up to maxRounds * 1088
!	Headers       [][]frontend.Variable
	HashRoundIdxs []frontend.Variable

	api frontend.API
}

The named constant CHUNK_HEADER_MAX_HASH_ROUNDS has value 5. In circuits/fabric/headers/headerutil/utils.go, the EncodeHeaders function is the one ultimately producing the Headers field, but instead of using CHUNK_HEADER_MAX_HASH_ROUNDS, it uses a hardcoded constant literal 5:

func EncodeHeaders(headers []types.Header, dummyHeaders bool) (encoded [][]frontend.Variable, idxs []frontend.Variable, err error) {
	for i, header := range headers {

        // ...

!         zerosToPad := 5*1088 - len(paddedBits)
		for i := 0; i < zerosToPad; i++ {
			fv = append(fv, 0)
		}
		encoded = append(encoded, fv)
	}
	return
}

We recommend to use CHUNK_HEADER_MAX_HASH_ROUNDS here instead of 5 to ensure consistency on future changes.

Zellic © 2025Back to top ↑