Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 0 additions & 4 deletions eth/tracers/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,6 @@ func (l *StructLogger) OnStorageChange(addr common.Address, slot common.Hash, pr
if l.interrupt.Load() {
return
}
// Processing a system call.
if l.skip {
return
}
// Initialize storage map for this address if not present
if l.storage[addr] == nil {
l.storage[addr] = make(Storage)
Expand Down
16 changes: 5 additions & 11 deletions rollup/fees/rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func TokenRate(state StateDB, tokenID uint16) (*big.Int, *big.Int, error) {
return nil, nil, err
}

if info.Scale == nil || info.Scale.Sign() == 0 {
log.Error("Invalid token scale", "tokenID", tokenID, "tokenAddr", info.TokenAddress.Hex())
}

// If token address is zero, this is not a valid token
if info.TokenAddress == (common.Address{}) {
log.Error("Invalid token address", "tokenID", tokenID)
Expand All @@ -32,17 +36,7 @@ func TokenRate(state StateDB, tokenID uint16) (*big.Int, *big.Int, error) {
return nil, nil, err
}

// Get scale from token info
scale, err := GetTokenScaleByIDWithState(state, tokenID)
if err != nil {
log.Error("Failed to get token scale", "tokenID", tokenID, "error", err)
return nil, nil, err
}
if scale == nil || scale.Sign() == 0 {
log.Error("Invalid token scale", "tokenID", tokenID, "tokenAddr", info.TokenAddress.Hex())
}

return rate, scale, err
return rate, info.Scale, err
}

func EthToAlt(state StateDB, tokenID uint16, amount *big.Int) (*big.Int, error) {
Expand Down
33 changes: 27 additions & 6 deletions rollup/tracing/tracing.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ func (env *TraceEnv) getTxResult(statedb *state.StateDB, index int, block *types
txStorageTrace.RootAfter = block.Root()
}

proofStorages := structLogger.UpdatedStorages()
// merge bytecodes
env.cMu.Lock()
for codeHash, codeInfo := range structLogger.TracedBytecodes() {
Expand All @@ -381,7 +382,6 @@ func (env *TraceEnv) getTxResult(statedb *state.StateDB, index int, block *types
if tx.Type() == types.AltFeeTxType && tx.FeeTokenID() != 0 {
tokenInfo, err := fees.GetTokenInfo(statedb, tx.FeeTokenID())
if err == nil && tokenInfo.TokenAddress != (common.Address{}) {

collectBytecode := func(addr common.Address) {
code := statedb.GetCode(addr)
keccakCodeHash := statedb.GetKeccakCodeHash(addr)
Expand All @@ -401,6 +401,31 @@ func (env *TraceEnv) getTxResult(statedb *state.StateDB, index int, block *types
}
collectBytecode(tokenInfo.TokenAddress)
collectBytecode(rcfg.L2TokenRegistryAddress)

if proofStorages[rcfg.L2TokenRegistryAddress] == nil {
proofStorages[rcfg.L2TokenRegistryAddress] = make(logger.Storage)
}

// Collect TokenInfo struct slots
baseSlot := fees.GetTokenInfoStructBaseSlot(tx.FeeTokenID())
log.Info("base slot", "base slot", baseSlot.String(), "token id", tx.FeeTokenID(), "token address", tokenInfo.TokenAddress.String())
registrySlots := []uint64{
0, // tokenAddress
1, // balanceSlot
2, // isActive + decimals (packed)
3, // scale
}
for _, offset := range registrySlots {
slot := fees.CalculateStructFieldSlot(baseSlot, offset)
log.Info("offset slot", "offset", offset, "slot", slot.String())
value := statedb.GetState(rcfg.L2TokenRegistryAddress, slot)
proofStorages[rcfg.L2TokenRegistryAddress][slot] = value
}

// Collect price ratio slot
priceRatioSlot := fees.CalculateUint16MappingSlot(tx.FeeTokenID(), rcfg.PriceRatioSlot)
priceRatioValue := statedb.GetState(rcfg.L2TokenRegistryAddress, priceRatioSlot)
proofStorages[rcfg.L2TokenRegistryAddress][priceRatioSlot] = priceRatioValue
}
}
env.cMu.Unlock()
Expand Down Expand Up @@ -440,7 +465,7 @@ func (env *TraceEnv) getTxResult(statedb *state.StateDB, index int, block *types
}

zkTrieBuildStart := time.Now()
proofStorages := structLogger.UpdatedStorages()

for addr, keys := range proofStorages {
if _, existed := txStorageTrace.StorageProofs[addr.String()]; !existed {
txStorageTrace.StorageProofs[addr.String()] = make(map[string][]hexutil.Bytes)
Expand Down Expand Up @@ -565,10 +590,6 @@ func (env *TraceEnv) fillBlockTrace(block *types.Block) (*types.BlockTrace, erro
},
rcfg.SequencerAddress: {rcfg.SequencerSetVerifyHashSlot},
rcfg.L2TokenRegistryAddress: {
rcfg.AllowListEnabledSlot,
rcfg.TokenRegistrySlot,
rcfg.TokenRegistrationSlot,
rcfg.PriceRatioSlot,
rcfg.AllowListSlot,
},
}
Expand Down