Expert on Shelby Protocol smart contracts on Aptos blockchain. Helps with blob metadata, micropayment channels, auditing system, storage commitments, placement group assignments, Move modules, and on-chain state management. Triggers on keywords Shelby smart contract, Shelby Move, blob metadata, micropayment channel, Shelby auditing, placement group assignment, storage commitment, Aptos contract.
Expert guidance on Shelby Protocol's smart contract layer built on Aptos blockchain using Move language. Covers blob metadata management, micropayment channels, auditing mechanisms, system participation, and on-chain coordination.
Auto-invoke when users ask about:
Smart contract documentation:
.claude/skills/blockchain/aptos/docs_shelby/
Key files:
protocol_architecture_smart-contracts.md - Smart contract architectureprotocol_architecture_overview.md - System interactionsprotocol_architecture_token-economics.md - Economic modelprotocol_architecture_white-paper.md - Formal specificationsSingle Source of Truth:
Key Functions:
Core Fields:
Step 1: SDK Prepares Transaction
User Data → SDK computes erasure coded chunks locally
→ SDK calculates cryptographic commitments for each chunk
→ SDK creates Merkle tree of chunk commitments
→ SDK prepares transaction with merkle root
Step 2: Blob Registration Transaction
Transaction submitted to smart contract includes:
Step 3: Smart Contract Execution
Smart contract:
Placement Group Assignment:
Step 4: Storage Provider Acknowledgments
After RPC distributes chunks:
Alternative: Storage providers can submit acknowledgments directly if RPC is unresponsive.
Step 5: State Transition to "Written"
When sufficient acknowledgments received:
No On-Chain Updates Required:
Information Retrieved:
Enable efficient payments from RPC servers to storage providers during read operations without on-chain overhead for each payment.
Channel Lifecycle:
RPC Server → Creates micropayment channel transaction
→ Deposits initial amount (e.g., 10000000 ShelbyUSD micro-units)
→ Smart contract locks funds
→ Channel opened for recipient (storage provider)
Read Request → RPC pays storage provider for chunk retrieval
→ Payment signed by RPC
→ Storage provider validates signature
→ No blockchain transaction needed
→ Provider accumulates signed payments
Storage Provider → Submits accumulated payments to smart contract
→ Smart contract validates signatures
→ Transfers funds from locked amount
→ Channel balance updated
Either Party → Submits closure transaction
→ Smart contract settles final balance
→ Returns unused funds to sender
→ Channel closed
Performance:
Security:
Flexibility:
// Pseudocode - SDK/RPC integration
class MicropaymentChannel {
async create(recipient: Address, amount: number) {
// Submit on-chain transaction
const tx = await contract.createChannel({
recipient,
amount,
sender: this.account.address()
});
return new Channel(tx.channelId);
}
async signPayment(channelId: string, amount: number) {
// Create signed payment (off-chain)
const payment = {
channelId,
amount,
nonce: this.getNonce()
};
return this.account.sign(payment);
}
async settle(signedPayments: SignedPayment[]) {
// Submit batch settlement (on-chain)
await contract.settlePayments({
payments: signedPayments
});
}
}
Joining the System:
Transaction to smart contract includes:
Smart Contract Actions:
Leaving the System:
On-Chain Structure:
Placement Group {
id: u64,
storage_providers: [Address; 16], // Exactly 16 slots
active: bool,
created_at: timestamp
}
Mapping: PlacementGroupId → [StorageProviderAddress; 16]
Dynamic Updates:
Ensure data integrity and honest storage provider behavior through cryptographic verification.
Periodic Audits:
Smart Contract → Selects random blob and chunk
→ Creates cryptographic challenge
→ Broadcasts to assigned storage provider
Storage Provider → Receives challenge
→ Generates succinct proof of possession
→ Proof uses chunk data and commitment
→ Submits proof to smart contract
Smart Contract → Validates proof against blob commitment
→ Checks proof correctness
→ Updates provider reputation
Success → Provider earns portion of storage payment
→ Reputation score increased
Failure → Provider penalized (stake reduction)
→ Reputation score decreased
→ May be removed from system if repeated failures
Write Payment Flow:
User pays during blob registration
Storage providers acknowledge writes
Audit intervals distribute payments
Failed audits forfeit payments
Reference: See whitepaper for:
1. Blob Registry
2. Placement Groups
3. Provider Registry
4. Payment Channels
5. System Parameters
Read Operations (Free, Fast):
Write Operations (Paid, Slower):
Move's Resource Model:
// Conceptual structure (not actual Shelby code)
module shelby::storage {
struct BlobMetadata has key {
name: String,
owner: address,
commitment: vector<u8>,
size: u64,
placement_group: u64,
expiration: u64,
state: u8, // 0=pending, 1=written, 2=expired
}
struct PlacementGroup has key {
id: u64,
providers: vector<address>,
active: bool
}
public entry fun register_blob(
account: &signer,
name: String,
commitment: vector<u8>,
size: u64,
expiration: u64
) {
// Validate inputs
// Take payment
// Assign placement group
// Create metadata resource
// Emit event
}
}
1. Blob Registration
// SDK submits transaction
const txn = await aptosClient.generateTransaction(account.address(), {
function: "shelby::storage::register_blob",
type_arguments: [],
arguments: [
blobName, // string
commitment, // vector<u8>
blobSize, // u64
expirationTime // u64
]
});
const signedTxn = await aptosClient.signTransaction(account, txn);
const result = await aptosClient.submitTransaction(signedTxn);
2. Acknowledgment Submission
// RPC or storage provider submits
const txn = await aptosClient.generateTransaction(provider.address(), {
function: "shelby::storage::acknowledge_write",
type_arguments: [],
arguments: [
blobOwner, // address
blobName, // string
chunkIndex, // u64
signature // vector<u8>
]
});
3. Micropayment Channel Creation
const txn = await aptosClient.generateTransaction(rpc.address(), {
function: "shelby::payments::create_channel",
type_arguments: [],
arguments: [
recipient, // address (storage provider)
depositAmount // u64 (ShelbyUSD micro-units)
]
});
Before On-Chain Transaction:
After On-Chain Transaction:
Upload Flow:
1. SDK: Compute commitments (off-chain)
2. SDK: Submit registration transaction (on-chain)
3. SDK: Wait for confirmation
4. SDK: Query placement group (on-chain read)
5. SDK: Send data to RPC (off-chain)
6. RPC: Distribute chunks (off-chain via private network)
7. Providers: Submit acknowledgments (on-chain)
8. Contract: Transition to "written" state (on-chain)
Batch Operations:
Efficient Data Structures:
try {
const result = await submitBlobRegistration(blob);
// Wait for confirmation
await waitForTransaction(result.hash);
} catch (error) {
if (error.code === 'INSUFFICIENT_FUNDS') {
// Handle funding issue
} else if (error.code === 'BLOB_EXISTS') {
// Handle duplicate blob
} else {
// Generic error handling
}
}
Track Blob State:
async function waitForWritten(account: string, blobName: string) {
while (true) {
const metadata = await contract.getBlobMetadata(account, blobName);
if (metadata.state === BlobState.WRITTEN) {
return metadata;
} else if (metadata.state === BlobState.FAILED) {
throw new Error('Blob write failed');
}
await sleep(5000); // Poll every 5 seconds
}
}
Monitor Channel Balance:
async function ensureChannelFunded(channelId: string, requiredAmount: number) {
const channel = await contract.getChannel(channelId);
if (channel.balance < requiredAmount) {
// Top up channel
await contract.fundChannel(channelId, additionalAmount);
}
}
Architecture Questions:
Integration Questions:
Debugging Questions:
# Smart contract architecture
Read docs_shelby/protocol_architecture_smart-contracts.md
# Overall system flow
Read docs_shelby/protocol_architecture_overview.md
# Economic model
Read docs_shelby/protocol_architecture_token-economics.md
Structure:
State Transitions:
Blob States:
pending → written → expired
↓
failed
Payment Flow:
User → Storage Payment → Smart Contract (escrow)
→ Audit-based distribution
→ Storage Providers (rewards)
Audit Cycle:
Challenge → Proof → Verification → Reward/Penalty
↓ ↓
Smart Contract Reputation Update
User: "How does Shelby verify storage providers actually stored my data?"
Response:
1. Explain blob commitment during registration
2. Describe acknowledgment mechanism
3. Detail periodic audit system with cryptographic proofs
4. Show proof verification in smart contract
5. Explain reward/penalty distribution
6. Reference: protocol_architecture_smart-contracts.md, whitepaper
After answering, suggest: