diff --git a/Makefile b/Makefile index fd61488d9..f91f2fa5a 100644 --- a/Makefile +++ b/Makefile @@ -55,4 +55,7 @@ deploy-config-engine-v2-ava :; forge script scripts/AaveV2ConfigEngine.s.sol:Dep download :; cast etherscan-source --chain ${chain} -d src/etherscan/${chain}_${address} ${address} git-diff : @mkdir -p diffs - @printf '%s\n%s\n%s\n' "\`\`\`diff" "$$(git diff --no-index --diff-algorithm=patience --ignore-space-at-eol ${before} ${after})" "\`\`\`" > diffs/${out}.md \ No newline at end of file + @printf '%s\n%s\n%s\n' "\`\`\`diff" "$$(git diff --no-index --diff-algorithm=patience --ignore-space-at-eol ${before} ${after})" "\`\`\`" > diffs/${out}.md + +## Claim zkEVM message +claim :; forge script scripts/ZkEVMClaim.s.sol:ClaimZkEVMMessage --rpc-url https://zkevm-rpc.com --broadcast --ledger --mnemonic-indexes ${MNEMONIC_INDEX} --sender ${LEDGER_SENDER} --verify -vvvv \ No newline at end of file diff --git a/fetch.js b/fetch.js new file mode 100644 index 000000000..488eda7c5 --- /dev/null +++ b/fetch.js @@ -0,0 +1,41 @@ +const { encodeAbiParameters, parseAbiParameters } = require('viem'); + +var args = process.argv.slice(2); + +async function fetchParams() { + const bridgeCall = await ( + await fetch(`https://bridge-api.zkevm-rpc.com/bridges/${args[0]}`) + ).json(); + if (process.env.VERBOSE) console.log(bridgeCall); + const deposit = bridgeCall.deposits.find( + (deposit) => deposit.claim_tx_hash == '' && deposit.ready_for_claim == true + ); + if (!deposit) throw new Error('No claimable deposit txn found'); + const proof = await ( + await fetch( + `https://bridge-api.zkevm-rpc.com/merkle-proof?deposit_cnt=${deposit.deposit_cnt}&net_id=${deposit.network_id}` + ) + ).json(); + + if (process.env.VERBOSE) console.log(proof); + const encodedData = encodeAbiParameters( + parseAbiParameters( + 'bytes32[32] smtProof, uint32 index, bytes32 mainnetExitRoot, bytes32 rollupExitRoot, uint32 originNetwork, address originAddress, uint32 destinationNetwork, address destinationAddress, uint256 amount, bytes metadata' + ), + [ + proof.proof.merkle_proof, + Number(deposit.deposit_cnt), + proof.proof.main_exit_root, + proof.proof.rollup_exit_root, + Number(deposit.orig_net), + deposit.orig_addr, + Number(deposit.dest_net), + deposit.dest_addr, + Number(deposit.amount), + deposit.metadata, + ] + ); + console.log(encodedData); +} + +fetchParams(); diff --git a/lib/aave-address-book b/lib/aave-address-book index 50b9acc87..96992a3b2 160000 --- a/lib/aave-address-book +++ b/lib/aave-address-book @@ -1 +1 @@ -Subproject commit 50b9acc87adc355d669895bdfc884a79fd4b9abe +Subproject commit 96992a3b2b3cb635cb828b12fa0e418bbf053182 diff --git a/package.json b/package.json index ae80002d3..2f7d1eb7d 100644 --- a/package.json +++ b/package.json @@ -24,5 +24,8 @@ "devDependencies": { "prettier": "^2.8.3", "prettier-plugin-solidity": "^1.1.3" + }, + "dependencies": { + "viem": "^1.16.4" } } diff --git a/scripts/ZkEVMClaim.s.sol b/scripts/ZkEVMClaim.s.sol new file mode 100644 index 000000000..719663b92 --- /dev/null +++ b/scripts/ZkEVMClaim.s.sol @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.0; + +import {Script} from 'forge-std/Script.sol'; + +interface ZkEVMBridge { + function claimMessage( + bytes32[32] calldata smtProof, + uint32 index, + bytes32 mainnetExitRoot, + bytes32 rollupExitRoot, + uint32 originNetwork, + address originAddress, + uint32 destinationNetwork, + address destinationAddress, + uint256 amount, + bytes calldata metadata + ) external; +} + +contract ClaimZkEVMMessage is Script { + address constant ZK_EVM_BRIDGE = 0x2a3DD3EB832aF982ec71669E178424b10Dca2EDe; + + address constant DESTINATION = 0x889c0cc3283DB588A34E89Ad1E8F25B0fc827b4b; + + function getProof() + internal + returns ( + bytes32[32] memory smtProof, + uint32 index, + bytes32 mainnetExitRoot, + bytes32 rollupExitRoot, + uint32 originNetwork, + address originAddress, + uint32 destinationNetwork, + address destinationAddress, + uint256 amount, + bytes memory metadata + ) + { + string[] memory inputs = new string[](3); + inputs[0] = 'node'; + inputs[1] = 'fetch.js'; + inputs[2] = vm.toString(DESTINATION); + bytes memory response = vm.ffi(inputs); + return + abi.decode( + response, + (bytes32[32], uint32, bytes32, bytes32, uint32, address, uint32, address, uint256, bytes) + ); + } + + function run() external { + ( + bytes32[32] memory smtProof, + uint32 index, + bytes32 mainnetExitRoot, + bytes32 rollupExitRoot, + uint32 originNetwork, + address originAddress, + uint32 destinationNetwork, + address destinationAddress, + uint256 amount, + bytes memory metadata + ) = getProof(); + vm.startBroadcast(); + ZkEVMBridge(ZK_EVM_BRIDGE).claimMessage( + smtProof, + index, + mainnetExitRoot, + rollupExitRoot, + originNetwork, + originAddress, + destinationNetwork, + destinationAddress, + amount, + metadata + ); + } +} diff --git a/yarn.lock b/yarn.lock index 48e2bbae0..7e7e3b7af 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,45 @@ # yarn lockfile v1 +"@adraffy/ens-normalize@1.9.4": + version "1.9.4" + resolved "https://registry.yarnpkg.com/@adraffy/ens-normalize/-/ens-normalize-1.9.4.tgz#aae21cb858bbb0411949d5b7b3051f4209043f62" + integrity sha512-UK0bHA7hh9cR39V+4gl2/NnBBjoXIxkuWAPCaY4X7fbH4L/azIi7ilWOCjMUYfpJgraLUAqkRi2BqrjME8Rynw== + +"@noble/curves@1.2.0", "@noble/curves@~1.2.0": + version "1.2.0" + resolved "https://registry.yarnpkg.com/@noble/curves/-/curves-1.2.0.tgz#92d7e12e4e49b23105a2555c6984d41733d65c35" + integrity sha512-oYclrNgRaM9SsBUBVbb8M6DTV7ZHRTKugureoYEncY5c65HOmRzvSiTE3y5CYaPYJA/GVkrhXEoF0M3Ya9PMnw== + dependencies: + "@noble/hashes" "1.3.2" + +"@noble/hashes@1.3.2", "@noble/hashes@~1.3.0", "@noble/hashes@~1.3.2": + version "1.3.2" + resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.2.tgz#6f26dbc8fbc7205873ce3cee2f690eba0d421b39" + integrity sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ== + +"@scure/base@~1.1.0", "@scure/base@~1.1.2": + version "1.1.3" + resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.1.3.tgz#8584115565228290a6c6c4961973e0903bb3df2f" + integrity sha512-/+SgoRjLq7Xlf0CWuLHq2LUZeL/w65kfzAPG5NH9pcmBhs+nunQTn4gvdwgMTIXnt9b2C/1SeL2XiysZEyIC9Q== + +"@scure/bip32@1.3.2": + version "1.3.2" + resolved "https://registry.yarnpkg.com/@scure/bip32/-/bip32-1.3.2.tgz#90e78c027d5e30f0b22c1f8d50ff12f3fb7559f8" + integrity sha512-N1ZhksgwD3OBlwTv3R6KFEcPojl/W4ElJOeCZdi+vuI5QmTFwLq3OFf2zd2ROpKvxFdgZ6hUpb0dx9bVNEwYCA== + dependencies: + "@noble/curves" "~1.2.0" + "@noble/hashes" "~1.3.2" + "@scure/base" "~1.1.2" + +"@scure/bip39@1.2.1": + version "1.2.1" + resolved "https://registry.yarnpkg.com/@scure/bip39/-/bip39-1.2.1.tgz#5cee8978656b272a917b7871c981e0541ad6ac2a" + integrity sha512-Z3/Fsz1yr904dduJD0NpiyRHhRYHdcnyh73FZWiV+/qhWi83wNJ3NWolYqCEN+ZWsUz2TWwajJggcRE9r1zUYg== + dependencies: + "@noble/hashes" "~1.3.0" + "@scure/base" "~1.1.0" + "@solidity-parser/parser@^0.16.0": version "0.16.0" resolved "https://registry.yarnpkg.com/@solidity-parser/parser/-/parser-0.16.0.tgz#1fb418c816ca1fc3a1e94b08bcfe623ec4e1add4" @@ -9,11 +48,21 @@ dependencies: antlr4ts "^0.5.0-alpha.4" +abitype@0.9.8: + version "0.9.8" + resolved "https://registry.yarnpkg.com/abitype/-/abitype-0.9.8.tgz#1f120b6b717459deafd213dfbf3a3dd1bf10ae8c" + integrity sha512-puLifILdm+8sjyss4S+fsUN09obiT1g2YW6CtcQF+QDzxR0euzgEB29MZujC6zMk2a6SVmtttq1fc6+YFA7WYQ== + antlr4ts@^0.5.0-alpha.4: version "0.5.0-alpha.4" resolved "https://registry.npmjs.org/antlr4ts/-/antlr4ts-0.5.0-alpha.4.tgz" integrity sha512-WPQDt1B74OfPv/IMS2ekXAKkTZIHl88uMetg6q3OTqgFxZ/dxDXI0EWLyZid/1Pe6hTftyg5N7gel5wNAGxXyQ== +isows@1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/isows/-/isows-1.0.3.tgz#93c1cf0575daf56e7120bab5c8c448b0809d0d74" + integrity sha512-2cKei4vlmg2cxEjm3wVSqn8pcoRF/LX/wpifuuNquFO4SQmPwarClT+SUCA2lt+l581tTeZIPIZuIDo2jWN1fg== + lru-cache@^6.0.0: version "6.0.0" resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz" @@ -47,6 +96,25 @@ solidity-comments-extractor@^0.0.7: resolved "https://registry.npmjs.org/solidity-comments-extractor/-/solidity-comments-extractor-0.0.7.tgz" integrity sha512-wciNMLg/Irp8OKGrh3S2tfvZiZ0NEyILfcRCXCD4mp7SgK/i9gzLfhY2hY7VMCQJ3kH9UB9BzNdibIVMchzyYw== +viem@^1.16.4: + version "1.16.4" + resolved "https://registry.yarnpkg.com/viem/-/viem-1.16.4.tgz#4cb90dd27d13356ea00d21f6fd363bdfe0628c4e" + integrity sha512-T9ziN3EERXz0BtQSS2VJM+P1EJ2W7K7PviobFrmvWCEYmNQ/vJDhfFqGjvq0ZL9LVz9HvevCbenEy8oIdMEZ+w== + dependencies: + "@adraffy/ens-normalize" "1.9.4" + "@noble/curves" "1.2.0" + "@noble/hashes" "1.3.2" + "@scure/bip32" "1.3.2" + "@scure/bip39" "1.2.1" + abitype "0.9.8" + isows "1.0.3" + ws "8.13.0" + +ws@8.13.0: + version "8.13.0" + resolved "https://registry.yarnpkg.com/ws/-/ws-8.13.0.tgz#9a9fb92f93cf41512a0735c8f4dd09b8a1211cd0" + integrity sha512-x9vcZYTrFPC7aSIbj7sRCYo7L/Xb8Iy+pW0ng0wt2vCJv7M9HOMy0UoN3rr+IFC7hb7vXoqS+P9ktyLLLhO+LA== + yallist@^4.0.0: version "4.0.0" resolved "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz"