Skip to content

Commit

Permalink
merge josh/proof-of-possesion
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarak Ben youssef authored and Tarak Ben youssef committed Oct 18, 2024
2 parents 4c10f40 + 8472e21 commit b4f3a13
Show file tree
Hide file tree
Showing 52 changed files with 825 additions and 4,632 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
.PHONY: test
test:
$(MAKE) generate -C lib/go
test: generate
$(MAKE) test -C lib/go
flow test --cover --covercode="contracts" tests/*.cdc

.PHONY: generate
generate:
$(MAKE) generate -C lib/go

.PHONY: ci
ci:
$(MAKE) ci -C lib/go
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ To run the tests in the repo, use `make test`.

These tests need to utilize the transaction templates that are contained in `transactions/`.

# Audit

Flow Core Contracts were audited by Quantstamp in July 2021: [final report](https://certificate.quantstamp.com/full/epoch-functionality-contracts.pdf).

# Getting Transaction Templates

If you need to use the contracts and transaction templates we have provided in an app, you don't necessarily
Expand All @@ -231,6 +235,6 @@ to the team and we would be happy to help!

## License

The works in these folders are under the [Unlicense](https://github.com/dapperlabs/flow-core-contracts/blob/master/LICENSE):
The works in these folders are under the [Unlicense](https://github.com/onflow/flow-core-contracts/blob/master/LICENSE):

- [src/contracts](https://github.com/dapperlabs/flow-core-contracts/tree/master/contracts)
- [src/contracts](https://github.com/onflow/flow-core-contracts/tree/master/contracts)
10 changes: 8 additions & 2 deletions contracts/FlowIDTableStaking.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -1162,7 +1162,7 @@ access(all) contract FlowIDTableStaking {
let slotLimits: {UInt8: UInt16} = FlowIDTableStaking.getRoleSlotLimits()

let openSlots = FlowIDTableStaking.getOpenNodeSlots()

let nodesToAdd: [String] = []

// Load and reset the candidate node list
Expand All @@ -1173,6 +1173,7 @@ access(all) contract FlowIDTableStaking {
for role in currentNodeCount.keys {

let candidateNodesForRole = candidateNodes[role]!
let nodesToRemoveFromCandidateNodes: [String] = []

if currentNodeCount[role]! >= slotLimits[role]! {
// if all slots are full, remove and refund all pending nodes
Expand Down Expand Up @@ -1205,7 +1206,7 @@ access(all) contract FlowIDTableStaking {
for nodeIndex in deletionList.keys {
let nodeID = candidateNodesForRole.keys[nodeIndex]
self.removeAndRefundNodeRecord(nodeID)
candidateNodesForRole.remove(key: nodeID)
nodesToRemoveFromCandidateNodes.append(nodeID)
}

// Set the current node count for the role to the limit for the role, since they were all filled
Expand All @@ -1218,6 +1219,11 @@ access(all) contract FlowIDTableStaking {
currentNodeCount[role] = currentNodeCount[role]! + UInt16(candidateNodesForRole.keys.length)
}

// Remove the refunded nodes from the candidate nodes list
for node in nodesToRemoveFromCandidateNodes {
candidateNodesForRole.remove(key: node)
}

nodesToAdd.appendAll(candidateNodesForRole.keys)

// Add the desired open slots for each role to the current node count
Expand Down
2 changes: 1 addition & 1 deletion contracts/FlowServiceAccount.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ access(all) contract FlowServiceAccount {
/// Returns 0 if the account has no default balance
access(all) view fun defaultTokenBalance(_ acct: &Account): UFix64 {
var balance = 0.0
if let balanceRef = acct.capabilities.borrow<&{FungibleToken.Balance}>(/public/flowTokenBalance) {
if let balanceRef = acct.capabilities.borrow<&FlowToken.Vault>(/public/flowTokenBalance) {
balance = balanceRef.balance
}

Expand Down
196 changes: 147 additions & 49 deletions contracts/FlowStakingCollection.cdc

Large diffs are not rendered by default.

13 changes: 11 additions & 2 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, stakingKeyPoP: String, 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, stakingKeyPoP: stakingKeyPoP, 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
45 changes: 25 additions & 20 deletions lib/go/contracts/go.mod
Original file line number Diff line number Diff line change
@@ -1,49 +1,53 @@
module github.com/onflow/flow-core-contracts/lib/go/contracts

go 1.18
go 1.22

toolchain go1.22.4

require (
github.com/kevinburke/go-bindata v3.24.0+incompatible
github.com/onflow/flow-core-contracts/lib/go/templates v0.15.2-0.20240215153337-0be5cb4b4bc9
github.com/onflow/flow-ft/lib/go/contracts v1.0.0
github.com/onflow/flow-nft/lib/go/contracts v1.2.1
github.com/stretchr/testify v1.8.4
github.com/onflow/flow-ft/lib/go/contracts v1.0.1
github.com/onflow/flow-nft/lib/go/contracts v1.2.2
github.com/stretchr/testify v1.9.0
)

require (
github.com/SaveTheRbtz/mph v0.1.1-0.20240117162131-4166ec7869bc // indirect
github.com/bits-and-blooms/bitset v1.7.0 // indirect
github.com/bits-and-blooms/bitset v1.10.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
github.com/ethereum/go-ethereum v1.13.5 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fxamacker/cbor/v2 v2.4.1-0.20230228173756-c0c9f774e40c // indirect
github.com/fxamacker/circlehash v0.3.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/holiman/uint256 v1.2.3 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/k0kubun/pp v3.0.1+incompatible // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/logrusorgru/aurora/v4 v4.0.0 // indirect
github.com/magiconair/properties v1.8.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f // indirect
github.com/onflow/cadence v1.0.0-M3 // indirect
github.com/onflow/crypto v0.25.0 // indirect
github.com/onflow/atree v0.8.0-rc.6 // indirect
github.com/onflow/cadence v1.0.0-preview.51 // indirect
github.com/onflow/crypto v0.25.1 // indirect
github.com/onflow/flow-ft/lib/go/templates v0.7.1-0.20240213220156-959b70719876 // indirect
github.com/onflow/flow-go-sdk v1.0.0-M1 // indirect
github.com/onflow/flow-go-sdk v1.0.0-preview.54 // indirect
github.com/onflow/flow-nft/lib/go/templates v0.0.0-20240213205729-48f42d9896f8 // indirect
github.com/onflow/flow/protobuf/go/flow v0.4.3 // indirect
github.com/onflow/go-ethereum v1.13.4 // indirect
github.com/pelletier/go-toml v1.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/psiemens/sconfig v0.1.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/spf13/afero v1.9.2 // indirect
github.com/spf13/cast v1.3.0 // indirect
github.com/spf13/cobra v1.5.0 // indirect
Expand All @@ -54,13 +58,14 @@ require (
github.com/turbolent/prettier v0.0.0-20220320183459-661cc755135d // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/zeebo/blake3 v0.2.3 // indirect
go.opentelemetry.io/otel v1.16.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc // indirect
golang.org/x/sys v0.15.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
golang.org/x/crypto v0.19.0 // indirect
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
gonum.org/v1/gonum v0.13.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
gonum.org/v1/gonum v0.14.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Expand Down
Loading

0 comments on commit b4f3a13

Please sign in to comment.