Skip to content

Commit

Permalink
slashing: add proof account functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
AshwinSekar committed Oct 24, 2024
1 parent b4a73a3 commit 9be74cb
Show file tree
Hide file tree
Showing 13 changed files with 993 additions and 12 deletions.
38 changes: 26 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ members = [
"shared-memory/program",
"single-pool/cli",
"single-pool/program",
"slashing/program",
"stake-pool/cli",
"stake-pool/program",
"stateless-asks/program",
Expand Down
5 changes: 5 additions & 0 deletions slashing/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Slashing Program

A program that validates a proof of a slashable event on chain for logging purposes.
Users can create a proof buffer for the flavor of slashable infraction, populate it,
and submit for verification.
30 changes: 30 additions & 0 deletions slashing/program/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[package]
name = "spl-slashing"
version = "0.1.0"
description = "Solana Program Library Slashing"
authors = ["Solana Labs Maintainers <[email protected]>"]
repository = "https://github.com/solana-labs/solana-program-library"
license = "Apache-2.0"
edition = "2021"

[features]
no-entrypoint = []
test-sbf = []

[dependencies]
bytemuck = { version = "1.19.0", features = ["derive"] }
num-derive = "0.4"
num-traits = "0.2"
solana-program = "2.0.3"
thiserror = "1.0"
spl-pod = { version = "0.4.0", path = "../../libraries/pod" }

[dev-dependencies]
solana-program-test = "2.0.3"
solana-sdk = "2.0.3"

[lib]
crate-type = ["cdylib", "lib"]

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
2 changes: 2 additions & 0 deletions slashing/program/Xargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.bpfel-unknown-unknown.dependencies.std]
features = []
1 change: 1 addition & 0 deletions slashing/program/program-id.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8sT74BE7sanh4iT84EyVUL8b77cVruLHXGjvTyJ4GwCe
14 changes: 14 additions & 0 deletions slashing/program/src/entrypoint.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//! Program entrypoint
#![cfg(all(target_os = "solana", not(feature = "no-entrypoint")))]

use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult, pubkey::Pubkey};

solana_program::entrypoint!(process_instruction);
fn process_instruction(
program_id: &Pubkey,
accounts: &[AccountInfo],
instruction_data: &[u8],
) -> ProgramResult {
crate::processor::process_instruction(program_id, accounts, instruction_data)
}
35 changes: 35 additions & 0 deletions slashing/program/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//! Error types
use {
num_derive::FromPrimitive,
solana_program::{decode_error::DecodeError, program_error::ProgramError},
thiserror::Error,
};

/// Errors that may be returned by the program.
#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
pub enum SlashingError {
/// Incorrect authority provided on write or close
#[error("Incorrect authority provided on write or close")]
IncorrectAuthority,

/// Invalid proof type
#[error("Invalid proof type")]
InvalidProofType,

/// Calculation overflow
#[error("Calculation overflow")]
Overflow,
}

impl From<SlashingError> for ProgramError {
fn from(e: SlashingError) -> Self {
ProgramError::Custom(e as u32)
}
}

impl<T> DecodeError<T> for SlashingError {
fn type_of() -> &'static str {
"Slashing Error"
}
}
Loading

0 comments on commit 9be74cb

Please sign in to comment.