Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

slashing: add proof account functionality #7394

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this file hasn't been needed for a long time, so we can remove it

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just used the default key when from when I deployed to testnet, can update once we decide how this is going to be deployed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem. Since this will be an "enshrined" program we could even add it a non-random address with a feature-gate, like S1ashing1111111111111....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, let me know if I have this correct for the deployment scheme:

  • We upload the program to some address A
  • On epoch boundary where the feature flag is active we create a program account owned by the system program S1ashing1111...
  • We them move the contents of A to this vanity address
  • Further upgrades to the program will require another feature flag

I did see that some of the other spl programs were deployed with a squads multi sig as the upgrade authority. Curious about your thoughts about that deployment schema.

It seems that would allow us more freedom in upgrading or disabling the slashing program should there be any vulnerabilities. But optically is it worse if the keys are held by anza & FD?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that would be the process. Anza / FD really can't hold the upgrade keys to something so sensitive -- we'll need to leave it up to the validators. We can start off with feature gates, and then eventually move to a validator DAO, if that ever materializes.

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,
Comment on lines +12 to +14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we could use ProgramError::IncorrectAuthority instead, but I don't feel too strongly about it


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

/// Calculation overflow
#[error("Calculation overflow")]
Overflow,
Comment on lines +20 to +22
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we could use ProgramError::ArithmeticOverflow instead

}

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