Skip to content

Commit

Permalink
Merge branch 'develop' into nonevm-984-reorg
Browse files Browse the repository at this point in the history
  • Loading branch information
Farber98 committed Dec 19, 2024
2 parents b6f4729 + 150f744 commit dff36b0
Show file tree
Hide file tree
Showing 28 changed files with 610 additions and 510 deletions.
12 changes: 8 additions & 4 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# 12/26 - @njegosrailic: I reviewed the codeowners file and confirmed all the teams are appropriate.

# CODEOWNERS Best Practices
# 1. Per Github docs: "Order is important; the last matching pattern takes the most precedence."
# Please define less specific codeowner paths before more specific codeowner paths in order for the more specific rule to have priority
# The following doc explains the CODEOWNERS file syntax:
# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners#codeowners-syntax

# global ownership
* @smartcontractkit/bix-build
Expand All @@ -11,11 +15,11 @@
# gauntlet ownership
/gauntlet @smartcontractkit/devx @smartcontractkit/bix-build

# relayer ownership
/pkg @smartcontractkit/bix-build

# monitoring ownership
/pkg/monitoring @smartcontractkit/realtime

# LOOP Plugin commands
/pkg/solana/cmd/chainlink-solana @smartcontractkit/foundations @smartcontractkit/bix-build

