Skip to content

Commit

Permalink
Switch common.Hex2Bytes to common.FromHex (ethereum-optimism#9283)
Browse files Browse the repository at this point in the history
  • Loading branch information
trianglesphere authored Jan 31, 2024
1 parent 5eacf43 commit 6de6b5f
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 35 deletions.
10 changes: 5 additions & 5 deletions op-chain-ops/deployer/deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,31 @@ func TestCreate2Address(t *testing.T) {
{
name: "SafeL2",
creatorAddress: common.HexToAddress("0x4e59b44847b379578588920cA78FbF26c0B4956C").Bytes(),
salt: common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000"),
salt: common.FromHex("0000000000000000000000000000000000000000000000000000000000000000"),
expectedAddress: common.HexToAddress("0x3E5c63644E683549055b9Be8653de26E0B4CD36E"),
},
{
name: "MultiSendCallOnly",
creatorAddress: common.HexToAddress("0x4e59b44847b379578588920cA78FbF26c0B4956C").Bytes(),
salt: common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000"),
salt: common.FromHex("0000000000000000000000000000000000000000000000000000000000000000"),
expectedAddress: common.HexToAddress("0x40A2aCCbd92BCA938b02010E17A5b8929b49130D"),
},
{
name: "MultiSend",
creatorAddress: common.HexToAddress("0x4e59b44847b379578588920cA78FbF26c0B4956C").Bytes(),
salt: common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000"),
salt: common.FromHex("0000000000000000000000000000000000000000000000000000000000000000"),
expectedAddress: common.HexToAddress("0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761"),
},
{
name: "Permit2",
creatorAddress: common.HexToAddress("0x4e59b44847b379578588920cA78FbF26c0B4956C").Bytes(),
salt: common.Hex2Bytes("0000000000000000000000000000000000000000d3af2663da51c10215000000"),
salt: common.FromHex("0000000000000000000000000000000000000000d3af2663da51c10215000000"),
expectedAddress: common.HexToAddress("0x000000000022D473030F116dDEE9F6B43aC78BA3"),
},
{
name: "EntryPoint",
creatorAddress: common.HexToAddress("0x4e59b44847b379578588920cA78FbF26c0B4956C").Bytes(),
salt: common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000000"),
salt: common.FromHex("0000000000000000000000000000000000000000000000000000000000000000"),
expectedAddress: common.HexToAddress("0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789"),
},
}
Expand Down
10 changes: 5 additions & 5 deletions op-chain-ops/deployer/testdata.go

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions op-challenger/game/fault/preimages/large_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,31 @@ func TestLargePreimageUploader_NewUUID(t *testing.T) {
{
name: "EmptyOracleData",
data: &types.PreimageOracleData{},
expectedUUID: new(big.Int).SetBytes(common.Hex2Bytes("827b659bbda2a0bdecce2c91b8b68462545758f3eba2dbefef18e0daf84f5ccd")),
expectedUUID: new(big.Int).SetBytes(common.FromHex("827b659bbda2a0bdecce2c91b8b68462545758f3eba2dbefef18e0daf84f5ccd")),
},
{
name: "OracleDataAndOffset_Control",
data: &types.PreimageOracleData{
OracleData: []byte{1, 2, 3},
OracleOffset: 0x010203,
},
expectedUUID: new(big.Int).SetBytes(common.Hex2Bytes("641e230bcf3ade8c71b7e591d210184cdb190e853f61ba59a1411c3b7aca9890")),
expectedUUID: new(big.Int).SetBytes(common.FromHex("641e230bcf3ade8c71b7e591d210184cdb190e853f61ba59a1411c3b7aca9890")),
},
{
name: "OracleDataAndOffset_DifferentOffset",
data: &types.PreimageOracleData{
OracleData: []byte{1, 2, 3},
OracleOffset: 0x010204,
},
expectedUUID: new(big.Int).SetBytes(common.Hex2Bytes("aec56de44401325420e5793f72b777e3e547778de7d8344004b31be086a3136d")),
expectedUUID: new(big.Int).SetBytes(common.FromHex("aec56de44401325420e5793f72b777e3e547778de7d8344004b31be086a3136d")),
},
{
name: "OracleDataAndOffset_DifferentData",
data: &types.PreimageOracleData{
OracleData: []byte{1, 2, 3, 4},
OracleOffset: 0x010203,
},
expectedUUID: new(big.Int).SetBytes(common.Hex2Bytes("ca38aa17d56805cf26376a050c2c7b15b6be4e709bc422a1c679fe21aa6aa8c7")),
expectedUUID: new(big.Int).SetBytes(common.FromHex("ca38aa17d56805cf26376a050c2c7b15b6be4e709bc422a1c679fe21aa6aa8c7")),
},
}

Expand Down
2 changes: 1 addition & 1 deletion op-challenger/game/fault/trace/alphabet/prestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
)

