Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated zkSync scripts & instructions #1587

Merged
merged 5 commits into from
Jan 15, 2025
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
3 changes: 1 addition & 2 deletions contracts/hardhat.ccip.zksync.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ let config = {
],
},
zksolc: {
version: '1.5.3',
settings: {
compilerPath: 'zksolc',
version: 'v1.5.3',
optimizer: {
enabled: true,
mode: '3',
Expand Down
4 changes: 4 additions & 0 deletions contracts/scripts/zksyncverify/README.md
Original file line number Diff line number Diff line change
@@ -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.0

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
Expand Down
45 changes: 41 additions & 4 deletions contracts/scripts/zksyncverify/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"context"
"encoding/hex"
"encoding/json"
"flag"
Expand All @@ -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")
Expand All @@ -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 = tx.Data[2:]
} else {
params = pointer.GetString(encodedConstructorArgs)
}
Expand All @@ -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 {
Expand All @@ -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]
Expand All @@ -98,3 +130,8 @@ func main() {
fmt.Println("Decoded Constructor Arguments in JSON Format:")
fmt.Println(string(decodedArgsJSON))
}

func calculateBytecodeSize(bytecode string) int {
bytecode = strings.TrimPrefix(bytecode, "0x")
return len(bytecode) / 2
}
Loading