Skip to content

Commit

Permalink
Address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinod Damle committed Sep 12, 2024
1 parent d3839ca commit c5eae36
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 45 deletions.
13 changes: 0 additions & 13 deletions validation/genesis/foundry-config.patch

This file was deleted.

41 changes: 9 additions & 32 deletions validation/genesis/genesis-allocs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ func testGenesisAllocs(t *testing.T, chain *ChainConfig) {
// weth9 contract bytecode before writing to file/comparing the outputs
if chainId == uint64(11155420) {
t.Log("✂️️ Trimming WETH9 bytecode CBOR hash for OP-Sepolia...")
expectedData, gotData = trimWeth9BytecodeMetadataHash(expectedData, gotData)
expectedData = trimWeth9BytecodeMetadataHash(expectedData)
gotData = trimWeth9BytecodeMetadataHash(gotData)
}

err = os.WriteFile(path.Join(monorepoDir, "regenerated-alloc.json"), expectedData, os.ModePerm) // regenerated
Expand All @@ -197,16 +198,17 @@ func testGenesisAllocs(t *testing.T, chain *ChainConfig) {
}

// trim the CBOR octets from the bytecode of a weth9 contract
func trimWeth9BytecodeMetadataHash(expectedData []byte, gotData []byte) ([]byte, []byte) {
var weth9ExpectedData, weth9GotData map[string]interface{}
func trimWeth9BytecodeMetadataHash(data []byte) []byte {
var weth9Data map[string]interface{}

err := json.Unmarshal(expectedData, &weth9ExpectedData)
err := json.Unmarshal(data, &weth9Data)
if err != nil {
fmt.Printf("error parsing regenerated alloc: %s", err)
}

// https://specs.optimism.io/protocol/predeploys.html#weth9
key := "0x4200000000000000000000000000000000000006"
if entry, ok := weth9ExpectedData[key].(map[string]interface{}); ok {
if entry, ok := weth9Data[key].(map[string]interface{}); ok {
if code, ok := entry["code"].(string); ok {
// Trim the last 100 characters (50 bytes) which is the CBOR length in octets
if len(code) > 100 {
Expand All @@ -221,37 +223,12 @@ func trimWeth9BytecodeMetadataHash(expectedData []byte, gotData []byte) ([]byte,
log.Fatalf("Key %s not found in regenerated bytecode", key)
}

// repeat for gotData
err = json.Unmarshal(gotData, &weth9GotData)
if err != nil {
fmt.Printf("error parsing registry alloc: %s", err)
}

if entry, ok := weth9GotData[key].(map[string]interface{}); ok {
if code, ok := entry["code"].(string); ok {
// Trim the last 100 characters (50 bytes) which is the CBOR length in octets
if len(code) > 100 {
entry["code"] = code[:len(code)-100]
} else {
fmt.Println("The registry bytecode length is less than 100 characters; no trimming performed.")
}
} else {
log.Fatalf("Field 'code' not found or is not a string in registry bytecode: %s", key)
}
} else {
log.Fatalf("Key %s not found in registry bytecode", key)
}

expectedData, err = json.Marshal(weth9ExpectedData)
data, err = json.Marshal(weth9Data)
if err != nil {
fmt.Printf("error marshalling regenerated bytecode: %s", err)
}
gotData, err = json.Marshal(weth9GotData)
if err != nil {
fmt.Printf("error marshalling registry bytecode: %s", err)
}

return expectedData, gotData
return data
}

func getDirOfThisFile() string {
Expand Down

0 comments on commit c5eae36

Please sign in to comment.