Skip to content

Commit

Permalink
Merge pull request #492 from ava-labs/e2e-test
Browse files Browse the repository at this point in the history
Staking contract E2E test setup
  • Loading branch information
cam-schultz authored Aug 20, 2024
2 parents e101b27 + 46a8d9e commit 2508603
Show file tree
Hide file tree
Showing 20 changed files with 4,428 additions and 1,131 deletions.
1,198 changes: 1,198 additions & 0 deletions abi-bindings/go/staking/ERC20TokenStakingManager/ERC20TokenStakingManager.go

Large diffs are not rendered by default.

1,198 changes: 1,198 additions & 0 deletions abi-bindings/go/staking/NativeTokenStakingManager/NativeTokenStakingManager.go

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions contracts/staking/ERC20TokenStakingManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ contract ERC20TokenStakingManager is Initializable, StakingManager, IERC20TokenS
uint256 stakeAmount,
bytes32 nodeID,
uint64 registrationExpiry,
bytes memory signature
bytes memory blsPublicKey
) external override returns (bytes32 validationID) {
return _initializeValidatorRegistration(nodeID, stakeAmount, registrationExpiry, signature);
return
_initializeValidatorRegistration(nodeID, stakeAmount, registrationExpiry, blsPublicKey);
}

// Must be guarded with reentrancy guard for safe transfer from
Expand Down
20 changes: 5 additions & 15 deletions contracts/staking/StakingManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,13 @@ abstract contract StakingManager is
* @notice Begins the validator registration process. Locks the provided native asset in the contract as the stake.
* @param nodeID The node ID of the validator being registered.
* @param registrationExpiry The time at which the reigistration is no longer valid on the P-Chain.
* @param signature The raw bytes of the Ed25519 signature over the concatenated bytes of
* [subnetID]+[nodeID]+[blsPublicKey]+[weight]+[balance]+[expiry]. This signature must correspond to the Ed25519
* public key that is used for the nodeID. This approach prevents NodeIDs from being unwillingly added to Subnets.
* balance is the minimum initial $nAVAX balance that must be attached to the validator serialized as a uint64.
* The signature field will be validated by the P-Chain. Implementations may choose to validate that the signature
* field is well-formed but it is not required.
* @param blsPublicKey The BLS public key of the validator.
*/
function _initializeValidatorRegistration(
bytes32 nodeID,
uint256 value,
uint64 registrationExpiry,
bytes memory signature
bytes memory blsPublicKey
) internal nonReentrant returns (bytes32) {
StakingManagerStorage storage $ = _getStakingManagerStorage();

Expand All @@ -144,12 +139,7 @@ abstract contract StakingManager is
// Ensure the nodeID is not the zero address, and is not already an active validator.
require(nodeID != bytes32(0), "StakingManager: Invalid node ID");
require($._activeValidators[nodeID] == bytes32(0), "StakingManager: Node ID already active");

// Ensure the signature is the proper length. The EVM does not provide an Ed25519 precompile to
// validate the signature, but the P-Chain will validate the signature. If the signature is invalid,
// the P-Chain will reject the registration, and the stake can be returned to the staker after the registration
// expiry has passed.
require(signature.length == 64, "StakingManager: Invalid signature length");
require(blsPublicKey.length == 48, "StakingManager: Invalid blsPublicKey length");

// Lock the stake in the contract.
uint256 lockedValue = _lock(value);
Expand All @@ -170,8 +160,8 @@ abstract contract StakingManager is
subnetID: $._subnetID,
nodeID: nodeID,
weight: weight,
registrationExpiry: registrationExpiry,
signature: signature
blsPublicKey: blsPublicKey,
registrationExpiry: registrationExpiry
})
);
$._pendingRegisterValidationMessages[validationID] = registerSubnetValidatorMessage;
Expand Down
Loading

0 comments on commit 2508603

Please sign in to comment.