From 296ff0346a7942bbff1821ab0a475a0634466fe8 Mon Sep 17 00:00:00 2001 From: Reinis Martinsons <77973553+Reinis-FRP@users.noreply.github.com> Date: Thu, 17 Apr 2025 15:37:49 +0300 Subject: [PATCH 1/3] fix(svm): pin rust toolchain for solana (#960) * fix(svm): pin rust toolchain for solana Signed-off-by: Reinis Martinsons * fix: add local toolchain Signed-off-by: Reinis Martinsons * fix: add rustfmt to nightly Signed-off-by: Reinis Martinsons * fix: pin nightly in lint scripts Signed-off-by: Reinis Martinsons --------- Signed-off-by: Reinis Martinsons --- .github/workflows/pr.yml | 6 +++--- package.json | 11 ++++++----- rust-toolchain.toml | 2 ++ scripts/anchor-build.sh | 16 ++++++++++++++++ scripts/anchor-test.sh | 19 +++++++++++++++++++ 5 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 rust-toolchain.toml create mode 100644 scripts/anchor-build.sh create mode 100644 scripts/anchor-test.sh diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 3b85c6d59..3b93ab3c0 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -28,11 +28,11 @@ jobs: - name: Install Cargo toolchain uses: actions-rs/toolchain@v1 with: - toolchain: nightly + toolchain: nightly-2025-04-01 profile: minimal components: rustc - name: Install packages - run: yarn install --frozen-lockfile && rustup component add --toolchain nightly-x86_64-unknown-linux-gnu rustfmt + run: yarn install --frozen-lockfile && rustup component add --toolchain nightly-2025-04-01-x86_64-unknown-linux-gnu rustfmt - name: Lint js shell: bash run: yarn lint-js @@ -69,7 +69,7 @@ jobs: - name: Install Cargo toolchain uses: actions-rs/toolchain@v1 with: - toolchain: stable + toolchain: nightly-2025-04-01 profile: minimal components: rustc - name: Cache Cargo dependencies diff --git a/package.json b/package.json index 7ae0acdae..8faafdbe0 100644 --- a/package.json +++ b/package.json @@ -22,24 +22,25 @@ "lint": "yarn lint-solidity && yarn lint-js && yarn lint-rust", "lint-solidity": "yarn solhint ./contracts/**/*.sol", "lint-js": "yarn prettier --list-different **/*.js **/*.ts", - "lint-rust": "cargo +nightly fmt --all -- --check && cargo clippy", - "lint-fix": "yarn prettier --write **/*.js **/*.ts ./programs/**/*.rs ./contracts**/*.sol && cargo +nightly fmt --all && cargo clippy", + "lint-rust": "cargo +nightly-2025-04-01 fmt --all -- --check && cargo clippy", + "lint-fix": "yarn prettier --write **/*.js **/*.ts ./programs/**/*.rs ./contracts**/*.sol && cargo +nightly-2025-04-01 fmt --all && cargo clippy", "clean-fast": "for dir in node_modules cache cache-zk artifacts artifacts-zk dist typechain; do mv \"${dir}\" \"_${dir}\"; rm -rf \"_${dir}\" &; done", "clean": "rm -rf node_modules cache cache-zk artifacts artifacts-zk dist typechain", "generate-svm-assets": "sh ./scripts/generate-svm-assets.sh && yarn generate-svm-clients", "generate-svm-clients": "yarn ts-node ./scripts/svm/utils/generate-svm-clients.ts && yarn ts-node ./scripts/svm/utils/rename-clients-imports.ts", "build-evm": "hardhat compile", - "build-svm": "echo 'Generating IDLs...' && anchor build > /dev/null 2>&1 || true && anchor run generateExternalTypes && anchor build", + "build-svm": "echo 'Generating IDLs...' && yarn anchor-build > /dev/null 2>&1 || true && anchor run generateExternalTypes && yarn anchor-build", "build-ts": "rm -rf ./dist && tsc && rsync -a --include '*/' --include '*.d.ts' --exclude '*' ./typechain ./dist/", "copy-idl": "mkdir -p dist/src/svm/assets/idl && cp src/svm/assets/idl/*.json dist/src/svm/assets/idl/", "build": "yarn build-evm && yarn build-svm && yarn generate-svm-assets && yarn build-ts && yarn copy-idl", "test-evm": "IS_TEST=true hardhat test", - "test-svm": "anchor test -- --features test", + "test-svm": "sh ./scripts/anchor-test.sh", "test": "yarn test-evm && yarn test-svm", "test:report-gas": "IS_TEST=true REPORT_GAS=true hardhat test", "generate-evm-assets": "rm -rf typechain && TYPECHAIN=ethers yarn hardhat typechain", "prepublish": "yarn build && hardhat export --export-all ./cache/massExport.json && ts-node ./scripts/processHardhatExport.ts && prettier --write ./deployments/deployments.json && yarn generate-evm-assets", - "pre-commit-hook": "sh scripts/preCommitHook.sh" + "pre-commit-hook": "sh scripts/preCommitHook.sh", + "anchor-build": "sh ./scripts/anchor-build.sh" }, "dependencies": { "@across-protocol/constants": "^3.1.46", diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 000000000..e5cd56d0f --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "nightly-2025-04-01" diff --git a/scripts/anchor-build.sh b/scripts/anchor-build.sh new file mode 100644 index 000000000..73752644c --- /dev/null +++ b/scripts/anchor-build.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +echo "๐Ÿ”จ Building anchor programs (no IDL)..." +anchor build --no-idl + +echo "๐Ÿ“ฆ Generating IDLs (using nightly)..." + +for program in programs/*; do + [ -d "$program" ] || continue + + dir_name=$(basename "$program") + program_name=$(echo "$dir_name" | tr '-' '_') + + echo "โ†’ IDL for $program_name" + RUSTUP_TOOLCHAIN="nightly-2025-04-01" anchor idl build -p "$dir_name" -o "target/idl/$program_name.json" -t "target/types/$program_name.ts" +done diff --git a/scripts/anchor-test.sh b/scripts/anchor-test.sh new file mode 100644 index 000000000..a5f121bfa --- /dev/null +++ b/scripts/anchor-test.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +echo "๐Ÿ”จ Building anchor programs (with test feature, no IDL)..." +anchor build --no-idl -- --features test + +echo "๐Ÿ“ฆ Generating IDLs (using nightly)..." + +for program in programs/*; do + [ -d "$program" ] || continue + + dir_name=$(basename "$program") + program_name=$(echo "$dir_name" | tr '-' '_') + + echo "โ†’ IDL for $program_name" + RUSTUP_TOOLCHAIN="nightly-2025-04-01" anchor idl build -p "$dir_name" -o "target/idl/$program_name.json" -t "target/types/$program_name.ts" +done + +echo "๐Ÿงช Running anchor tests..." +anchor test --skip-build From e2b0bb377245bab15ba77ecdab75233badc2bd29 Mon Sep 17 00:00:00 2001 From: Reinis Martinsons Date: Thu, 17 Apr 2025 13:41:06 +0000 Subject: [PATCH 2/3] fix(svm): N-03 use consistent variable names in the instruction constraint Signed-off-by: Reinis Martinsons --- programs/svm-spoke/src/instructions/fill.rs | 6 +++--- .../src/instructions/instruction_params.rs | 4 ++-- programs/svm-spoke/src/instructions/slow_fill.rs | 14 +++++++------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/programs/svm-spoke/src/instructions/fill.rs b/programs/svm-spoke/src/instructions/fill.rs index 248947388..1d6efb682 100644 --- a/programs/svm-spoke/src/instructions/fill.rs +++ b/programs/svm-spoke/src/instructions/fill.rs @@ -16,7 +16,7 @@ use crate::{ #[event_cpi] #[derive(Accounts)] -#[instruction(relay_hash: [u8; 32], relay_data: Option)] +#[instruction(_relay_hash: [u8; 32], relay_data: Option)] pub struct FillRelay<'info> { #[account(mut)] pub signer: Signer<'info>, @@ -65,10 +65,10 @@ pub struct FillRelay<'info> { init_if_needed, payer = signer, space = DISCRIMINATOR_SIZE + FillStatusAccount::INIT_SPACE, - seeds = [b"fills", relay_hash.as_ref()], + seeds = [b"fills", _relay_hash.as_ref()], bump, constraint = is_relay_hash_valid( - &relay_hash, + &_relay_hash, &relay_data.clone().unwrap_or_else(|| instruction_params.as_ref().unwrap().relay_data.clone()), &state) @ SvmError::InvalidRelayHash )] diff --git a/programs/svm-spoke/src/instructions/instruction_params.rs b/programs/svm-spoke/src/instructions/instruction_params.rs index f93c1be46..88654f14a 100644 --- a/programs/svm-spoke/src/instructions/instruction_params.rs +++ b/programs/svm-spoke/src/instructions/instruction_params.rs @@ -3,7 +3,7 @@ use anchor_lang::{prelude::*, solana_program::system_program}; use crate::error::SvmError; #[derive(Accounts)] -#[instruction(total_size: u32)] +#[instruction(_total_size: u32)] pub struct InitializeInstructionParams<'info> { #[account(mut)] pub signer: Signer<'info>, @@ -12,7 +12,7 @@ pub struct InitializeInstructionParams<'info> { #[account( init, payer = signer, - space = total_size as usize, + space = _total_size as usize, seeds = [b"instruction_params", signer.key().as_ref()], bump )] diff --git a/programs/svm-spoke/src/instructions/slow_fill.rs b/programs/svm-spoke/src/instructions/slow_fill.rs index 8c9f4f5a6..7c3ae336c 100644 --- a/programs/svm-spoke/src/instructions/slow_fill.rs +++ b/programs/svm-spoke/src/instructions/slow_fill.rs @@ -13,7 +13,7 @@ use crate::{ #[event_cpi] #[derive(Accounts)] -#[instruction(relay_hash: [u8; 32], relay_data: Option)] +#[instruction(_relay_hash: [u8; 32], relay_data: Option)] pub struct RequestSlowFill<'info> { #[account(mut)] pub signer: Signer<'info>, @@ -33,10 +33,10 @@ pub struct RequestSlowFill<'info> { init_if_needed, payer = signer, space = DISCRIMINATOR_SIZE + FillStatusAccount::INIT_SPACE, - seeds = [b"fills", relay_hash.as_ref()], + seeds = [b"fills", _relay_hash.as_ref()], bump, constraint = is_relay_hash_valid( - &relay_hash, + &_relay_hash, &relay_data.clone().unwrap_or_else(|| instruction_params.as_ref().unwrap().relay_data.clone()), &state) @ SvmError::InvalidRelayHash )] @@ -133,7 +133,7 @@ impl SlowFill { #[event_cpi] #[derive(Accounts)] -#[instruction(relay_hash: [u8; 32], slow_fill_leaf: Option, root_bundle_id: Option)] +#[instruction(_relay_hash: [u8; 32], slow_fill_leaf: Option, _root_bundle_id: Option)] pub struct ExecuteSlowRelayLeaf<'info> { pub signer: Signer<'info>, @@ -148,7 +148,7 @@ pub struct ExecuteSlowRelayLeaf<'info> { seeds = [ b"root_bundle", state.seed.to_le_bytes().as_ref(), - root_bundle_id + _root_bundle_id .unwrap_or_else(|| instruction_params.as_ref().unwrap().root_bundle_id) .to_le_bytes() .as_ref(), @@ -159,11 +159,11 @@ pub struct ExecuteSlowRelayLeaf<'info> { #[account( mut, - seeds = [b"fills", relay_hash.as_ref()], + seeds = [b"fills", _relay_hash.as_ref()], bump, // Make sure caller provided relay_hash used in PDA seeds is valid. constraint = is_relay_hash_valid( - &relay_hash, + &_relay_hash, &slow_fill_leaf .clone() .unwrap_or_else(|| instruction_params.as_ref().unwrap().slow_fill_leaf.clone()) From 60a87576e3bac4fe883496b7bf403de373254c93 Mon Sep 17 00:00:00 2001 From: Reinis Martinsons Date: Wed, 23 Apr 2025 19:03:29 +0000 Subject: [PATCH 3/3] fix: restore relay_hash naming in FillRelay context Signed-off-by: Reinis Martinsons --- programs/svm-spoke/src/instructions/fill.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/programs/svm-spoke/src/instructions/fill.rs b/programs/svm-spoke/src/instructions/fill.rs index 2f2d3c775..d8f965d81 100644 --- a/programs/svm-spoke/src/instructions/fill.rs +++ b/programs/svm-spoke/src/instructions/fill.rs @@ -16,7 +16,7 @@ use crate::{ #[event_cpi] #[derive(Accounts)] -#[instruction(_relay_hash: [u8; 32], relay_data: Option)] +#[instruction(relay_hash: [u8; 32], relay_data: Option)] pub struct FillRelay<'info> { #[account(mut)] pub signer: Signer<'info>, @@ -64,10 +64,10 @@ pub struct FillRelay<'info> { init_if_needed, payer = signer, space = DISCRIMINATOR_SIZE + FillStatusAccount::INIT_SPACE, - seeds = [b"fills", _relay_hash.as_ref()], + seeds = [b"fills", relay_hash.as_ref()], bump, constraint = is_relay_hash_valid( - &_relay_hash, + &relay_hash, &relay_data.clone().unwrap_or_else(|| instruction_params.as_ref().unwrap().relay_data.clone()), &state) @ SvmError::InvalidRelayHash )]