Assessment reports>Brevis>Informational findings>Incorrect specification for ,MinGeneric, and ,MaxGeneric
Category: Coding Mistakes

Incorrect specification for MinGeneric and MaxGeneric

Informational Severity
Informational Impact
N/A Likelihood

Description

Functions to calculate the maximum and minimum over data streams is provided in sdk/datastream.go. The documentation and implementation of MaxGeneric is as follows:

// MaxGeneric finds out the maximum value from the data stream with the user
// defined sort function. Uses Reduce under the hood. Note if the data stream is
// empty (all data points are toggled off), this function returns 0.
func MaxGeneric[T CircuitVariable](ds *DataStream[T], initialMax T, gt SortFunc[T]) T {
	return Reduce(ds, initialMax, func(max, current T) (newMax T) {
		curGtMax := gt(current, max)
		return Select(ds.api, curGtMax, current, max)
	})
}

The documentation comment specifies this function as returning 0 on empty data streams. However, this function will in fact return the argument initialMax in that case.

An analogous mismatch between documentation and implementation is present for MinGeneric.

Impact

The two functions MaxGeneric and MinGeneric do not behave as the documentation states. However, this is unlikely to lead to incorrect use in practice, as users will have to pass an argument initialMax (or initialMin), so in the process of understanding what this argument does, users should become aware of this mismatch themselves.

Recommendations

We recommend to update the documentation so that it matches the implementation.

Remediation

This issue has been acknowledged by Brevis, and a fix was implemented in commit df205d0e.

Zellic © 2025Back to top ↑