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

zkSync: research how to compile our contracts for zkSync with ape #2150

Open
istankovic opened this issue Aug 17, 2023 · 1 comment
Open
Assignees

Comments

@istankovic
Copy link
Contributor

As part of this item, we need to answer the following questions:

  • how do we use ape to compile our contracts for zkSync?
    • is there already an ape plugin that we can use and what is the maintenance status of it?
    • if there is a plugin, but it needs fixing, how much effort it is to fix it?
    • if there is no plugin, how much effort is it to write one?
    • can support for zkSync be added to the existing ape-solidity plugin (if that makes sense)?
  • does ape support zkSync as a network for local testing?
  • does the contract ABI data differ between regular solc and zksolc?
  • does the contract bytecode data differ between regular solc and zksolc?
  • is there a need for multiple different bytecode targets (EVM compatible, zkSync) build files to co-exist at the same time?
    • if yes, how are we going to handle the different sets of build output files?
    • if yes, how are we going to adjust the npm deployments package?
  • are there any special considerations regarding zkSync on our CI?
@compojoom
Copy link
Contributor

Since I didn't do any notes (I didn't expect that it will take us that much time to get to this), I'm writing this based on memories.
the best ape_zksync plugin I found was this: https://github.com/delaaxe/ape-zksync . I think that it was build during a hackathon and now it is also outdated as it uses old zksync binaries. In my tests it didn't manage to properly compile the code. The plugin itself is for the most part copy of ape-solidity with modifications to match the syntax of the hardhat zksync plugin: https://era.zksync.io/docs/tools/hardhat/hardhat-zksync-solc.html
I couldn't make this plugin work, so what I did is I manually compiled the requestmanager contract and manually changed the bytecode in our code.
The part that was the most confusing was that our import mappings were not properly resovled by ape-zksync. So I ended up copying all the code from the imported contracts in the same file to make it work.

Then with the use of zksync python package I was able to deploy:
https://github.com/zksync-sdk/zksync2-python

I had to change the deploy function in deploy/util.py

