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
12 changes: 6 additions & 6 deletions execution/abi/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty
fields []reflect.StructField
elems []*Type
names []string
expression string // canonical parameter expression
expression strings.Builder // canonical parameter expression
)
expression += "("
expression.WriteString("(")
overloadedNames := make(map[string]string)
for idx, c := range components {
cType, err := NewType(c.Type, c.InternalType, c.Components)
Expand All @@ -185,18 +185,18 @@ func NewType(t string, internalType string, components []ArgumentMarshaling) (ty
})
elems = append(elems, &cType)
names = append(names, c.Name)
expression += cType.stringKind
expression.WriteString(cType.stringKind)
if idx != len(components)-1 {
expression += ","
expression.WriteString(",")
}
}
expression += ")"
expression.WriteString(")")

typ.TupleType = reflect.StructOf(fields)
typ.TupleElems = elems
typ.TupleRawNames = names
typ.T = TupleTy
typ.stringKind = expression
typ.stringKind = expression.String()

const structPrefix = "struct "
// After solidity 0.5.10, a new field of abi "internalType"
Expand Down
10 changes: 6 additions & 4 deletions execution/commitment/trie/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"encoding/hex"
"fmt"
"io"
"strings"

"github.com/erigontech/erigon/common"
)
Expand Down Expand Up @@ -59,15 +60,16 @@ func (t *Trie) PrintDiff(t2 *Trie, w io.Writer) {
}

func (n *FullNode) fstring(ind string) string {
resp := fmt.Sprintf("full\n%s ", ind)
var resp strings.Builder
resp.WriteString(fmt.Sprintf("full\n%s ", ind))
for i, node := range &n.Children {
if node == nil {
resp += indices[i] + ": <nil> "
resp.WriteString(indices[i] + ": <nil> ")
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String concatenation (indices[i] + \": <nil> \") defeats the purpose of using strings.Builder. Use resp.WriteString(indices[i]) followed by resp.WriteString(\": <nil> \") to avoid intermediate string allocation.

Suggested change
resp.WriteString(indices[i] + ": <nil> ")
resp.WriteString(indices[i])
resp.WriteString(": <nil> ")

Copilot uses AI. Check for mistakes.
} else {
resp += indices[i] + ": " + node.fstring(ind+" ")
resp.WriteString(indices[i] + ": " + node.fstring(ind+" "))
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple string concatenations (indices[i] + \": \" + node.fstring(...) and ind+\" \") create intermediate allocations. Split into separate WriteString calls: resp.WriteString(indices[i]), resp.WriteString(\": \"), resp.WriteString(node.fstring(ind+\" \")). Consider also passing a strings.Builder to fstring to avoid the inner concatenation ind+\" \".

Copilot uses AI. Check for mistakes.
}
}
return resp + "\n" + ind + "]"
return resp.String() + "\n" + ind + "]"
}
func (n *FullNode) print(w io.Writer) {
fmt.Fprintf(w, "f(")
Expand Down
7 changes: 4 additions & 3 deletions execution/protocol/block_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"encoding/json"
"fmt"
"slices"
"strings"
"time"

"golang.org/x/crypto/sha3"
Expand Down Expand Up @@ -400,13 +401,13 @@ var alwaysSkipReceiptCheck = dbg.EnvBool("EXEC_SKIP_RECEIPT_CHECK", false)

func BlockPostValidation(gasUsed, blobGasUsed uint64, checkReceipts bool, receipts types.Receipts, h *types.Header, isMining bool, txns types.Transactions, chainConfig *chain.Config, logger log.Logger) error {
if gasUsed != h.GasUsed {
var txgas string
var txgas strings.Builder
sep := ""
for _, receipt := range receipts {
txgas += fmt.Sprintf("%s%d=%d", sep, receipt.TransactionIndex, receipt.GasUsed)
txgas.WriteString(fmt.Sprintf("%s%d=%d", sep, receipt.TransactionIndex, receipt.GasUsed))
sep = ", "
}
logger.Warn("gas used mismatch", "block", h.Number.Uint64(), "header", h.GasUsed, "execution", gasUsed, "txgas", txgas)
logger.Warn("gas used mismatch", "block", h.Number.Uint64(), "header", h.GasUsed, "execution", gasUsed, "txgas", txgas.String())
return fmt.Errorf("gas used by execution: %d, in header: %d, headerNum=%d, %x",
gasUsed, h.GasUsed, h.Number.Uint64(), h.Hash())
}
Expand Down
8 changes: 4 additions & 4 deletions execution/vm/asm/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,16 @@ func (c *Compiler) Compile() (string, []error) {
}

// turn the binary to hex
var bin string
var bin strings.Builder
for _, v := range c.binary {
switch v := v.(type) {
case vm.OpCode:
bin += hex.EncodeToString([]byte{byte(v)})
bin.WriteString(hex.EncodeToString([]byte{byte(v)}))
case []byte:
bin += hex.EncodeToString(v)
bin.WriteString(hex.EncodeToString(v))
}
}
return bin, errors
return bin.String(), errors
}

// next returns the next token and increments the
Expand Down
17 changes: 10 additions & 7 deletions execution/vm/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package vm

import (
"fmt"
"strings"
"testing"

"github.com/holiman/uint256"
Expand Down Expand Up @@ -273,16 +274,17 @@ func TestReadonlyBasicCases(t *testing.T) {
copy(isEVMSliceTest, testCase.readonlySliceTest)
evmsTest[i].emvs = isEVMSliceTest

suffix := "-isEVMSliceTest"
var suffix strings.Builder
suffix.WriteString("-isEVMSliceTest")
for _, evmParam := range testCase.readonlySliceTest {
if evmParam {
suffix += "-true"
suffix.WriteString("-true")
} else {
suffix += "-false"
suffix.WriteString("-false")
}
}

evmsTest[i].suffix = suffix
evmsTest[i].suffix = suffix.String()
}

for _, testCase := range cases {
Expand Down Expand Up @@ -425,9 +427,10 @@ func (st *testSequential) Run(_ *Contract, _ []byte, _ bool) ([]byte, uint64, er
}

func trace(isEVMSlice []bool, readOnlySlice []*readOnlyState) string {
res := "trace:\n"
var res strings.Builder
res.WriteString("trace:\n")
for i := 0; i < len(isEVMSlice); i++ {
res += fmt.Sprintf("%d: EVM %t, readonly %t\n", i, isEVMSlice[i], readOnlySlice[i].in)
res.WriteString(fmt.Sprintf("%d: EVM %t, readonly %t\n", i, isEVMSlice[i], readOnlySlice[i].in))
}
return res
return res.String()
}
Loading