Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
5 changes: 0 additions & 5 deletions contracts/artifacts/abi/LightClient.json
Original file line number Diff line number Diff line change
Expand Up @@ -1256,11 +1256,6 @@
"name": "InvalidProof",
"inputs": []
},
{
"type": "error",
"name": "InvalidScalar",
"inputs": []
},
{
"type": "error",
"name": "NoChangeRequired",
Expand Down
5 changes: 0 additions & 5 deletions contracts/artifacts/abi/LightClientMock.json
Original file line number Diff line number Diff line change
Expand Up @@ -1336,11 +1336,6 @@
"name": "InvalidProof",
"inputs": []
},
{
"type": "error",
"name": "InvalidScalar",
"inputs": []
},
{
"type": "error",
"name": "NoChangeRequired",
Expand Down
5 changes: 0 additions & 5 deletions contracts/artifacts/abi/LightClientV2.json
Original file line number Diff line number Diff line change
Expand Up @@ -1777,11 +1777,6 @@
"name": "InvalidProof",
"inputs": []
},
{
"type": "error",
"name": "InvalidScalar",
"inputs": []
},
{
"type": "error",
"name": "MissingEpochRootUpdate",
Expand Down
5 changes: 0 additions & 5 deletions contracts/artifacts/abi/LightClientV2Mock.json
Original file line number Diff line number Diff line change
Expand Up @@ -1923,11 +1923,6 @@
"name": "InvalidProof",
"inputs": []
},
{
"type": "error",
"name": "InvalidScalar",
"inputs": []
},
{
"type": "error",
"name": "MissingEpochRootUpdate",
Expand Down
15 changes: 0 additions & 15 deletions contracts/artifacts/abi/StakeTable.json
Original file line number Diff line number Diff line change
Expand Up @@ -819,11 +819,6 @@
"name": "BLSSigVerificationFailed",
"inputs": []
},
{
"type": "error",
"name": "BN254PairingProdFailed",
"inputs": []
},
{
"type": "error",
"name": "BlsKeyAlreadyUsed",
Expand Down Expand Up @@ -887,11 +882,6 @@
"name": "InvalidCommission",
"inputs": []
},
{
"type": "error",
"name": "InvalidG1",
"inputs": []
},
{
"type": "error",
"name": "InvalidInitialization",
Expand Down Expand Up @@ -934,11 +924,6 @@
}
]
},
{
"type": "error",
"name": "PowPrecompileFailed",
"inputs": []
},
{
"type": "error",
"name": "PrematureWithdrawal",
Expand Down
2 changes: 1 addition & 1 deletion contracts/lib/bn254
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like an accidental submodule downgrade. Probably missing a git submodule update after pulling main.

127 changes: 5 additions & 122 deletions contracts/rust/adapter/src/bindings/light_client.rs

Large diffs are not rendered by default.

127 changes: 5 additions & 122 deletions contracts/rust/adapter/src/bindings/light_client_arbitrum.rs

Large diffs are not rendered by default.

127 changes: 5 additions & 122 deletions contracts/rust/adapter/src/bindings/light_client_arbitrum_v2.rs

Large diffs are not rendered by default.

127 changes: 5 additions & 122 deletions contracts/rust/adapter/src/bindings/light_client_arbitrum_v3.rs

Large diffs are not rendered by default.

127 changes: 5 additions & 122 deletions contracts/rust/adapter/src/bindings/light_client_mock.rs

Large diffs are not rendered by default.

127 changes: 5 additions & 122 deletions contracts/rust/adapter/src/bindings/light_client_v2.rs

Large diffs are not rendered by default.

127 changes: 5 additions & 122 deletions contracts/rust/adapter/src/bindings/light_client_v2_mock.rs

Large diffs are not rendered by default.

127 changes: 5 additions & 122 deletions contracts/rust/adapter/src/bindings/light_client_v3.rs

Large diffs are not rendered by default.

127 changes: 5 additions & 122 deletions contracts/rust/adapter/src/bindings/light_client_v3_mock.rs

Large diffs are not rendered by default.

920 changes: 49 additions & 871 deletions contracts/rust/adapter/src/bindings/plonk_verifier.rs

Large diffs are not rendered by default.

920 changes: 49 additions & 871 deletions contracts/rust/adapter/src/bindings/plonk_verifier_v2.rs

Large diffs are not rendered by default.

920 changes: 49 additions & 871 deletions contracts/rust/adapter/src/bindings/plonk_verifier_v3.rs

Large diffs are not rendered by default.

358 changes: 5 additions & 353 deletions contracts/rust/adapter/src/bindings/stake_table.rs

Large diffs are not rendered by default.

808 changes: 437 additions & 371 deletions contracts/rust/adapter/src/bindings/stake_table_v2.rs

Large diffs are not rendered by default.

40 changes: 39 additions & 1 deletion contracts/src/StakeTableV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ import { SafeTransferLib } from "solmate/utils/SafeTransferLib.sol";
///
/// 8. The commission rate for validators can be updated with the `updateCommission` function.
///
/// 9. The `totalValidatorStake` and `totalStake` functions are added to allow governance to
/// track the total stake in the contract. The totalValidatorStake is the total stake in active
/// validators and the totalStake is the total stake in all states (active + exiting +
/// pendingWithdrawal).
///
/// @notice The StakeTableV2 contract ABI is a superset of the original ABI. Consumers of the
/// contract can use the V2 ABI, even if they would like to maintain backwards compatibility.
contract StakeTableV2 is StakeTable, PausableUpgradeable, AccessControlUpgradeable {
Expand Down Expand Up @@ -84,6 +89,12 @@ contract StakeTableV2 is StakeTable, PausableUpgradeable, AccessControlUpgradeab
/// @notice Maximum commission increase allowed per increase (in basis points)
uint16 public maxCommissionIncrease;

/// @notice Total stake in active (not marked for exit) validators in the contract
uint256 public totalValidatorStake;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the naming because I couldn't tell just from the names what the variables track.

I feel like it would be best to have pendingWithdrawals, pendingExits, activeStake and totalTracked but this would be 4 storage edits for each delegation which is quite expensive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the delegate gas cost is up 46% so i'm looking at other gas saving measures

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you make sure this isn't the first delegation? The first one will create 4 new storage entries, subsequent ones only edit the 4 entries.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it also sounds about right/expected. A delegation doesn't do much other than moving the token (changing balance of delegator and stake table) and increasing the balance of the delegator for the validator in the stake table.

Overall it feels not ideal to have a user pay so much for something that isn't useful for them. However at current gas prices it's probably fine.

Copy link
Contributor Author

@alysiahuggins alysiahuggins Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's fair at first delegation, in this case, i used the average fees to compare.
If we only store totalValidatorStake which i'm thinking to rename to totalEffectiveStake or totalConsensusStake, the (average) gas increase for a delegation is 25%.

I've made the change to only track totalValidatorStake here, if you agree, i'll merge it into this pr #3630


/// @notice Total stake in all states (active + exiting + pendingWithdrawal) in the contract
uint256 public totalStake;

/// @notice Commission tracking for each validator
mapping(address validator => CommissionTracking tracking) public commissionTracking;

Expand Down Expand Up @@ -254,6 +265,9 @@ contract StakeTableV2 is StakeTable, PausableUpgradeable, AccessControlUpgradeab
// it's only decremented during withdrawal
validators[validator].delegatedAmount -= amount;

// finally, update the total stake as the balance was withdrawn
totalStake -= amount;

SafeTransferLib.safeTransfer(token, delegator, amount);

emit Withdrawal(delegator, amount);
Expand All @@ -263,7 +277,26 @@ contract StakeTableV2 is StakeTable, PausableUpgradeable, AccessControlUpgradeab
/// @param validator The validator to withdraw from
/// @dev This function is overridden to add pausable functionality
function claimWithdrawal(address validator) public virtual override whenNotPaused {
super.claimWithdrawal(validator);
address delegator = msg.sender;
// If entries are missing at any of the levels of the mapping this will return zero
uint256 amount = undelegations[validator][delegator].amount;
if (amount == 0) {
revert NothingToWithdraw();
}

if (block.timestamp < undelegations[validator][delegator].unlocksAt) {
revert PrematureWithdrawal();
}

// Mark funds as spent
delete undelegations[validator][delegator];

// update the total stake managed by the contract
totalStake -= amount;

SafeTransferLib.safeTransfer(token, delegator, amount);

emit Withdrawal(delegator, amount);
}

/// @notice Delegate funds to a validator
Expand All @@ -272,6 +305,9 @@ contract StakeTableV2 is StakeTable, PausableUpgradeable, AccessControlUpgradeab
/// @dev This function is overridden to add pausable functionality
function delegate(address validator, uint256 amount) public virtual override whenNotPaused {
super.delegate(validator, amount);

totalStake += amount;
totalValidatorStake += amount;
}

/// @notice Undelegate funds from a validator
Expand All @@ -280,6 +316,7 @@ contract StakeTableV2 is StakeTable, PausableUpgradeable, AccessControlUpgradeab
/// @dev This function is overridden to add pausable functionality
function undelegate(address validator, uint256 amount) public virtual override whenNotPaused {
super.undelegate(validator, amount);
totalValidatorStake -= amount;
}

/// @notice Deregister a validator
Expand All @@ -295,6 +332,7 @@ contract StakeTableV2 is StakeTable, PausableUpgradeable, AccessControlUpgradeab
validatorExits[validator] = block.timestamp + exitEscrowPeriod;
// in v2, the delegatedAmount is not updated until withdrawal

totalValidatorStake -= validators[validator].delegatedAmount;
emit ValidatorExit(validator);
}

Expand Down
Loading
Loading