Skip to main content
Version: v2.0_alpha

LazyIMTData

A struct that holds a LazyIMT data

struct LazyIMTData {
uint40 maxIndex;
uint40 numberOfLeaves;
mapping(uint256 => uint256) elements;
}

DefaultZeroBadIndex

error DefaultZeroBadIndex()

Custom errors

DepthTooLarge

error DepthTooLarge()

DepthCannotBeZero

error DepthCannotBeZero()

NumberOfLeavesCannotBeZero

error NumberOfLeavesCannotBeZero()

AmbiguousDepth

error AmbiguousDepth()

InternalLazyIMT

This implementation is taken from zk-kit https://github.com/privacy-scaling-explorations/zk-kit/blob/main/packages/imt.sol/contracts/internal/InternalLazyIMT.sol and modified to work with MACI.

A LazyIMT with Zeroes value set to the hash of a MACI Blank State Leaf

MAX_DEPTH

uint256 MAX_DEPTH

MAX_INDEX

uint40 MAX_INDEX

Z_0

uint256 Z_0

Z_1

uint256 Z_1

Z_2

uint256 Z_2

Z_3

uint256 Z_3

Z_4

uint256 Z_4

Z_5

uint256 Z_5

Z_6

uint256 Z_6

Z_7

uint256 Z_7

Z_8

uint256 Z_8

Z_9

uint256 Z_9

Z_10

uint256 Z_10

Z_11

uint256 Z_11

Z_12

uint256 Z_12

Z_13

uint256 Z_13

Z_14

uint256 Z_14

Z_15

uint256 Z_15

Z_16

uint256 Z_16

Z_17

uint256 Z_17

Z_18

uint256 Z_18

Z_19

uint256 Z_19

Z_20

uint256 Z_20

Z_21

uint256 Z_21

Z_22

uint256 Z_22

Z_23

uint256 Z_23

Z_24

uint256 Z_24

Z_25

uint256 Z_25

Z_26

uint256 Z_26

Z_27

uint256 Z_27

Z_28

uint256 Z_28

Z_29

uint256 Z_29

Z_30

uint256 Z_30

Z_31

uint256 Z_31

Z_32

uint256 Z_32

_defaultZero

function _defaultZero(uint8 index) internal pure returns (uint256)

Returns the default zero value for a given index

Parameters

NameTypeDescription
indexuint8The index of the zero value

Return Values

NameTypeDescription
[0]uint256The zero value

_init

function _init(struct LazyIMTData self, uint8 depth) internal

Initializes the LazyIMT

Parameters

NameTypeDescription
selfstruct LazyIMTDataThe LazyIMTData
depthuint8The depth of the tree

_indexForElement

function _indexForElement(uint8 level, uint40 index) internal pure returns (uint40)

Returns the index for a given level and index

Parameters

NameTypeDescription
leveluint8The level
indexuint40The index

Return Values

NameTypeDescription
[0]uint40The index for the element

_insert

function _insert(struct LazyIMTData self, uint256 leaf) internal

Inserts a leaf into the LazyIMT

Parameters

NameTypeDescription
selfstruct LazyIMTDataThe LazyIMTData
leafuint256The leaf to insert

_root

function _root(struct LazyIMTData self) internal view returns (uint256)

Returns the root of the LazyIMT

Parameters

NameTypeDescription
selfstruct LazyIMTDataThe LazyIMTData

Return Values

NameTypeDescription
[0]uint256The root of the LazyIMT

_root

function _root(struct LazyIMTData self, uint40 numberOfLeaves, uint8 depth) internal view returns (uint256)

Returns the root of the LazyIMT

Here it's assumed that the depth value is valid. If it is either 0 or > 2^8-1 this function will panic.

Parameters

NameTypeDescription
selfstruct LazyIMTDataThe LazyIMTData
numberOfLeavesuint40The number of leaves
depthuint8The depth of the tree

Return Values

NameTypeDescription
[0]uint256The root of the LazyIMT

_levels

function _levels(struct LazyIMTData self, uint40 numberOfLeaves, uint8 depth, uint256[] levels) internal view

Updates the levels of the LazyIMT

Parameters

NameTypeDescription
selfstruct LazyIMTDataThe LazyIMTData
numberOfLeavesuint40The number of leaves
depthuint8The depth of the tree
levelsuint256[]The levels of the tree