Created
June 6, 2023 14:30
-
-
Save bzpassersby/f104be26f010a70387322666415457c8 to your computer and use it in GitHub Desktop.
POC L1 finalize withdraw succeed with 0 hardcoded gas value.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable camelcase */ | |
import { ethers, network } from 'hardhat' | |
import { Signer, Contract, constants, BigNumber } from 'ethers' | |
import { smock, FakeContract, MockContract } from '@defi-wonderland/smock' | |
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers' | |
import { expect } from 'chai' | |
import { | |
REGISTRY_DEPLOY_TX, | |
REGISTRY_DEPLOYER_ADDRESS, | |
NON_NULL_BYTES32, | |
NON_ZERO_ADDRESS, | |
} from './utils/constants' | |
const hre = require('hardhat') | |
const PORTAL_L2ORACLE_ADDRESS = '0xaBBAABbaaBbAABbaABbAABbAABbaAbbaaBbaaBBa' | |
const PORTAL_GUARDIAN = '0x1234512345123451234512345123451234512345' | |
const DUMMY_L2_ERC20_ADDRESS = '0xaBBAABbaaBbAABbaABbAABbAABbaAbbaaBbaaBBa' | |
const DUMMY_L2_BRIDGE_ADDRESS = '0xACDCacDcACdCaCDcacdcacdCaCdcACdCAcDcaCdc' | |
const DUMMY_L1_ERC20_ADDRESS = '0xACDCacDcACdCaCDcacdcacdCaCdcACdCAcDcaCdc' | |
const DUMMY_PROXY_ADMIN_ADDRESS = '0x1234512345123451234512345123451234512345' | |
const INITIAL_INFLATION_MULTIPLIER = BigNumber.from('1000000000000000000') | |
// 2e18 | |
const INITIAL_TOTAL_L1_SUPPLY = BigNumber.from('2000000000000000000') | |
describe('L1ECOBridgeWithdrawRevert', () => { | |
let l1MessengerImpersonator: Signer | |
let alice: SignerWithAddress | |
let bob: SignerWithAddress | |
let portal_systemconfig: SignerWithAddress | |
before(async () => { | |
;[l1MessengerImpersonator, alice, bob, portal_systemconfig] = | |
await ethers.getSigners() | |
await ( | |
await alice.sendTransaction({ | |
to: REGISTRY_DEPLOYER_ADDRESS, | |
value: ethers.utils.parseEther('0.08'), | |
}) | |
).wait() | |
if (alice.provider) { | |
await (await alice.provider.sendTransaction(REGISTRY_DEPLOY_TX)).wait() | |
} | |
}) | |
let l1CrossDomainMessenger: MockContract<Contract> | |
let optimismPortal: MockContract<Contract> | |
let L1ERC20: MockContract<Contract> | |
let L1ECOBridge: MockContract | |
let Fake_SystemConfig: FakeContract | |
beforeEach(async () => { | |
//Deploy L1ERC20 | |
L1ERC20 = await ( | |
await smock.mock( | |
'@helix-foundation/currency/contracts/currency/ECO.sol:ECO' | |
) | |
).deploy( | |
DUMMY_L1_ERC20_ADDRESS, | |
alice.address, | |
ethers.utils.parseEther('10000'), | |
alice.address | |
) | |
console.log('L1ERC20.address', L1ERC20.address) | |
await L1ERC20.setVariable('_balances', { | |
[alice.address]: INITIAL_TOTAL_L1_SUPPLY.mul( | |
INITIAL_INFLATION_MULTIPLIER | |
), | |
}) | |
await L1ERC20.setVariable('checkpoints', { | |
[alice.address]: [ | |
{ | |
fromBlock: 0, | |
value: INITIAL_TOTAL_L1_SUPPLY.mul(INITIAL_INFLATION_MULTIPLIER), | |
}, | |
], | |
}) | |
optimismPortal = await ( | |
await smock.mock( | |
'@eth-optimism/contracts-bedrock/contracts/L1/OptimismPortal.sol:OptimismPortal' | |
) | |
).deploy( | |
PORTAL_L2ORACLE_ADDRESS, | |
PORTAL_GUARDIAN, | |
false, | |
portal_systemconfig.address | |
) | |
console.log('optimismPortal.address', optimismPortal.address) | |
// Deploy SystemConfig | |
Fake_SystemConfig = await smock.fake<Contract>( | |
'@eth-optimism/contracts-bedrock/contracts/L1/SystemConfig.sol:SystemConfig', | |
{ address: portal_systemconfig.address } | |
) | |
Fake_SystemConfig.resourceConfig.returns({ | |
maxResourceLimit: 120000000, | |
elasticityMultiplier: 1, | |
baseFeeMaxChangeDenominator: 100, | |
minimumBaseFee: 0, | |
systemTxMaxGas: 1200000, | |
maximumBaseFee: 10, | |
}) | |
console.log('Fake_SystemConfig.address', Fake_SystemConfig.address) | |
l1CrossDomainMessenger = await ( | |
await smock.mock( | |
'@eth-optimism/contracts-bedrock/contracts/L1/L1CrossDomainMessenger.sol:L1CrossDomainMessenger' | |
) | |
).deploy(optimismPortal.address) | |
console.log( | |
'l1CrossDomainMessenger.address', | |
l1CrossDomainMessenger.address | |
) | |
l1CrossDomainMessenger.xDomainMessageSender.returns(DUMMY_L2_BRIDGE_ADDRESS) | |
// Deploy the bridge | |
L1ECOBridge = await (await smock.mock('L1ECOBridge')).deploy() | |
console.log('L1ERC20Bridge.address', L1ECOBridge.address) | |
await L1ECOBridge.setVariable('_initializing', false) | |
await L1ECOBridge.connect(alice).initialize( | |
l1CrossDomainMessenger.address, | |
DUMMY_L2_BRIDGE_ADDRESS, | |
L1ERC20.address, | |
DUMMY_L2_ERC20_ADDRESS, | |
DUMMY_PROXY_ADMIN_ADDRESS, | |
alice.address | |
) | |
}) | |
describe('L1WithdrawSucceed', () => { | |
const withdrawalAmount = INITIAL_TOTAL_L1_SUPPLY | |
it('should succeed when FinalizedWithdrawal is called', async () => { | |
await hre.network.provider.request({ | |
method: 'hardhat_impersonateAccount', | |
params: [l1CrossDomainMessenger.address], | |
}) | |
const messenger = await ethers.getSigner(l1CrossDomainMessenger.address) | |
await network.provider.send('hardhat_setBalance', [ | |
messenger.address, | |
'0x100000000000000000000000', | |
]) | |
await expect( | |
L1ECOBridge.connect(messenger).finalizeERC20Withdrawal( | |
L1ERC20.address, | |
DUMMY_L2_ERC20_ADDRESS, | |
NON_ZERO_ADDRESS, | |
NON_ZERO_ADDRESS, | |
withdrawalAmount.mul(INITIAL_INFLATION_MULTIPLIER), | |
NON_NULL_BYTES32 | |
) | |
).to.be.emit(optimismPortal, 'TransactionDeposited') | |
}) | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment