Skip to content
Draft
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
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
@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
41 changes: 41 additions & 0 deletions fetch.js
Original file line number Diff line number Diff line change
@@ -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();
2 changes: 1 addition & 1 deletion lib/aave-address-book
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@
"devDependencies": {
"prettier": "^2.8.3",
"prettier-plugin-solidity": "^1.1.3"
},
"dependencies": {
"viem": "^1.16.4"
}
}
80 changes: 80 additions & 0 deletions scripts/ZkEVMClaim.s.sol
Original file line number Diff line number Diff line change
@@ -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
);
}
}
68 changes: 68 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,67 @@
# 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"
integrity sha512-ESipEcHyRHg4Np4SqBCfcXwyxxna1DgFVz69bgpLV8vzl/NP1DtcKsJ4dJZXWQhY/Z4J2LeKBiOkOVZn9ct33Q==
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"
Expand Down Expand Up @@ -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"
Expand Down