forked from 0xPolygonHermez/zkevm-contracts
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request 0xPolygonHermez#9 from hermeznetwork/feature/addDo…
…ckers Small changes + dockers
- Loading branch information
Showing
16 changed files
with
405 additions
and
61 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
MNEMONIC="test test test test test test test test test test test test" | ||
MNEMONIC="test test test test test test test test test test test junk" | ||
INFURA_PROJECT_ID="" | ||
ETHERSCAN_API_KEY="" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,5 @@ coverage | |
artifacts/ | ||
docs/interfaces | ||
docs/mocks | ||
.vscode/launch.json | ||
.vscode/launch.json | ||
deploy_output.json |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// SPDX-License-Identifier: AGPL-3.0 | ||
pragma solidity 0.8.9; | ||
|
||
import "../ProofOfEfficiency.sol"; | ||
import "hardhat/console.sol"; | ||
|
||
/** | ||
* Contract responsible for managing the state and the updates of it of the L2 Hermez network. | ||
* There will be sequencer, wich are able to send transactions. That transactions will be stored in the contract. | ||
* The aggregators are forced to process and validate the sequencers transactions in the same order by using a verifier. | ||
* To enter and exit of the L2 network will be used a Bridge smart contract | ||
*/ | ||
contract ProofOfEfficiencyMock is ProofOfEfficiency { | ||
/** | ||
* @param _bridge Bridge contract address | ||
* @param _matic MATIC token address | ||
* @param _rollupVerifier rollup verifier address | ||
*/ | ||
constructor( | ||
BridgeInterface _bridge, | ||
IERC20 _matic, | ||
VerifierRollupInterface _rollupVerifier | ||
) ProofOfEfficiency(_bridge, _matic, _rollupVerifier) {} | ||
|
||
/** | ||
* @notice Calculate the circuit input | ||
* @param currentStateRoot Current state Root | ||
* @param currentLocalExitRoot Current local exit root | ||
* @param newStateRoot New State root once the batch is processed | ||
* @param newLocalExitRoot New local exit root once the batch is processed | ||
* @param sequencerAddress Sequencer address | ||
* @param batchL2HashData Batch hash data | ||
* @param batchChainID Batch chain ID | ||
* @param batchNum Batch number that the aggregator intends to verify, used as a sanity check | ||
*/ | ||
function calculateCircuitInput( | ||
bytes32 currentStateRoot, | ||
bytes32 currentLocalExitRoot, | ||
bytes32 newStateRoot, | ||
bytes32 newLocalExitRoot, | ||
address sequencerAddress, | ||
bytes32 batchL2HashData, | ||
uint32 batchChainID, | ||
uint32 batchNum | ||
) public pure returns (uint256) { | ||
uint256 input = uint256( | ||
keccak256( | ||
abi.encodePacked( | ||
currentStateRoot, | ||
currentLocalExitRoot, | ||
newStateRoot, | ||
newLocalExitRoot, | ||
sequencerAddress, | ||
batchL2HashData, | ||
batchChainID, | ||
batchNum | ||
) | ||
) | ||
); | ||
return input; | ||
} | ||
|
||
/** | ||
* @notice Calculate the circuit input | ||
* @param newStateRoot New State root once the batch is processed | ||
* @param newLocalExitRoot New local exit root once the batch is processed | ||
* @param batchNum Batch number that the aggregator intends to verify, used as a sanity check | ||
*/ | ||
function getNextCircuitInput( | ||
bytes32 newStateRoot, | ||
bytes32 newLocalExitRoot, | ||
uint32 batchNum | ||
) public view returns (uint256) { | ||
// sanity check | ||
require( | ||
batchNum == lastVerifiedBatch + 1, | ||
"ProofOfEfficiency::verifyBatch: BATCH_DOES_NOT_MATCH" | ||
); | ||
|
||
// Calculate Circuit Input | ||
BatchData memory currentBatch = sentBatches[batchNum]; | ||
address sequencerAddress = currentBatch.sequencerAddress; | ||
|
||
uint32 batchChainID; | ||
if (sequencers[sequencerAddress].chainID != 0) { | ||
batchChainID = sequencers[sequencerAddress].chainID; | ||
} else { | ||
// If the sequencer is not registered use the default chainID | ||
batchChainID = DEFAULT_CHAIN_ID; | ||
} | ||
|
||
uint256 input = uint256( | ||
keccak256( | ||
abi.encodePacked( | ||
currentStateRoot, | ||
currentLocalExitRoot, | ||
newStateRoot, | ||
newLocalExitRoot, | ||
sequencerAddress, | ||
currentBatch.batchL2HashData, | ||
batchChainID, | ||
batchNum | ||
) | ||
) | ||
); | ||
return input; | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM ethereum/client-go | ||
|
||
EXPOSE 8545 | ||
|
||
COPY docker/gethData / | ||
|
||
ENTRYPOINT ["geth"] | ||
CMD ["--http", "--http.addr", "0.0.0.0","--http.corsdomain", "*", "--http.vhosts" ,"*", "--ws", "--ws.origins", "*", "--ws.addr", "0.0.0.0", "--dev", "--datadir", "/geth_data"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Docker deployment | ||
|
||
By default the following mnemonic will be used to deploy the smart contracts `MNEMONIC="test test test test test test test test test test test junk"`. | ||
Also the first 20 accounts of this mnemonic will be funded with ether. | ||
The first account of the mnemonic will be the deployer of the smart contracts and therefore the holder of all the MATIC test tokens, which are necessary to pay the `sendBatch` transactions. | ||
You can change the deployment `mnemonic` creating a `.env` file in the project root with the following variable: | ||
`MNEMONIC=<YOUR_MENMONIC>` | ||
|
||
## Requirements | ||
|
||
- node version: 14.x | ||
- npm version: 7.x | ||
- docker | ||
- docker-compose | ||
|
||
## Build dockers | ||
|
||
In project root execute: | ||
|
||
``` | ||
npm i | ||
npm run dockerContracts | ||
``` | ||
|
||
A new docker `hermez-geth1.3:latest` will be created | ||
This docker will contain a geth node with the deployed contracts | ||
The deployment output can be found in: `docker/deploymentOutput/deploy_output.json` | ||
To run the docker you can use: `docker run -p 8545:8545 hermez-geth1.3:latest` |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
version: "3.3" | ||
services: | ||
geth: | ||
image: ethereum/client-go | ||
environment: | ||
- DEV_PERIOD | ||
ports: | ||
- "8545:8545" | ||
volumes: | ||
- ./gethData/geth_data:/geth_data | ||
entrypoint: | ||
- geth | ||
- --http | ||
- --http.addr | ||
- "0.0.0.0" | ||
- --dev | ||
- --dev.period | ||
- $DEV_PERIOD | ||
- --datadir | ||
- /geth_data |
Oops, something went wrong.