Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 037cda5

Browse files
committed
slashing: add proof account functionality
1 parent b4a73a3 commit 037cda5

File tree

13 files changed

+993
-12
lines changed

13 files changed

+993
-12
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ members = [
4949
"shared-memory/program",
5050
"single-pool/cli",
5151
"single-pool/program",
52+
"slashing/program",
5253
"stake-pool/cli",
5354
"stake-pool/program",
5455
"stateless-asks/program",

slashing/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Slashing Program
2+
3+
A program that validates a proof of a slashable event on chain for logging purposes.
4+
Users can create a proof buffer for the flavor of slashable infraction, populate it,
5+
and submit for verification.

slashing/program/Cargo.toml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
[package]
2+
name = "spl-slashing"
3+
version = "0.1.0"
4+
description = "Solana Program Library Slashing"
5+
authors = ["Solana Labs Maintainers <[email protected]>"]
6+
repository = "https://github.com/solana-labs/solana-program-library"
7+
license = "Apache-2.0"
8+
edition = "2021"
9+
10+
[features]
11+
no-entrypoint = []
12+
test-sbf = []
13+
14+
[dependencies]
15+
bytemuck = { version = "1.19.0", features = ["derive"] }
16+
num-derive = "0.4"
17+
num-traits = "0.2"
18+
solana-program = "2.0.3"
19+
thiserror = "1.0"
20+
spl-pod = { version = "0.4.0", path = "../../libraries/pod" }
21+
22+
[dev-dependencies]
23+
solana-program-test = "2.0.3"
24+
solana-sdk = "2.0.3"
25+
26+
[lib]
27+
crate-type = ["cdylib", "lib"]
28+
29+
[package.metadata.docs.rs]
30+
targets = ["x86_64-unknown-linux-gnu"]

slashing/program/Xargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[target.bpfel-unknown-unknown.dependencies.std]
2+
features = []

slashing/program/program-id.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8sT74BE7sanh4iT84EyVUL8b77cVruLHXGjvTyJ4GwCe

slashing/program/src/entrypoint.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//! Program entrypoint
2+
3+
#![cfg(all(target_os = "solana", not(feature = "no-entrypoint")))]
4+
5+
use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey};
6+
7+
solana_program::entrypoint!(process_instruction);
8+
fn process_instruction(
9+
program_id: &Pubkey,
10+
accounts: &[AccountInfo],
11+
instruction_data: &[u8],
12+
) -> ProgramResult {
13+
crate::processor::process_instruction(program_id, accounts, instruction_data)
14+
}

slashing/program/src/error.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//! Error types
2+
3+
use {
4+
num_derive::FromPrimitive,
5+
solana_program::{decode_error::DecodeError, program_error::ProgramError},
6+
thiserror::Error,
7+
};
8+
9+
/// Errors that may be returned by the program.
10+
#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
11+
pub enum SlashingError {
12+
/// Incorrect authority provided on write or close
13+
#[error("Incorrect authority provided on write or close")]
14+
IncorrectAuthority,
15+
16+
/// Invalid proof type
17+
#[error("Invalid proof type")]
18+
InvalidProofType,
19+
20+
/// Calculation overflow
21+
#[error("Calculation overflow")]
22+
Overflow,
23+
}
24+
25+
impl From<SlashingError> for ProgramError {
26+
fn from(e: SlashingError) -> Self {
27+
ProgramError::Custom(e as u32)
28+
}
29+
}
30+
31+
impl<T> DecodeError<T> for SlashingError {
32+
fn type_of() -> &'static str {
33+
"Slashing Error"
34+
}
35+
}

0 commit comments

Comments
 (0)