Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
yashnevatia committed Dec 8, 2024
1 parent d88f2d9 commit b0dbc5c
Show file tree
Hide file tree
Showing 10 changed files with 288 additions and 168 deletions.
78 changes: 62 additions & 16 deletions core/gethwrappers/abigen.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func Abigen(a AbigenArgs) {

ImproveAbigenOutput(a.Out, a.ABI)
if a.ZkBinPath != "" {
ImproveAbigenOutput_zks(a.Out, a.ZkBinPath)
ImproveAbigenOutputZKs(a.Out, a.ZkBinPath)
}
}

Expand Down Expand Up @@ -471,7 +471,7 @@ func addHeader(code []byte) []byte {
}

// ZK stack logic
func ImproveAbigenOutput_zks(path string, zkBinPath string) {
func ImproveAbigenOutputZKs(path string, zkBinPath string) {

bs, err := os.ReadFile(path)
if err != nil {
Expand Down Expand Up @@ -507,10 +507,10 @@ func addZKSyncBin(fileNode *ast.File, contractName string, zkHexString string) *
// zksync
newVarSpec := &ast.ValueSpec{
Names: []*ast.Ident{ast.NewIdent(fmt.Sprintf("%sZKBin", contractName))},
Type: ast.NewIdent("string"),
// Type: ast.NewIdent("string"),
Values: []ast.Expr{
&ast.BasicLit{
Kind: token.STRING,
// Kind: token.STRING,
Value: fmt.Sprintf("(\"0x%s\")", zkHexString),
},
},
Expand All @@ -537,30 +537,76 @@ func updateDeployMethod(contractName string, fset *token.FileSet, fileNode *ast.
}

// only add this import if Deploy method found
astutil.AddImport(fset, fileNode, "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated_zks")
astutil.AddImport(fset, fileNode, "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated")

// Extract the parameters from the existing function x
paramList := getConstructorParams(x.Type.Params.List)
// get the `if zksync()` block
zkSyncBlock := getZKSyncBlock(contractName, paramList)
// insert the `if zksync()` block
addZKSyncBlock(*x, zkSyncBlock)
// update the return type in the function signature
updateTxReturnType(*x)
// update the actual return value
updateReturnStmt(*x)

node, err := parser.ParseFile(token.NewFileSet(), "", zkSyncBlock, parser.SkipObjectResolution)
if err != nil {
return false
}

var newFuncDecl *ast.FuncDecl
for _, decl := range node.Decls {
if funcDecl, ok := decl.(*ast.FuncDecl); ok {
newFuncDecl = funcDecl
break
}
}

// Add the standalone function to the file
fileNode.Decls = append(fileNode.Decls, newFuncDecl)

return false
}, nil).(*ast.File)
}

func parseFuncDecl(funcCode string) (*ast.FuncDecl, error) {
// Parse the function string into a Go AST
node, err := parser.ParseFile(token.NewFileSet(), "", funcCode, parser.SkipObjectResolution)
if err != nil {
return nil, fmt.Errorf("error parsing function: %w", err)
}

// Extract the first declaration from the file node
for _, decl := range node.Decls {
if funcDecl, ok := decl.(*ast.FuncDecl); ok {
return funcDecl, nil
}
}

return nil, fmt.Errorf("no function declaration found")
}

var zkcode = `
package main
func Deploy%sZK(auth *bind.TransactOpts, backend bind.ContractBackend, params string) (common.Address, *generated.Transaction, *%s, error) {
parsed, err := %sMetaData.GetAbi()
if err != nil {
return common.Address{}, nil, nil, err
}
if parsed == nil {
return common.Address{}, nil, nil, errors.New("GetABI returned nil")
}
address, ethTx, contract, err := generated.DeployContract(auth, parsed, common.FromHex(%sZKBin), backend, params)
if err != nil {
return common.Address{}, nil, nil, err
}
return address, ethTx, &%s{address: address, abi: *parsed, %sCaller: %sCaller{contract: contract}, %sTransactor: %sTransactor{contract: contract}, %sFilterer: %sFilterer{contract: contract}}, nil
}
`

// get the `if zksync()` block
func getZKSyncBlock(contractName, paramList string) string {
zkSyncBlock := `if generated_zks.IsZKSync(backend) {
address, ethTx, contractBind, _ := generated_zks.DeployContract(auth, parsed, common.FromHex(%sZKBin), backend, %params)
contractReturn := &%s{address: address, abi: *parsed, %sCaller: %sCaller{contract: contractBind}, %sTransactor: %sTransactor{contract: contractBind},%sFilterer: %sFilterer{contract: contractBind}}
return address, ethTx, contractReturn, err
}`
// zkSyncBlock := `if generated_zks.IsZKSync(backend) {
// address, ethTx, contractBind, _ := generated_zks.DeployContract(auth, parsed, common.FromHex(%sZKBin), backend, %params)
// contractReturn := &%s{address: address, abi: *parsed, %sCaller: %sCaller{contract: contractBind}, %sTransactor: %sTransactor{contract: contractBind},%sFilterer: %sFilterer{contract: contractBind}}
// return address, ethTx, contractReturn, err
// }`
zkSyncBlock := zkcode
zkSyncBlock = strings.ReplaceAll(zkSyncBlock, "%s", contractName)
zkSyncBlock = strings.ReplaceAll(zkSyncBlock, "%params", paramList)
return strings.ReplaceAll(zkSyncBlock, "%s", contractName)
Expand Down
27 changes: 0 additions & 27 deletions core/gethwrappers/ccip/gen_to_gen_zks.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// Code generated - DO NOT EDIT.
// This file is a generated binding and any manual changes will be lost.

package maybe_revert_message_receiver

import (
Expand Down Expand Up @@ -562,3 +559,34 @@ type MaybeRevertMessageReceiverInterface interface {

Address() common.Address
}

var MaybeRevertMessageReceiverZKBin = ("0x00000060031002700000005f033001970000000100200190000000270000c13d0000008002000039000000400020043f000000040030008c0000005c0000413d000000000401043b000000e0044002700000006b0040009c000000700000a13d0000006c0040009c000000820000613d0000006d0040009c0000009f0000613d0000006e0040009c000000fb0000c13d000000240030008c000000fb0000413d0000000002000416000000000002004b000000fb0000c13d0000000401100370000000000101043b000000000001004b0000000002000039000000010200c039000000000021004b000000fb0000c13d000000000001004b0000000001000019000000620100c041000000000200041a0000006402200197000000000112019f000000000010041b0000000001000019000001770001042e0000000002000416000000000002004b000000fb0000c13d0000001f0230003900000060022001970000008002200039000000400020043f0000001f0430018f00000061053001980000008002500039000000380000613d0000008006000039000000000701034f000000007807043c0000000006860436000000000026004b000000340000c13d000000000004004b000000450000613d000000000151034f0000000304400210000000000502043300000000054501cf000000000545022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000151019f0000000000120435000000200030008c000000fb0000413d000000800100043d000000000001004b0000000002000039000000010200c039000000000021004b000000fb0000c13d000000000001004b0000000001000019000000620100c041000000000200041a0000006302200197000000000112019f00000000020004110000006402200197000000000121019f000000000010041b0000002001000039000001000010044300000120000004430000006501000041000001770001042e000000000003004b000000fb0000c13d000000000100041a00000066001001980000007e0000c13d0000000001000416000000800010043f00000000010004140000005f0010009c0000005f01008041000000c00110021000000069011001c70000800d0200003900000001030000390000006a04000041017601710000040f0000000100200190000000fb0000613d0000000001000019000001770001042e0000006f0040009c000000bc0000613d000000700040009c000000fb0000c13d0000000001000416000000000001004b000000fb0000c13d000000000100041a00000066001001980000000001000039000000010100c039000000800010043f0000007e01000041000001770001042e0000006701000041000000800010043f00000068010000410000017800010430000000240030008c000000fb0000413d0000000002000416000000000002004b000000fb0000c13d0000000402100370000000000502043b000000710050009c000000fb0000213d0000002302500039000000000032004b000000fb0000813d0000000406500039000000000261034f000000000202043b000000780020009c000000990000813d0000001f0720003900000082077001970000003f077000390000008207700197000000790070009c000000f40000a13d0000007c01000041000000000010043f0000004101000039000000040010043f0000007d010000410000017800010430000000240030008c000000fb0000413d0000000004000416000000000004004b000000fb0000c13d0000000401100370000000000101043b000000710010009c000000fb0000213d0000000001130049000000720010009c000000fb0000213d000000a40010008c000000fb0000413d000000000100041a0000006600100198000000cd0000c13d00000000010004140000005f0010009c0000005f01008041000000c00110021000000076011001c70000800d0200003900000001030000390000007704000041017601710000040f00000001002001900000006e0000c13d000000fb0000013d000000240030008c000000fb0000413d0000000002000416000000000002004b000000fb0000c13d0000000401100370000000000101043b0000007f00100198000000fb0000c13d000000800010009c00000000020000390000000102006039000000810010009c00000001022061bf000000800020043f0000007e01000041000001770001042e0000007301000041000000800010043f0000002001000039000000840010043f0000000104000039000000000304041a000000010530019000000001013002700000007f0110618f0000001f0010008c00000000060000390000000106002039000000000663013f0000000100600190000000e20000613d0000007c01000041000000000010043f0000002201000039000000040010043f0000007d010000410000017800010430000000a40010043f000000000005004b000000fd0000613d000000000040043f000000000001004b000001020000613d000000740200004100000000040000190000000003040019000000000402041a000000c405300039000000000045043500000001022000390000002004300039000000000014004b000000ea0000413d000000a002300039000001020000013d0000008007700039000000400070043f000000800020043f00000000052500190000002405500039000000000035004b000001080000a13d000000000100001900000178000104300000008302300197000000c40020043f000000000001004b000000a00200003900000080020060390000003c0120008a0000005f0010009c0000005f01008041000000600110021000000075011001c700000178000104300000002003600039000000000331034f00000082052001980000001f0620018f000000a001500039000001140000613d000000a007000039000000000803034f000000008908043c0000000007970436000000000017004b000001100000c13d000000000006004b000001210000613d000000000353034f0000000305600210000000000601043300000000065601cf000000000656022f000000000303043b0000010005500089000000000353022f00000000035301cf000000000363019f0000000000310435000000a0012000390000000000010435000000800200043d000000710020009c000000990000213d0000000101000039000000000301041a000000010530019000000001033002700000007f0330618f0000001f0030008c00000000060000390000000106002039000000000065004b000000dc0000c13d000000200030008c000001420000413d0000000105000039000000000050043f0000001f0520003900000005055002700000007a0550009a000000200020008c00000074050040410000001f0330003900000005033002700000007a0330009a000000000035004b000001420000813d000000000005041b0000000105500039000000000035004b0000013e0000413d0000001f0020008c0000014a0000a13d000000000010043f0000008204200198000001540000c13d000000a0050000390000007403000041000001620000013d000000000002004b00000000030000190000014e0000613d000000a00300043d0000000304200210000000840440027f0000008404400167000000000343016f00000001022002100000016d0000013d00000074030000410000002006000039000000010540008a00000005055002700000007b0550009a000000000706001900000080066000390000000006060433000000000063041b00000020067000390000000103300039000000000053004b000001590000c13d000000a005700039000000000024004b0000016b0000813d0000000304200210000000f80440018f000000840440027f00000084044001670000000005050433000000000445016f000000000043041b00000001032002100000000002010019000000000223019f000000000021041b0000000001000019000001770001042e00000174002104210000000102000039000000000001042d0000000002000019000000000001042d0000017600000432000001770001042e000001780001043000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffff00000000000000000000000000000000000000000000000000000001ffffffe000000000000000000000000000000000000000000000000000000000ffffffe00000000000000000000000010000000000000000000000000000000000000000ffffffffffffffffffffff000000000000000000000000000000000000000000ffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffff00000002000000000000000000000000000000400000010000000000000000000000000000000000000000ff00000000000000000000000000000000000000003085b8db0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000008000000000000000000200000000000000000000000000000000000020000000800000000000000000e12e3b7047ff60a2dd763cf536a43597e5ce7fe7aa7476345bd4cd079912bcef0000000000000000000000000000000000000000000000000000000077f5b0e50000000000000000000000000000000000000000000000000000000077f5b0e60000000000000000000000000000000000000000000000000000000085572ffb000000000000000000000000000000000000000000000000000000008fb5f1710000000000000000000000000000000000000000000000000000000001ffc9a7000000000000000000000000000000000000000000000000000000005100fc21000000000000000000000000000000000000000000000000ffffffffffffffff7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff5a4ff67100000000000000000000000000000000000000000000000000000000b10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf600000000000000000000000000000000000000000000008000000000000000000200000000000000000000000000000000000000000000000000000000000000d82ce31e3523f6eeb2d24317b2b4133001e8472729657f663b68624c45f8f3e80000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000ffffffffffffff7f4ef1d2ad89edf8c4d91132028e8195cdf30bb4b5053d4f8cd260341d4805f30a4ef1d2ad89edf8c4d91132028e8195cdf30bb4b5053d4f8cd260341d4805f3094e487b71000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000002000000080000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff01ffc9a70000000000000000000000000000000000000000000000000000000085572ffb00000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")

func DeployMaybeRevertMessageReceiverZK(auth *bind.TransactOpts, backend bind.ContractBackend, params string) (common.Address, *generated.
Transaction,

*MaybeRevertMessageReceiver, error) {
parsed, err := MaybeRevertMessageReceiverMetaData.
GetAbi()
if err != nil {
return common.Address{}, nil, nil, err
}
if parsed == nil {
return common.Address{}, nil, nil, errors.
New("GetABI returned nil")
}
address, ethTx,
contract, err := generated.DeployContract(auth, parsed, common.FromHex(MaybeRevertMessageReceiverZKBin), backend,

params,
)
if err !=
nil {
return common.Address{}, nil,
nil, err
}
return address,
ethTx, &MaybeRevertMessageReceiver{address: address,
abi: *parsed, MaybeRevertMessageReceiverCaller: MaybeRevertMessageReceiverCaller{contract: contract}, MaybeRevertMessageReceiverTransactor: MaybeRevertMessageReceiverTransactor{contract: contract},
MaybeRevertMessageReceiverFilterer: MaybeRevertMessageReceiverFilterer{contract: contract}}, nil
}
Loading

0 comments on commit b0dbc5c

Please sign in to comment.