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

fix AdapterParams generation logic error #91

Merged
merged 1 commit into from
Mar 29, 2024
Merged
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
8 changes: 4 additions & 4 deletions examples/base/scripts/baseTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ task('changeFeeParams', 'Change fee params for zkLink').setAction(async (_, hre)
});

task('encodeChangeFeeParams', 'Get the calldata of changing fee params for zkLink').setAction(async (_, hre) => {
const { messenger, ethereumName, baseName } = await initMessenger();
const { ethereumName, baseName } = await initMessenger();

await encodeChangeFeeParams(hre, messenger, ethereumName, baseName);
await encodeChangeFeeParams(hre, ethereumName, baseName);
});

task('encodeSetValidator', 'Get the calldata of set validator for zkLink')
Expand All @@ -120,9 +120,9 @@ task('encodeSetValidator', 'Get the calldata of set validator for zkLink')
const isActive = taskArgs.active;
console.log(`The validator: address: ${validatorAddr}, active: ${isActive}`);

const { messenger, ethereumName, baseName } = await initMessenger();
const { ethereumName, baseName } = await initMessenger();

await encodeSetValidator(hre, messenger, ethereumName, baseName, validatorAddr, isActive);
await encodeSetValidator(hre, ethereumName, baseName, validatorAddr, isActive);
});

task('encodeL1ToL2Calldata', 'Encode call data for l1 to l2')
Expand Down
8 changes: 4 additions & 4 deletions examples/blast/scripts/blastTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ task('changeFeeParams', 'Change fee params for zkLink').setAction(async (taskArg
});

task('encodeChangeFeeParams', 'Get the calldata of changing fee params for zkLink').setAction(async (_, hre) => {
const { messenger, ethereumName, blastName } = await initMessenger();
const { ethereumName, blastName } = await initMessenger();

await encodeChangeFeeParams(hre, messenger, ethereumName, blastName);
await encodeChangeFeeParams(hre, ethereumName, blastName);
});

task('encodeSetValidator', 'Get the calldata of set validator for zkLink')
Expand All @@ -282,9 +282,9 @@ task('encodeSetValidator', 'Get the calldata of set validator for zkLink')
const isActive = taskArgs.active;
console.log(`The validator: address: ${validatorAddr}, active: ${isActive}`);

const { messenger, ethereumName, blastName } = await initMessenger();
const { ethereumName, blastName } = await initMessenger();

await encodeSetValidator(hre, messenger, ethereumName, blastName, validatorAddr, isActive);
await encodeSetValidator(hre, ethereumName, blastName, validatorAddr, isActive);
});

task('encodeL1ToL2Calldata', 'Encode call data for l1 to l2')
Expand Down
8 changes: 4 additions & 4 deletions examples/manta/scripts/mantaTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ task('encodeSetValidator', 'Get the calldata of set validator for zkLink')
const isActive = taskArgs.active;
console.log(`The validator: address: ${validatorAddr}, active: ${isActive}`);

const { messenger, ethereumName, mantaName } = await initMessenger();
const { ethereumName, mantaName } = await initMessenger();

await encodeSetValidator(hre, messenger, ethereumName, mantaName, validatorAddr, isActive);
await encodeSetValidator(hre, ethereumName, mantaName, validatorAddr, isActive);
});

task('encodeChangeFeeParams', 'Get the calldata of changing fee params for zkLink').setAction(async (_, hre) => {
const { messenger, ethereumName, mantaName } = await initMessenger();
const { ethereumName, mantaName } = await initMessenger();

await encodeChangeFeeParams(hre, messenger, ethereumName, mantaName);
await encodeChangeFeeParams(hre, ethereumName, mantaName);
});

task('encodeL1ToL2Calldata', 'Encode call data for l1 to l2')
Expand Down
74 changes: 23 additions & 51 deletions examples/optimism/scripts/opstack-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,45 +61,36 @@ async function getContractAddresses(ethereumName, opChainName) {
};
}

