@typesol/cli 0.50.0 → 0.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +144 -0
- package/README.md +12 -10
- package/SECURITY.md +5 -3
- package/dist/cli.js +36 -5
- package/dist/compiler/analyze.d.ts +8 -1
- package/dist/compiler/analyze.js +227 -19
- package/dist/compiler/diagnostics.d.ts +4 -0
- package/dist/compiler/diagnostics.js +5 -1
- package/dist/compiler/emit/base.d.ts +31 -1
- package/dist/compiler/emit/base.js +37 -1
- package/dist/compiler/emit/calls.js +27 -6
- package/dist/compiler/emit/cpi-core.d.ts +3 -0
- package/dist/compiler/emit/cpi-core.js +8 -2
- package/dist/compiler/emit/cpi.js +4 -2
- package/dist/compiler/emit/create.js +9 -9
- package/dist/compiler/emit/expressions.d.ts +8 -1
- package/dist/compiler/emit/expressions.js +65 -0
- package/dist/compiler/emit/function.d.ts +2 -0
- package/dist/compiler/emit/function.js +59 -7
- package/dist/compiler/emit/outline.d.ts +35 -0
- package/dist/compiler/emit/outline.js +547 -0
- package/dist/compiler/emit/program.js +11 -2
- package/dist/compiler/emit/shared.d.ts +57 -2
- package/dist/compiler/emit/shared.js +18 -3
- package/dist/compiler/emit/statements.d.ts +28 -1
- package/dist/compiler/emit/statements.js +279 -24
- package/dist/compiler/emit/storage.d.ts +16 -0
- package/dist/compiler/emit/storage.js +122 -3
- package/dist/compiler/hints.d.ts +1 -1
- package/dist/compiler/hints.js +9 -1
- package/dist/compiler/idl.js +1 -1
- package/dist/compiler/index.d.ts +15 -1
- package/dist/compiler/index.js +47 -10
- package/dist/compiler/model.d.ts +13 -1
- package/dist/compiler/stack.d.ts +71 -0
- package/dist/compiler/stack.js +309 -0
- package/dist/compiler/toolchain.d.ts +87 -5
- package/dist/compiler/toolchain.js +384 -19
- package/dist/workspace.d.ts +1 -0
- package/dist/workspace.js +1 -1
- package/docker/deps/0.51.0.lock.json +1206 -0
- package/docs/architecture.md +1 -1
- package/docs/audit.md +13 -11
- package/docs/case-study-escrow.md +1 -1
- package/docs/cli.md +2 -2
- package/docs/glossary.md +2 -1
- package/docs/language-basics.md +25 -1
- package/docs/language-pdas.md +6 -2
- package/docs/language-statements.md +101 -11
- package/docs/language-types.md +80 -5
- package/docs/runtime.md +1 -1
- package/docs/security-model.md +5 -3
- package/docs/stability.md +5 -1
- package/docs/troubleshooting.md +45 -1
- package/llms-full.txt +271 -27
- package/package.json +1 -1
- package/releases/0.50.0.json +874 -0
- package/runtime/typesol_rt.h +125 -51
package/runtime/typesol_rt.h
CHANGED
|
@@ -748,7 +748,9 @@ static inline __attribute__((always_inline)) uint64_t ts_invoke(TsParams *params
|
|
|
748
748
|
* The same addresses sol_create_program_address / sol_try_find_program_address compute — sha256 of the seeds, the
|
|
749
749
|
* program id and "ProgramDerivedAddress", valid only off the ed25519 curve — from the sha256 and curve-validation
|
|
750
750
|
* syscalls, which cost a fraction of the 1500 compute units the PDA syscalls charge per attempt. The seed limits are the
|
|
751
|
-
* syscalls' (at most 16 seeds of at most 32 bytes, the bump included), and so is the result for every input.
|
|
751
|
+
* syscalls' (at most 16 seeds of at most 32 bytes, the bump included), and so is the result for every input. The
|
|
752
|
+
* `_fit` forms leave the limits out: the compiler calls them for seed lists it proved within them (every seed of a
|
|
753
|
+
* length known at compile time, and few enough seeds), where the check cannot fail.
|
|
752
754
|
*/
|
|
753
755
|
uint64_t sol_curve_validate_point(uint64_t curve_id, const uint8_t *point, uint8_t *result);
|
|
754
756
|
#define TS_MAX_PDA_SEEDS 16
|
|
@@ -778,6 +780,10 @@ static inline uint64_t ts_create_pda_address(const SolSignerSeed *seeds, int n,
|
|
|
778
780
|
if (!ts_pda_seeds_ok(seeds, n, TS_MAX_PDA_SEEDS) || !ts_pda_hash(seeds, n, NULL, program, out)) return 1; /* not SUCCESS: the PDA syscalls fail the same inputs */
|
|
779
781
|
return SUCCESS;
|
|
780
782
|
}
|
|
783
|
+
static inline uint64_t ts_create_pda_address_fit(const SolSignerSeed *seeds, int n, const SolPubkey *program, SolPubkey *out) {
|
|
784
|
+
if (!ts_pda_hash(seeds, n, NULL, program, out)) return 1; /* not SUCCESS: on the curve, no PDA */
|
|
785
|
+
return SUCCESS;
|
|
786
|
+
}
|
|
781
787
|
|
|
782
788
|
/* msg!("{prefix}{base64(bytes)}") with standard padding, as Raydium's ray_log writes it (at most 300 bytes in). */
|
|
783
789
|
static __attribute__((noinline, unused)) void ts_log_base64(const char *prefix, uint64_t plen, const uint8_t *data, uint64_t len) {
|
|
@@ -801,9 +807,12 @@ static __attribute__((noinline, unused)) void ts_log_base64(const char *prefix,
|
|
|
801
807
|
sol_log_(out, o);
|
|
802
808
|
}
|
|
803
809
|
|
|
804
|
-
/*
|
|
805
|
-
|
|
806
|
-
|
|
810
|
+
/*
|
|
811
|
+
* sol_try_find_program_address: the canonical (highest) bump. As the syscall (and Pubkey::find_program_address), it
|
|
812
|
+
* tries the bumps 255 down to 1: bump 0 is never tried, and seeds whose 255 attempts all land on the curve have no
|
|
813
|
+
* address.
|
|
814
|
+
*/
|
|
815
|
+
static inline uint64_t ts_find_pda_fit(const SolSignerSeed *seeds, int n, const SolPubkey *program, SolPubkey *out, uint8_t *bump_out) {
|
|
807
816
|
/* The seed list is built once; each attempt only changes the bump byte it points at. */
|
|
808
817
|
SolBytes parts[TS_MAX_PDA_SEEDS + 2];
|
|
809
818
|
int k = 0;
|
|
@@ -812,7 +821,7 @@ static inline uint64_t ts_find_pda(const SolSignerSeed *seeds, int n, const SolP
|
|
|
812
821
|
parts[k++] = (SolBytes){&bump, 1};
|
|
813
822
|
parts[k++] = (SolBytes){program->x, 32};
|
|
814
823
|
parts[k++] = (SolBytes){(const uint8_t *)"ProgramDerivedAddress", 21};
|
|
815
|
-
for (int b = 255; b >=
|
|
824
|
+
for (int b = 255; b >= 1; b--) {
|
|
816
825
|
bump = (uint8_t)b;
|
|
817
826
|
sol_sha256(parts, k, out->x);
|
|
818
827
|
uint8_t ignored;
|
|
@@ -823,6 +832,22 @@ static inline uint64_t ts_find_pda(const SolSignerSeed *seeds, int n, const SolP
|
|
|
823
832
|
}
|
|
824
833
|
return 1; /* not SUCCESS: the PDA syscalls fail the same inputs */
|
|
825
834
|
}
|
|
835
|
+
static inline uint64_t ts_find_pda(const SolSignerSeed *seeds, int n, const SolPubkey *program, SolPubkey *out, uint8_t *bump_out) {
|
|
836
|
+
if (!ts_pda_seeds_ok(seeds, n, TS_MAX_PDA_SEEDS - 1)) return 1; /* not SUCCESS: the PDA syscalls fail the same inputs */
|
|
837
|
+
return ts_find_pda_fit(seeds, n, program, out, bump_out);
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
/*
|
|
841
|
+
* The account-creating helpers below (ts_create_pda_owned, ts_create_pda, ts_create_pda_if_needed, ts_create_owned,
|
|
842
|
+
* ts_token_existing) take seed lists from the program. Where the compiler proved every list a program passes them within the limits, it
|
|
843
|
+
* defines TS_PDA_SEEDS_FIT and they leave the check out; a program with one list it could not prove keeps the check in
|
|
844
|
+
* all of them, so that they stay one copy each.
|
|
845
|
+
*/
|
|
846
|
+
#ifdef TS_PDA_SEEDS_FIT
|
|
847
|
+
#define ts_find_pda_given ts_find_pda_fit
|
|
848
|
+
#else
|
|
849
|
+
#define ts_find_pda_given ts_find_pda
|
|
850
|
+
#endif
|
|
826
851
|
|
|
827
852
|
/* ---- Account checks ------------------------------------------------------ */
|
|
828
853
|
/* Copy between two places of the same type that cannot overlap (TS_COPY_LOCAL: one is a local of the function):
|
|
@@ -1204,7 +1229,7 @@ static inline uint64_t ts_check_program_data(const TsAccount *a, const SolPubkey
|
|
|
1204
1229
|
SolSignerSeed seed = {(const uint8_t *)program_id, 32};
|
|
1205
1230
|
SolPubkey expected;
|
|
1206
1231
|
uint8_t bump;
|
|
1207
|
-
if (
|
|
1232
|
+
if (ts_find_pda_fit(&seed, 1, &TS_BPF_UPGRADEABLE_LOADER_ID, &expected, &bump) != SUCCESS || !ts_key_eq(&expected, &a->key))
|
|
1208
1233
|
TS_FAIL(TS_ERR_ADDRESS, "TypeSOL: not this program's ProgramData account");
|
|
1209
1234
|
return SUCCESS;
|
|
1210
1235
|
}
|
|
@@ -1214,7 +1239,7 @@ static const uint8_t TS_EVENT_IX_TAG[8] = {0xe4, 0x45, 0xa5, 0x2e, 0x51, 0xcb, 0
|
|
|
1214
1239
|
static inline uint64_t ts_check_event_authority(const TsAccount *a, const SolPubkey *program_id, uint8_t *bump) {
|
|
1215
1240
|
SolSignerSeed seed = {(const uint8_t *)"__event_authority", 17};
|
|
1216
1241
|
SolPubkey expected;
|
|
1217
|
-
if (
|
|
1242
|
+
if (ts_find_pda_fit(&seed, 1, program_id, &expected, bump) != SUCCESS || !ts_key_eq(&expected, &a->key))
|
|
1218
1243
|
TS_FAIL(TS_ERR_SEEDS, "TypeSOL: not this program's event authority");
|
|
1219
1244
|
return SUCCESS;
|
|
1220
1245
|
}
|
|
@@ -1288,6 +1313,12 @@ static inline uint64_t ts_require_pda(const TsAccount *a, const SolSignerSeed *s
|
|
|
1288
1313
|
TS_FAIL(TS_ERR_SEEDS, "TypeSOL: PDA seeds do not match account");
|
|
1289
1314
|
return SUCCESS;
|
|
1290
1315
|
}
|
|
1316
|
+
static inline uint64_t ts_require_pda_fit(const TsAccount *a, const SolSignerSeed *seeds, int n, const SolPubkey *program_id) {
|
|
1317
|
+
SolPubkey derived;
|
|
1318
|
+
if (ts_create_pda_address_fit(seeds, n, program_id, &derived) != SUCCESS || !ts_key_eq(&derived, &a->key))
|
|
1319
|
+
TS_FAIL(TS_ERR_SEEDS, "TypeSOL: PDA seeds do not match account");
|
|
1320
|
+
return SUCCESS;
|
|
1321
|
+
}
|
|
1291
1322
|
|
|
1292
1323
|
/* ---- System program CPIs ------------------------------------------------- */
|
|
1293
1324
|
static inline uint64_t ts_system_transfer_signed(TsParams *params, TsAccount *from, TsAccount *to,
|
|
@@ -1317,7 +1348,7 @@ static inline uint64_t ts_create_pda_owned(TsParams *params, TsAccount *payer, T
|
|
|
1317
1348
|
uint8_t *bump_out) {
|
|
1318
1349
|
SolPubkey derived;
|
|
1319
1350
|
uint8_t bump;
|
|
1320
|
-
if (
|
|
1351
|
+
if (ts_find_pda_given(seeds, n, params->program_id, &derived, &bump) != SUCCESS ||
|
|
1321
1352
|
!ts_key_eq(&derived, &acct->key))
|
|
1322
1353
|
TS_FAIL(TS_ERR_SEEDS, "TypeSOL: PDA seeds do not match account");
|
|
1323
1354
|
/* No check that the address is free: as Anchor's init, the System Program refuses one in use (AccountAlreadyInUse,
|
|
@@ -1381,7 +1412,7 @@ static inline uint64_t ts_create_owned(TsParams *params, TsAccount *payer, TsAcc
|
|
|
1381
1412
|
uint8_t bump = 0;
|
|
1382
1413
|
if (n > 0) {
|
|
1383
1414
|
SolPubkey derived;
|
|
1384
|
-
if (
|
|
1415
|
+
if (ts_find_pda_given(seeds, n, params->program_id, &derived, &bump) != SUCCESS || !ts_key_eq(&derived, &acct->key))
|
|
1385
1416
|
TS_FAIL(TS_ERR_SEEDS, "TypeSOL: PDA seeds do not match account");
|
|
1386
1417
|
seeds[n].addr = ≎
|
|
1387
1418
|
seeds[n].len = 1;
|
|
@@ -1475,7 +1506,7 @@ static inline uint64_t ts_token_existing(TsParams *params, TsAccount *acct, TsAc
|
|
|
1475
1506
|
*bump_out = 0;
|
|
1476
1507
|
if (n > 0) {
|
|
1477
1508
|
SolPubkey derived;
|
|
1478
|
-
if (
|
|
1509
|
+
if (ts_find_pda_given(seeds, n, params->program_id, &derived, bump_out) != SUCCESS || !ts_key_eq(&derived, &acct->key))
|
|
1479
1510
|
TS_FAIL(TS_ERR_SEEDS, "TypeSOL: PDA seeds do not match account");
|
|
1480
1511
|
}
|
|
1481
1512
|
if (!ts_key_eq(&acct->owner, &tp->key)) TS_FAIL(TS_ERR_WRONG_OWNER, "TypeSOL: account not owned by the token program");
|
|
@@ -1557,7 +1588,7 @@ static inline uint64_t ts_create_pda_if_needed(TsParams *params, TsAccount *paye
|
|
|
1557
1588
|
if (ts_key_eq(&acct->owner, params->program_id)) {
|
|
1558
1589
|
SolPubkey derived;
|
|
1559
1590
|
uint8_t bump;
|
|
1560
|
-
if (
|
|
1591
|
+
if (ts_find_pda_given(seeds, n, params->program_id, &derived, &bump) != SUCCESS ||
|
|
1561
1592
|
!ts_key_eq(&derived, &acct->key))
|
|
1562
1593
|
TS_FAIL(TS_ERR_SEEDS, "TypeSOL: PDA seeds do not match account");
|
|
1563
1594
|
if (acct->data_len < min_space) TS_FAIL(TS_ERR_ACCOUNT_TOO_SMALL, "TypeSOL: account data too small");
|
|
@@ -2465,46 +2496,89 @@ static uint64_t ts_metas_scratch(TsParams *params, SolAccountMeta **out) {
|
|
|
2465
2496
|
}
|
|
2466
2497
|
#endif
|
|
2467
2498
|
|
|
2468
|
-
/*
|
|
2469
|
-
|
|
2499
|
+
/* The base-58^5 limbs of a value below 2^96 (the last 12 bytes of `in`; the first 20 are zero), by long division:
|
|
2500
|
+
cheaper there than the products of ts_base58_32. Five limbs hold it (58^25 > 2^96); the four above are zero. */
|
|
2501
|
+
static __attribute__((noinline)) void ts_base58_low(const uint8_t *in, uint64_t r[9]) {
|
|
2502
|
+
const uint64_t R = 656356768ULL; /* 58^5 */
|
|
2503
|
+
uint64_t a = __builtin_bswap32(*(const ts_u32_unaligned *)(in + 20));
|
|
2504
|
+
uint64_t b = __builtin_bswap32(*(const ts_u32_unaligned *)(in + 24));
|
|
2505
|
+
uint64_t c = __builtin_bswap32(*(const ts_u32_unaligned *)(in + 28));
|
|
2506
|
+
for (int j = 0; j < 4; j++) r[j] = 0;
|
|
2507
|
+
for (int j = 8; j >= 4; j--) {
|
|
2508
|
+
uint64_t q = a / R, rem = a - q * R;
|
|
2509
|
+
a = q;
|
|
2510
|
+
uint64_t cur = (rem << 32) | b;
|
|
2511
|
+
q = cur / R;
|
|
2512
|
+
rem = cur - q * R;
|
|
2513
|
+
b = q;
|
|
2514
|
+
cur = (rem << 32) | c;
|
|
2515
|
+
q = cur / R;
|
|
2516
|
+
r[j] = cur - q * R;
|
|
2517
|
+
c = q;
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
|
|
2521
|
+
/*
|
|
2522
|
+
* Base58 text of a 32-byte value (a Pubkey or Hash in a template), on the heap. The value is eight big-endian u32 limbs
|
|
2523
|
+
* (limb i weighs 2^(32*(7-i))), turned into nine limbs of base 58^5 that give five digits each, at once: row i of T is
|
|
2524
|
+
* 2^(32*(7-i)) written in base 58^5, most significant limb first, so limb j of the result is the sum over i of
|
|
2525
|
+
* limb[i] * T[i][j] plus the carries from the limbs after it (Firedancer's fd_base58 does the same). A value below
|
|
2526
|
+
* 2^96 takes a long division instead (ts_base58_low). Both give the same text for every value
|
|
2527
|
+
* (test/language/base58.test.ts).
|
|
2528
|
+
*/
|
|
2470
2529
|
static uint64_t ts_base58_32(const uint8_t *in, TS_Str *out) {
|
|
2471
2530
|
static const char digits[] = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
2472
|
-
const uint64_t
|
|
2473
|
-
uint64_t
|
|
2474
|
-
|
|
2475
|
-
|
|
2476
|
-
|
|
2531
|
+
const uint64_t R = 656356768ULL; /* 58^5 */
|
|
2532
|
+
uint64_t r[9];
|
|
2533
|
+
if ((*(const ts_u64_unaligned *)in | *(const ts_u64_unaligned *)(in + 8) | *(const ts_u32_unaligned *)(in + 16)) == 0) {
|
|
2534
|
+
if ((*(const ts_u64_unaligned *)(in + 20) | *(const ts_u32_unaligned *)(in + 28)) == 0) {
|
|
2535
|
+
/* Zero (the System Program's address): a '1' for each byte. */
|
|
2536
|
+
uint8_t *p;
|
|
2537
|
+
TS_TRY(ts_alloc(32, &p));
|
|
2538
|
+
for (int i = 0; i < 4; i++) *(ts_u64_unaligned *)(p + 8 * i) = 0x3131313131313131ULL; /* "11111111" */
|
|
2539
|
+
*out = ts_str(p, 32);
|
|
2540
|
+
return SUCCESS;
|
|
2541
|
+
}
|
|
2542
|
+
ts_base58_low(in, r);
|
|
2543
|
+
} else {
|
|
2544
|
+
static const uint32_t T[8][9] = {
|
|
2545
|
+
{0u, 513735u, 77223048u, 437087610u, 300156666u, 605448490u, 214625350u, 141436834u, 379377856u},
|
|
2546
|
+
{0u, 0u, 78508u, 646269101u, 118408823u, 91512303u, 209184527u, 413102373u, 153715680u},
|
|
2547
|
+
{0u, 0u, 0u, 11997u, 486083817u, 3737691u, 294005210u, 247894721u, 289024608u},
|
|
2548
|
+
{0u, 0u, 0u, 0u, 1833u, 324463681u, 385795061u, 551597588u, 21339008u},
|
|
2549
|
+
{0u, 0u, 0u, 0u, 0u, 280u, 127692781u, 389432875u, 357132832u},
|
|
2550
|
+
{0u, 0u, 0u, 0u, 0u, 0u, 42u, 537767569u, 410450016u},
|
|
2551
|
+
{0u, 0u, 0u, 0u, 0u, 0u, 0u, 6u, 356826688u},
|
|
2552
|
+
{0u, 0u, 0u, 0u, 0u, 0u, 0u, 0u, 1u},
|
|
2553
|
+
};
|
|
2554
|
+
uint64_t limb[8];
|
|
2555
|
+
for (int i = 0; i < 8; i++) limb[i] = __builtin_bswap32(*(const ts_u32_unaligned *)(in + 4 * i)); /* big-endian words */
|
|
2556
|
+
for (int j = 0; j < 9; j++) {
|
|
2557
|
+
/* Each product is below 2^32 * 58^5 < 2^62, so four of them fit in 64 bits: two sums of four. */
|
|
2558
|
+
uint64_t a = 0, b = 0;
|
|
2559
|
+
for (int i = 0; i < 4; i++) a += limb[i] * (uint64_t)T[i][j];
|
|
2560
|
+
for (int i = 4; i < 8; i++) b += limb[i] * (uint64_t)T[i][j];
|
|
2561
|
+
r[j] = a % R + b % R;
|
|
2562
|
+
if (j > 0) r[j - 1] += a / R + b / R; /* column 0 of T is 0: r[0] gets only carries */
|
|
2563
|
+
}
|
|
2564
|
+
for (int j = 8; j > 0; j--) {
|
|
2565
|
+
r[j - 1] += r[j] / R;
|
|
2566
|
+
r[j] %= R;
|
|
2567
|
+
}
|
|
2568
|
+
}
|
|
2569
|
+
/* r[0] < 58^5 now, as the value is below 2^256 < 58^45. Five digits per limb from the first nonzero one (the limbs
|
|
2570
|
+
above it give none). */
|
|
2571
|
+
int top = 0;
|
|
2572
|
+
while (top < 8 && r[top] == 0) top++;
|
|
2573
|
+
/* Digits are written from the end of `buf`; 32 bytes need at most 44. */
|
|
2574
|
+
char buf[45];
|
|
2477
2575
|
uint64_t pos = sizeof(buf);
|
|
2478
|
-
int
|
|
2479
|
-
|
|
2480
|
-
|
|
2481
|
-
|
|
2482
|
-
|
|
2483
|
-
#define TS_B58_STEP(i) \
|
|
2484
|
-
{ \
|
|
2485
|
-
uint64_t cur = (rem << 32) | limb[i]; \
|
|
2486
|
-
uint64_t q = cur / D; \
|
|
2487
|
-
rem = cur - q * D; \
|
|
2488
|
-
limb[i] = q; \
|
|
2489
|
-
}
|
|
2490
|
-
switch (start) {
|
|
2491
|
-
case 0: TS_B58_STEP(0) /* fallthrough */
|
|
2492
|
-
case 1: TS_B58_STEP(1) /* fallthrough */
|
|
2493
|
-
case 2: TS_B58_STEP(2) /* fallthrough */
|
|
2494
|
-
case 3: TS_B58_STEP(3) /* fallthrough */
|
|
2495
|
-
case 4: TS_B58_STEP(4) /* fallthrough */
|
|
2496
|
-
case 5: TS_B58_STEP(5) /* fallthrough */
|
|
2497
|
-
case 6: TS_B58_STEP(6) /* fallthrough */
|
|
2498
|
-
default: TS_B58_STEP(7)
|
|
2576
|
+
for (int j = 8; j >= top; j--) {
|
|
2577
|
+
uint64_t v = r[j];
|
|
2578
|
+
for (int k = 0; k < 5; k++) {
|
|
2579
|
+
buf[--pos] = digits[v % 58];
|
|
2580
|
+
v /= 58;
|
|
2499
2581
|
}
|
|
2500
|
-
#undef TS_B58_STEP
|
|
2501
|
-
while (start < 8 && limb[start] == 0) start++;
|
|
2502
|
-
uint64_t q;
|
|
2503
|
-
q = rem / 58; buf[--pos] = digits[rem - q * 58]; rem = q;
|
|
2504
|
-
q = rem / 58; buf[--pos] = digits[rem - q * 58]; rem = q;
|
|
2505
|
-
q = rem / 58; buf[--pos] = digits[rem - q * 58]; rem = q;
|
|
2506
|
-
q = rem / 58; buf[--pos] = digits[rem - q * 58]; rem = q;
|
|
2507
|
-
buf[--pos] = digits[rem];
|
|
2508
2582
|
}
|
|
2509
2583
|
/* Leading zero digits of the number are not printed; each leading zero byte is a '1'. */
|
|
2510
2584
|
while (pos < sizeof(buf) && buf[pos] == '1') pos++;
|
|
@@ -2883,7 +2957,7 @@ static const SolPubkey TS_MPL_METADATA_ID = {{11,112,101,177,227,209,124,69,56,1
|
|
|
2883
2957
|
static inline uint64_t ts_ata_address(const SolPubkey *owner, const SolPubkey *mint, const SolPubkey *token_program, SolPubkey *out) {
|
|
2884
2958
|
SolSignerSeed seeds[3] = {{(const uint8_t *)owner, 32}, {(const uint8_t *)token_program, 32}, {(const uint8_t *)mint, 32}};
|
|
2885
2959
|
uint8_t bump;
|
|
2886
|
-
if (
|
|
2960
|
+
if (ts_find_pda_fit(seeds, 3, &TS_ATA_PROGRAM_ID, out, &bump) != SUCCESS)
|
|
2887
2961
|
TS_FAIL(TS_ERR_SEEDS, "TypeSOL: cannot derive the associated token address");
|
|
2888
2962
|
return SUCCESS;
|
|
2889
2963
|
}
|
|
@@ -3207,7 +3281,7 @@ static __attribute__((unused)) uint64_t ts_token_transfer_checked_hook(TsParams
|
|
|
3207
3281
|
static inline uint64_t ts_metadata_address(const SolPubkey *mint, SolPubkey *out) {
|
|
3208
3282
|
SolSignerSeed seeds[3] = {{(const uint8_t *)"metadata", 8}, {(const uint8_t *)&TS_MPL_METADATA_ID, 32}, {(const uint8_t *)mint, 32}};
|
|
3209
3283
|
uint8_t bump;
|
|
3210
|
-
if (
|
|
3284
|
+
if (ts_find_pda_fit(seeds, 3, &TS_MPL_METADATA_ID, out, &bump) != SUCCESS)
|
|
3211
3285
|
TS_FAIL(TS_ERR_SEEDS, "TypeSOL: cannot derive the metadata address");
|
|
3212
3286
|
return SUCCESS;
|
|
3213
3287
|
}
|
|
@@ -3218,7 +3292,7 @@ static inline uint64_t ts_master_edition_address(const SolPubkey *mint, SolPubke
|
|
|
3218
3292
|
{(const uint8_t *)mint, 32},
|
|
3219
3293
|
{(const uint8_t *)"edition", 7}};
|
|
3220
3294
|
uint8_t bump;
|
|
3221
|
-
if (
|
|
3295
|
+
if (ts_find_pda_fit(seeds, 4, &TS_MPL_METADATA_ID, out, &bump) != SUCCESS)
|
|
3222
3296
|
TS_FAIL(TS_ERR_SEEDS, "TypeSOL: cannot derive the master edition address");
|
|
3223
3297
|
return SUCCESS;
|
|
3224
3298
|
}
|
|
@@ -3378,7 +3452,7 @@ static inline uint64_t ts_update_extra_metas(TsParams *params, TsAccount *payer,
|
|
|
3378
3452
|
SolSignerSeed seeds[2] = {{(const uint8_t *)"extra-account-metas", 19}, {(const uint8_t *)mint, 32}};
|
|
3379
3453
|
SolPubkey pda;
|
|
3380
3454
|
uint8_t bump;
|
|
3381
|
-
if (
|
|
3455
|
+
if (ts_find_pda_fit(seeds, 2, params->program_id, &pda, &bump) != SUCCESS || !ts_key_eq(&pda, &acct->key))
|
|
3382
3456
|
TS_FAIL(TS_ERR_SEEDS, "TypeSOL: not the mint's extra-account-metas PDA");
|
|
3383
3457
|
if (!ts_key_eq(&acct->owner, params->program_id)) TS_FAIL(TS_ERR_WRONG_OWNER, "TypeSOL: the extra-account-metas account is not this program's");
|
|
3384
3458
|
if (acct->data_len < 16 || ts_ld64(acct->data) != ts_ld64(TS_TRANSFER_HOOK_EXECUTE_DISC))
|