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

Staking contract E2E test setup #492

Merged
merged 29 commits into from
Aug 20, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9d1f56d
native staking manager abi
cam-schultz Aug 9, 2024
088810d
grab commit from go mod
cam-schultz Aug 9, 2024
17ae18f
update deps
cam-schultz Aug 9, 2024
8174c18
Merge branch 'staking-contract' into e2e-test
cam-schultz Aug 9, 2024
460a943
erc20 staking manager abi
cam-schultz Aug 9, 2024
93cd255
wip
cam-schultz Aug 13, 2024
3d21241
passing
cam-schultz Aug 14, 2024
2436a31
remove dbg code
cam-schultz Aug 14, 2024
5d4e337
update deps
cam-schultz Aug 14, 2024
cf8b064
codec id to message formats
cam-schultz Aug 2, 2024
ba68b8e
update staking messages to latest spec
cam-schultz Aug 14, 2024
79104a6
delist validator working
cam-schultz Aug 15, 2024
935cd86
scope listing and delisting steps
cam-schultz Aug 15, 2024
aa975ac
add back in churn tracker
cam-schultz Aug 15, 2024
4c33139
refactor utils
cam-schultz Aug 15, 2024
5c04d20
staking contract test utils
cam-schultz Aug 15, 2024
662b0d2
enable all tests
cam-schultz Aug 15, 2024
ea47515
lint
cam-schultz Aug 15, 2024
63b3884
erc20 staking e2e
cam-schultz Aug 15, 2024
b4baff1
format
cam-schultz Aug 15, 2024
50e878b
correct comment
cam-schultz Aug 19, 2024
726f16c
Update tests/flows/erc20_token_staking.go
cam-schultz Aug 20, 2024
2ee977e
Update tests/flows/erc20_token_staking.go
cam-schultz Aug 20, 2024
d50cf3f
rename helpers
cam-schultz Aug 20, 2024
e1eabfd
set weight via contract helper
cam-schultz Aug 20, 2024
5f5b74a
remove utils suffix from fname
cam-schultz Aug 20, 2024
9a485b9
format comment
cam-schultz Aug 20, 2024
a315e0f
(temp) warp validation helpers
cam-schultz Aug 20, 2024
46a8d9e
Merge branch 'e2e-test' of github.com:ava-labs/teleporter into e2e-test
cam-schultz Aug 20, 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
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");

Choose a reason for hiding this comment

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

can have a constant for the length

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since these packing/unpacking methods are likely to be refactored/optimized significantly in the future, I'm going to hold off on making further changes for now. Also pointing out that there were no length constants in the previous implementation.


// 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