Skip to content

Commit

Permalink
updated zkSync scripts & instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
simsonraj committed Jan 6, 2025
1 parent c279cbb commit acd4039
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 7 deletions.
5 changes: 2 additions & 3 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: {
settings: {
compilerPath: 'zksolc',
version: 'v1.5.3',
version: '1.5.3',
settings: {

Check failure on line 93 in contracts/hardhat.ccip.zksync.config.ts

View workflow job for this annotation

GitHub Actions / Solidity Lint

Delete `······`
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.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
Expand Down
49 changes: 45 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 = string(tx.Data[2:])

Check failure on line 75 in contracts/scripts/zksyncverify/main.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary conversion (unconvert)
} 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,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") {

Check failure on line 136 in contracts/scripts/zksyncverify/main.go

View workflow job for this annotation

GitHub Actions / lint

S1017: should replace this `if` statement with an unconditional `strings.TrimPrefix` (gosimple)
bytecode = bytecode[2:]
}
// Calculate the size in bytes
return len(bytecode) / 2
}

0 comments on commit acd4039

Please sign in to comment.