Skip to content

Commit 8472e21

Browse files
committed
add POP changes to a new branch
1 parent 44e80f4 commit 8472e21

26 files changed

+294
-101
lines changed

contracts/FlowIDTableStaking.cdc

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ access(all) contract FlowIDTableStaking {
160160
networkingAddress: String,
161161
networkingKey: String,
162162
stakingKey: String,
163+
stakingKeyPoP: String,
163164
tokensCommitted: @{FungibleToken.Vault}
164165
) {
165166
pre {
@@ -180,13 +181,20 @@ access(all) contract FlowIDTableStaking {
180181
signatureAlgorithm: SignatureAlgorithm.BLS_BLS12_381
181182
)
182183

184+
// Verify the proof of possesion of the private staking key
185+
assert(
186+
stakeKey.verifyPoP(stakingKeyPoP.decodeHex()),
187+
message:
188+
"FlowIDTableStaking.NodeRecord.init: Cannot create node with ID "
189+
.concat(id).concat(". The Proof of Possession (").concat(stakingKeyPoP)
190+
.concat(") for the node's staking key (").concat(") is invalid")
191+
)
192+
183193
let netKey = PublicKey(
184194
publicKey: networkingKey.decodeHex(),
185195
signatureAlgorithm: SignatureAlgorithm.ECDSA_P256
186196
)
187197

188-
// TODO: Verify the provided Proof of Possession of the staking private key
189-
190198
self.id = id
191199
self.role = role
192200
self.networkingAddress = networkingAddress
@@ -1560,6 +1568,7 @@ access(all) contract FlowIDTableStaking {
15601568
networkingAddress: String,
15611569
networkingKey: String,
15621570
stakingKey: String,
1571+
stakingKeyPoP: String,
15631572
tokensCommitted: @{FungibleToken.Vault}): @NodeStaker
15641573
{
15651574
assert (
@@ -1572,6 +1581,7 @@ access(all) contract FlowIDTableStaking {
15721581
networkingAddress: networkingAddress,
15731582
networkingKey: networkingKey,
15741583
stakingKey: stakingKey,
1584+
stakingKeyPoP: stakingKeyPoP,
15751585
tokensCommitted: <-FlowToken.createEmptyVault(vaultType: Type<@FlowToken.Vault>()))
15761586

15771587
let minimum = self.minimumStakeRequired[role]!

contracts/FlowStakingCollection.cdc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ access(all) contract FlowStakingCollection {
473473
networkingAddress: String,
474474
networkingKey: String,
475475
stakingKey: String,
476+
stakingKeyPoP: String,
476477
amount: UFix64,
477478
payer: auth(BorrowValue) &Account
478479
): auth(Storage, Capabilities, Contracts, Keys, Inbox) &Account? {
@@ -485,6 +486,7 @@ access(all) contract FlowStakingCollection {
485486
networkingAddress: networkingAddress,
486487
networkingKey: networkingKey,
487488
stakingKey: stakingKey,
489+
stakingKeyPoP: stakingKeyPoP,
488490
tokensCommitted: <-tokens
489491
)
490492

contracts/LockedTokens.cdc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,10 @@ access(all) contract LockedTokens {
194194
195195
/// Registers a new node operator with the Flow Staking contract
196196
/// and commits an initial amount of locked tokens to stake
197-
access(account) fun registerNode(nodeInfo: StakingProxy.NodeInfo, amount: UFix64) {
197+
access(account) fun registerNode(nodeInfo: StakingProxy.NodeInfo,
198+
stakingKeyPoP: String,
199+
amount: UFix64
200+
) {
198201
if let nodeStaker <- self.nodeStaker <- nil {
199202
let stakingInfo = FlowIDTableStaking.NodeInfo(nodeID: nodeStaker.id)
200203

@@ -210,7 +213,13 @@ access(all) contract LockedTokens {
210213

211214
let tokens <- vaultRef.withdraw(amount: amount)
212215

213-
let nodeStaker <- self.nodeStaker <- FlowIDTableStaking.addNodeRecord(id: nodeInfo.id, role: nodeInfo.role, networkingAddress: nodeInfo.networkingAddress, networkingKey: nodeInfo.networkingKey, stakingKey: nodeInfo.stakingKey, tokensCommitted: <-tokens)
216+
let nodeStaker <- self.nodeStaker <- FlowIDTableStaking.addNodeRecord(id: nodeInfo.id,
217+
role: nodeInfo.role,
218+
networkingAddress: nodeInfo.networkingAddress,
219+
networkingKey: nodeInfo.networkingKey,
220+
stakingKey: nodeInfo.stakingKey,
221+
stakingKeyPoP: stakingKeyPoP,
222+
tokensCommitted: <-tokens)
214223

215224
destroy nodeStaker
216225

@@ -378,9 +387,9 @@ access(all) contract LockedTokens {
378387

379388
/// The user calls this function if they want to register as a node operator
380389
/// They have to provide all the info for their node
381-
access(TokenOperations) fun createNodeStaker(nodeInfo: StakingProxy.NodeInfo, amount: UFix64) {
390+
access(TokenOperations) fun createNodeStaker(nodeInfo: StakingProxy.NodeInfo, stakingKeyPoP: String, amount: UFix64) {
382391

383-
self.borrowTokenManager().registerNode(nodeInfo: nodeInfo, amount: amount)
392+
self.borrowTokenManager().registerNode(nodeInfo: nodeInfo, stakingKeyPoP: stakingKeyPoP, amount: amount)
384393

385394
// Create a new staker proxy that can be accessed in transactions
386395
self.nodeStakerProxy = LockedNodeStakerProxy(tokenManager: self.tokenManager)

contracts/testContracts/TestFlowIDTableStaking.cdc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ access(all) contract FlowIDTableStaking {
253253
networkingAddress: String,
254254
networkingKey: String,
255255
stakingKey: String,
256+
stakingKeyPoP: String,
256257
tokensCommitted: @{FungibleToken.Vault}
257258
): @NodeStaker {
258259
destroy tokensCommitted

lib/go/contracts/internal/assets/assets.go

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/go/templates/cmd/manifest/manifest.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ func generateManifest(env templates.Environment) *manifest {
128128
}
129129

130130
sampleStakingKey := cadenceValue{
131-
cadence.String("9e9ae0d645fd5fd9050792e0b0daa82cc1686d9133afa0f81a784b375c42ae48567d1545e7a9e1965f2c1a32f73cf8575ebb7a967f6e4d104d2df78eb8be409135d12da0499b8a00771f642c1b9c49397f22b440439f036c3bdee82f5309dab3"),
131+
cadence.String("8dec36ed8a91e3e5d737b06434d94a8a561c7889495d6c7081cd5e123a42124415b9391c9b9aa165c2f71994bf9607cb0ea262ad162fec74146d1ebc482a33b9dad203d16a83bbfda89b3f6e1cd1d8fb2e704a162d259a0ac9f26bc8635d74f6"),
132+
}
133+
134+
sampleStakingKeyPoP := cadenceValue{
135+
cadence.String("828a68a2be392804044d85888100462702a422901da3269fb6512defabad07250aad24f232671e4ac8ae531f54e062fc"),
132136
}
133137

134138
sampleNullOptional := cadenceValue{
@@ -474,6 +478,12 @@ func generateManifest(env templates.Environment) *manifest {
474478
Label: "Staking Key",
475479
SampleValues: []cadenceValue{sampleStakingKey},
476480
},
481+
{
482+
Type: "String",
483+
Name: "stakingKeyPoP",
484+
Label: "Staking Key PoP",
485+
SampleValues: []cadenceValue{sampleStakingKeyPoP},
486+
},
477487
{
478488
Type: "UFix64",
479489
Name: "amount",

0 commit comments

Comments
 (0)