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

Change cross chain messages #2250

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
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
7 changes: 5 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"vscode": {
"extensions": [
"766b.go-outliner",
"golang.go"
"golang.go",
"zxh404.vscode-proto3",
"NomicFoundation.hardhat-solidity"
],
"settings": {
"go.testTimeout": "10m"
Expand All @@ -24,7 +26,8 @@
},
"postCreateCommand": "bash -i ./.devcontainer/install-deps.sh",
"containerEnv": {
"LOCALHOST_URL": "http://host.docker.internal"
"LOCALHOST_URL": "http://host.docker.internal",
"IDE": "true"
}

// Features to add to the dev container. More info: https://containers.dev/features.
Expand Down
6 changes: 5 additions & 1 deletion .devcontainer/install-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ go install github.com/ethereum/go-ethereum/cmd/[email protected];
nvm install 18;
cd contracts;
npm install;
cd ..
cd ..
sudo apt-get update;
sudo apt-get install -y protobuf-compiler;
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest;
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest;
57 changes: 25 additions & 32 deletions contracts/deployment_scripts/testing/003_simple_withdrawal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ async function waitForRootPublished(management, msg, proof, root, provider: Ethe
var gas_estimate = null
const l1Ethers = new HardhatEthersProvider(provider, "layer1")

console.log(`balance of management contract = ${await l1Ethers.getBalance(management.getAddress())}`)

const startTime = Date.now();
while (gas_estimate === null) {
try {
Expand All @@ -51,10 +53,24 @@ async function waitForRootPublished(management, msg, proof, root, provider: Ethe
console.log(`Estimation took ${Date.now() - startTime} ms`)
return gas_estimate
}

async function retryLoop(callback: ()=>Promise<boolean>, interval = 20000, timeout = 12000000) {
const startTime = Date.now();
while (true) {
try {
const result = await callback();
if (result) {
return result;
}
} catch (error) {
console.log(`Error in retry loop: ${error}`);
}
await sleep(interval);
}
}


const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
return;
const l2Network = hre;
const {deployer} = await hre.getNamedAccounts();

Expand All @@ -81,41 +97,18 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const msgHash = _processed_value_transfer[1]
const decoded = decode_base64(block.crossChainTree)

console.log(` Sender: ${value_transfer['args'].sender}`)
console.log(` Receiver: ${value_transfer['args'].receiver}`)
console.log(` Amount: ${value_transfer['args'].amount}`)
console.log(` Sequence: ${value_transfer['args'].sequence}`)
console.log(` VTrans Hash: ${msgHash}`)
console.log(` XChain tree: ${decoded}`)

if (decoded[0][1] != msgHash) {
console.error('Value transfer hash is not in the xchain tree!');
return;
}

const tree = StandardMerkleTree.of(decoded, ["string", "bytes32"]);
const proof = tree.getProof(['v',msgHash])
console.log(` Merkle root: ${tree.root}`)
console.log(` Merkle proof: ${JSON.stringify(proof, null,2)}`)

if (block.crossChainTreeHash != tree.root) {
console.error('Constructed merkle root matches block crossChainTreeHash');
return
}
console.log(`Decoded = ${JSON.stringify(decoded, null, 2)}`)
console.log(`Getting cross chain proof for 'v' and msgHash = ${msgHash}`)

const l1Accounts = await hre.companionNetworks.layer1.getNamedAccounts()
const fundTx = await hre.companionNetworks.layer1.deployments.rawTx({
from: l1Accounts.deployer,
to: messageBusAddress,
value: "1000",
})
console.log(`Message bus funding status = ${fundTx.status}`)
const proof : any = await retryLoop(() => hre.ethers.provider.send('ten_getCrossChainProof', ['v', msgHash]))

const code = await hre.companionNetworks.layer1.provider.request({method: 'eth_getCode', params: [mgmtContractAddress, 'latest']});
console.log(`Management contract code = ${(code as string).length}`);
console.log(`Proof = ${JSON.stringify(proof, null, 2)}`)

var managementContract = await hre.ethers.getContractAt("ManagementContract", mgmtContractAddress);
const estimation = await waitForRootPublished(managementContract, msg, proof, tree.root, hre.companionNetworks.layer1.provider)

const decoded_proof = hre.ethers.decodeRlp(proof.Proof)

const estimation = await waitForRootPublished(managementContract, msg, decoded_proof, proof.Root, hre.companionNetworks.layer1.provider)
console.log(`Estimation for native value extraction = ${estimation}`)
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ async function buildMerkleProof(tree: any, message: any) {
}

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
return;
const l2Network = hre;
const l1Network = hre.companionNetworks.layer1!;
const { deployer } = await hre.getNamedAccounts();
Expand Down
110 changes: 14 additions & 96 deletions contracts/generated/ManagementContract/ManagementContract.go

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/generated/MessageBus/MessageBus.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/generated/PublicCallbacks/PublicCallbacks.go

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contracts/generated/SystemDeployer/SystemDeployer.go

Large diffs are not rendered by default.

Loading
Loading