Skip to content

Commit 5c0df39

Browse files
committed
Intial rough sketch of Smartnodes v2, inspired by Smartnodes v1
0 parents  commit 5c0df39

17 files changed

+646
-0
lines changed

.github/workflows/test.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
workflow_dispatch:
7+
8+
env:
9+
FOUNDRY_PROFILE: ci
10+
11+
jobs:
12+
check:
13+
name: Foundry project
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
submodules: recursive
19+
20+
- name: Install Foundry
21+
uses: foundry-rs/foundry-toolchain@v1
22+
23+
- name: Show Forge version
24+
run: |
25+
forge --version
26+
27+
- name: Run Forge fmt
28+
run: |
29+
forge fmt --check
30+
id: fmt
31+
32+
- name: Run Forge build
33+
run: |
34+
forge build --sizes
35+
id: build
36+
37+
- name: Run Forge tests
38+
run: |
39+
forge test -vvv
40+
id: test

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Compiler files
2+
cache/
3+
out/
4+
5+
# Ignores development broadcast logs
6+
!/broadcast
7+
/broadcast/*/31337/
8+
/broadcast/**/dry-run/
9+
10+
# Docs
11+
docs/
12+
13+
# Dotenv file
14+
.env

.gitmodules

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[submodule "lib/forge-std"]
2+
path = lib/forge-std
3+
url = https://github.com/foundry-rs/forge-std
4+
[submodule "lib/openzeppelin-contracts"]
5+
path = lib/openzeppelin-contracts
6+
url = https://github.com/Openzeppelin/openzeppelin-contracts
7+
[submodule "lib/foundry-huff"]
8+
path = lib/foundry-huff
9+
url = https://github.com/huff-language/foundry-huff

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Smartnodes
2+
3+
![Static Badge](https://img.shields.io/badge/v0.1.2-Smartnodes-pink?logo=) ![License](https://img.shields.io/badge/License-MIT-blue.svg) ![GitHub Repo stars](https://img.shields.io/github/stars/smartnodes-lab/smartnodes?style=social)
4+
5+
A framework for distributed resource sharing across peer-to-peer networks. Enables both local and global computational resource sharing, secured and incentivized by smart contracts.
6+
7+
## Introduction
8+
9+
Smartnodes is an ecosystem of peer-to-peer (P2P) networks designed to democratize access to computational resources and data-driven technologies. Our goal is to create an open and decentralized economy of distributed resources, empowering individuals and researchers with advanced tools while allowing people to monetize their hardware and time. Through smart contract-secured P2P networks, Smartnodes facilitates coordination of nodes and resources, driving advancements in artificial intelligence, data analysis, and other computational fields by providing secure, scalable, and flexible resource sharing.
10+
11+
For a deeper dive into Smartnodes' features, capabilities, and underlying principles, please refer to the
12+
[lightpaper](docs/Lightpaper.md) and [documentation](https://smartnodes.ca/docs).
13+
14+
## Smart Contracts
15+
16+
At the core of the Smartnodes ecosystem lies a deployment of smart contracts that handle critical functions, ensuring seamless coordination, security, and transparency within the network.
17+
18+
## Smartnodes Core
19+
20+
Delegation of Roles and Permissions: role-specific permissions to methods ensure proper access control, validator-multisig control over job and state updates.
21+
Storage of Worker and Validator History: keeps track of the history and reputation of users, along with storage of key user and node data.
22+
Distribution of Rewards and Payments: native token SNO generated and distributed fairly among workers and validators. To be used for payment of services and securing validator nodes.
23+
24+
The main contract is managed by a multisignature wallet composed of active, collateralized validators. Contract updates operate on a rolling basis, where proposals are submitted every 10 minutes by a random selection of validators. The proposal receiving the most votes triggers a contract update with the provided information, such as user registration, worker information, and job-related events. Every state update is accompanied by a token generation event which is distributed fairly among participating validators and workers.
25+
26+
## Peer-to-Peer Networks
27+
28+
P2P networks built on Smartnodes enable efficient and secure interactions between workers and users to provide frictionless access to services. Individual networks are designed for a specific use case, and specialized to aggregate, distribute, and deliver a certain resource to users. Participants of the Smartnodes ecosystem possess a set of cryptographic keys that link their off-chain identity to the smart contract. This cryptographic layer ensures that only those with explicit authority to establish connections can do so, bolstering the security and authenticity of every interaction. Users can be classified into three categories.
29+
30+
Users interact with the Smartnodes network to submit job requests for access to the network’s pooled resources. They connect to validators to request jobs and initialize connections with workers for task execution.
31+
32+
Validators are responsible for the management of on and off-chain information. These validators operate on a specific P2P network, working to maintain a distributed hash table for node and job querying, while managing interactions between users and workers. They peer into worker-user processes, conduct proof-of-work requests to ensure proper actions, and update the job data structure with relevant information (e.g., worker reputations, job-specific data). Validators aggregate this off-chain data and vote on the integrity of these updates to the main contract, where information is finalized.
33+
34+
Workers are task-specific nodes that carry out jobs for users. They stand by and execute computational tasks assigned by validators, ensuring efficient completion of user requests.
35+
36+
Malicious workers are identified, and their reputations are updated or blacklisted based on their behavior.
37+
By leveraging these mechanisms, Smartnodes creates a secure, efficient, and accessible platform for computational tasks, ensuring fair and transparent interactions among all participants.
38+
39+
## Donate
40+
41+
If you would like to support our work, consider buying us a coffee! Your contributions help us continue developing and improving Tensorlink.
42+
43+
<a href="https://www.buymeacoffee.com/smartnodes" target="_blank">
44+
<img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me a Coffee" style="width: 150px; height: auto;">
45+
</a>

foundry.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[profile.default]
2+
src = "src"
3+
out = "out"
4+
libs = ["lib"]
5+
remappings = [
6+
"@openzeppelin/=lib/openzeppelin-contracts/",
7+
"foundry-huff/=lib/foundry-huff/src"
8+
]
9+
ffi = true
10+
11+
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

lib/forge-std

Submodule forge-std added at 77041d2

lib/foundry-huff

Submodule foundry-huff added at 7d1ce15

lib/openzeppelin-contracts

Submodule openzeppelin-contracts added at e4f7021

script/Deploy.s.sol

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.20;
3+
4+
import {Script} from "forge-std/Script.sol";
5+
import {SmartnodesCore} from "../src/SmartnodesCore.sol";
6+
7+
contract DeploySmartnodes is Script {
8+
function run() external returns (SmartnodesCore) {
9+
address[] memory validators;
10+
validators[0] = 0x1234567890123456789012345678901234567890;
11+
validators[1] = 0x0987654321098765432109876543210987654321;
12+
13+
vm.startBroadcast();
14+
SmartnodesCore smartnodesCore = new SmartnodesCore(validators);
15+
vm.startBroadcast();
16+
return smartnodesCore;
17+
}
18+
}

src/HorseStore.huff

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#define function updateHorseNumber(uint256) nonpayable returns()
2+
#define function readNumberOfHorses() view returns (uint256)
3+
4+
#define constant NUMBER_OF_HORSES_STORAGE_SLOT = FREE_STORAGE_POINTER()
5+
6+
#define macro MAIN() = takes(0) returns (0) {
7+
0x00 // Push 0
8+
calldataload // Load calldata
9+
0xe0 // Push 224 bits
10+
shr // Shift to right by 224 bits to get first 32 bits of calldata (ie function selector)
11+
dup1 // Duplicate whats on the stack (function selector)
12+
13+
__FUNC_SIG(updateHorseNumber) // updateHorseNumber(uint256) function selector
14+
eq // check if function selector matches
15+
updateJump // update program counter, returns true/false (1/0)
16+
jumpi // jump if match
17+
18+
__FUNC_SIG(readNumberOfHorses)
19+
eq
20+
readJump
21+
jumpi
22+
23+
0x00 0x00 revert
24+
25+
updateJump:
26+
SET_NUMBER_OF_HORSES()
27+
28+
readJump:
29+
GET_NUMBER_OF_HORSES()
30+
}
31+
32+
#define macro SET_NUMBER_OF_HORSES() = takes(0) returns (0) {
33+
0x04 // we want to get rid of the first 4 bytes of calldata (ie function selector)
34+
calldataload
35+
[NUMBER_OF_HORSES_STORAGE_SLOT]
36+
sstore
37+
stop
38+
}
39+
40+
#define macro GET_NUMBER_OF_HORSES() = takes(0) returns (0) {
41+
[NUMBER_OF_HORSES_STORAGE_SLOT] // [key]
42+
sload // [value]
43+
0x00 // [0, value]
44+
mstore // [] // Memory: [value]
45+
46+
0x20 0x00 return
47+
}

0 commit comments

Comments
 (0)