Skip to content

Commit

Permalink
update bridge mock
Browse files Browse the repository at this point in the history
  • Loading branch information
invocamanman committed Oct 3, 2022
1 parent 93525be commit e0404cc
Show file tree
Hide file tree
Showing 19 changed files with 587 additions and 1,927 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ To run the docker you can use: `docker run -p 8545:8545 hermez-geth1.3:latest`

Polygon `zkevm-contracts` was developed by Polygon. While we plan to adopt an open source license, we haven’t selected one yet, so all rights are reserved for the time being. Please reach out to us if you have thoughts on licensing.

## Note

In order to test, the following private keys are being used. This keys are not meant to be used in any production environment:

- private key: `0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80`
- address:`0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266`
- private key: `0xdfd01798f92667dbf91df722434e8fbe96af0211d4d1b82bbbbc8f1def7a814f`
- address:`0xc949254d682d8c9ad5682521675b8f43b102aec4`

### Disclaimer

This code has not yet been audited, and should not be used in any production systems.
4 changes: 2 additions & 2 deletions compiled-contracts/Bridge.json

Large diffs are not rendered by default.

98 changes: 80 additions & 18 deletions compiled-contracts/BridgeMock.json

Large diffs are not rendered by default.

17 changes: 15 additions & 2 deletions compiled-contracts/ProofOfEfficiencyMock.json

Large diffs are not rendered by default.

