Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): introduce preflight API for proving system #368

Draft
wants to merge 23 commits into
base: taiko
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d226b0c
feat(state): implement PreflightStateDB and TouchedAccounts for enhan…
johntaiko Jan 22, 2025
d404374
feat(taiko): add documentation for ProvingPreflights function
johntaiko Jan 22, 2025
5b421e6
feat(taiko): enhance ProvingPreflights with error handling and accoun…
johntaiko Jan 22, 2025
555af28
feat(taiko): enhance provingPreflights to initialize account proofs a…
johntaiko Jan 22, 2025
74972a1
feat(state): remove PreflightStateDB implementation to streamline sta…
johntaiko Jan 22, 2025
c38e3be
feat(taiko): refactor provingPreflights to enhance account proof retr…
johntaiko Jan 22, 2025
8a6cfa6
feat(taiko): refactor hash handling in provingPreflights for improved…
johntaiko Jan 22, 2025
b4fc8ca
fix(taiko): correct assignment of AncestorHashes in provingPreflights…
johntaiko Jan 22, 2025
8705c3a
refactor(state): simplify key retrieval in TouchedAccounts using maps…
johntaiko Jan 22, 2025
54e5744
docs(taiko): enhance comments in ProvingPreflights and provingPreflig…
johntaiko Jan 22, 2025
72694d2
feat(taiko): implement ApplyTransactionWithTimeout for transaction ex…
johntaiko Jan 22, 2025
8828c03
feat(taiko): integrate hash function wrapper into block context for t…
johntaiko Jan 22, 2025
f976df2
refactor(taiko): rename ApplyTransactionWithTimeout to ApplyTransacti…
johntaiko Jan 22, 2025
61962af
docs(taiko): improve comments in ApplyTransactionWithContext for clar…
johntaiko Jan 22, 2025
2633d05
refactor(taiko): remove ApplyTransactionWithContext and related apply…
johntaiko Jan 22, 2025
fa7801d
Update taiko_api.go
johntaiko Jan 22, 2025
dd4ecbf
refactor(taiko): update TouchedAccounts logic to include self-destruc…
johntaiko Jan 24, 2025
fb33230
refactor(taiko): streamline TestTouchedAccounts by consolidating acco…
johntaiko Jan 24, 2025
160e3dc
refactor(taiko): remove unnecessary blank line in TestTouchedAccounts…
johntaiko Jan 24, 2025
ac059ae
refactor(taiko): update provingPreflightResult to use common.Address …
johntaiko Jan 24, 2025
701116d
refactor(taiko): update Contracts map to use common.Address for impro…
johntaiko Jan 24, 2025
5deb506
refactor(taiko): modify ProvingPreflights to return results directly …
johntaiko Jan 24, 2025
3e40d89
Merge branch 'taiko' into feat/preflight
davidtaikocha Feb 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions core/state/taiko_statedb.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package state

import (
"github.com/ethereum/go-ethereum/common"
"golang.org/x/exp/maps"
)

// TouchedAccounts represents the storage of an account at a specific point in time.
type TouchedAccounts map[common.Address][]common.Hash

// TouchedAccounts returns a map of all touched accounts and their storage.
// Incudes self-destructed accounts, loaded accounts and new accounts exclude empty account.
func (s *StateDB) TouchedAccounts() TouchedAccounts {
touched := make(TouchedAccounts, len(s.stateObjects))
for addr, obj := range s.stateObjects {
touched[addr] = maps.Keys(obj.originStorage)
}
for addr, obj := range s.stateObjectsDestruct {
// ignore empty account because it won't affect the state
if !obj.empty() {
touched[addr] = maps.Keys(obj.originStorage)
}
}
return touched
}
56 changes: 56 additions & 0 deletions core/taiko_state_processor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package core

import (
"context"
"errors"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/params"
)

// ApplyTransactionWithContext applies a transaction to the current state with the given context.
// It converts the transaction to a message, creates a new EVM environment, and executes the transaction.
//
// Parameters:
// - ctx: The context to control the execution timeout and cancellation.
// - hashFuncWrapper: A function to wrap the block's GetHash function.
// - config: The chain configuration parameters.
// - bc: The blockchain context.
// - author: The address of the block author.
// - gp: The gas pool for the current block.
// - statedb: The state database.
// - header: The block header.
// - tx: The transaction to be applied.
// - usedGas: A pointer to the amount of gas used.
// - cfg: The EVM configuration.
//
// Returns:
// - *types.Receipt: The receipt of the transaction.
// - error: An error if the transaction could not be applied.
func ApplyTransactionWithContext(ctx context.Context, hashFuncWrapper func(vm.GetHashFunc) vm.GetHashFunc, config *params.ChainConfig, bc ChainContext, author *common.Address, gp *GasPool, statedb *state.StateDB, header *types.Header, tx *types.Transaction, usedGas *uint64, cfg vm.Config) (*types.Receipt, error) {
msg, err := TransactionToMessage(tx, types.MakeSigner(config, header.Number, header.Time), header.BaseFee)
if err != nil {
return nil, err
}
// CHANGE(taiko): decode the basefeeSharingPctg config from the extradata, and
// add it to the Message, if its an ontake block.
if config.IsOntake(header.Number) {
msg.BasefeeSharingPctg = DecodeOntakeExtraData(header.Extra)
}
// Create a new context to be used in the EVM environment
blockContext := NewEVMBlockContext(header, bc, author)
blockContext.GetHash = hashFuncWrapper(blockContext.GetHash)
txContext := NewEVMTxContext(msg)
vmenv := vm.NewEVM(blockContext, txContext, statedb, config, cfg)
go func() {
<-ctx.Done()
if errors.Is(ctx.Err(), context.DeadlineExceeded) {
// Stop evm execution. Note cancellation is not necessarily immediate.
vmenv.Cancel()
}
}()
return ApplyTransactionWithEVM(msg, config, gp, statedb, header.Number, header.Hash(), tx, usedGas, vmenv)
}
Loading
Loading