@@ -633,20 +633,30 @@ contract Staking is Governed {
633
633
634
634
// Only allocations with a token amount are allowed
635
635
require (_tokens > 0 , "Allocation: cannot allocate zero tokens " );
636
+
636
637
// Need to have tokens in our stake to be able to allocate
637
638
require (indexerStake.hasTokens (), "Allocation: indexer has no stakes " );
639
+
638
640
// Need to have free capacity not used for other purposes to allocate
639
641
require (
640
642
getIndexerCapacity (indexer) >= _tokens,
641
643
"Allocation: not enough tokens available to allocate "
642
644
);
645
+
643
646
// Can only allocate tokens to a SubgraphDeployment if not currently allocated
644
647
require (
645
648
indexerStake.hasAllocation (_subgraphDeploymentID) == false ,
646
649
"Allocation: cannot allocate if already allocated "
647
650
);
651
+
652
+ // Channel public key must be in uncompressed format
653
+ require (
654
+ uint8 (_channelPubKey[0 ]) == 4 && _channelPubKey.length == 65 ,
655
+ "Allocation: invalid channel public key "
656
+ );
657
+
648
658
// Cannot reuse a channelID that has been used in the past
649
- address channelID = publicKeyToAddress ( bytes (_channelPubKey[1 :])); // solium-disable-line
659
+ address channelID = address ( uint256 ( keccak256 ( bytes (_channelPubKey[1 :])) )); // solium-disable-line
650
660
require (isChannel (channelID) == false , "Allocation: channel ID already in use " );
651
661
652
662
// Allocate and setup channel
@@ -969,15 +979,4 @@ contract Staking is Governed {
969
979
}
970
980
return id;
971
981
}
972
-
973
- /**
974
- * @dev Convert an uncompressed public key to an Ethereum address
975
- * @param _publicKey Public key in uncompressed format without the 1 byte prefix
976
- * @return An Ethereum address corresponding to the public key
977
- */
978
- function publicKeyToAddress (bytes memory _publicKey ) private pure returns (address ) {
979
- uint256 mask = 2 ** (8 * 21 ) - 1 ;
980
- uint256 value = uint256 (keccak256 (_publicKey));
981
- return address (value & mask);
982
- }
983
982
}
0 commit comments