def deploy_contract(
        zk_web3: Web3, abi_manager: ABIManager, constructor_spec: Union[str, Sequence]
) -> HexAddress:
    """Deploy compiled contract with constructor on zkSync network using create() opcode

    :param zk_web3:
        Instance of ZkSyncBuilder that interacts with zkSync network

    :param account:
        From which account the deployment contract tx will be made

    :param compiled_contract:
        Compiled contract source.

    :param constructor_args:
        Constructor arguments that can be provided via:
        dictionary: {"_incrementer": 2}
        tuple: tuple([2])

    :return:
        Address of deployed contract.
    """
    # Get chain id of zkSync network
    chain_id = zk_web3.zksync.chain_id

    if isinstance(constructor_spec, str):
        name = constructor_spec
        args: Sequence = ()
    else:
        name = constructor_spec[0]
        args = constructor_spec[1:]

    abi = abi_manager.get_abi(name)
    # bytecode = abi_manager.get_bytecode(name)
    bytecode = bytes.fromhex("00030000000000020005000000000002000200000001035500000060011002700000013b0010019d000100000000001f0000008001000039000000400010043f00000001012001900000004c0000c13d0000000001000031000000040110008c000004000000413d0000000201000367000000000101043b000000e001100270000001410210009c000000660000a13d000001420210009c000000940000a13d000001430210009c000001300000613d000001440210009c0000014b0000613d000001450110009c000004000000c13d0000000001000416000000000101004b000004000000c13d000000040100008a00000000011000310000014d02000041000000200310008c000000000300001900000000030240190000014d01100197000000000401004b000000000200a0190000014d0110009c00000000010300190000000001026019000000000101004b000004000000c13d00000004010000390000000201100367000000000601043b0000013e0160009c000004000000213d000000000100041a0000013e021001970000000005000411000000000252004b000002520000c13d000000000206004b000002630000c13d000000400100043d00000064021000390000014e03000041000000000032043500000044021000390000014f030000410000000000320435000000240210003900000026030000390000000000320435000001500200004100000000002104350000000402100039000000200300003900000000003204350000013b020000410000013b0310009c0000000001028019000000400110021000000151011001c7000004ea000104300000000001000416000000000101004b000004000000c13d000000000200041a0000013c012001970000000006000411000000000161019f000000000010041b0000013b0100004100000000030004140000013b0430009c0000000001034019000000c0011002100000013d011001c70000013e052001970000800d0200003900000003030000390000013f0400004104e804de0000040f0000000101200190000004000000613d0000002001000039000001000010044300000120000004430000014001000041000004e90001042e000001480210009c000001050000213d0000014b0210009c000001c00000613d0000014c0110009c000004000000c13d0000000001000416000000000101004b000004000000c13d000000040100008a00000000011000310000014d02000041000000200310008c000000000300001900000000030240190000014d01100197000000000401004b000000000200a0190000014d0110009c00000000010300190000000001026019000000000101004b000004000000c13d00000004010000390000000201100367000000000101043b00000000001004350000000201000039000000200010043f000000000100001904e8048f0000040f000000000201041a0000000101100039000000000101041a0000013e01100197000000400300043d000000200430003900000000001404350000013e0120019700000000001304350000013b010000410000013b0230009c0000000001034019000000400110021000000173011001c7000004e90001042e000001460210009c000001ee0000613d000001470110009c000004000000c13d0000000001000416000000000101004b000004000000c13d000000040100008a00000000011000310000014d02000041000000200310008c000000000300001900000000030240190000014d01100197000000000401004b000000000200a0190000014d0110009c00000000010300190000000001026019000000000101004b000004000000c13d00000004010000390000000201100367000000000301043b0000013e0130009c000004000000213d000000000100041a0000013e011001970000000002000411000000000121004b000002520000c13d000000000103004b000002110000613d000001530100004100000000001004390000013b010000410000000002000414000500000003001d0000013b0320009c0000000001024019000000c00110021000000154011001c70000800b0200003904e804e30000040f0000000102200190000004000000613d000000000101043b00000000001004350000000101000039000400000001001d000000200010043f0000013b0100004100000000020004140000013b0320009c0000000001024019000000c00110021000000152011001c7000080100200003904e804e30000040f00000005030000290000000102200190000004000000613d000000000101043b000000000101041a0000013e01100198000002e60000c13d000000400200043d0000015c0120009c000003df0000213d0000004001200039000000400010043f000300000002001d0000000001320436000500000001001d0000000000010435000001530100004100000000001004390000013b0100004100000000020004140000013b0320009c0000000001024019000000c00110021000000154011001c70000800b0200003904e804e30000040f0000000102200190000004000000613d000000000101043b00000000001004350000000401000029000000200010043f0000013b0100004100000000020004140000013b0320009c0000000001024019000000c00110021000000152011001c7000080100200003904e804e30000040f0000000102200190000004000000613d000000000101043b000000030200002900000000020204330000013e02200197000000000021041b0000000101100039000000050200002900000000020204330000013e02200197000000000021041b0000000001000019000004e90001042e000001490210009c000002260000613d0000014a0110009c000004000000c13d0000000001000416000000000101004b000004000000c13d000000040100008a00000000011000310000014d02000041000000000301004b000000000300001900000000030240190000014d01100197000000000401004b000000000200a0190000014d0110009c00000000010300190000000001026019000000000101004b000004000000c13d000000000100041a0000013e021001970000000005000411000000000252004b000002520000c13d0000013c01100197000000000010041b0000013b0100004100000000020004140000013b0320009c0000000001024019000000c0011002100000013d011001c70000800d0200003900000003030000390000013f04000041000000000600001904e804de0000040f0000000101200190000004000000613d0000000001000019000004e90001042e0000000001000416000000000101004b000004000000c13d000000040100008a00000000011000310000014d02000041000000000301004b000000000300001900000000030240190000014d01100197000000000401004b000000000200a0190000014d0110009c00000000010300190000000001026019000000000101004b000004000000c13d000000000100041a0000013e01100197000000400200043d00000000001204350000013b010000410000013b0320009c000000000102401900000040011002100000016a011001c7000004e90001042e0000000001000416000000000101004b000004000000c13d000000040100008a00000000011000310000014d02000041000000a00310008c000000000300001900000000030240190000014d01100197000000000401004b000000000200a0190000014d0110009c00000000010300190000000001026019000000000101004b000004000000c13d00000002010003670000008402100370000000000202043b000500000002001d0000013e0220009c000004000000213d0000004401100370000000000101043b00000000001004350000000101000039000000200010043f0000013b0100004100000000020004140000013b0320009c0000000001024019000000c00110021000000152011001c7000080100200003904e804e30000040f0000000102200190000004000000613d000000000101043b000300000001001d000000000101041a000400000001001d000001530100004100000000001004390000013b0100004100000000020004140000013b0320009c0000000001024019000000c00110021000000154011001c70000800b0200003904e804e30000040f00000004030000290000013e033001970000000102200190000004000000613d000000000201043b00000002010003670000004404100370000000000404043b000000000224004b000002730000c13d0000000002000411000000000232004b000002c70000c13d0000006401100370000000000101043b00000000001004350000000201000039000000200010043f0000013b0100004100000000020004140000013b0320009c0000000001024019000000c00110021000000152011001c7000080100200003904e804e30000040f0000000102200190000004000000613d000000400300043d0000015c0230009c000003df0000213d000000000101043b0000004002300039000000400020043f000000000201041a0000013e02200198000400000003001d00000000022304360000000101100039000000000101041a0000013e01100197000300000002001d0000000000120435000003760000c13d000000400100043d00000064021000390000016803000041000000000032043500000044021000390000016903000041000000000032043500000024021000390000002d030000390000000000320435000001500200004100000000002104350000000402100039000000200300003900000000003204350000013b020000410000013b0310009c0000000001028019000000400110021000000151011001c7000004ea000104300000000001000416000000000101004b000004000000c13d000000040100008a00000000011000310000014d02000041000000400310008c000000000300001900000000030240190000014d01100197000000000401004b000000000200a0190000014d0110009c00000000010300190000000001026019000000000101004b000004000000c13d00000002010003670000002402100370000000000202043b000500000002001d0000000401100370000000000101043b00000000001004350000000101000039000000200010043f0000013b0100004100000000020004140000013b0320009c0000000001024019000000c00110021000000152011001c7000080100200003904e804e30000040f00000005030000290000000102200190000004000000613d000000010230008c000004000000213d000000000101043b0000000001310019000000000101041a0000013e01100197000000800010043f0000017401000041000004e90001042e0000000001000416000000000101004b000004000000c13d000000040100008a00000000011000310000014d02000041000000600310008c000000000300001900000000030240190000014d01100197000000000401004b000000000200a0190000014d0110009c00000000010300190000000001026019000000000101004b000004000000c13d00000002010003670000000402100370000000000302043b0000002402100370000000000402043b0000013e0240009c000004000000213d0000004401100370000000000501043b0000013e0150009c000004000000213d000000000100041a0000013e011001970000000002000411000000000121004b000002520000c13d000000000104004b0000028d0000c13d000000400100043d000000640210003900000170030000410000000000320435000000440210003900000171030000410000000000320435000000240210003900000023030000390000000000320435000001500200004100000000002104350000000402100039000000200300003900000000003204350000013b020000410000013b0310009c0000000001028019000000400110021000000151011001c7000004ea000104300000000001000416000000000101004b000004000000c13d000000000100003104e804a10000040f000300000001001d000200000002001d000400000003001d04e804bc0000040f000000400100043d000500000001001d04e804d30000040f00000004010000290000013e0110019700000005030000290000002002300039000400000002001d000000000012043500000002010000290000013e011001970000000000130435000000030100002900000000001004350000000201000039000000200010043f000000000100001904e8048f0000040f000000050200002900000000020204330000013e02200197000000000301041a0000013c03300197000000000223019f000000000021041b000000040200002900000000020204330000013e022001970000000101100039000000000301041a0000013c03300197000000000223019f000000000021041b0000000001000019000004e90001042e000000400100043d00000044021000390000017203000041000000000032043500000150020000410000000000210435000000240210003900000020030000390000000000320435000000040210003900000000003204350000013b020000410000013b0310009c0000000001028019000000400110021000000159011001c7000004ea000104300000013c01100197000000000161019f000000000010041b0000013b0100004100000000020004140000013b0320009c0000000001024019000000c0011002100000013d011001c70000800d0200003900000003030000390000013f0400004104e804de0000040f00000001012001900000012e0000c13d000004000000013d000000400a00043d00000003010000290000000101100039000000000101041a0000013e021001980000002404a000390000000401a00039000002d80000c13d0000006402a000390000015a0300004100000000003204350000004402a000390000015b03000041000000000032043500000022020000390000000000240435000001500200004100000000002a0435000000200200003900000000002104350000013b010000410000013b02a0009c00000000010a4019000000400110021000000151011001c7000004ea0001043000000000003004350000000101000039000200000001001d000000200010043f0000013b010000410000000002000414000500000003001d0000013b0320009c0000000001024019000000c00110021000000152011001c70000801002000039000400000004001d000300000005001d04e804e30000040f0000000305000029000000040400002900000005030000290000000102200190000004000000613d000000000101043b000000000101041a0000013e01100198000002e60000c13d000000400200043d0000016d0120009c000003df0000813d0000004001200039000000400010043f000100000002001d0000000001420436000400000001001d000000000051043500000000003004350000000201000029000000200010043f0000013b0100004100000000020004140000013b0320009c0000000001024019000000c00110021000000152011001c7000080100200003904e804e30000040f0000000102200190000004000000613d000000000101043b000000010200002900000000020204330000013e02200197000000000021041b0000000101100039000000040200002900000000020204330000013e02200197000000000021041b0000000001000019000004e90001042e000000400100043d00000044021000390000015803000041000000000032043500000150020000410000000000210435000000240210003900000020030000390000000000320435000000040210003900000000003204350000013b020000410000013b0310009c0000000001028019000000400110021000000159011001c7000004ea0001043000000000050004110000013e055001970000000000540435000001550400004100000000004a043500000000003104350000000001000414000000040320008c000002fb0000c13d0000000103000031000000200130008c000000200400003900000000040340190000032b0000013d000000400100043d00000064021000390000016b03000041000000000032043500000044021000390000016c030000410000000000320435000000240210003900000026030000390000000000320435000001500200004100000000002104350000000402100039000000200300003900000000003204350000013b020000410000013b0310009c0000000001028019000000400110021000000151011001c7000004ea000104300000013b030000410000013b0410009c00000000010380190000013b04a0009c00000000030a40190000004003300210000000c001100210000000000131019f00000156011001c700040000000a001d04e804e30000040f000000040a000029000000000301001900000060033002700000013b03300197000000200430008c000000200400003900000000040340190000001f0540018f0000000506400272000003190000613d0000000007000019000000050870021000000000098a0019000000000881034f000000000808043b00000000008904350000000107700039000000000867004b000003110000413d000000000705004b000003280000613d0000000506600210000000000761034f00000000066a00190000000305500210000000000806043300000000085801cf000000000858022f000000000707043b0000010005500089000000000757022f00000000055701cf000000000585019f0000000000560435000100000003001f0000000102200190000003500000613d0000001f01400039000000600210018f0000000001a20019000000000221004b00000000020000190000000102004039000001570410009c000003df0000213d0000000102200190000003df0000c13d000000400010043f000000200230008c000004000000413d00000000020a0433000000000302004b0000000003000019000000010300c039000000000332004b000004000000c13d000000000202004b000003b70000c13d00000044021000390000015803000041000000000032043500000150020000410000000000210435000000240210003900000020030000390000000000320435000000040210003900000000003204350000013b020000410000013b0310009c0000000001028019000000400110021000000159011001c7000004ea00010430000000400200043d0000001f0430018f00000005033002720000035d0000613d000000000500001900000005065002100000000007620019000000000661034f000000000606043b00000000006704350000000105500039000000000635004b000003550000413d000000000504004b0000036c0000613d0000000503300210000000000131034f00000000033200190000000304400210000000000503043300000000054501cf000000000545022f000000000101043b0000010004400089000000000141022f00000000014101cf000000000151019f00000000001304350000013b0100004100000001030000310000013b0430009c00000000030180190000013b0420009c000000000102401900000040011002100000006002300210000000000112019f000004ea00010430000000000101004b0000038d0000c13d000000400100043d000000640210003900000166030000410000000000320435000000440210003900000167030000410000000000320435000000240210003900000027030000390000000000320435000001500200004100000000002104350000000402100039000000200300003900000000003204350000013b020000410000013b0310009c0000000001028019000000400110021000000151011001c7000004ea00010430000000400100043d000200000001001d00000020011000390000000502000029000000000202004b000003b90000c13d0000015f02000041000000000021043500000004010000390000000201100367000000000101043b00000002030000290000002402300039000000000012043500000024010000390000000201100367000000000101043b00000044023000390000000000120435000001530100004100000000001004390000013b0100004100000000020004140000013b0320009c0000000001024019000000c00110021000000154011001c70000800b0200003904e804e30000040f0000000102200190000004000000613d000000000101043b00000002030000290000006402300039000000000012043500000064010000390000000000130435000000a001000039000001600230009c0000000403000029000003df0000213d000003e50000013d00000002010003670000018c0000013d0000015d02000041000000000021043500000004010000390000000201100367000000000101043b00000002030000290000002402300039000000000012043500000024010000390000000201100367000000000101043b00000044023000390000000000120435000001530100004100000000001004390000013b0100004100000000020004140000013b0320009c0000000001024019000000c00110021000000154011001c70000800b0200003904e804e30000040f0000000102200190000004000000613d000000000101043b00000002040000290000008402400039000000050300002900000000003204350000006402400039000000000012043500000084010000390000000000140435000000c0010000390000015e0240009c0000000403000029000003e50000a13d0000016e0100004100000000001004350000004101000039000000040010043f0000016f01000041000004ea0001043000000002020000290000000001210019000000400010043f0000000001030433000400000001001d00000003010000290000000001010433000001610200004100000000002004390000013e01100197000300000001001d00000004001004430000013b0100004100000000020004140000013b0320009c0000000001024019000000c00110021000000162011001c7000080020200003904e804e30000040f00000004030000290000013e033001970000000102200190000004000000613d000000000101043b000000000101004b000004020000c13d0000000001000019000004ea00010430000000400400043d00000024014000390000004002000039000000000021043500000163010000410000000001140436000100000001001d000000040140003900000000003104350000000206000029000000000106043300000044024000390000000000120435000400000004001d0000006402400039000000000301004b0000041b0000613d000000000300001900000000042300190000002003300039000000000563001900000000050504330000000000540435000000000413004b000004140000413d0000000002210019000000000002043500000000020004140000000303000029000000040330008c0000043b0000613d0000001f01100039000000200300008a000000000131016f0000013b0300004100000004050000290000013b0450009c00000000040300190000000004054019000000400440021000000064011000390000013b0510009c00000000010380190000006001100210000000000141019f0000013b0420009c0000000002038019000000c002200210000000000112019f000000030200002904e804de0000040f000000000301001900000060033002700001013b0030019d0000013b043001970000000102200190000004690000613d0000000401000029000001570110009c000003df0000213d0000000404000029000000400040043f00000064010000390000000201100367000000000101043b000000000014043500000044010000390000000201100367000000000101043b0000000102000029000000000012043500000005010000290000013e0110019700000004020000390000000202200367000000000202043b000000600340003900000000001304350000004001400039000000000021043500000024010000390000000201100367000000000101043b000000800240003900000000001204350000013b010000410000013b0240009c0000000002010019000000000204401900000000030004140000013b0430009c00000000010340190000004002200210000000c001100210000000000121019f00000164011001c70000800d020000390000000103000039000001650400004104e804de0000040f00000001012001900000012e0000c13d000004000000013d000000400200043d0000001f0340018f0000000504400272000004760000613d000000000500001900000005065002100000000007620019000000000661034f000000000606043b00000000006704350000000105500039000000000645004b0000046e0000413d000000000503004b000004850000613d0000000504400210000000000141034f00000000044200190000000303300210000000000504043300000000053501cf000000000535022f000000000101043b0000010003300089000000000131022f00000000013101cf000000000151019f00000000001404350000013b0100004100000001030000310000013b0430009c00000000030180190000013b0420009c000000000102401900000040011002100000006002300210000000000112019f000004ea000104300000013b0200004100000000030004140000013b0430009c00000000030280190000013b0410009c00000000010280190000004001100210000000c002300210000000000112019f00000152011001c7000080100200003904e804e30000040f00000001022001900000049f0000613d000000000101043b000000000001042d0000000001000019000004ea00010430000000040110008a0000014d020000410000005f0310008c000000000300001900000000030220190000014d01100197000000000401004b00000000020080190000014d0110009c00000000010300190000000001026019000000000101004b000004ba0000613d00000002030003670000000401300370000000000101043b0000002402300370000000000202043b0000013e0420009c000004ba0000213d0000004403300370000000000303043b0000013e0430009c000004ba0000213d000000000001042d0000000001000019000004ea00010430000000000100041a0000013e011001970000000002000411000000000121004b000004c20000c13d000000000001042d000000400100043d00000044021000390000017203000041000000000032043500000150020000410000000000210435000000240210003900000020030000390000000000320435000000040210003900000000003204350000013b020000410000013b0310009c0000000001028019000000400110021000000159011001c7000004ea000104300000016d0210009c000004d80000813d0000004001100039000000400010043f000000000001042d0000016e0100004100000000001004350000004101000039000000040010043f0000016f01000041000004ea00010430000004e1002104210000000102000039000000000001042d0000000002000019000000000001042d000004e6002104230000000102000039000000000001042d0000000002000019000000000001042d000004e800000432000004e90001042e000004ea00010430000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffff00000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffff8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e00000000200000000000000000000000000000040000001000000000000000000000000000000000000000000000000000000000000000000000000007203ae3a000000000000000000000000000000000000000000000000000000008da5cb5a000000000000000000000000000000000000000000000000000000008da5cb5b00000000000000000000000000000000000000000000000000000000a56e3c3800000000000000000000000000000000000000000000000000000000f2fde38b000000000000000000000000000000000000000000000000000000007203ae3b00000000000000000000000000000000000000000000000000000000747293fb0000000000000000000000000000000000000000000000000000000044596f9a0000000000000000000000000000000000000000000000000000000044596f9b00000000000000000000000000000000000000000000000000000000715018a6000000000000000000000000000000000000000000000000000000000e19a1c600000000000000000000000000000000000000000000000000000000308634a5800000000000000000000000000000000000000000000000000000000000000064647265737300000000000000000000000000000000000000000000000000004f776e61626c653a206e6577206f776e657220697320746865207a65726f206108c379a000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008400000000000000000000000002000000000000000000000000000000000000400000000000000000000000009a8a0592ac89c5ad3bc6df8224c17b485976f597df104ee20d0df415241f670b0200000200000000000000000000000000000004000000000000000000000000845c5443000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000044000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffff5265737472696374656443616c6c733a2063616c6c20646973616c6c6f776564000000000000000000000000000000000000006400000000000000000000000065740000000000000000000000000000000000000000000000000000000000005265737472696374656443616c6c733a206d657373656e676572206e6f742073000000000000000000000000000000000000000000000000ffffffffffffffbf5b3a6ef200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffff3f03fc4c3700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffff5f1806aa1896bbf26568e884a7374b41e002500962caba6a15023a8d90e8508b830200000200000000000000000000000000000024000000000000000000000000bb5ddb0f0000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000a000000000000000000000000044702e0d5959cc77a7f68b33530b86546d1b157d0d74b27010d5f519adae07cb6520636861696e000000000000000000000000000000000000000000000000004e6f206d657373656e67657220617661696c61626c6520666f7220736f75726320736f7572636520636861696e000000000000000000000000000000000000004e6f2072657175657374206d616e6167657220617661696c61626c6520666f72000000000000000000000000000000000000002000000000000000000000000065786973747300000000000000000000000000000000000000000000000000005265737472696374656443616c6c733a2063616c6c657220616c726561647920000000000000000000000000000000000000000000000000ffffffffffffffc04e487b7100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002400000000000000000000000065203000000000000000000000000000000000000000000000000000000000005265737472696374656443616c6c733a2063616c6c65722063616e6e6f7420624f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65720000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000002000000080000000000000000000000000000000000000000000000000000000000000000000000000000000008d6712ae0cbbb830c55d181943aca18f249a0a63eee6ac24c4171f4d86978cf7")

    address = zk_web3.eth.default_account
    account = zk_web3.eth.account

    myaccount = Account.from_key(bytes.fromhex("7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110"))
    # account.address = address
    print(account)
    print(address)
    # Signer is used to generate signature of provided transaction
    signer = PrivateKeyEthSigner(myaccount, chain_id)

    # Get nonce of ETH address on zkSync network
    nonce = zk_web3.zksync.get_transaction_count(
        address, EthBlockParams.PENDING.value
    )

    # Get deployment nonce
    deployment_nonce = NonceHolder(zk_web3, myaccount).get_deployment_nonce(address)

    # Precompute the address of smart contract
    # Use this if there is a case where contract address should be known before deployment
    deployer = PrecomputeContractDeployer(zk_web3)
    precomputed_address = deployer.compute_l2_create_address(address, deployment_nonce)

    # Get contract ABI and bytecode information
    # incrementer_contract = ContractEncoder.from_json(zk_web3, compiled_contract)[0]
    incrementer_contract = ContractEncoder(web3=zk_web3, abi=abi, bytecode=bytecode)

    print(name)
    print(args)
    # Encode the constructor arguments
    encoded_constructor = incrementer_contract.encode_constructor(*args)

    # Get current gas price in Wei
    gas_price = zk_web3.zksync.gas_price

    # Create deployment contract transaction
    create_contract = TxCreateContract(
        web3=zk_web3,
        chain_id=chain_id,
        nonce=nonce,
        from_=address,
        gas_price=gas_price,
        bytecode=incrementer_contract.bytecode,
        call_data=encoded_constructor,
    )

    # ZkSync transaction gas estimation
    estimate_gas = zk_web3.zksync.eth_estimate_gas(create_contract.tx)
    print(f"Fee for transaction is: {Web3.from_wei(estimate_gas * gas_price, 'ether')} ETH")

    # Convert transaction to EIP-712 format
    tx_712 = create_contract.tx712(estimate_gas)

    # Sign message
    signed_message = signer.sign_typed_data(tx_712.to_eip712_struct())

    # Encode signed message
    msg = tx_712.encode(signed_message)

    # Deploy contract
    tx_hash = zk_web3.zksync.send_raw_transaction(msg)

    # Wait for deployment contract transaction to be included in a block
    tx_receipt = zk_web3.zksync.wait_for_transaction_receipt(
        tx_hash, timeout=240, poll_latency=0.5
    )

    print(f"Tx status: {tx_receipt['status']}")
    contract_address = tx_receipt["contractAddress"]
    print(f"Contract address: {contract_address}")

    # Check does precompute address match with deployed address
    if precomputed_address.lower() != contract_address.lower():
        raise RuntimeError("Precomputed contract address does now match with deployed contract address")

    txhash =  encode_hex(tx_receipt["transactionHash"])
    address = contract_address
    deployed = cast(DeployedContract, zk_web3.eth.contract(address=address, abi=abi))
    deployed.deployment_block = tx_receipt["blockNumber"]
    deployed.deployment_txhash = txhash
    deployed.deployment_args = list(args)
    deployed.name = name

    log.info("Deployed contract", contract=name, address=address, txhash=txhash)
    return deployed

I also had to attach the ZkSync provider to our web3 instance:

    w3 = Web3(HTTPProvider(url, request_kwargs=dict(timeout=timeout)))
    # w3 = ZkSyncBuilder.build(url)

    zksync_provider = ZkSyncProvider(url)
    zksync_middleware = build_zksync_middleware(zksync_provider)
    w3.middleware_onion.add(zksync_middleware)
    attach_modules(w3, {"zksync": (ZkSync,)})

The ABI generated by the zksolc plugin is the same as the ABI generated by solc. In fact the zksolc compiler internally uses the solc compiler. The generated bytecode is different though.

@bilbeyt bilbeyt self-assigned this Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants