Skip to content

Commit

Permalink
This commit trims the leading zeroes from an address for readability (#…
Browse files Browse the repository at this point in the history
…543)

Co-authored-by: anishnaik <[email protected]>
  • Loading branch information
priyankabose and anishnaik authored Jan 22, 2025
1 parent fdf3148 commit 31a41da
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion fuzzing/calls/call_sequence.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func (cse *CallSequenceElement) String() string {
cse.Call.GasLimit,
cse.Call.GasPrice.String(),
cse.Call.Value.String(),
cse.Call.From,
utils.TrimLeadingZeroesFromAddress(cse.Call.From.String()),
)
}

Expand Down
9 changes: 5 additions & 4 deletions fuzzing/executiontracer/execution_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/crytic/medusa/fuzzing/valuegeneration"
"github.com/crytic/medusa/logging"
"github.com/crytic/medusa/logging/colors"
"github.com/crytic/medusa/utils"
"github.com/ethereum/go-ethereum/accounts/abi"
coreTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
Expand Down Expand Up @@ -141,19 +142,19 @@ func (t *ExecutionTrace) generateCallFrameEnterElements(callFrame *CallFrame) ([
var callInfo string
if callFrame.IsProxyCall() {
if callFrame.ExecutedCode {
callInfo = fmt.Sprintf("%v -> %v.%v(%v) (addr=%v, code=%v, value=%v, sender=%v)", proxyContractName, codeContractName, methodName, *inputArgumentsDisplayText, callFrame.ToAddress.String(), callFrame.CodeAddress.String(), callFrame.CallValue, callFrame.SenderAddress.String())
callInfo = fmt.Sprintf("%v -> %v.%v(%v) (addr=%v, code=%v, value=%v, sender=%v)", proxyContractName, codeContractName, methodName, *inputArgumentsDisplayText, utils.TrimLeadingZeroesFromAddress(callFrame.ToAddress.String()), utils.TrimLeadingZeroesFromAddress(callFrame.CodeAddress.String()), callFrame.CallValue, utils.TrimLeadingZeroesFromAddress(callFrame.SenderAddress.String()))
} else {
callInfo = fmt.Sprintf("(addr=%v, value=%v, sender=%v)", callFrame.ToAddress.String(), callFrame.CallValue, callFrame.SenderAddress.String())
callInfo = fmt.Sprintf("(addr=%v, value=%v, sender=%v)", utils.TrimLeadingZeroesFromAddress(callFrame.ToAddress.String()), callFrame.CallValue, utils.TrimLeadingZeroesFromAddress(callFrame.SenderAddress.String()))
}
} else {
if callFrame.ExecutedCode {
if callFrame.ToAddress == chain.ConsoleLogContractAddress {
callInfo = fmt.Sprintf("%v.%v(%v)", codeContractName, methodName, *inputArgumentsDisplayText)
} else {
callInfo = fmt.Sprintf("%v.%v(%v) (addr=%v, value=%v, sender=%v)", codeContractName, methodName, *inputArgumentsDisplayText, callFrame.ToAddress.String(), callFrame.CallValue, callFrame.SenderAddress.String())
callInfo = fmt.Sprintf("%v.%v(%v) (addr=%v, value=%v, sender=%v)", codeContractName, methodName, *inputArgumentsDisplayText, utils.TrimLeadingZeroesFromAddress(callFrame.ToAddress.String()), callFrame.CallValue, utils.TrimLeadingZeroesFromAddress(callFrame.SenderAddress.String()))
}
} else {
callInfo = fmt.Sprintf("(addr=%v, value=%v, sender=%v)", callFrame.ToAddress.String(), callFrame.CallValue, callFrame.SenderAddress.String())
callInfo = fmt.Sprintf("(addr=%v, value=%v, sender=%v)", utils.TrimLeadingZeroesFromAddress(callFrame.ToAddress.String()), callFrame.CallValue, utils.TrimLeadingZeroesFromAddress(callFrame.SenderAddress.String()))
}
}

Expand Down
14 changes: 13 additions & 1 deletion utils/address_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package utils

import (
"encoding/hex"
"github.com/ethereum/go-ethereum/common"
"strings"

"github.com/ethereum/go-ethereum/common"
)

// HexStringToAddress converts a hex string (with or without the "0x" prefix) to a common.Address. Returns the parsed
Expand Down Expand Up @@ -45,3 +46,14 @@ func HexStringsToAddresses(addressHexStrings []string) ([]common.Address, error)
}
return addresses, nil
}

// TrimLeadingZeroesFromAddress removes the leading zeroes from an address for readability
// Example: sender=0x0000000000000000000000000000000000030000 becomes sender=0x30000 when shown on console
func TrimLeadingZeroesFromAddress(hexString string) string {
if strings.HasPrefix(hexString, "0x") {
// Retain "0x" and trim leading zeroes from the rest of the string
return "0x" + strings.TrimLeft(hexString[2:], "0")
}
// Trim leading zeroes if there's no "0x" prefix
return strings.TrimLeft(hexString, "0")
}

0 comments on commit 31a41da

Please sign in to comment.