var absolutePrestate = common.Hex2Bytes("0000000000000000000000000000000000000000000000000000000000000060")
var absolutePrestate = common.FromHex("0000000000000000000000000000000000000000000000000000000000000060")
var absolutePrestateInt = new(big.Int).SetBytes(absolutePrestate)

var _ types.PrestateProvider = (*AlphabetPrestateProvider)(nil)
Expand Down
8 changes: 4 additions & 4 deletions op-challenger/game/fault/trace/cannon/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ func TestGetStepData(t *testing.T) {
provider, generator := setupWithTestData(t, dataDir, prestate)
value, proof, data, err := provider.GetStepData(context.Background(), PositionFromTraceIndex(provider, new(big.Int)))
require.NoError(t, err)
expected := common.Hex2Bytes("b8f068de604c85ea0e2acd437cdb47add074a2d70b81d018390c504b71fe26f400000000000000000000000000000000000000000000000000000000000000000000000000")
expected := common.FromHex("b8f068de604c85ea0e2acd437cdb47add074a2d70b81d018390c504b71fe26f400000000000000000000000000000000000000000000000000000000000000000000000000")
require.Equal(t, expected, value)
expectedProof := common.Hex2Bytes("08028e3c0000000000000000000000003c01000a24210b7c00200008000000008fa40004")
expectedProof := common.FromHex("08028e3c0000000000000000000000003c01000a24210b7c00200008000000008fa40004")
require.Equal(t, expectedProof, proof)
// TODO: Need to add some oracle data
require.Nil(t, data)
Expand Down Expand Up @@ -207,9 +207,9 @@ func TestGetStepData(t *testing.T) {
provider, generator := setupWithTestData(t, dataDir, prestate)
value, proof, data, err := provider.GetStepData(context.Background(), PositionFromTraceIndex(provider, big.NewInt(2)))
require.NoError(t, err)
expected := common.Hex2Bytes("cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc")
expected := common.FromHex("cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc")
require.Equal(t, expected, value)
expectedProof := common.Hex2Bytes("dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd")
expectedProof := common.FromHex("dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd")
require.Equal(t, expectedProof, proof)
require.Empty(t, generator.generated)
require.Nil(t, data)
Expand Down
8 changes: 4 additions & 4 deletions op-challenger/game/fault/trace/outputs/split_adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,23 +167,23 @@ func TestCreateLocalContext(t *testing.T) {
prePosition: types.NewPositionFromGIndex(big.NewInt(2)),
postValue: common.HexToHash("cc00000000000000000000000000000000000000000000000000000000000000"),
postPosition: types.NewPositionFromGIndex(big.NewInt(3)),
expected: common.Hex2Bytes("abcdef0123456789abcdef0123456789abcdef0123456789abcdef01234567890000000000000000000000000000000000000000000000000000000000000002cc000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003"),
expected: common.FromHex("abcdef0123456789abcdef0123456789abcdef0123456789abcdef01234567890000000000000000000000000000000000000000000000000000000000000002cc000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003"),
},
{
name: "LargePositions",
preValue: common.HexToHash("abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789"),
prePosition: types.NewPositionFromGIndex(new(big.Int).SetBytes(common.Hex2Bytes("cbcdef0123456789abcdef0123456789abcdef0123456789abcdef012345678c"))),
prePosition: types.NewPositionFromGIndex(new(big.Int).SetBytes(common.FromHex("cbcdef0123456789abcdef0123456789abcdef0123456789abcdef012345678c"))),
postValue: common.HexToHash("dd00000000000000000000000000000000000000000000000000000000000000"),
postPosition: types.NewPositionFromGIndex(new(big.Int).SetUint64(math.MaxUint64)),
expected: common.Hex2Bytes("abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789cbcdef0123456789abcdef0123456789abcdef0123456789abcdef012345678cdd00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffff"),
expected: common.FromHex("abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789cbcdef0123456789abcdef0123456789abcdef0123456789abcdef012345678cdd00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffff"),
},
{
name: "AbsolutePreState",
preValue: common.Hash{},
prePosition: types.Position{},
postValue: common.HexToHash("cc00000000000000000000000000000000000000000000000000000000000000"),
postPosition: types.NewPositionFromGIndex(big.NewInt(3)),
expected: common.Hex2Bytes("cc000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003"),
expected: common.FromHex("cc000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003"),
},
}

Expand Down
2 changes: 1 addition & 1 deletion op-challenger/game/keccak/matrix/matrix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestStateCommitment(t *testing.T) {
t.Run("", func(t *testing.T) {
state := NewStateMatrix()
copy(state.s.a[:], test.matrix)
expected := crypto.Keccak256Hash(common.Hex2Bytes(test.expectedPacked))
expected := crypto.Keccak256Hash(common.FromHex(test.expectedPacked))
actual := state.StateCommitment()
require.Equal(t, test.expectedPacked, common.Bytes2Hex(state.StateSnapshot().Pack()))
require.Equal(t, expected, actual)
Expand Down
4 changes: 2 additions & 2 deletions op-service/eth/ssz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,11 @@ func createPayloadWithWithdrawals(w *types.Withdrawals) *ExecutionPayload {
GasLimit: Uint64Quantity(333),
GasUsed: Uint64Quantity(444),
Timestamp: Uint64Quantity(555),
ExtraData: common.Hex2Bytes("6666"),
ExtraData: common.FromHex("6666"),
BaseFeePerGas: *uint256.NewInt(777),
BlockHash: common.HexToHash("0x888"),
Withdrawals: w,
Transactions: []Data{common.Hex2Bytes("9999")},
Transactions: []Data{common.FromHex("9999")},
}
}

Expand Down
12 changes: 6 additions & 6 deletions op-service/sources/receipts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func TestVerifyReceipts(t *testing.T) {
Type: 2,
Status: 0,
CumulativeGasUsed: 0x3035b,
Bloom: types.BytesToBloom(common.Hex2Bytes("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")),
Bloom: types.BytesToBloom(common.FromHex("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")),
Logs: nil,
TxHash: txHashes[0],
GasUsed: 0x3035b,
Expand All @@ -369,7 +369,7 @@ func TestVerifyReceipts(t *testing.T) {
Type: 2,
Status: 1,
CumulativeGasUsed: 0xa9ae4,
Bloom: types.BytesToBloom(common.Hex2Bytes("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")),
Bloom: types.BytesToBloom(common.FromHex("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")),
Logs: nil,
TxHash: txHashes[1],
GasUsed: 0x79789,
Expand All @@ -382,7 +382,7 @@ func TestVerifyReceipts(t *testing.T) {
Type: 0,
Status: 1,
CumulativeGasUsed: 0x101f09,
Bloom: types.BytesToBloom(common.Hex2Bytes("00000000000000000000000000000200000400000000000000000000000000800000000000040000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002002000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000800000000000000000000000000000000000000000000000000000400000000000000020000000000000000000000000002000000000000000000000000000000000000000000")),
Bloom: types.BytesToBloom(common.FromHex("00000000000000000000000000000200000400000000000000000000000000800000000000040000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002002000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000800000000000000000000000000000000000000000000000000000400000000000000020000000000000000000000000002000000000000000000000000000000000000000000")),
Logs: []*types.Log{
{
Address: common.HexToAddress("0x759c5e44a9e4be8b7e9bd25a790ceb662c924c45"),
Expand All @@ -391,7 +391,7 @@ func TestVerifyReceipts(t *testing.T) {
common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000426a80"),
common.HexToHash("0x000000000000000000000000a6275ee214f80a532c3abee0a4cbbc2d1dc22a72"),
},
Data: common.Hex2Bytes("00000000000000000000000000000000000000000000000000000000000005dc"),
Data: common.FromHex("00000000000000000000000000000000000000000000000000000000000005dc"),
BlockNumber: block.Number,
TxHash: txHashes[2],
TxIndex: 2,
Expand All @@ -411,7 +411,7 @@ func TestVerifyReceipts(t *testing.T) {
Type: 0,
Status: 1,
CumulativeGasUsed: 0x1227ab,
Bloom: types.BytesToBloom(common.Hex2Bytes("00000000000000000000000000000200000400000000000000000000000000800000000000040000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002002000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000800000000000000000000000000000000000000000000000000000400000000000000020000000000000000000000000002000000000000000000000000000000000000000000")),
Bloom: types.BytesToBloom(common.FromHex("00000000000000000000000000000200000400000000000000000000000000800000000000040000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002002000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000800000000000000000000000000000000000000000000000000000400000000000000020000000000000000000000000002000000000000000000000000000000000000000000")),
Logs: []*types.Log{
{
Address: common.HexToAddress("0x759c5e44a9e4be8b7e9bd25a790ceb662c924c45"),
Expand All @@ -420,7 +420,7 @@ func TestVerifyReceipts(t *testing.T) {
common.HexToHash("0x0000000000000000000000000000000000000000000000000000000000426a80"),
common.HexToHash("0x000000000000000000000000a6275ee214f80a532c3abee0a4cbbc2d1dc22a72"),
},
Data: common.Hex2Bytes("00000000000000000000000000000000000000000000000000000000000005dc"),
Data: common.FromHex("00000000000000000000000000000000000000000000000000000000000005dc"),
BlockNumber: block.Number,
TxHash: txHashes[3],
TxIndex: 3,
Expand Down
4 changes: 2 additions & 2 deletions op-service/sources/reth_db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ func TestRethDBReceiptsLoad(t *testing.T) {
require.Equal(t, receipt.Type, uint8(2))
require.Equal(t, receipt.Status, uint64(1))
require.Equal(t, receipt.CumulativeGasUsed, uint64(115_316))
require.Equal(t, receipt.Bloom, types.BytesToBloom(common.Hex2Bytes("00200000000000000000000080001000000000000000000000000000000000000000000000000000000000000000100002000100080000000000000000000000000000000000000000000008000000200000000400000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000400000000000001000000000000000100000000080000004000000000000000000000000000000000000002000000000000000000000000000000000000000006000000000000000000000000000000000000001000000000000000000000200000000000000100000000020000000000000000000000000000000010")))
require.Equal(t, receipt.Bloom, types.BytesToBloom(common.FromHex("00200000000000000000000080001000000000000000000000000000000000000000000000000000000000000000100002000100080000000000000000000000000000000000000000000008000000200000000400000000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000400000000000001000000000000000100000000080000004000000000000000000000000000000000000002000000000000000000000000000000000000000006000000000000000000000000000000000000001000000000000000000000200000000000000100000000020000000000000000000000000000000010")))
require.Equal(t, receipt.Logs[0].Address, common.HexToAddress("c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"))
require.Equal(t, receipt.Logs[0].Topics[0], common.HexToHash("ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"))
require.Equal(t, receipt.Logs[0].Topics[1], common.HexToHash("00000000000000000000000000000000003b3cc22af3ae1eac0440bcee416b40"))
require.Equal(t, receipt.Logs[0].Data, common.Hex2Bytes("00000000000000000000000000000000000000000000000008a30cd230000000"))
require.Equal(t, receipt.Logs[0].Data, common.FromHex("00000000000000000000000000000000000000000000000008a30cd230000000"))
require.Equal(t, receipt.TxHash, common.HexToHash("0x88b2d153a4e893ba91ac235325c44b1aa0c802fcb42657701e1a73e1c675f7ca"))

require.Equal(t, receipt.BlockHash, blockHash)
Expand Down
2 changes: 1 addition & 1 deletion op-service/testutils/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func NextRandomL2Ref(rng *rand.Rand, l2BlockTime uint64, parent eth.L2BlockRef,
// Output is deterministic when the supplied rng generates the same random sequence.
func InsecureRandomKey(rng *rand.Rand) *ecdsa.PrivateKey {
idx := rng.Intn(len(randomEcdsaKeys))
key, err := crypto.ToECDSA(common.Hex2Bytes(randomEcdsaKeys[idx]))
key, err := crypto.ToECDSA(common.FromHex(randomEcdsaKeys[idx]))
if err != nil {
// Should never happen because the list of keys is hard coded and known to be valid.
panic(fmt.Errorf("invalid pre-generated ecdsa key at index %v: %w", idx, err))
Expand Down

0 comments on commit 6de6b5f

Please sign in to comment.