9 changes: 3 additions & 6 deletions contracts/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ contract Bridge is DepositContract {
function initialize(
uint32 _networkID,
IGlobalExitRootManager _globalExitRootManager
) public initializer {
) public virtual initializer {
networkID = _networkID;
globalExitRootManager = _globalExitRootManager;
tokenImplementation = address(new TokenWrapped());
Expand Down Expand Up @@ -107,7 +107,7 @@ contract Bridge is DepositContract {
address destinationAddress,
uint256 amount,
bytes calldata permitData
) public payable {
) public payable virtual {
require(
destinationNetwork != networkID,
"Bridge::bridge: DESTINATION_CANT_BE_ITSELF"
Expand Down Expand Up @@ -411,10 +411,7 @@ contract Bridge is DepositContract {
bytes calldata permitData
) internal {
bytes4 sig = _getSelector(permitData);
require(
sig == _PERMIT_SIGNATURE,
"Bridge::_permit: NOT_VALID_CALL"
);
require(sig == _PERMIT_SIGNATURE, "Bridge::_permit: NOT_VALID_CALL");
(
address owner,
address spender,
Expand Down
50 changes: 45 additions & 5 deletions contracts/mocks/BridgeMock.sol
Original file line number Diff line number Diff line change
@@ -1,24 +1,64 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.15;
import "../Bridge.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";

/**
* Bridge that will be deployed on both networks Ethereum and Polygon zkEVM
* Contract responsible to manage the token interactions with other networks
*/
contract BridgeMock is Bridge {
contract BridgeMock is Bridge, OwnableUpgradeable {
uint256 public maxEtherBridge;

/**
* @param _networkID networkID
* @param _globalExitRootManager global exit root manager address
*/
constructor(
function initialize(
uint32 _networkID,
IGlobalExitRootManager _globalExitRootManager
) {
initialize(_networkID, _globalExitRootManager);
) public override initializer {
networkID = _networkID;
globalExitRootManager = _globalExitRootManager;
tokenImplementation = address(new TokenWrapped());
__DepositContract_init();
__Ownable_init();
maxEtherBridge = 0.25 ether;
}

function setNetworkID(uint32 _networkID) public {
function setNetworkID(uint32 _networkID) public onlyOwner {
networkID = _networkID;
}

function setMaxEtherBridge(uint256 _maxEtherBridge) public onlyOwner {
maxEtherBridge = _maxEtherBridge;
}

/**
* @notice Deposit add a new leaf to the merkle tree
* @param token Token address, 0 address is reserved for ether
* @param destinationNetwork Network destination
* @param destinationAddress Address destination
* @param amount Amount of tokens
* @param permitData Raw data of the call `permit` of the token
*/
function bridge(
address token,
uint32 destinationNetwork,
address destinationAddress,
uint256 amount,
bytes calldata permitData
) public payable override {
require(
msg.value <= maxEtherBridge,
"Bridge::bridge: Cannot bridge more than maxEtherBridge in internal testnet"
);
super.bridge(
token,
destinationNetwork,
destinationAddress,
amount,
permitData
);
}
}
8 changes: 8 additions & 0 deletions contracts/mocks/ProofOfEfficiencyMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,14 @@ contract ProofOfEfficiencyMock is ProofOfEfficiency, OwnableUpgradeable {
lastBatchSequenced = _numBatch;
}

/**
* @notice Set network name
* @param _networkName New verifier
*/
function setNetworkName(string memory _networkName) public onlyOwner {
networkName = _networkName;
}

/**
* @notice Allows an aggregator to verify a batch
* @param newLocalExitRoot New local exit root once the batch is processed
Expand Down
4 changes: 4 additions & 0 deletions deployment/deployment_v2-0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ To verify contracts run `npm run verify:PoE2_0:${network}`, for example:
```
npm run verify:PoE2_0:goerli
```

## Notes

- `gensis.json` has been generated using the tool: `zkevm-commonjs/tools/fill-genesis/create-genesis.js` using as generator file: `genesis-gen.json`
16 changes: 11 additions & 5 deletions deployment/deployment_v2-0/deployPoE_v2-0.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function main() {
const atemptsDeployProxy = 20;

let currentProvider = ethers.provider;
if(deployParameters.multiplierGas || deployParameters.maxFeePerGas) {
if (deployParameters.multiplierGas || deployParameters.maxFeePerGas) {
if (process.env.HARDHAT_NETWORK != "hardhat") {
currentProvider = new ethers.providers.JsonRpcProvider(`https://${process.env.HARDHAT_NETWORK}.infura.io/v3/${process.env.INFURA_PROJECT_ID}`);
if (deployParameters.maxPriorityFeePerGas && deployParameters.maxFeePerGas) {
Expand All @@ -41,12 +41,12 @@ async function main() {
};
}
currentProvider.getFeeData = overrideFeeData;
}
}
}
}

let deployer;
if(deployParameters.privateKey) {
if (deployParameters.privateKey) {
deployer = new ethers.Wallet(deployParameters.privateKey, currentProvider);
} else {
deployer = ethers.Wallet.fromMnemonic(process.env.MNEMONIC, `m/44'/60'/0'/0/0`).connect(currentProvider);
Expand Down Expand Up @@ -106,7 +106,13 @@ async function main() {
}

// deploy bridge
const bridgeFactory = await ethers.getContractFactory('Bridge', deployer);
let bridgeFactory;
if (deployParameters.bridgeMock) {
bridgeFactory = await ethers.getContractFactory('BridgeMock', deployer);
} else {
bridgeFactory = await ethers.getContractFactory('Bridge', deployer);
}

let bridgeContract;
for (let i = 0; i < atemptsDeployProxy; i++) {
try {
Expand Down
3 changes: 2 additions & 1 deletion deployment/deployment_v2-0/deploy_parameters.json.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"maxFeePerGas":0,
"maxPriorityFeePerGas":0,
"multiplierGas": 0,
"trustedSequencerPvtKey":""
"trustedSequencerPvtKey":"",
"bridgeMock":false
}
64 changes: 64 additions & 0 deletions deployment/deployment_v2-0/genesis-gen.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

{
"defaultChainId": 1000,
"sequencerAddress": "0xC949254d682D8c9ad5682521675b8F43b102aec4",
"genesis": [
{
"address": "0x9D98DeAbC42dd696Deb9e40b4f1CAB7dDBF55988",
"pvtKey": "0x00",
"balance": "100000000000000000000000",
"nonce": "0"
},
{
"address": "0xC949254d682D8c9ad5682521675b8F43b102aec4",
"pvtKey": "0xdfd01798f92667dbf91df722434e8fbe96af0211d4d1b82bbbbc8f1def7a814f",
"balance": "0",
"nonce": "0"
}
],
"txs": [
{
"from": "0xC949254d682D8c9ad5682521675b8F43b102aec4",
"nonce": 0,
"value": "0",
"gasLimit": 10000000,
"gasPrice": "0",
"chainId": 1000,
"paramsDeploy": {
"types": [
"address"
],
"values": [
"0x9D98DeAbC42dd696Deb9e40b4f1CAB7dDBF55988"
]
},
"contractName": "GlobalExitRootManagerL2",
"reason": ""
},
{
"from": "0xC949254d682D8c9ad5682521675b8F43b102aec4",
"nonce": 1,
"value": "0",
"gasLimit": 10000000,
"gasPrice": "0",
"chainId": 1000,
"contractName": "Bridge"
},
{
"from": "0xC949254d682D8c9ad5682521675b8F43b102aec4",
"to": "0x9D98DeAbC42dd696Deb9e40b4f1CAB7dDBF55988",
"nonce": 2,
"value": "0",
"gasLimit": 10000000,
"gasPrice": "0",
"chainId": 1000,
"function": "initialize",
"paramsFunction": [
1,
"0xAE4bB80bE56B819606589DE61d5ec3b522EEB032"
],
"contractName": "Bridge"
}
],
"timestamp": 1944498031
}
Loading

0 comments on commit e0404cc

Please sign in to comment.