From acd403988d93e5a0cf4622e7e9fe09d9310edcf1 Mon Sep 17 00:00:00 2001 From: simsonraj Date: Mon, 6 Jan 2025 22:46:18 +0530 Subject: [PATCH 1/3] updated zkSync scripts & instructions --- contracts/hardhat.ccip.zksync.config.ts | 5 +-- contracts/scripts/zksyncverify/README.md | 4 ++ contracts/scripts/zksyncverify/main.go | 49 ++++++++++++++++++++++-- 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/contracts/hardhat.ccip.zksync.config.ts b/contracts/hardhat.ccip.zksync.config.ts index b8f2e1d154..db4d6377a9 100644 --- a/contracts/hardhat.ccip.zksync.config.ts +++ b/contracts/hardhat.ccip.zksync.config.ts @@ -89,9 +89,8 @@ let config = { ], }, zksolc: { - settings: { - compilerPath: 'zksolc', - version: 'v1.5.3', + version: '1.5.3', + settings: { optimizer: { enabled: true, mode: '3', diff --git a/contracts/scripts/zksyncverify/README.md b/contracts/scripts/zksyncverify/README.md index 97158f660b..f6800ed6e9 100644 --- a/contracts/scripts/zksyncverify/README.md +++ b/contracts/scripts/zksyncverify/README.md @@ -1,5 +1,9 @@ # Verify ZkSync Contracts For CCIP +G++ <-> CCIP repo artifacts mapping +- The current version of zkSync artifacts in G++ was generated with `v2.14.0-ccip1.5.0` version of zkSync contracts. +- For MCMS contracts change the zkSolc version to v1.5.3 + Pre-requisites: - `pnpm install` at contracts directory - `pnpm run zksync:compile `>> for compiling the contracts, you can uncomment `contractsToCompile` in [hardhat.ccip.zksync.config.ts](../../hardhat.ccip.zksync.config.ts) to compile only the contracts you need diff --git a/contracts/scripts/zksyncverify/main.go b/contracts/scripts/zksyncverify/main.go index 99a7ef4a9e..a19e49e11a 100644 --- a/contracts/scripts/zksyncverify/main.go +++ b/contracts/scripts/zksyncverify/main.go @@ -1,7 +1,6 @@ package main import ( - "context" "encoding/hex" "encoding/json" "flag" @@ -13,10 +12,39 @@ import ( "github.com/AlekSi/pointer" "github.com/ethereum/go-ethereum/accounts/abi" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethclient" + "github.com/ethereum/go-ethereum/rpc" ) +// CustomTx represents a custom transaction structure with selected fields +type CustomTx struct { + Hash string `json:"hash"` + Data string `json:"data"` +} + +func getTransaction(rpcClient *rpc.Client, txHash string) (*CustomTx, error) { + var result map[string]interface{} + if err := rpcClient.Call(&result, "eth_getTransactionByHash", txHash); err != nil { + return nil, fmt.Errorf("failed to fetch transaction: %w", err) + } + + data, ok := result["input"].(string) + if !ok { + return nil, fmt.Errorf("missing or invalid 'input' field in transaction result") + } + + hash, ok := result["hash"].(string) + if !ok { + return nil, fmt.Errorf("missing or invalid 'hash' field in transaction result") + } + + tx := &CustomTx{ + Hash: hash, + Data: data, + } + return tx, nil +} + // This script decodes the constructor arguments of a contract from a hex string func main() { abiFilePath := flag.String("abiPath", "", "Absolute Path to the compiled contract ABI JSON file") @@ -38,11 +66,13 @@ func main() { if err != nil { log.Fatalf("Failed to connect to the rpc client: %v", err) } - tx, _, err := client.TransactionByHash(context.Background(), common.HexToHash(pointer.GetString(deploymentTx))) + + rpcClient := client.Client() + tx, err := getTransaction(rpcClient, pointer.GetString(deploymentTx)) if err != nil { log.Fatalf("Failed to get transaction receipt: %v", err) } - params = string(tx.Data()) + params = string(tx.Data[2:]) } else { params = pointer.GetString(encodedConstructorArgs) } @@ -61,6 +91,7 @@ func main() { log.Fatalf("Failed to unmarshal ABI file content: %v", err) } + fmt.Println("Bytecode Size:", calculateBytecodeSize(compiledFile.DeployedBytecode)) // Parse the ABI parsedABI, err := abi.JSON(strings.NewReader(string(compiledFile.ABI))) if err != nil { @@ -84,6 +115,7 @@ func main() { // Create a map to hold the named constructor arguments constructorArgsMap := make(map[string]interface{}) + fmt.Println("Constructor Arguments order for reference:") for i, arg := range parsedABI.Constructor.Inputs { fmt.Println(arg.Name) constructorArgsMap[arg.Name] = decodedArgs[i] @@ -98,3 +130,12 @@ func main() { fmt.Println("Decoded Constructor Arguments in JSON Format:") fmt.Println(string(decodedArgsJSON)) } + +func calculateBytecodeSize(bytecode string) int { + // Remove the "0x" prefix if present + if strings.HasPrefix(bytecode, "0x") { + bytecode = bytecode[2:] + } + // Calculate the size in bytes + return len(bytecode) / 2 +} From 2e6a1775b787891cc3beed274b8eebf22f4c3d00 Mon Sep 17 00:00:00 2001 From: simsonraj Date: Mon, 6 Jan 2025 23:07:09 +0530 Subject: [PATCH 2/3] nit --- contracts/scripts/zksyncverify/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/scripts/zksyncverify/README.md b/contracts/scripts/zksyncverify/README.md index f6800ed6e9..95f1737d18 100644 --- a/contracts/scripts/zksyncverify/README.md +++ b/contracts/scripts/zksyncverify/README.md @@ -2,7 +2,7 @@ G++ <-> CCIP repo artifacts mapping - The current version of zkSync artifacts in G++ was generated with `v2.14.0-ccip1.5.0` version of zkSync contracts. -- For MCMS contracts change the zkSolc version to v1.5.3 +- For MCMS contracts change the zkSolc version to v1.5.0 Pre-requisites: - `pnpm install` at contracts directory From 7b8bd5bd67bf1f23aff98656a5f9ef24adcee09a Mon Sep 17 00:00:00 2001 From: simsonraj Date: Tue, 7 Jan 2025 12:14:58 +0530 Subject: [PATCH 3/3] lint --- contracts/hardhat.ccip.zksync.config.ts | 2 +- contracts/scripts/zksyncverify/main.go | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/contracts/hardhat.ccip.zksync.config.ts b/contracts/hardhat.ccip.zksync.config.ts index db4d6377a9..58bff2ce03 100644 --- a/contracts/hardhat.ccip.zksync.config.ts +++ b/contracts/hardhat.ccip.zksync.config.ts @@ -90,7 +90,7 @@ let config = { }, zksolc: { version: '1.5.3', - settings: { + settings: { optimizer: { enabled: true, mode: '3', diff --git a/contracts/scripts/zksyncverify/main.go b/contracts/scripts/zksyncverify/main.go index a19e49e11a..a49821ba2a 100644 --- a/contracts/scripts/zksyncverify/main.go +++ b/contracts/scripts/zksyncverify/main.go @@ -72,7 +72,7 @@ func main() { if err != nil { log.Fatalf("Failed to get transaction receipt: %v", err) } - params = string(tx.Data[2:]) + params = tx.Data[2:] } else { params = pointer.GetString(encodedConstructorArgs) } @@ -132,10 +132,6 @@ func main() { } func calculateBytecodeSize(bytecode string) int { - // Remove the "0x" prefix if present - if strings.HasPrefix(bytecode, "0x") { - bytecode = bytecode[2:] - } - // Calculate the size in bytes + bytecode = strings.TrimPrefix(bytecode, "0x") return len(bytecode) / 2 }