Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ jobs:
with:
go-version: '1.21.5'
- name: Install Flow CLI
run: sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/feature/stable-cadence/install.sh)"
run: sh -ci "$(curl -fsSL https://raw.githubusercontent.com/onflow/flow-cli/master/install.sh)"
- name: Flow cli Version
run: flow-c1 version
run: flow version
- name: Update PATH
run: echo "/root/.local/bin" >> $GITHUB_PATH
- name: Run tests
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ git
coverage.json
coverage.lcov
flow.json
lcov.info
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
test:
$(MAKE) generate -C lib/go
$(MAKE) test -C lib/go
flow-c1 test --cover --covercode="contracts" tests/*.cdc
flow test --cover --covercode="contracts" tests/*.cdc

.PHONY: ci
ci:
$(MAKE) ci -C lib/go
flow-c1 test --cover --covercode="contracts" tests/*.cdc
flow test --cover --covercode="contracts" tests/*.cdc
16 changes: 12 additions & 4 deletions contracts/FlowIDTableStaking.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,6 @@ access(all) contract FlowIDTableStaking {
access(all) var networkingKey: String
access(all) var stakingKey: String

/// TODO: Proof of Possession (PoP) of the staking private key

/// The total tokens that only this node currently has staked, not including delegators
/// This value must always be above the minimum requirement to stay staked or accept delegators
access(mapping Identity) var tokensStaked: @FlowToken.Vault
Expand Down Expand Up @@ -160,6 +158,7 @@ access(all) contract FlowIDTableStaking {
networkingAddress: String,
networkingKey: String,
stakingKey: String,
stakingKeyPoP: String,
tokensCommitted: @{FungibleToken.Vault}
) {
pre {
Expand All @@ -180,13 +179,20 @@ access(all) contract FlowIDTableStaking {
signatureAlgorithm: SignatureAlgorithm.BLS_BLS12_381
)

// Verify the proof of possesion of the private staking key
assert(
stakeKey.verifyPoP(stakingKeyPoP.decodeHex()),
message:
"FlowIDTableStaking.NodeRecord.init: Cannot create node with ID "
.concat(id).concat(". The Proof of Possession (").concat(stakingKeyPoP)
.concat(") for the node's staking key (").concat(") is invalid")
)

let netKey = PublicKey(
publicKey: networkingKey.decodeHex(),
signatureAlgorithm: SignatureAlgorithm.ECDSA_P256
)

// TODO: Verify the provided Proof of Possession of the staking private key

self.id = id
self.role = role
self.networkingAddress = networkingAddress
Expand Down Expand Up @@ -1554,6 +1560,7 @@ access(all) contract FlowIDTableStaking {
networkingAddress: String,
networkingKey: String,
stakingKey: String,
stakingKeyPoP: String,
tokensCommitted: @{FungibleToken.Vault}): @NodeStaker
{
assert (
Expand All @@ -1566,6 +1573,7 @@ access(all) contract FlowIDTableStaking {
networkingAddress: networkingAddress,
networkingKey: networkingKey,
stakingKey: stakingKey,
stakingKeyPoP: stakingKeyPoP,
tokensCommitted: <-FlowToken.createEmptyVault(vaultType: Type<@FlowToken.Vault>()))

let minimum = self.minimumStakeRequired[role]!
Expand Down
2 changes: 2 additions & 0 deletions contracts/FlowStakingCollection.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ access(all) contract FlowStakingCollection {
networkingAddress: String,
networkingKey: String,
stakingKey: String,
stakingKeyPoP: String,
amount: UFix64,
payer: auth(BorrowValue) &Account
): auth(Storage, Capabilities, Contracts, Keys, Inbox) &Account? {
Expand All @@ -433,6 +434,7 @@ access(all) contract FlowStakingCollection {
networkingAddress: networkingAddress,
networkingKey: networkingKey,
stakingKey: stakingKey,
stakingKeyPoP: stakingKeyPoP,
tokensCommitted: <-tokens
)

Expand Down
17 changes: 13 additions & 4 deletions contracts/LockedTokens.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,10 @@ access(all) contract LockedTokens {

/// Registers a new node operator with the Flow Staking contract
/// and commits an initial amount of locked tokens to stake
access(account) fun registerNode(nodeInfo: StakingProxy.NodeInfo, amount: UFix64) {
access(account) fun registerNode(nodeInfo: StakingProxy.NodeInfo,
stakingKeyPoP: String,
amount: UFix64
) {
if let nodeStaker <- self.nodeStaker <- nil {
let stakingInfo = FlowIDTableStaking.NodeInfo(nodeID: nodeStaker.id)

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

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

let nodeStaker <- self.nodeStaker <- FlowIDTableStaking.addNodeRecord(id: nodeInfo.id, role: nodeInfo.role, networkingAddress: nodeInfo.networkingAddress, networkingKey: nodeInfo.networkingKey, stakingKey: nodeInfo.stakingKey, tokensCommitted: <-tokens)
let nodeStaker <- self.nodeStaker <- FlowIDTableStaking.addNodeRecord(id: nodeInfo.id,
role: nodeInfo.role,
networkingAddress: nodeInfo.networkingAddress,
networkingKey: nodeInfo.networkingKey,
stakingKey: nodeInfo.stakingKey,
stakingKeyPoP: stakingKeyPoP,
tokensCommitted: <-tokens)

destroy nodeStaker

Expand Down Expand Up @@ -378,9 +387,9 @@ access(all) contract LockedTokens {

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

self.borrowTokenManager().registerNode(nodeInfo: nodeInfo, amount: amount)
self.borrowTokenManager().registerNode(nodeInfo: nodeInfo, stakingKeyPoP: stakingKeyPoP, amount: amount)

// Create a new staker proxy that can be accessed in transactions
self.nodeStakerProxy = LockedNodeStakerProxy(tokenManager: self.tokenManager)
Expand Down
1 change: 1 addition & 0 deletions contracts/testContracts/TestFlowIDTableStaking.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ access(all) contract FlowIDTableStaking {
networkingAddress: String,
networkingKey: String,
stakingKey: String,
stakingKeyPoP: String,
tokensCommitted: @{FungibleToken.Vault}
): @NodeStaker {
destroy tokensCommitted
Expand Down
24 changes: 12 additions & 12 deletions lib/go/contracts/internal/assets/assets.go

Large diffs are not rendered by default.

76 changes: 74 additions & 2 deletions lib/go/templates/cmd/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ func generateManifest(env templates.Environment) *manifest {
}

sampleStakingKey := cadenceValue{
cadence.String("9e9ae0d645fd5fd9050792e0b0daa82cc1686d9133afa0f81a784b375c42ae48567d1545e7a9e1965f2c1a32f73cf8575ebb7a967f6e4d104d2df78eb8be409135d12da0499b8a00771f642c1b9c49397f22b440439f036c3bdee82f5309dab3"),
cadence.String("8dec36ed8a91e3e5d737b06434d94a8a561c7889495d6c7081cd5e123a42124415b9391c9b9aa165c2f71994bf9607cb0ea262ad162fec74146d1ebc482a33b9dad203d16a83bbfda89b3f6e1cd1d8fb2e704a162d259a0ac9f26bc8635d74f6"),
}

sampleStakingKeyPoP := cadenceValue{
cadence.String("828a68a2be392804044d85888100462702a422901da3269fb6512defabad07250aad24f232671e4ac8ae531f54e062fc"),
}

sampleNullOptional := cadenceValue{
Expand Down Expand Up @@ -442,7 +446,7 @@ func generateManifest(env templates.Environment) *manifest {
m.addTemplate(generateTemplate(
"SCO.03", "Register Node",
env,
templates.GenerateCollectionRegisterNode,
templates.GenerateCollectionRegisterNodeOld,
[]argument{
{
Type: "String",
Expand Down Expand Up @@ -830,6 +834,74 @@ func generateManifest(env templates.Environment) *manifest {
},
))

m.addTemplate(generateTemplate(
"SCO.17", "Register Node",
env,
templates.GenerateCollectionRegisterNode,
[]argument{
{
Type: "String",
Name: "id",
Label: "Node ID",
SampleValues: []cadenceValue{sampleNodeID},
},
{
Type: "UInt8",
Name: "role",
Label: "Node Role",
SampleValues: []cadenceValue{sampleNodeRole},
},
{
Type: "String",
Name: "networkingAddress",
Label: "Networking Address",
SampleValues: []cadenceValue{sampleNetworkingAddress},
},
{
Type: "String",
Name: "networkingKey",
Label: "Networking Key",
SampleValues: []cadenceValue{sampleNetworkingKey},
},
{
Type: "String",
Name: "stakingKey",
Label: "Staking Key",
SampleValues: []cadenceValue{sampleStakingKey},
},
{
Type: "String",
Name: "stakingKeyPoP",
Label: "Staking Key PoP",
SampleValues: []cadenceValue{sampleStakingKeyPoP},
},
{
Type: "UFix64",
Name: "amount",
Label: "Amount",
SampleValues: []cadenceValue{sampleAmount},
},
{
Type: "String",
Name: "machineAccountKey",
Label: "Machine Account Public Key",
SampleValues: []cadenceValue{sampleKey},
},
{
Type: "UInt8",
Name: "machineAccountKeySignatureAlgorithm",
Label: "Raw Value for Machine Account Signature Algorithm Enum",
SampleValues: []cadenceValue{sampleSigAlgoEnumRawValue},
},
{
Type: "UInt8",
Name: "machineAccountKeyHashAlgorithm",
Label: "Raw Value for Machine Account Hash Algorithm Enum",
SampleValues: []cadenceValue{sampleHashAlgoEnumRawValue},
},
},
))

return m
}

Expand Down
14 changes: 14 additions & 0 deletions lib/go/templates/idtable_staking_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,3 +576,17 @@ func GenerateGetApprovedNodesScript(env Environment) []byte {

return []byte(ReplaceAddresses(code, env))
}

func GenerateEndStakingTestScript(env Environment) []byte {
code := `
import FlowIDTableStaking from "FlowIDTableStaking"

access(all) fun main() {
let acct = getAuthAccount<auth(BorrowValue) &Account>("FlowIDTableStaking")
let adminRef = acct.storage.borrow<&FlowIDTableStaking.Admin>(from: FlowIDTableStaking.StakingAdminStoragePath)
?? panic("Could not borrow reference to staking admin")

adminRef.endStakingAuction()
}`
return []byte(ReplaceAddresses(code, env))
}
Loading