在 solana 中创建帐户或查找帐户的种子是什么,种子可以是任何东西还是特定的?
What is the seeds in creating account or finding the account in solana, and could the seeds be anything or be specific?
我的问题是:
- 种子是什么?
- 为什么需要种子?
- 种子输入是随机的还是特定的?
例如:
- 第一个参数是函数的种子
findProgramAddress
const [_pda, _nonce] = await PublicKey.findProgramAddress(
[Buffer.from(anchor.utils.bytes.utf8.encode("escrow"))],
program.programId
)
- 第二个参数是函数 createWithSeed 的种子?
const GREETING_SEED = 'hello';
const greetedPubkey = await PublicKey.createWithSeed(
payer.publicKey,
GREETING_SEED,
programId,
);
在为 Solana 链上程序创建程序派生地址时,函数 Pubkey::create_program_address
只是将种子与程序地址哈希在一起,以创建一些新的 32 字节地址。然而,这个 32 字节的地址可能是 ed25519 曲线上的一个点,这意味着有一个私钥与之关联。这意味着攻击者可以真正为您的程序派生地址签名,从而破坏 Solana 编程模型的安全性。
为了绕过这种攻击,如果结果值 是 ed25519 曲线上的有效点,Pubkey::create_program_address
将失败。因此,为了让开发人员更轻松,Pubkey::find_program_address
将迭代调用 Pubkey::create_program_address
,直到它为给定的种子和程序 ID 找到一个安全地址。第一个 return 值是安全地址,第二个 return 值是用于创建程序地址的附加种子。
这里有一些额外的资源:
我的问题是:
- 种子是什么?
- 为什么需要种子?
- 种子输入是随机的还是特定的?
例如:
- 第一个参数是函数的种子
findProgramAddress
const [_pda, _nonce] = await PublicKey.findProgramAddress(
[Buffer.from(anchor.utils.bytes.utf8.encode("escrow"))],
program.programId
)
- 第二个参数是函数 createWithSeed 的种子?
const GREETING_SEED = 'hello';
const greetedPubkey = await PublicKey.createWithSeed(
payer.publicKey,
GREETING_SEED,
programId,
);
在为 Solana 链上程序创建程序派生地址时,函数 Pubkey::create_program_address
只是将种子与程序地址哈希在一起,以创建一些新的 32 字节地址。然而,这个 32 字节的地址可能是 ed25519 曲线上的一个点,这意味着有一个私钥与之关联。这意味着攻击者可以真正为您的程序派生地址签名,从而破坏 Solana 编程模型的安全性。
为了绕过这种攻击,如果结果值 是 ed25519 曲线上的有效点,Pubkey::create_program_address
将失败。因此,为了让开发人员更轻松,Pubkey::find_program_address
将迭代调用 Pubkey::create_program_address
,直到它为给定的种子和程序 ID 找到一个安全地址。第一个 return 值是安全地址,第二个 return 值是用于创建程序地址的附加种子。
这里有一些额外的资源: