Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rvdevelop #6

Open
wants to merge 43 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c8b4b4d
Committing KaaS Compute Setup for RV Testing / Development
F-WRunTime Jun 12, 2024
c2db612
Test using variables to get org name / repo name
F-WRunTime Jun 12, 2024
bb73582
Merge conflict resolution
F-WRunTime Jun 12, 2024
ef5a282
Revert changes to lido-ci.yml for merge into parent repo
lucasmt Jun 12, 2024
740b5c5
Committing KaaS Compute Setup for RV Testing / Development
F-WRunTime Jun 12, 2024
3e2804d
Test using variables to get org name / repo name
F-WRunTime Jun 12, 2024
979bd73
Merge conflict resolution
F-WRunTime Jun 12, 2024
bef8491
Adding workflow_dispatch event triggers
F-WRunTime Jun 14, 2024
49c836f
Add StETH token model
lucasmt Jun 17, 2024
29d4c76
Add new version of Escrow model using rebasable StETH token
lucasmt Jun 17, 2024
dd713cf
Rename original Escrow model to EscrowNonRebasable.sol
lucasmt Jun 18, 2024
e145cbc
Make the Escrow version using StETH the default Escrow contract in th…
lucasmt Jun 18, 2024
ee7d042
Adapt VetoSignalling tests to StETH
lucasmt Jun 18, 2024
51c4470
Split off test set-up and helper functions into separate base contract
lucasmt Jun 18, 2024
ac347ff
Reduce SMT timeout in run-kontrol.sh script
lucasmt Jun 18, 2024
b074a16
Add test to run-kontrol.sh script
lucasmt Jun 18, 2024
1cc7737
Update versions.json to the latest kontrol version
lucasmt Jun 18, 2024
4eff4c7
Adjust StETH model to be closer to original StETH contract
lucasmt Jun 21, 2024
748790e
renaming contracts for easier use with Kontrol
PetarMax Jun 21, 2024
19fb17a
additional lemma for cleaning up specification of getRageQuitSupport
PetarMax Jun 22, 2024
e26f832
assumptions
PetarMax Jun 22, 2024
5f84969
Refactor DualGovernanceSetUp into 3 contracts for more fine-grained f…
lucasmt Jun 24, 2024
a8b7377
Make Escrow storage setup compatible with the new storage layout of t…
lucasmt Jun 24, 2024
f26be16
Fix assumptions on StETHModel to avoid division by 0 problem
lucasmt Jun 25, 2024
ac4dde4
Rename variable in comment of DualGovernanceSetUp
lucasmt Jun 25, 2024
538c657
Add --verbose and --max-frontier-parallel options to run-kontrol.sh s…
lucasmt Jun 25, 2024
28ee0ed
further limiting branching
PetarMax Jun 22, 2024
7ab371f
additional constraints to minimise calls to calculateDynamicTimelock
PetarMax Jun 22, 2024
5e3c1e8
merge
PetarMax Jun 26, 2024
a825995
Update unlock function in EscrowModel to unlock all of the user's shares
lucasmt Jul 1, 2024
eb9461c
Add EscrowAccountingTest
lucasmt Jul 1, 2024
7320f8d
Add EscrowAccounting tests to run-kontrol.sh script
lucasmt Jul 1, 2024
5317bd2
Add EscrowOperationsTest and update Setup
qian-hu Jul 4, 2024
235f93d
Add EscrowOperations tests to run-kontrol.sh script
qian-hu Jul 4, 2024
9e0f326
Add postconditions to testLockStEth and testUnlockStEth, accounting f…
lucasmt Jul 5, 2024
aab4073
Fix submissionTime and comment out activateNextState()
qian-hu Jul 8, 2024
98c8857
Add ProposalOperationsTest
qian-hu Jul 8, 2024
1187c06
Add ProposalOperations tests to run-kontrol.sh script
qian-hu Jul 8, 2024
8a8905a
Update testCanceledOrExecutedActionsCannotBeRescheduled
qian-hu Jul 8, 2024
60a2a5f
Fix cancelAllNonExecutedProposals in the timelock model
qian-hu Jul 9, 2024
e7a8fb6
Add testOnlyAdminProposersCanCancelProposals to ProposalOperations tests
qian-hu Jul 9, 2024
68c00e9
Moving kaas changes to primary default branch, updating this workflow…
F-WRunTime Jun 14, 2024
b2ea538
Resolve Conflict, take develop branch changes
F-WRunTime Jul 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/lido-ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
---
name: "Test Proofs"
on:
workflow_dispatch:
push:
branches:
- develop
- rvdevelop
jobs:
test:
runs-on: ubuntu-latest
Expand All @@ -23,7 +25,7 @@
-H "Authorization: Bearer ${{ secrets.RV_COMPUTE_TOKEN }}" \
https://api.github.com/repos/runtimeverification/_kaas_lidofinance_dual-governance/actions/workflows/lido-ci.yml/dispatches \
-d '{
"ref": "develop",
"ref": "master",
"inputs": {
"branch_name": "'"${{ github.event.pull_request.head.sha || github.sha }}"'",
"extra_args": "script",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ pragma solidity ^0.8.0;

import "@openzeppelin/contracts/utils/math/Math.sol";

import "./EmergencyProtectedTimelock.sol";
import "./Escrow.sol";
import "./EmergencyProtectedTimelockModel.sol";
import "./EscrowModel.sol";

/**
* @title Dual Governance Mechanism
Expand All @@ -13,7 +13,7 @@ import "./Escrow.sol";
*/

// DualGovernance contract to handle proposal submissions and lifecycle management.
contract DualGovernance {
contract DualGovernanceModel {
enum State {
Normal,
VetoSignalling,
Expand All @@ -22,13 +22,12 @@ contract DualGovernance {
RageQuit
}

EmergencyProtectedTimelock public emergencyProtectedTimelock;
Escrow public signallingEscrow;
Escrow public rageQuitEscrow;
EmergencyProtectedTimelockModel public emergencyProtectedTimelock;
EscrowModel public signallingEscrow;
EscrowModel public rageQuitEscrow;
address public fakeETH;

// State Variables
State public currentState;
mapping(address => bool) public proposers;
mapping(address => bool) public admin_proposers;
uint256 public lastStateChangeTime;
Expand All @@ -37,6 +36,8 @@ contract DualGovernance {
uint256 public lastVetoSignallingTime;
uint256 public rageQuitSequenceNumber;

State public currentState;

// Constants
uint256 public constant FIRST_SEAL_RAGE_QUIT_SUPPORT = 10 ** 16; // Threshold required for transition from Normal to Veto Signalling state (1%).
uint256 public constant SECOND_SEAL_RAGE_QUIT_SUPPORT = 10 ** 17; // Transition to Rage Quit occurs if t - t^S_{act} > DynamicTimelockMaxDuration and R > SecondSealRageQuitSupport (10%).
Expand All @@ -52,8 +53,8 @@ contract DualGovernance {
currentState = State.Normal;
lastStateChangeTime = block.timestamp;
fakeETH = _fakeETH;
emergencyProtectedTimelock = new EmergencyProtectedTimelock(address(this), emergencyProtectionTimelock);
signallingEscrow = new Escrow(address(this), _fakeETH);
emergencyProtectedTimelock = new EmergencyProtectedTimelockModel(address(this), emergencyProtectionTimelock);
signallingEscrow = new EscrowModel(address(this), _fakeETH);
}

// Operations
Expand All @@ -62,7 +63,7 @@ contract DualGovernance {
* Proposals can be submitted when in the Normal state or during Veto Signalling; however they cannot be executed in Veto Signalling.
*/
function submitProposal(ExecutorCall[] calldata calls) external returns (uint256 proposalId) {
activateNextState();
// activateNextState();

require(proposers[msg.sender], "Caller is not authorized to submit proposals.");
require(calls.length != 0, "Empty calls.");
Expand All @@ -79,7 +80,7 @@ contract DualGovernance {
* Scheduling is allowed in Normal and Veto Cooldown states to prepare proposals for decision-making.
*/
function scheduleProposal(uint256 proposalId) external {
activateNextState();
// activateNextState();

require(
currentState == State.Normal || currentState == State.VetoCooldown,
Expand All @@ -98,7 +99,7 @@ contract DualGovernance {

// Cancel all non-executed proposals.
function cancelAllPendingProposals() external {
activateNextState();
// activateNextState();

require(admin_proposers[msg.sender], "Caller is not admin proposers.");
require(
Expand All @@ -117,7 +118,7 @@ contract DualGovernance {
function calculateDynamicTimelock(uint256 rageQuitSupport) public pure returns (uint256) {
if (rageQuitSupport <= FIRST_SEAL_RAGE_QUIT_SUPPORT) {
return 0;
} else if (rageQuitSupport < SECOND_SEAL_RAGE_QUIT_SUPPORT) {
} else if (rageQuitSupport <= SECOND_SEAL_RAGE_QUIT_SUPPORT) {
return linearInterpolation(rageQuitSupport);
} else {
return DYNAMIC_TIMELOCK_MAX_DURATION;
Expand All @@ -132,6 +133,13 @@ contract DualGovernance {
function linearInterpolation(uint256 rageQuitSupport) private pure returns (uint256) {
uint256 L_min = DYNAMIC_TIMELOCK_MIN_DURATION;
uint256 L_max = DYNAMIC_TIMELOCK_MAX_DURATION;
// Assumption: No underflow
require(FIRST_SEAL_RAGE_QUIT_SUPPORT <= rageQuitSupport);
// Assumption: No overflow
require(
((rageQuitSupport - FIRST_SEAL_RAGE_QUIT_SUPPORT) * (L_max - L_min)) / (L_max - L_min)
== (rageQuitSupport - FIRST_SEAL_RAGE_QUIT_SUPPORT)
);
return L_min
+ ((rageQuitSupport - FIRST_SEAL_RAGE_QUIT_SUPPORT) * (L_max - L_min))
/ (SECOND_SEAL_RAGE_QUIT_SUPPORT - FIRST_SEAL_RAGE_QUIT_SUPPORT);
Expand All @@ -149,7 +157,7 @@ contract DualGovernance {
signallingEscrow.startRageQuit();
rageQuitSequenceNumber++;
rageQuitEscrow = signallingEscrow;
signallingEscrow = new Escrow(address(this), fakeETH);
signallingEscrow = new EscrowModel(address(this), fakeETH);
}

lastStateChangeTime = block.timestamp;
Expand Down Expand Up @@ -180,6 +188,11 @@ contract DualGovernance {
// State Transitions

function activateNextState() public {
// Assumption: various time stamps are in the past
require(lastStateChangeTime <= block.timestamp);
require(lastSubStateActivationTime <= block.timestamp);
require(lastStateReactivationTime <= block.timestamp);

uint256 rageQuitSupport = signallingEscrow.getRageQuitSupport();

State previousState;
Expand Down Expand Up @@ -224,12 +237,14 @@ contract DualGovernance {

// Check the conditions for transitioning to RageQuit or Veto Deactivation based on the time elapsed and support level.
if (
block.timestamp - lastStateChangeTime > DYNAMIC_TIMELOCK_MAX_DURATION
block.timestamp != lastStateChangeTime
&& block.timestamp - lastStateChangeTime > DYNAMIC_TIMELOCK_MAX_DURATION
&& rageQuitSupport > SECOND_SEAL_RAGE_QUIT_SUPPORT
) {
transitionState(State.RageQuit);
} else if (
block.timestamp - lastStateChangeTime > calculateDynamicTimelock(rageQuitSupport)
block.timestamp != lastStateChangeTime
&& block.timestamp - lastStateChangeTime > calculateDynamicTimelock(rageQuitSupport)
&& block.timestamp - Math.max(lastStateChangeTime, lastStateReactivationTime)
> VETO_SIGNALLING_MIN_ACTIVE_DURATION
) {
Expand All @@ -247,7 +262,8 @@ contract DualGovernance {
uint256 elapsed = block.timestamp - lastSubStateActivationTime;
// Check the conditions for transitioning to VetoCooldown or back to VetoSignalling
if (
block.timestamp - lastStateChangeTime <= calculateDynamicTimelock(rageQuitSupport)
block.timestamp == lastStateChangeTime
|| block.timestamp - lastStateChangeTime <= calculateDynamicTimelock(rageQuitSupport)
|| rageQuitSupport > SECOND_SEAL_RAGE_QUIT_SUPPORT
) {
exitSubState(State.VetoSignalling);
Expand All @@ -264,7 +280,7 @@ contract DualGovernance {
require(currentState == State.VetoCooldown, "Must be in Veto Cooldown state.");

// Ensure the Veto Cooldown has lasted for at least the minimum duration.
if (block.timestamp - lastStateChangeTime > VETO_COOLDOWN_DURATION) {
if (block.timestamp != lastStateChangeTime && block.timestamp - lastStateChangeTime > VETO_COOLDOWN_DURATION) {
// Depending on the level of rage quit support, transition to Normal or Veto Signalling.
if (rageQuitSupport <= FIRST_SEAL_RAGE_QUIT_SUPPORT) {
transitionState(State.Normal);
Expand All @@ -279,7 +295,7 @@ contract DualGovernance {
* Checks if withdrawal process is complete, cooldown period expired.
* Transitions to VetoCooldown if support has decreased below the threshold; otherwise, transitions to VetoSignalling.
*/
function fromRageQuit(uint256 rageQuitSupport) private {
function fromRageQuit(uint256 rageQuitSupport) public {
require(currentState == State.RageQuit, "Must be in Rage Quit state.");

// Check if the withdrawal process is completed and if the RageQuitExtensionDelay has elapsed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct Proposal {

// This contract manages the timelocking of proposals with emergency intervention capabilities.
// It provides controls for entering and managing emergency states as well as executing proposals under normal and emergency conditions.
contract EmergencyProtectedTimelock {
contract EmergencyProtectedTimelockModel {
// Addresses associated with governance roles and permissions.
address public governance;
address public emergencyGovernance;
Expand Down Expand Up @@ -124,11 +124,13 @@ contract EmergencyProtectedTimelock {
function cancelAllNonExecutedProposals() public {
require(msg.sender == governance, "Caller is not authorized to cancel proposal.");

// Loop through all the proposals stored in the contract.
for (uint256 i = 0; i < nextProposalId; i++) {
// Ensure that only proposals in 'Submitted' or 'Scheduled' status are canceled.
if (proposals[i].status != ProposalStatus.Executed) {
proposals[i].status = ProposalStatus.Canceled;
if (nextProposalId > 0) {
// Loop through all the proposals stored in the contract.
for (uint256 i = 0; i < nextProposalId; i++) {
// Ensure that only proposals in 'Submitted' or 'Scheduled' status are canceled.
if (proposals[i].status != ProposalStatus.Executed) {
proposals[i].status = ProposalStatus.Canceled;
}
}
}
}
Expand Down
Loading
Loading