Files
linea-monorepo/prover/utils/utils_test.go
AlexandreBelling 7325f38c88 Prover: beta v1.2 integration changes (#692)
* bump go-corset

* fix compile errors

* constraints: bump to v0.1.0-rc1 for beta-v1.2

* bump to latest go-corset

* constraints: bump to beta-v1.2 / v0.1.0-rc2

* bump go-corset

* bump zkevm bin

* use next power of two value for non-power of two size columns (e.g., MMIO)

* remove a check for the power of two size

* bump corset to 9.7.18

* bump zkevm.bin

* bump corset to v9.7.18

* update zkevm.bin

* added interleaved to the compilediop columns

* adjusted size for corset columns

* Prover/Codehash Non Power of Two Column Size (#618)

* Revert "adjusted size for corset columns"

This reverts commit b1a7319fa586319a04ba57f421f10b55492124ff.

* fixed bug and added panic message for a non power of two size column

* removing panic

* reinsteaded the panic

---------

Co-authored-by: gusiri <dreamerty@postech.ac.kr>

* adjusted size for corset columns

* constraints: bump to beta v1.2/v0.1.0-rc3

* update constraints version to rc3

* bump to latest go-corset

* apply hotfix for BLOCKDATA

* move NextPowerOfTwo unit test to utils

* add logs for adjusted columns with non-power of two size

* turn off trace version check

* fix golangcli-lint

* Prover/fix public input timestamps from new blockdata (#644)

* updated timestamp fetcher and arithmetization mock data for unit testing.

* fix(codehash): uses 0x0 for the codehash of non-existing accounts instead of the default EOA codehash

* fix(mimccodehash): unimport the rom codehash for initialization code

* fixup(execDataHash): revert the exec-data hash check

* timestamp byte change

* fix(execdatahash): adds the real blockhash in the execdata hash instead of 0x0

* fixup previous commit

* fixup(build): removes imports

* Revert "fixup(execDataHash): revert the exec-data hash check"

This reverts commit eb8d984e13fab627a853dc98b2c94980a7eed0b3.

* fix(consistency): adds a smaller size to the consistency module

* feat(mimc): alex -- mimc simplification -- start

* optimize factorExpression

* feat(exec): uses the ProveCheck in the execution proof

* Revert "feat(mimc): alex -- mimc simplification -- start"

This reverts commit 184771b92746070dedb5ca356ed81f989a3daea5.

* fix (public-input): changed the hashing method to match compression

* perf(mem): adds a detector for constant regular column.

* fixup(mem): support the edge-case for smartvectors of size 1

* fix(codehash): support the case where the ROM is empty

* feat(csv): adds a feature to rename columns when using fmtcsv

* fixup(codehash): supports the case where no codehash are available

* test(codehash): adds test for empty rom or statesummary

* fix(ss-connect): skip the integration connector test

---------

Co-authored-by: gusiri <dreamerty@postech.ac.kr>
Co-authored-by: Soleimani193 <azam.soleimanian@ens.fr>
Co-authored-by: Arijit Dutta <37040536+arijitdutta67@users.noreply.github.com>
Co-authored-by: Bogdan Ursu <bogdanursuoffice@gmail.com>
2025-02-17 12:46:07 +01:00

78 lines
2.2 KiB
Go

package utils_test
import (
"fmt"
"testing"
"github.com/consensys/linea-monorepo/prover/utils"
"github.com/go-playground/assert/v2"
"github.com/stretchr/testify/require"
)
func TestDivCeil(t *testing.T) {
require.Equal(t, 1, utils.DivCeil(1, 10))
require.Equal(t, 1, utils.DivCeil(2, 10))
require.Equal(t, 1, utils.DivCeil(3, 10))
require.Equal(t, 1, utils.DivCeil(4, 10))
require.Equal(t, 1, utils.DivCeil(5, 10))
require.Equal(t, 1, utils.DivCeil(6, 10))
require.Equal(t, 1, utils.DivCeil(7, 10))
require.Equal(t, 1, utils.DivCeil(8, 10))
require.Equal(t, 1, utils.DivCeil(9, 10))
require.Equal(t, 1, utils.DivCeil(10, 10))
require.Equal(t, 2, utils.DivCeil(11, 10))
require.Equal(t, 2, utils.DivCeil(19, 10))
require.Equal(t, 2, utils.DivCeil(20, 10))
require.Equal(t, 3, utils.DivCeil(21, 10))
}
func TestIsPowerOfTwo(t *testing.T) {
require.Equal(t, true, utils.IsPowerOfTwo(4))
// The below negative number is the only one giving true if the constraint in
// IsPowerOfTwo were n != 0 instead of n > 0 (found by zkSecurity audit)
require.Equal(t, false, utils.IsPowerOfTwo(-9223372036854775808))
}
func TestNextPowerOfTwo(t *testing.T) {
require.Equal(t, 4, utils.NextPowerOfTwo(3))
// To Test the method with a power of two input,
// the output should be equal to the input
powTwoInp := 1 << 32
require.Equal(t, powTwoInp, utils.NextPowerOfTwo(powTwoInp))
// 2 ** 62 is the largest output of the method NextPowerOfTwo()
num := 1 << 61
num++
require.Equal(t, 1<<62, utils.NextPowerOfTwo(num))
// To check if the code panics if large values (e.g. val > 2 ** 62) are sent as input
largeNum := 1 << 62
largeNum++
require.PanicsWithValue(t, "input out of range", func() { utils.NextPowerOfTwo(largeNum) },
"NextPowerOfTwo should panic with 'Input is too large' message")
}
func TestNextPowerOfTwoExample(t *testing.T) {
tests := []struct {
input int
expected int
}{
{1, 1},
{2, 2},
{5, 8},
{12, 16},
{20, 32},
{33, 64},
{100, 128},
{255, 256},
{500, 512},
}
for _, test := range tests {
t.Run(fmt.Sprintf("NextPowerOfTwo(%d)", test.input), func(t *testing.T) {
result := utils.NextPowerOfTwo(test.input)
assert.Equal(t, test.expected, result)
})
}
}