async function generateAdapterParams(hre, messenger, l2GatewayAddr, executeCalldata) {
const l2Gateway = await hre.ethers.getContractAt('IMessageClaimer', l2GatewayAddr);
const sendData = l2Gateway.interface.encodeFunctionData('claimMessageCallback', [0, executeCalldata]);

const gasLimit = await messenger.estimateGas.sendMessage({
direction: 1, // L2_TO_L1, Estimating the Gas Required on L2
target: l2GatewayAddr,
message: sendData,
});
console.log(`The gas limit: ${gasLimit.toString()}`);

const adapterParams = ethers.AbiCoder.defaultAbiCoder().encode(['uint256'], [gasLimit.toString()]);
async function generateAdapterParams() {
// NOTE: op stack series gateway,
// the _minGasaLimit parameter required for SendMessage is defaulted to 0, on L2 GasLimit is fixed to 288648.
// This value needs to be adjusted when an OutOfGas error occurs.
const minGasLimit = 0;
const adapterParams = ethers.utils.defaultAbiCoder.encode(['uint256'], [minGasLimit]);
console.log(`The adapter params: ${adapterParams}`);

return adapterParams;
}

async function syncBatchRoot(hre, messenger, ethereumName, opChainName) {
const { arbitratorAddr, zkLinkAddr, l1GatewayAddr, l2GatewayAddr } = await getContractAddresses(
ethereumName,
opChainName,
);
const { arbitratorAddr, zkLinkAddr, l1GatewayAddr } = await getContractAddresses(ethereumName, opChainName);
const l1Wallet = messenger.l1Signer;
const l2Provider = messenger.l2Provider;

const l1WalletAddress = await l1Wallet.getAddress();
const l1WalletBalance = ethers.formatEther((await l1Wallet.getBalance()).toString());
const l1WalletBalance = ethers.utils.formatEther((await l1Wallet.getBalance()).toString());
console.log(`${l1WalletAddress} balance on l1: ${l1WalletBalance} ether`);

// pre-execution calldata
const zkLink = await hre.ethers.getContractAt('DummyZkLink', zkLinkAddr);
const zklinkIface = zkLink.interface;
const blockNumber = await l2Provider.getBlockNumber();
console.log(`The current block number on l1: ${blockNumber}`);
const l2LogsRootHash = ethers.keccak256(ethers.toUtf8Bytes(`L2 logs root hash ${blockNumber}`));
const l2LogsRootHash = ethers.utils.keccak256(ethers.utils.toUtf8Bytes(`L2 logs root hash ${blockNumber}`));
console.log(`The l2 logs root hash: ${l2LogsRootHash}`);
const executeCalldata = zklinkIface.encodeFunctionData('syncBatchRoot', [blockNumber, l2LogsRootHash, 0]);
console.log(`The call data: ${executeCalldata}`);
const adapterParams = await generateAdapterParams(hre, messenger, l2GatewayAddr, executeCalldata);
const adapterParams = await generateAdapterParams();
// forward message to L2
const arbitrator = await hre.ethers.getContractAt('DummyArbitrator', arbitratorAddr, l1Wallet);
const sendData = arbitrator.interface.encodeFunctionData('forwardMessage', [
Expand Down Expand Up @@ -136,19 +127,13 @@ async function syncBatchRoot(hre, messenger, ethereumName, opChainName) {
}

async function setValidator(hre, messenger, ethereumName, opChainName, validatorAddr, isActive) {
const { arbitratorAddr, zkLinkAddr, l1GatewayAddr, l2GatewayAddr } = await getContractAddresses(
ethereumName,
opChainName,
);
const { arbitratorAddr, l1GatewayAddr } = await getContractAddresses(ethereumName, opChainName);
const l1Wallet = messenger.l1Signer;
const l1WalletAddress = await l1Wallet.getAddress();
const l1WalletBalance = ethers.formatEther((await l1Wallet.getBalance()).toString());
const l1WalletBalance = ethers.utils.formatEther((await l1Wallet.getBalance()).toString());
console.log(`${l1WalletAddress} balance on l1: ${l1WalletBalance} ether`);

// pre-execution calldata
const zkLink = await hre.ethers.getContractAt('ZkLink', zkLinkAddr);
const executeCalldata = zkLink.interface.encodeFunctionData('setValidator', [validatorAddr, isActive]);
const adapterParams = await generateAdapterParams(hre, messenger, l2GatewayAddr, executeCalldata);
const adapterParams = await generateAdapterParams();

// forward message to L2
const arbitrator = await hre.ethers.getContractAt('Arbitrator', arbitratorAddr, l1Wallet);
Expand Down Expand Up @@ -185,19 +170,13 @@ async function setValidator(hre, messenger, ethereumName, opChainName, validator
}

async function changeFeeParams(hre, messenger, ethereumName, opChainName) {
const { arbitratorAddr, zkLinkAddr, l1GatewayAddr, l2GatewayAddr } = await getContractAddresses(
ethereumName,
opChainName,
);
const { arbitratorAddr, l1GatewayAddr } = await getContractAddresses(ethereumName, opChainName);
const l1Wallet = messenger.l1Signer;
const l1WalletAddress = await l1Wallet.getAddress();
const l1WalletBalance = ethers.formatEther((await l1Wallet.getBalance()).toString());
const l1WalletBalance = ethers.utils.formatEther((await l1Wallet.getBalance()).toString());
console.log(`${l1WalletAddress} balance on l1: ${l1WalletBalance} ether`);

// pre-execution calldata
const zkLink = await hre.ethers.getContractAt('ZkLink', zkLinkAddr);
const executeCalldata = zkLink.interface.encodeFunctionData('changeFeeParams', [INIT_FEE_PARAMS]);
const adapterParams = await generateAdapterParams(hre, messenger, l2GatewayAddr, executeCalldata);
const adapterParams = await generateAdapterParams();

// forward message to L2
const arbitrator = await hre.ethers.getContractAt('Arbitrator', arbitratorAddr, l1Wallet);
Expand Down Expand Up @@ -238,7 +217,7 @@ async function syncL2Requests(hre, messenger, ethereumName, opChainName, txs) {
const l1Wallet = messenger.l1Signer;

const l2WalletAddress = await l2Wallet.getAddress();
const l2WalletBalance = ethers.formatEther((await l2Wallet.getBalance()).toString());
const l2WalletBalance = ethers.utils.formatEther((await l2Wallet.getBalance()).toString());
console.log(`${l2WalletAddress} balance on l2: ${l2WalletBalance} ether`);

const zkLink = await hre.ethers.getContractAt('ZkLink', zkLinkAddr, l2Wallet);
Expand Down Expand Up @@ -299,12 +278,9 @@ async function syncL2Requests(hre, messenger, ethereumName, opChainName, txs) {
console.log(`The message has been relayed`);
}

async function encodeSetValidator(hre, messenger, ethereumName, opChainName, validatorAddr, isActive) {
const { zkLinkAddr, l1GatewayAddr, l2GatewayAddr } = await getContractAddresses(ethereumName, opChainName);
// pre-execution calldata
const zkLink = await hre.ethers.getContractAt('ZkLink', zkLinkAddr);
const executeCalldata = zkLink.interface.encodeFunctionData('setValidator', [validatorAddr, isActive]);
const adapterParams = await generateAdapterParams(hre, messenger, l2GatewayAddr, executeCalldata);
async function encodeSetValidator(hre, ethereumName, opChainName, validatorAddr, isActive) {
const { l1GatewayAddr } = await getContractAddresses(ethereumName, opChainName);
const adapterParams = await generateAdapterParams();

const arbitratorFactory = await hre.ethers.getContractFactory('Arbitrator');
const calldata = arbitratorFactory.interface.encodeFunctionData('setValidator', [
Expand All @@ -318,13 +294,9 @@ async function encodeSetValidator(hre, messenger, ethereumName, opChainName, val
return calldata;
}

async function encodeChangeFeeParams(hre, messenger, ethereumName, opChainName) {
const { zkLinkAddr, l1GatewayAddr, l2GatewayAddr } = await getContractAddresses(ethereumName, opChainName);
// pre-execution calldata
const zkLink = await hre.ethers.getContractAt('ZkLink', zkLinkAddr);
console.log(`The zkLink address: ${zkLink.address}`);
const executeCalldata = zkLink.interface.encodeFunctionData('changeFeeParams', [INIT_FEE_PARAMS]);
const adapterParams = await generateAdapterParams(hre, messenger, l2GatewayAddr, executeCalldata);
async function encodeChangeFeeParams(hre, ethereumName, opChainName) {
const { l1GatewayAddr } = await getContractAddresses(ethereumName, opChainName);
const adapterParams = await generateAdapterParams();

const arbitratorFactory = await hre.ethers.getContractFactory('Arbitrator');
const calldata = arbitratorFactory.interface.encodeFunctionData('changeFeeParams', [
Expand Down
8 changes: 4 additions & 4 deletions examples/optimism/scripts/optimismTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ task('encodeSetValidator', 'Get the calldata of set validator for zkLink')
const isActive = taskArgs.active;
console.log(`The validator: address: ${validatorAddr}, active: ${isActive}`);

const { messenger, ethereumName, optimismName } = await initMessenger();
const { ethereumName, optimismName } = await initMessenger();

await encodeSetValidator(hre, messenger, ethereumName, optimismName, validatorAddr, isActive);
await encodeSetValidator(hre, ethereumName, optimismName, validatorAddr, isActive);
});

task('encodeChangeFeeParams', 'Get the calldata of changing fee params for zkLink').setAction(async (_, hre) => {
const { messenger, ethereumName, optimismName } = await initMessenger();
const { ethereumName, optimismName } = await initMessenger();

await encodeChangeFeeParams(hre, messenger, ethereumName, optimismName);
await encodeChangeFeeParams(hre, ethereumName, optimismName);
});

task('encodeL1ToL2Calldata', 'Encode call data for l1 to l2')
Expand Down
Loading