Skip to content

Commit 2f9daf9

Browse files
authored
Merge pull request #1 from filecoin-project/biglep/reviewing-initial-code
Small contract cleanups when reading through the code and configuration
2 parents 46a6001 + 3529912 commit 2f9daf9

File tree

4 files changed

+45
-35
lines changed

4 files changed

+45
-35
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ For the full motivation and detailed design, please refer to the [FIP discussion
1010
- **Controlled Update Mechanism:** Requires consensus from Lotus, Forest, and Venus teams.
1111
- **Finalization and Self-Disabling:** Automatically disables after six months if not activated.
1212

13+
## Development
14+
1. Install yarn (e.g., `brew install yarn`)
15+
2. Initialize yarn in the repo: `yarn`
16+
3. Set `PRIVATE_KEY` environment variable (e.g., `export PRIVATE_KEY='0000000000000000000000000000000000000000000000000000000000000000'`)
17+
4. Run tests: `yarn hardhat test`
18+
1319
## License
1420

1521
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

contracts/F3Parameters.sol

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@ pragma solidity 0.8.23;
44
/// @title F3Parameters
55
/// @dev This contract manages parameters for the F3 system, allowing changes until the activation epoch.
66
/// It ensures a review period for the community before activation.
7+
/// @notice https://github.com/filecoin-project/FIPs/discussions/1102
78

89
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
910

1011
contract F3Parameters is Ownable {
1112
/// @dev The expiry timestamp after which updates are not allowed.
13+
/// Note: updates also aren't allowed after the _activationEpoch.
1214
uint64 private immutable _expiry;
1315

14-
/// @dev The block number at which the parameters become active.
16+
/// @dev The block number at which the parameters become active,
17+
/// and no further updates to _manifestData are accepted.
1518
uint64 private _activationEpoch;
1619

1720
/// @dev The data associated with the manifest for the parameters.
21+
/// It is up to consumers (e.g., Lotus) to parse this data and be defensive in what they allowed be mutated as a result.
1822
bytes private _manifesetData;
1923

2024
/// @notice Initializes the contract with the owner and expiry block number.
@@ -81,10 +85,10 @@ contract F3Parameters is Ownable {
8185
revert UpdateAlreadyActive();
8286
}
8387
if (activationEpoch <= block.number) {
84-
revert UpdateActivationEpochInvalid(uint64(block.number), activationEpoch, "before current block");
88+
revert UpdateActivationEpochInvalid(uint64(block.number), activationEpoch, "activationEpoch is before current block");
8589
}
8690
if (uint128(activationEpoch - block.number) < MIN_ACTIVATION_HEADROOM_BLOCKS) {
87-
revert UpdateActivationEpochInvalid(uint64(block.number), activationEpoch, "based on block time");
91+
revert UpdateActivationEpochInvalid(uint64(block.number), activationEpoch, "activationEpoch is within minActivationHeadroomBlocks from the current block");
8892
}
8993

9094
_activationEpoch = activationEpoch;

ignition/modules/F3Parameters.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

22
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
33

4-
const JAN_1ST_2030 = 1893456000;
4+
const JAN_1ST_2030_EPOCH_SECONDS = Math.floor(new Date('2030-01-01T00:00:00Z').getTime() / 1000);
55
const ONE_GWEI = 1_000_000_000n;
66

77
export default buildModule("F3ParametersModule", (m) => {
88
const owner = m.getParameter("owner", m.getAccount(0));
9-
const expiration = m.getParameter("expirationTime", JAN_1ST_2030);
9+
const expiration = m.getParameter("expirationTime", JAN_1ST_2030_EPOCH_SECONDS);
1010

1111
const f3params = m.contract("F3Parameters", [owner, expiration]);
1212
return { f3params };

test/F3Parameters.js

+30-30
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ describe("F3Parameters", function () {
1616
// Contracts are deployed using the first signer/account by default
1717
const [owner, otherAccount] = await ethers.getSigners();
1818

19-
const F3Param = await ethers.getContractFactory("F3Parameters");
20-
const f3param = await F3Param.deploy(owner, expireTime);
19+
const f3ParamContractFactory = await ethers.getContractFactory("F3Parameters");
20+
const f3ParamContract = await f3ParamContractFactory.deploy(owner, expireTime);
2121

22-
return { f3param, expireTime, owner, otherAccount };
22+
return { f3param: f3ParamContract, expireTime, owner, otherAccount };
2323
}
2424

2525
describe("Deployment", function () {
@@ -59,44 +59,29 @@ describe("F3Parameters", function () {
5959
expect(data).to.equal(manifestData);
6060
});
6161

62-
it("Should revert if activation epoch is less than minActivationHeadroomBlocks ahead of current block", async function () {
63-
const { f3param, owner } = await loadFixture(deployOneYearExpireFixture);
64-
const currentBlockNumber = BigInt(await ethers.provider.getBlockNumber());
65-
const minActivationHeadroomBlocks = await f3param.getMinActivationHeadroomBlocks();
66-
const newActivationEpoch = currentBlockNumber + minActivationHeadroomBlocks - BigInt(1);
67-
const manifestData = "0x123456";
68-
69-
await expect(
70-
f3param.connect(owner).updateActivationInformation(newActivationEpoch, manifestData)
71-
).to.be.revertedWithCustomError(f3param, "UpdateActivationEpochInvalid")
72-
.withArgs(anyValue, newActivationEpoch, "based on block time");
73-
});
74-
75-
it("Should revert if update is attempted after expiry", async function () {
62+
it("Should revert if activation epoch is set to a past block", async function () {
7663
const { f3param, owner } = await loadFixture(deployOneYearExpireFixture);
77-
const currentBlockNumber = BigInt(await ethers.provider.getBlockNumber());
78-
const minActivationHeadroomBlocks = await f3param.getMinActivationHeadroomBlocks();
79-
const newActivationEpoch = currentBlockNumber + minActivationHeadroomBlocks + BigInt(1);
64+
await mine(10)
65+
const pastBlock = BigInt(await ethers.provider.getBlockNumber() - 2);
8066
const manifestData = "0x123456";
8167

82-
const expiryTime = BigInt(await f3param.expiresAt());
83-
await time.increaseTo(expiryTime + BigInt(100));
84-
8568
await expect(
86-
f3param.connect(owner).updateActivationInformation(newActivationEpoch, manifestData)
87-
).to.be.revertedWithCustomError(f3param, "UpdateExpired");
69+
f3param.connect(owner).updateActivationInformation(pastBlock, manifestData)
70+
).to.be.revertedWithCustomError(f3param, "UpdateActivationEpochInvalid")
71+
.withArgs(anyValue, pastBlock, "activationEpoch is before current block");
8872
});
8973

90-
it("Should revert if activation epoch is set to a past block", async function () {
74+
it("Should revert if activation epoch is less than minActivationHeadroomBlocks ahead of current block", async function () {
9175
const { f3param, owner } = await loadFixture(deployOneYearExpireFixture);
92-
await mine(10)
93-
const pastBlock = BigInt(await ethers.provider.getBlockNumber() - 2);
76+
const currentBlockNumber = BigInt(await ethers.provider.getBlockNumber());
77+
const minActivationHeadroomBlocks = await f3param.getMinActivationHeadroomBlocks();
78+
const newActivationEpoch = currentBlockNumber + minActivationHeadroomBlocks - BigInt(1);
9479
const manifestData = "0x123456";
9580

9681
await expect(
97-
f3param.connect(owner).updateActivationInformation(pastBlock, manifestData)
82+
f3param.connect(owner).updateActivationInformation(newActivationEpoch, manifestData)
9883
).to.be.revertedWithCustomError(f3param, "UpdateActivationEpochInvalid")
99-
.withArgs(anyValue, pastBlock, "before current block");
84+
.withArgs(anyValue, newActivationEpoch, "activationEpoch is within minActivationHeadroomBlocks from the current block")
10085
});
10186

10287
it("Should revert if update is attempted after activation", async function () {
@@ -115,6 +100,21 @@ describe("F3Parameters", function () {
115100
).to.be.revertedWithCustomError(f3param, "UpdateAlreadyActive");
116101
});
117102

103+
it("Should revert if update is attempted after expiry", async function () {
104+
const { f3param, owner } = await loadFixture(deployOneYearExpireFixture);
105+
const currentBlockNumber = BigInt(await ethers.provider.getBlockNumber());
106+
const minActivationHeadroomBlocks = await f3param.getMinActivationHeadroomBlocks();
107+
const newActivationEpoch = currentBlockNumber + minActivationHeadroomBlocks + BigInt(1);
108+
const manifestData = "0x123456";
109+
110+
const expiryTime = BigInt(await f3param.expiresAt());
111+
await time.increaseTo(expiryTime + BigInt(100));
112+
113+
await expect(
114+
f3param.connect(owner).updateActivationInformation(newActivationEpoch, manifestData)
115+
).to.be.revertedWithCustomError(f3param, "UpdateExpired");
116+
});
117+
118118
it("Should revert if non-owner attempts to updateActivationInformation", async function() {
119119
const { f3param, otherAccount } = await loadFixture(deployOneYearExpireFixture);
120120
const currentBlockNumber = BigInt(await ethers.provider.getBlockNumber());

0 commit comments

Comments
 (0)