Skip to content

Commit

Permalink
Add reverse csc and test script (#42)
Browse files Browse the repository at this point in the history
Add reverse csc and test script
  • Loading branch information
GalaxySciTech authored May 30, 2024
1 parent 9e06fcd commit 38e7834
Show file tree
Hide file tree
Showing 22 changed files with 1,983 additions and 139 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ dbg.project.json
contracts-dbg/
deployment.config.json
upgrade.config.json
yarn.lock
yarn.lock
.vscode/
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,13 @@ We recommend setting up the contract in a Python virtual environment since it ut

Complete the fields in `deployment.config.json`:

- `validators`: List of initial validator addresses
- `gap`: GAP block number on the public chain
- `epoch`: EPOCH block number on the public chain
- `subnet`: subnet deploy config :
- `validators`: List of initial validator addresses
- `gap`: GAP block number on the public chain
- `epoch`: Blocks per epoch on the public chain
- `parentnet`: Subnet deploy config :
- `epoch`: Blocks per epoch on the public chain
- `v2esbn`: V2 epoch start block number, epoch block required

Configure your network in `network.config.json`:

Expand All @@ -61,6 +65,12 @@ Deploy the contract and obtain the deployed contract address as follows:
npx hardhat run scripts/LiteCheckpointDeploy.js --network xdcparentnet
```

2. **Reverse Full Checkpoint Deployment**

```shell
npx hardhat run scripts/ReverseFullCheckpointDeploy.js --network xdcsubnet
```

## Additional Commands

For further assistance or to execute other operations, utilize the commands below:
Expand All @@ -82,7 +92,7 @@ npx solhint 'contracts/**/*.sol' --fix
## Gas Report

Refer to the gas report:
![Gas Report](image-1.png)
![Gas Report](gasrepoter.png)

## Upgrade Module

Expand Down
17 changes: 9 additions & 8 deletions contracts/FullCheckpoint.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;
pragma solidity =0.8.23;

import {HeaderReader} from "./libraries/HeaderReader.sol";

Expand Down Expand Up @@ -92,7 +92,7 @@ contract FullCheckpoint {
});
validators[1] = Validators({
set: initialValidatorSet,
threshold: int256((initialValidatorSet.length * 2 * 100) / 3)
threshold: int256((initialValidatorSet.length * 667 ))
});
currentValidators = validators[1];
setLookup(initialValidatorSet);
Expand Down Expand Up @@ -131,15 +131,16 @@ contract FullCheckpoint {
),
"Old Block"
);
Header memory header = headerTree[validationParams.parentHash];
require(
headerTree[validationParams.parentHash].mix != 0,
header.mix != 0,
"Parent Missing"
);
require(
int256(
uint256(
uint64(
headerTree[validationParams.parentHash].mix >> 128
header.mix >> 128
)
)
) +
Expand All @@ -148,12 +149,12 @@ contract FullCheckpoint {
"Invalid N"
);
require(
uint64(headerTree[validationParams.parentHash].mix >> 64) <
uint64(header.mix >> 64) <
validationParams.roundNumber,
"Invalid RN"
);
require(
uint64(headerTree[validationParams.parentHash].mix >> 64) ==
uint64(header.mix >> 64) ==
validationParams.prevRoundNumber,
"Invalid PRN"
);
Expand Down Expand Up @@ -181,7 +182,7 @@ contract FullCheckpoint {
if (!isUnique) {
revert("Repeated Validator");
}
if (uniqueCounter * 100 < currentValidators.threshold) {
if (uniqueCounter * 1000 < currentValidators.threshold) {
revert("Insufficient Signatures");
}

Expand Down Expand Up @@ -239,7 +240,7 @@ contract FullCheckpoint {

validators[validationParams.number] = Validators({
set: next,
threshold: int256((next.length * 2 * 100) / 3)
threshold: int256((next.length * 667 ))
});
} else revert("Invalid Next Block");
}
Expand Down
8 changes: 4 additions & 4 deletions contracts/LiteCheckpoint.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity =0.8.19;
pragma solidity =0.8.23;

import {HeaderReader} from "./libraries/HeaderReader.sol";

Expand Down Expand Up @@ -61,7 +61,7 @@ contract LiteCheckpoint {
bytes32 block1HeaderHash = keccak256(block1);
validators[1] = Validators({
set: initialValidatorSet,
threshold: int256((initialValidatorSet.length * 2 * 100) / 3)
threshold: int256((initialValidatorSet.length * 667 ))
});
currentValidators = validators[1];
setLookup(initialValidatorSet);
Expand Down Expand Up @@ -237,7 +237,7 @@ contract LiteCheckpoint {

validators[validationParams.number] = Validators({
set: next,
threshold: int256((next.length * 2 * 100) / 3)
threshold: int256((next.length * 667 ))
});
latestEpoch = blockHash;
currentTree.push(blockHash);
Expand Down Expand Up @@ -297,7 +297,7 @@ contract LiteCheckpoint {
if (!isUnique) {
revert("Repeated Validator");
}
if (uniqueCounter * 100 < currentValidators.threshold) {
if (uniqueCounter * 1000 < currentValidators.threshold) {
revert("Insufficient Signatures");
}
}
Expand Down
Loading

0 comments on commit 38e7834

Please sign in to comment.