Documentation ¶
Index ¶
- Constants
- func AssertShomeiAgree(t *testing.T, state State, traces [][]StateAccessLog)
- func InitShomeiState(state State) *statemanager.WorldState
- func MapKeysToSlice[K comparable, V any](accountSet map[K]V) []K
- func PrependDummyVector[T any](vector []T, fullLength int, currentLength int) []T
- func SampleTypeToString(sampleType int) string
- func StateLogsToShomeiTraces(shomeiState *statemanager.WorldState, logs [][]StateAccessLog) [][]statemanager.DecodedTrace
- type AccountHistory
- type AccountState
- type OperationType
- type State
- func (s State) DeepCopy() State
- func (s State) GetBalance(a types.EthAddress) *big.Int
- func (s State) GetCodeHash(a types.EthAddress) types.FullBytes32
- func (s State) GetCodeSize(a types.EthAddress) int64
- func (s State) GetMimcCodeHash(a types.EthAddress) types.Bytes32
- func (s State) GetNonce(a types.EthAddress) int64
- func (s State) GetStorage(a types.EthAddress, key types.FullBytes32) types.FullBytes32
- func (s State) InsertContract(a types.EthAddress, mimcCodeHash types.Bytes32, ...)
- func (s State) InsertEOA(a types.EthAddress, nonce int64, balance *big.Int)
- func (s State) SetBalance(a types.EthAddress, balance *big.Int)
- func (s State) SetCodeHash(a types.EthAddress, codeHash types.FullBytes32)
- func (s State) SetCodeSize(a types.EthAddress, codeSize int64)
- func (s State) SetMimcCodeHash(a types.EthAddress, codeHash types.Bytes32)
- func (s State) SetNonce(a types.EthAddress, nonce int64)
- func (s State) SetStorage(a types.EthAddress, key, value types.FullBytes32)
- type StateAccessLog
- type StateLogBuilder
- func (b *StateLogBuilder) Done() [][]StateAccessLog
- func (b *StateLogBuilder) EraseAccount() *StateLogBuilder
- func (b *StateLogBuilder) GoNextBlock() *StateLogBuilder
- func (b *StateLogBuilder) IncNonce() *StateLogBuilder
- func (b *StateLogBuilder) InitContract(codeSize int64, keccakCodeHash types.FullBytes32, mimcCodeHash types.Bytes32) *StateLogBuilder
- func (b *StateLogBuilder) InitEoa() *StateLogBuilder
- func (b *StateLogBuilder) ReadBalance() *StateLogBuilder
- func (b *StateLogBuilder) ReadCodeHash() *StateLogBuilder
- func (b *StateLogBuilder) ReadCodeSize() *StateLogBuilder
- func (b *StateLogBuilder) ReadNonce() *StateLogBuilder
- func (b *StateLogBuilder) ReadStorage(key types.FullBytes32) *StateLogBuilder
- func (b *StateLogBuilder) WithAddress(address types.EthAddress) *StateLogBuilder
- func (b *StateLogBuilder) WriteBalance(balance *big.Int) *StateLogBuilder
- func (b *StateLogBuilder) WriteStorage(key types.FullBytes32, value types.FullBytes32) *StateLogBuilder
- type StateManagerVectors
- type Stitcher
- type StorageHistory
Constants ¶
const ( GENERATE_ACP_SAMPLE int = 0 GENERATE_SCP_SAMPLE int = 1 )
Variables ¶
This section is empty.
Functions ¶
func AssertShomeiAgree ¶
func AssertShomeiAgree(t *testing.T, state State, traces [][]StateAccessLog)
AssertShomeiAgree obtains frames from a StateLogBuilder which was run on an initial state It then generates corresponding shomei traces from the frames using StateLogsToShomeiTraces it uses statemanager.CheckTraces to obtain a sequence of root hashes and checks whether the first root hash is corresponds to the hash of the initial state
func InitShomeiState ¶
func InitShomeiState(state State) *statemanager.WorldState
InitShomeiState initializes the state of a Shomei tree by applying the provided state. The shomei state is deterministically initialized. The accounts are initialized in alphabetical order of their addresses and the storage keys of each account are also initialized in alphabetical order.
func MapKeysToSlice ¶
func MapKeysToSlice[K comparable, V any](accountSet map[K]V) []K
MapKeysToSlice is an utility function that will output the key set as a slice this is necessary because we need to list the keys in the columns in a sorted manner. and in order to use the sort function we need a slice
func PrependDummyVector ¶
PrependDummyVector is used inside PadToNearestPowerOf2 to prepend the slices with zeroes in order for their length to be a power of two
func SampleTypeToString ¶
func StateLogsToShomeiTraces ¶
func StateLogsToShomeiTraces(shomeiState *statemanager.WorldState, logs [][]StateAccessLog) [][]statemanager.DecodedTrace
StateLogsToShomeiTraces applies the state logs to the given shomei state and returns the associated Shomei traces. The state logs are squashed by accounts blocks and by storage keys.
Types ¶
type AccountHistory ¶
type AccountHistory struct {
// contains filtered or unexported fields
}
AccountHistory contains the segments that describe the evolution of the Account the data is kept as field elements, and will be stitched together to form the columns of a StateManagerAccountColumns struct
func NewAccountHistory ¶
func NewAccountHistory() *AccountHistory
NewAccountHistory initializes a new account history where each column Exists but is empty
func (*AccountHistory) AddFrame ¶
func (accHistory *AccountHistory) AddFrame(frame StateAccessLog, initialState *State, address eth.Address) *AccountHistory
AddFrame uses the information inside a frame to add one more row in AccountHistory by appending one entry to each slice contained in AccountHistory
func (*AccountHistory) InitializeNewRow ¶
func (accHistory *AccountHistory) InitializeNewRow(currentBlock int, initialState *State, address eth.Address) *AccountHistory
InitializeNewRow creates a new cell in each column, which is initialized either with special values if this is the start of the AccountHistory otherwise the current row is initialized with the values of the previous row this simplified the process of adding a row, as most information is duplicated (for example during reads, or when writing only modifies a single value and the others remain unchanged) so we will duplicate and only make the changes for the few cells that must be changed
type AccountState ¶
type AccountState struct { Nonce int64 Balance *big.Int KeccakCodeHash types.FullBytes32 MimcCodeHash types.Bytes32 CodeSize int64 Storage map[types.FullBytes32]types.FullBytes32 DeploymentNumber int64 }
AccountState stores all the informations of an account in a basic fashion, it is meant to be used by the StateAccessFrame builder internally to initialize the state and keep track of the state.
type OperationType ¶
type OperationType int
OperationType specifies the part of an account that is touched by a state access. The 0 value corresponds to an invalid OperationType.
const ( // Storage denotes an access to the storage of an account Storage OperationType = iota + 1 // Balance denotes an access to the balance of an account Balance // Nonce denotes an access to the nonce of an account Nonce // CodeSize denotes an access to the code size of an account. Only for // read-only operations. Otherwise, it would be a deploy. Codesize // CodeHash denotes an access to the code hash of an account. Only for // read-only operations. Otherwise, it would be a deploy. Codehash // SquashedAccount denotes an summary of all the accesses made on an account // aside from its storage. This is meant to be used by the Shomei trace // generator. SquashedAccount // AccountErasal indicates that the account deleted from the state. This // happens at the end of a transaction calling selfdestruct when the account // was existing before the transaction or during a transaction when the // selfdestruct is called on an ephemeral account (i.e. an account created // by the same transaction). AccountErasal // AccountInit indicates that the account has been (re)deployed or simply // initialized. This can happen when CREATE or CREATE2 are called or when // a non-existing account receives a transfer. AccountInit )
type State ¶
type State map[types.EthAddress]*AccountState
State is a basic in-memory data-structure storing the state of the EVM. It is used to initialize and track the state of the EVM in our mock.
func (State) DeepCopy ¶
deepCopyState makes a hard copy of the state so that modifications of the copy will not affect the original state.
func (State) GetBalance ¶
func (s State) GetBalance(a types.EthAddress) *big.Int
GetBalance returns the balance of the account. Returns 0 if the account does not exist.
func (State) GetCodeHash ¶
func (s State) GetCodeHash(a types.EthAddress) types.FullBytes32
GetCodeHash returns the code hash of an account and zero if the account does not exist.
func (State) GetCodeSize ¶
func (s State) GetCodeSize(a types.EthAddress) int64
SetCodeSize returns the code size of an account and initializes the account to an empty value if it does not exist.
func (State) GetMimcCodeHash ¶
func (s State) GetMimcCodeHash(a types.EthAddress) types.Bytes32
GetMimcCodeHash returns the Mimc code hash of an account and zero if the account does not exist.
func (State) GetNonce ¶
func (s State) GetNonce(a types.EthAddress) int64
GetNonce returns the nonce of the account. Returns 0 if the account does not exists.
func (State) GetStorage ¶
func (s State) GetStorage(a types.EthAddress, key types.FullBytes32) types.FullBytes32
GetStorage returns a storage value for the given address and returns 0 if the account does not exist.
func (State) InsertContract ¶
func (s State) InsertContract(a types.EthAddress, mimcCodeHash types.Bytes32, keccakCodeHash types.FullBytes32, codeSize int64)
InsertContract inserts an empty contract into the account. The contract has empty storage and no balance
func (State) SetBalance ¶
func (s State) SetBalance(a types.EthAddress, balance *big.Int)
SetBalance initializes the balance of an account. If the account does not already exists, it will be initialized as empty.
func (State) SetCodeHash ¶
func (s State) SetCodeHash(a types.EthAddress, codeHash types.FullBytes32)
SetCodeHash initializes the keccak code hash of an account and initializes an empty account with the value. If the account does not already exist.
func (State) SetCodeSize ¶
func (s State) SetCodeSize(a types.EthAddress, codeSize int64)
SetCodeSize initializes the code size of an account and initializes the account to an empty value if it does not exist.
func (State) SetMimcCodeHash ¶
func (s State) SetMimcCodeHash(a types.EthAddress, codeHash types.Bytes32)
SetMimcCodeHash initializes the mimc code hash of an account and initializes an empty account with the value. If the account does not already exist.
func (State) SetNonce ¶
func (s State) SetNonce(a types.EthAddress, nonce int64)
SetNonce initializes the nonce of an account. If the account does not exists in the map it will be created.
func (State) SetStorage ¶
func (s State) SetStorage(a types.EthAddress, key, value types.FullBytes32)
SetCodeSize initializes the code size of an account and initializes the account to an empty value if it does not exist.
type StateAccessLog ¶
type StateAccessLog struct { // Address indicates the address of the account being accessed by the // current state log. Address types.EthAddress // Block indicates the block in which the access takes place. Block int // Type adds information about which part of the account is being accessed // or the type of access. Type OperationType // Key is only used for storage accesses and indicates the storage key // being accessed. Key types.FullBytes32 // Value contains the "read" value if the log is a read-only log or the // new value if the log is write operation. Value any // OldValue is used only for write operations and indicates the value // of the accessed state item prior to being updated. OldValue any // IsWrite tells whether the logged state access is a write operation or // a read-only operation. IsWrite bool // false means read }
StateAccessLog represents an atomic operation over an account, the operation can relate to the account itself or to the storage of the account. Stacking StateAccessLog in a slice allows representing a succession of operation on the state of Ethereum. However, this is different from a sequence of EVM opcode: StateAccessLog have to be understood as "immediately" effective while EVM opcodes can have deferred effect on the state.
An example of these two being differents is that self-destruct does not immediately remove the account from the state if the account pre-existed the transaction.
type StateLogBuilder ¶
type StateLogBuilder struct {
// contains filtered or unexported fields
}
StateLogBuilder is a utility tool to construct sequences StateAccessLog spanning across several blocks and account. It is meant to be used to generate mocked shomei and arithmetization traces
@alex: add wayyyyy more doc
func NewStateLogBuilder ¶
func NewStateLogBuilder(currentBlock int, initialState State) *StateLogBuilder
NewStateLogBuilder creates a StateLogBuilder that is ready to be used. The returned object still needs to be given a "current" account to work on. For this reason, the Builder should call [WithAddress] immediately after being initialized.
func (*StateLogBuilder) Done ¶
func (b *StateLogBuilder) Done() [][]StateAccessLog
Done returns the state frames built so far.
func (*StateLogBuilder) EraseAccount ¶
func (b *StateLogBuilder) EraseAccount() *StateLogBuilder
EraseAccount instructs the StateFrameBuilder to generate a frame for erasing the account. Its use-case are, either at the end of a SELFDESTRUCT calling transaction when the account pre-existed or during the transaction if the account is transient.
func (*StateLogBuilder) GoNextBlock ¶
func (b *StateLogBuilder) GoNextBlock() *StateLogBuilder
GoNextBlock tells the StateFrameBuilder that the traces coming next belong to a new block.
func (*StateLogBuilder) IncNonce ¶
func (b *StateLogBuilder) IncNonce() *StateLogBuilder
IncNonce instructs the StateFrameBuilder to generate a frame representing the incrementation of the nonce.
func (*StateLogBuilder) InitContract ¶
func (b *StateLogBuilder) InitContract(codeSize int64, keccakCodeHash types.FullBytes32, mimcCodeHash types.Bytes32) *StateLogBuilder
Create instructs the StateFrameBuilder that a new contract was deployed to the current address.
func (*StateLogBuilder) InitEoa ¶
func (b *StateLogBuilder) InitEoa() *StateLogBuilder
SetNoCode initializes an EOA with no balance and a nonce of zero. This is a short-hand for "Deploy" with no code.
func (*StateLogBuilder) ReadBalance ¶
func (b *StateLogBuilder) ReadBalance() *StateLogBuilder
ReadBalance instruct the StateFrameBuilder to generate a frame representing an account balance read access.
func (*StateLogBuilder) ReadCodeHash ¶
func (b *StateLogBuilder) ReadCodeHash() *StateLogBuilder
ReadCodeHash instructs the StateFrameBuilder to generate a frame for reading the (keccak) code hash of the current contract.
func (*StateLogBuilder) ReadCodeSize ¶
func (b *StateLogBuilder) ReadCodeSize() *StateLogBuilder
ReadCodeSize instructs the StateFrameBuilder to generate a frame for reading the codesize of the current contract.
func (*StateLogBuilder) ReadNonce ¶
func (b *StateLogBuilder) ReadNonce() *StateLogBuilder
ReadNonce instructs the StateFrameBuilder to generate a frame representing the read of the nonce of the current account.
func (*StateLogBuilder) ReadStorage ¶
func (b *StateLogBuilder) ReadStorage(key types.FullBytes32) *StateLogBuilder
ReadStorage generates StateAccessLog corresponding to a SLOAD in the current account and the current block.
func (*StateLogBuilder) WithAddress ¶
func (b *StateLogBuilder) WithAddress(address types.EthAddress) *StateLogBuilder
WithAddress specifies in which account the StateLogBuilder must generate the following StateAccessLogs. Meaning, to what account will the next logs be operating on.
func (*StateLogBuilder) WriteBalance ¶
func (b *StateLogBuilder) WriteBalance(balance *big.Int) *StateLogBuilder
WriteBalance instructs the StateFrameBuilder to generate a frame representing a update the balance of an account. This panics over a negative value.
func (*StateLogBuilder) WriteStorage ¶
func (b *StateLogBuilder) WriteStorage(key types.FullBytes32, value types.FullBytes32) *StateLogBuilder
WriteStorage generates a new StateAccessLog corresponding to an SSTORE in the current account.
type StateManagerVectors ¶
type StateManagerVectors struct { // account data Address []eth.Address // helper column AddressHI, AddressLO []field.Element Nonce, NonceNew []field.Element MimcCodeHash, MimcCodeHashNew []field.Element CodeHashHI, CodeHashLO, CodeHashHINew, CodeHashLONew []field.Element CodeSizeOld, CodeSizeNew []field.Element BalanceOld, BalanceNew []field.Element // storage data KeyHI, KeyLO []field.Element ValueHICurr, ValueLOCurr, ValueHINext, ValueLONext []field.Element // helper numbers DeploymentNumber, DeploymentNumberInf []field.Element BlockNumber []field.Element // helper columns Exists, ExistsNew []field.Element PeekAtAccount []field.Element PeekAtStorage []field.Element // first and last marker columns FirstAOC, LastAOC []field.Element FirstKOC, LastKOC []field.Element // block markers FirstAOCBlock, LastAOCBlock []field.Element FirstKOCBlock, LastKOCBlock []field.Element MinDeploymentBlock, MaxDeploymentBlock []field.Element }
StateManagerVectors contains all the arithmetization columns needed for the state management at the account and storage levels (all these columns belong to the HUB module in the arithmetization) these slices will be at a later point be transformed into corresponding ifaces.Column() structs
func NewStateManagerVectors ¶
func NewStateManagerVectors() *StateManagerVectors
NewStateManagerVectors will initialize a StateManagerVectors struct, where the containing slices are initialized but are empty
func (*StateManagerVectors) PadToNearestPowerOf2 ¶
func (stateManagerVectors *StateManagerVectors) PadToNearestPowerOf2()
PadToNearestPowerOf2 will pad all the vectors with zeroes so that their length becomes a power of two and they can be transformed into iColumn structs
func (*StateManagerVectors) Size ¶
func (smv *StateManagerVectors) Size() int
type Stitcher ¶
type Stitcher struct {
// contains filtered or unexported fields
}
The Stitcher constructs the vector slices of field.Element that will correspond to the HUB columns it will store every AccountHistory which appears in the columns, and manages that using a map
func (*Stitcher) AddFrame ¶
func (stitcher *Stitcher) AddFrame(frame StateAccessLog)
func (*Stitcher) Finalize ¶
func (stitcher *Stitcher) Finalize(sampleType int) *StateManagerVectors
Finalize uses the information in the AccountHistory structs that are stored inside the Stitcher and concatenates these vectors AccountHistory contains multiple StorageHistory, one for each storage key that ever gets accessed. Finalize also adds the information in StorageHistory to the concatenated vectors. The final result is padded so that the length of the columns is a power of 2.
type StorageHistory ¶
type StorageHistory struct {
// contains filtered or unexported fields
}
StorageHistory contains column segments that describe the storage evolution for a specific key the KeyHI, KeyLO values are always the same and will be used for stitching
func NewStorageHistory ¶
func NewStorageHistory() *StorageHistory
NewStorageHistory contains the history of storage accesses, where each row corresponds to a storage access
func (*StorageHistory) AddFrame ¶
func (stoHistory *StorageHistory) AddFrame(frame StateAccessLog, currentDeploymentNo int, currentExistence int) *StorageHistory
AddFrame uses the information inside a frame to create a new row in the StorageHistory, by adding one entry to each column currentExistence is derived from the accountHistory and is used to compute the Exists and ExistsNew columns currentDeploymentNumber is derived from the accountHistory and will be used to compute the deployment number