Skip to content

Commit

Permalink
Merge pull request #114 from kroma-network/dev
Browse files Browse the repository at this point in the history
feat: merge dev into main
  • Loading branch information
Pangssu authored Jun 3, 2024
2 parents 4aa06db + c71ef60 commit 1209a8e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 15 deletions.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ ARG BUILDNUM=""
# Build Geth in a stock Go builder container
FROM golang:1.21-alpine as builder

ARG VERSION

RUN apk add --no-cache gcc musl-dev linux-headers git

# Get dependencies - will also be cached if we won't change go.mod/go.sum
Expand All @@ -14,7 +16,7 @@ COPY go.sum /go-ethereum/
RUN cd /go-ethereum && go mod download

ADD . /go-ethereum
RUN cd /go-ethereum && go run build/ci.go install -static ./cmd/geth
RUN cd /go-ethereum && go run build/ci.go install -git-tag=$VERSION -static ./cmd/geth

# Pull Geth into a second stage deploy alpine container
FROM alpine:latest
Expand Down
13 changes: 2 additions & 11 deletions core/vm/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package vm

import (
"bytes"
"encoding/hex"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -272,6 +271,7 @@ func (l *StructLogger) CaptureState(pc uint64, op OpCode, gas, cost uint64, scop
// Copy a snapshot of the current memory state to a new buffer
if l.cfg.EnableMemory {
// [Scroll: START]
structlog.Memory = make([]byte, len(memory.Data()))
copy(structlog.Memory, memory.Data())
structlog.MemorySize = memory.Len()
// [Scroll: END]
Expand Down Expand Up @@ -321,6 +321,7 @@ func (l *StructLogger) CaptureState(pc uint64, op OpCode, gas, cost uint64, scop
// [Scroll: END]
if l.cfg.EnableReturnData {
// [Scroll: START]
structlog.ReturnData = make([]byte, len(rData))
copy(structlog.ReturnData, rData)
// [Scroll: END]
}
Expand Down Expand Up @@ -503,16 +504,6 @@ func (l *StructLogger) MaybeAddFeeRecipientsToStatesAffected(tx *types.Transacti
}
}

func (l *StructLogger) MaybeAddL1BlockInfo(tx *types.Transaction) {
if tx.To() == nil {
return
}
if contractAddress := *tx.To(); bytes.Equal(contractAddress[:], types.L1BlockAddr[:]) {
l.storage[contractAddress][types.OverheadSlot] = l.env.StateDB.GetState(contractAddress, types.OverheadSlot)
l.storage[contractAddress][types.ScalarSlot] = l.env.StateDB.GetState(contractAddress, types.ScalarSlot)
}
}

// WriteTrace writes a formatted trace to the given writer
// [Scroll: START]
func WriteTrace(writer io.Writer, logs []*StructLog) {
Expand Down
7 changes: 5 additions & 2 deletions core/vm/logger_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,18 @@ func (l *JSONLogger) CaptureState(pc uint64, op OpCode, gas, cost uint64, scope
}
if l.cfg.EnableMemory {
// [Scroll: START]
log.Memory = memory.Data()
log.Memory = make([]byte, len(memory.Data()))
copy(log.Memory, memory.Data())
log.MemorySize = memory.Len()
// [Scroll: END]
}
if !l.cfg.DisableStack {
log.Stack = stack.Data()
}
if l.cfg.EnableReturnData {
// [Scroll: START]
log.ReturnData = rData
log.ReturnData = make([]byte, len(rData))
copy(log.ReturnData, rData)
// [Scroll: END]
}
l.encoder.Encode(log)
Expand Down
1 change: 0 additions & 1 deletion eth/tracers/api_blocktrace.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ func (api *API) getTxResult(env *traceEnv, state *state.StateDB, index int, bloc
}

tracer.MaybeAddFeeRecipientsToStatesAffected(tx)
tracer.MaybeAddL1BlockInfo(tx)

// merge required proof data
proofAccounts := tracer.UpdatedAccounts()
Expand Down
10 changes: 10 additions & 0 deletions trie/zk/merkle_tree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,16 @@ func TestCanonicalValueWithKeyPreimage(t *testing.T) {
assertEqual(scrolLeaf.Value(), kromaLeaf.CanonicalValueWithKeyPreimage(scrolLeaf.NodeKey.Bytes()))
}

func TestCopyNode(t *testing.T) {
leaf := must(NewLeafNode([]byte("key"), []byte{1}))
leafCopy := copyNode(leaf).(*LeafNode)

leaf.Data()[0] = 10
if bytes.Equal(leaf.Data(), leafCopy.Data()) {
t.Errorf("shallow copy detected.")
}
}

func BenchmarkUpdateAndHash(b *testing.B) {
type testTree struct {
Update func(k, v []byte) error
Expand Down
15 changes: 15 additions & 0 deletions trie/zk/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ func copyNode(n TreeNode) TreeNode {
switch node := n.(type) {
case *ParentNode:
return &ParentNode{childL: copyNode(node.childL), childR: copyNode(node.childR), hash: node.hash}
case *LeafNode:
valuePreimages := make([]zkt.Byte32, len(node.ValuePreimage))
for i, value := range node.ValuePreimage {
valuePreimages[i] = *zkt.NewByte32FromBytes(value.Bytes())
}
var hash *zkt.Hash
if node.hash != nil {
hash = zkt.NewHashFromBytes(node.hash.Bytes())
}
return &LeafNode{
Key: common.CopyBytes(node.Key),
ValuePreimage: valuePreimages,
CompressedFlags: node.CompressedFlags,
hash: hash,
}
}
return n
}
Expand Down

0 comments on commit 1209a8e

Please sign in to comment.