Skip to content

Commit

Permalink
updated updateConsensusKeys function, enhance test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
alysiahuggins committed Dec 9, 2024
1 parent f8c0210 commit 5124d9d
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 147 deletions.
11 changes: 6 additions & 5 deletions contracts/src/StakeTable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -447,13 +447,11 @@ contract StakeTable is AbstractStakeTable {
/// queue
/// @dev The validator will need to give up either its old BLS key and/or old Schnorr key
/// @dev The validator will need to provide a BLS signature over the new BLS key
/// @param currBlsVK The current BLS verification key
/// @param newBlsVK The new BLS verification key
/// @param newSchnorrVK The new Schnorr verification key
/// @param newBlsSig The BLS signature that the account owns the new BLS key
/// TODO: This function should be tested
function updateConsensusKeys(
BN254.G2Point memory currBlsVK,
BN254.G2Point memory newBlsVK,
EdOnBN254.EdOnBN254Point memory newSchnorrVK,
BN254.G1Point memory newBlsSig
Expand All @@ -472,7 +470,10 @@ contract StakeTable is AbstractStakeTable {

// The staker does not provide a key change
if (
(_isEqualBlsKey(newBlsVK, currBlsVK) && EdOnBN254.isEqual(newSchnorrVK, node.schnorrVK))
(
_isEqualBlsKey(newBlsVK, node.blsVK)
&& EdOnBN254.isEqual(newSchnorrVK, node.schnorrVK)
)
|| (
_isEqualBlsKey(
newBlsVK,
Expand All @@ -498,7 +499,7 @@ contract StakeTable is AbstractStakeTable {

// Update the node's bls key once it's not the same as the old one and it's nonzero
if (
!_isEqualBlsKey(newBlsVK, currBlsVK)
!_isEqualBlsKey(newBlsVK, node.blsVK)
&& !_isEqualBlsKey(
newBlsVK,
BN254.G2Point(
Expand All @@ -521,7 +522,7 @@ contract StakeTable is AbstractStakeTable {
nodes[msg.sender] = node;

// Emit the event
emit ConsensusKeysUpdated(msg.sender);
emit UpdatedConsensusKeys(msg.sender);
}

/// @notice Minimum stake amount
Expand Down
4 changes: 1 addition & 3 deletions contracts/src/interfaces/AbstractStakeTable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract contract AbstractStakeTable {

/// @notice Signals a consensus key update for a validator
/// @param account the address of the validator
event ConsensusKeysUpdated(address account);
event UpdatedConsensusKeys(address account);

/// @dev (sadly, Solidity doesn't support type alias on non-primitive types)
// We avoid declaring another struct even if the type info helps with readability,
Expand Down Expand Up @@ -135,12 +135,10 @@ abstract contract AbstractStakeTable {
/// queue
/// @dev The validator will need to give up either its old BLS key and/or old Schnorr key
/// @dev The validator will need to provide a BLS signature over the new BLS key
/// @param currBlsVK The current BLS verification key
/// @param newBlsVK The new BLS verification key
/// @param newSchnorrVK The new Schnorr verification key
/// @param newBlsSig The BLS signature that the account owns the new BLS key
function updateConsensusKeys(
BN254.G2Point memory currBlsVK,
BN254.G2Point memory newBlsVK,
EdOnBN254.EdOnBN254Point memory newSchnorrVK,
BN254.G1Point memory newBlsSig
Expand Down
Loading

0 comments on commit 5124d9d

Please sign in to comment.