fix: bn clipping in create_program_address (#11951)
This commit is contained in:
@ -105,7 +105,7 @@ export class PublicKey {
|
|||||||
Buffer.from('ProgramDerivedAddress'),
|
Buffer.from('ProgramDerivedAddress'),
|
||||||
]);
|
]);
|
||||||
let hash = await sha256(new Uint8Array(buffer));
|
let hash = await sha256(new Uint8Array(buffer));
|
||||||
let publicKeyBytes = new BN(hash, 16).toArray();
|
let publicKeyBytes = new BN(hash, 16).toArray(null, 32);
|
||||||
if (is_on_curve(publicKeyBytes)) {
|
if (is_on_curve(publicKeyBytes)) {
|
||||||
throw new Error(`Invalid seeds, address must fall off the curve`);
|
throw new Error(`Invalid seeds, address must fall off the curve`);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
// @flow
|
// @flow
|
||||||
|
import BN from 'bn.js';
|
||||||
|
|
||||||
import {PublicKey} from '../src/publickey';
|
import {PublicKey} from '../src/publickey';
|
||||||
|
|
||||||
test('invalid', () => {
|
test('invalid', () => {
|
||||||
@ -276,6 +278,23 @@ test('createProgramAddress', async () => {
|
|||||||
programId,
|
programId,
|
||||||
);
|
);
|
||||||
expect(programAddress.equals(programAddress2)).toBe(false);
|
expect(programAddress.equals(programAddress2)).toBe(false);
|
||||||
|
|
||||||
|
// https://github.com/solana-labs/solana/issues/11950
|
||||||
|
{
|
||||||
|
let seeds = [
|
||||||
|
new PublicKey('H4snTKK9adiU15gP22ErfZYtro3aqR9BTMXiH3AwiUTQ').toBuffer(),
|
||||||
|
new BN(2).toArrayLike(Buffer, 'le', 8),
|
||||||
|
];
|
||||||
|
let programId = new PublicKey(
|
||||||
|
'4ckmDgGdxQoPDLUkDT3vHgSAkzA3QRdNq5ywwY4sUSJn',
|
||||||
|
);
|
||||||
|
programAddress = await PublicKey.createProgramAddress(seeds, programId);
|
||||||
|
expect(
|
||||||
|
programAddress.equals(
|
||||||
|
new PublicKey('12rqwuEgBYiGhBrDJStCiqEtzQpTTiZbh7teNVLuYcFA'),
|
||||||
|
),
|
||||||
|
).toBe(true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('findProgramAddress', async () => {
|
test('findProgramAddress', async () => {
|
||||||
|
Reference in New Issue
Block a user