# CI/CD
/.github/** @smartcontractkit/releng
/.github/** @smartcontractkit/releng @smartcontractkit/bix-build
9 changes: 9 additions & 0 deletions contracts/Cargo.lock

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

25 changes: 25 additions & 0 deletions contracts/crates/chainlink-solana-data-streams/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "chainlink_solana_data_streams"
description = "Chainlink Data Streams Uility for Solana. Can be used on-chain/off-chain to get `verify` transaction instructions."
version = "1.0.0"
edition = "2018"
license = "MIT"

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

[features]
default = []

[dependencies]
borsh = "0.10.3"

[target.'cfg(target_os = "solana")'.dependencies]
solana-program = "1.17"

[target.'cfg(not(target_os = "solana"))'.dependencies]
solana-sdk = "1.17"

[dev-dependencies]
solana-sdk = "1.17"
21 changes: 21 additions & 0 deletions contracts/crates/chainlink-solana-data-streams/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2018 SmartContract ChainLink, Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
3 changes: 3 additions & 0 deletions contracts/crates/chainlink-solana-data-streams/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# chainlink-solana-data-streams

This tool is provided under an MIT license and is for convenience and illustration purposes only.
121 changes: 121 additions & 0 deletions contracts/crates/chainlink-solana-data-streams/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
//! Chainlink Data Streams Client for Solana
mod solana {
#[cfg(not(target_os = "solana"))]
pub use solana_sdk::{
instruction::{AccountMeta, Instruction},
pubkey::Pubkey,
};

#[cfg(target_os = "solana")]
pub use solana_program::{
instruction::{AccountMeta, Instruction},
pubkey::Pubkey,
};
}

use crate::solana::{AccountMeta, Instruction, Pubkey};
use borsh::{BorshDeserialize, BorshSerialize};

/// Program function name discriminators
pub mod discriminator {
pub const VERIFY: [u8; 8] = [133, 161, 141, 48, 120, 198, 88, 150];
}

#[derive(BorshSerialize, BorshDeserialize)]
struct VerifyParams {
signed_report: Vec<u8>,
}

/// A helper struct for creating Verifier program instructions
pub struct VerifierInstructions;

impl VerifierInstructions {
/// Creates a verify instruction.
///
/// # Parameters:
///
/// * `program_id` - The public key of the verifier program.
/// * `verifier_account` - The public key of the verifier account. The function [`Self::get_verifier_config_pda`] can be used to calculate this.
/// * `access_controller_account` - The public key of the access controller account.
/// * `user` - The public key of the user - this account must be a signer
/// * `report_config_account` - The public key of the report configuration account. The function [`Self::get_config_pda`] can be used to calculate this.
/// * `signed_report` - The signed report data as a vector of bytes. Returned from data streams API/WS
///
/// # Returns
///
/// Returns an `Instruction` object that can be sent to the Solana runtime.
pub fn verify(
program_id: &Pubkey,
verifier_account: &Pubkey,
access_controller_account: &Pubkey,
user: &Pubkey,
report_config_account: &Pubkey,
signed_report: Vec<u8>,
) -> Instruction {
let accounts = vec![
AccountMeta::new_readonly(*verifier_account, false),
AccountMeta::new_readonly(*access_controller_account, false),
AccountMeta::new_readonly(*user, true),
AccountMeta::new_readonly(*report_config_account, false),
];

// 8 bytes for discriminator
// 4 bytes size of the length prefix for the signed_report vector
let mut instruction_data = Vec::with_capacity(8 + 4 + signed_report.len());
instruction_data.extend_from_slice(&discriminator::VERIFY);

let params = VerifyParams { signed_report };
let param_data = params.try_to_vec().unwrap();
instruction_data.extend_from_slice(&param_data);

Instruction {
program_id: *program_id,
accounts,
data: instruction_data,
}
}

/// Helper to compute the verifier config PDA account.
pub fn get_verifier_config_pda(program_id: &Pubkey) -> Pubkey {
Pubkey::find_program_address(&[b"verifier"], program_id).0
}

/// Helper to compute the report config PDA account. This uses the first 32 bytes of the
/// uncompressed report as the seed. This is validated within the verifier program
pub fn get_config_pda(report: &[u8], program_id: &Pubkey) -> Pubkey {
Pubkey::find_program_address(&[&report[..32]], program_id).0
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_create_verify_instruction() {
let program_id = Pubkey::new_unique();
let verifier = Pubkey::new_unique();
let controller = Pubkey::new_unique();
let user = Pubkey::new_unique();
let report = vec![1u8; 64];

// Calculate expected PDA before moving report
let expected_config = VerifierInstructions::get_config_pda(&report, &program_id);

let ix = VerifierInstructions::verify(
&program_id,
&verifier,
&controller,
&user,
&expected_config,
report,
);

assert!(ix.data.starts_with(&discriminator::VERIFY));
assert_eq!(ix.program_id, program_id);
assert_eq!(ix.accounts.len(), 4);
assert!(ix.accounts[2].is_signer);
assert_eq!(ix.accounts[3].pubkey, expected_config);
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/jpillora/backoff v1.0.0
github.com/pelletier/go-toml/v2 v2.2.0
github.com/prometheus/client_golang v1.17.0
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241127162636-07aa781ee1f4
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241212163958-6a43e61b9d49
github.com/smartcontractkit/libocr v0.0.0-20241007185508-adbe57025f12
github.com/stretchr/testify v1.9.0
go.uber.org/zap v1.27.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,8 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241127162636-07aa781ee1f4 h1:atCZ1jol7a+tdtgU/wNqXgliBun5H7BjGBicGL8Tj6o=
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241127162636-07aa781ee1f4/go.mod h1:bQktEJf7sJ0U3SmIcXvbGUox7SmXcnSEZ4kUbT8R5Nk=
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241212163958-6a43e61b9d49 h1:ZA92CTX9JtEArrxgZw7PNctVxFS+/DmSXumkwf1WiMY=
github.com/smartcontractkit/chainlink-common v0.3.1-0.20241212163958-6a43e61b9d49/go.mod h1:bQktEJf7sJ0U3SmIcXvbGUox7SmXcnSEZ4kUbT8R5Nk=
github.com/smartcontractkit/grpc-proxy v0.0.0-20240830132753-a7e17fec5ab7 h1:12ijqMM9tvYVEm+nR826WsrNi6zCKpwBhuApq127wHs=
github.com/smartcontractkit/grpc-proxy v0.0.0-20240830132753-a7e17fec5ab7/go.mod h1:FX7/bVdoep147QQhsOPkYsPEXhGZjeYx6lBSaSXtZOA=
github.com/smartcontractkit/libocr v0.0.0-20241007185508-adbe57025f12 h1:NzZGjaqez21I3DU7objl3xExTH4fxYvzTqar8DC6360=
Expand Down
Loading

0 comments on commit dff36b0

Please sign in to comment.