Skip to content

Commit 44adc7c

Browse files
fix: use system program assign to prevent invalid runtime failure (#46)
1 parent acfcbbe commit 44adc7c

File tree

4 files changed

+30
-20
lines changed

4 files changed

+30
-20
lines changed

rust/Cargo.lock

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

rust/Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ members = [
1111
resolver = "2"
1212

1313
[workspace.package]
14-
version = "0.2.9"
14+
version = "0.2.10"
1515
authors = ["Magicblock Labs <[email protected]>"]
1616
edition = "2021"
1717
license = "MIT"
@@ -22,10 +22,10 @@ readme = "README.md"
2222
keywords = ["solana", "crypto", "delegation", "ephemeral-rollups", "magicblock"]
2323

2424
[workspace.dependencies]
25-
ephemeral-rollups-sdk = { path = "sdk", version = "=0.2.9" }
26-
ephemeral-rollups-sdk-attribute-ephemeral = { path = "ephemeral", version = "=0.2.9" }
27-
ephemeral-rollups-sdk-attribute-delegate = { path = "delegate", version = "=0.2.9" }
28-
ephemeral-rollups-sdk-attribute-commit = { path = "commit-attribute", version = "=0.2.9" }
25+
ephemeral-rollups-sdk = { path = "sdk", version = "=0.2.10" }
26+
ephemeral-rollups-sdk-attribute-ephemeral = { path = "ephemeral", version = "=0.2.10" }
27+
ephemeral-rollups-sdk-attribute-delegate = { path = "delegate", version = "=0.2.10" }
28+
ephemeral-rollups-sdk-attribute-commit = { path = "commit-attribute", version = "=0.2.10" }
2929

3030
## External crates
3131
anchor-lang = { version = ">=0.28.0" }

rust/sdk/src/cpi.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
use crate::consts::BUFFER;
2+
use crate::types::DelegateAccountArgs;
3+
use crate::utils::{close_pda_with_system_transfer, create_pda, seeds_with_bump};
14
use borsh::BorshSerialize;
25
use solana_program::account_info::AccountInfo;
36
use solana_program::entrypoint::ProgramResult;
47
use solana_program::instruction::{AccountMeta, Instruction};
8+
use solana_program::program::invoke_signed;
59
use solana_program::program_error::ProgramError;
6-
use solana_program::program_memory::{sol_memcpy, sol_memset};
10+
use solana_program::program_memory::sol_memset;
711
use solana_program::pubkey::Pubkey;
8-
9-
// TODO: import from the delegation program crate once open-sourced
10-
use crate::consts::BUFFER;
11-
use crate::types::DelegateAccountArgs;
12-
use crate::utils::{close_pda_with_system_transfer, create_pda, seeds_with_bump};
12+
use solana_program::system_instruction;
1313

1414
pub struct DelegateAccounts<'a, 'info> {
1515
pub payer: &'a AccountInfo<'info>,
@@ -76,7 +76,7 @@ pub fn delegate_account<'a, 'info>(
7676
{
7777
let pda_ro = accounts.pda.try_borrow_data()?;
7878
let mut buf = accounts.buffer.try_borrow_mut_data()?;
79-
sol_memcpy(&mut buf, &pda_ro, data_len);
79+
buf.copy_from_slice(&pda_ro);
8080
}
8181

8282
// Zero PDA (single RW borrow)
@@ -85,7 +85,17 @@ pub fn delegate_account<'a, 'info>(
8585
sol_memset(&mut pda_mut, 0, data_len);
8686
}
8787

88-
accounts.pda.assign(accounts.delegation_program.key);
88+
// Assign the PDA to the delegation program if not already assigned
89+
if accounts.pda.owner != accounts.system_program.key {
90+
accounts.pda.assign(accounts.system_program.key);
91+
}
92+
if accounts.pda.owner != accounts.delegation_program.key {
93+
invoke_signed(
94+
&system_instruction::assign(accounts.pda.key, accounts.delegation_program.key),
95+
&[accounts.pda.clone(), accounts.system_program.clone()],
96+
pda_signer_seeds,
97+
)?;
98+
}
8999

90100
let seeds_vec: Vec<Vec<u8>> = pda_seeds.iter().map(|&slice| slice.to_vec()).collect();
91101

ts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@magicblock-labs/ephemeral-rollups-sdk",
3-
"version": "0.2.9",
3+
"version": "0.2.10",
44
"author": "MagicBlock Labs",
55
"license": "MIT",
66
"publishConfig": {

0 commit comments

Comments
 (0)