From 12c3985af4ce77e168b46639c2f0267a8bf9d233 Mon Sep 17 00:00:00 2001 From: ibhatt-jumptrading Date: Wed, 27 Nov 2024 17:09:47 +0000 Subject: [PATCH] flamenco: simplify cu account for try find syscall --- .../try_find_program_address.list | 69 +++++++++++++++++++ src/flamenco/vm/syscall/fd_vm_syscall_pda.c | 11 +-- 2 files changed, 71 insertions(+), 9 deletions(-) diff --git a/contrib/test/test-vectors-fixtures/syscall-fixtures/try_find_program_address.list b/contrib/test/test-vectors-fixtures/syscall-fixtures/try_find_program_address.list index abe371e045..dcec705c74 100644 --- a/contrib/test/test-vectors-fixtures/syscall-fixtures/try_find_program_address.list +++ b/contrib/test/test-vectors-fixtures/syscall-fixtures/try_find_program_address.list @@ -14,3 +14,72 @@ dump/test-vectors/syscall/fixtures/try_find_program_address/ec866785e8574e21ea47 dump/test-vectors/syscall/fixtures/try_find_program_address/f461b693c74ee0419f3bcf1db6c43f6fb7dc2ad3_6888.fix dump/test-vectors/syscall/fixtures/try_find_program_address/fee80a4e7a81c0388760a08e54bfec4fca9794d8_6452.fix dump/test-vectors/syscall/fixtures/try_find_program_address/d6a5add962547812679d386de1133f182a327230_2273084.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/01072a52d914831d0235d130181314071094412d_2643488.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/06c9a138ab612a12611b978e27c104ab692aa773_2676473.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/0aa777deade805bc33ff64446a963ecd47386803_2679308.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/0b92735a4b16469a7fb8fbc1e61cadcd27a4e8a2_2672930.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/0c6c83533c3537d01775320e869680d21ef35e7c_2123760.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/15343a30a2f2a0a13182e2e10ac13870626b182a_2163453.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/1eb390fd924d9336826d56186894eb083dd52c53_2675723.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/1ebe7cf44ab498a777910c7cd14f761a1c8d5583_2554930.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/207a181059b9099a54a4684c0d82e20d5c268772_2677809.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/2108392ddc44ecadb2dd37ebc47550b1f20671bf_2596579.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/225b5c879a4771e62d8e644796533c0cc7d9dc7c_2675892.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/245f6cd36c012d74644e7ad4e2949c8069453ed0_2677089.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/29bd955e2fa49d01a2460a8a844112f66ee1439d_2479321.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/2ab773af9277d8c478800b41d00588d1ad8d7d0b_1941862.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/2fdeb9fe4178ed57b307ece6cb3911e193b74bd8_2681105.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/370680f46d97254e405545451bba10dff416c9db_2679514.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/39490a0aadf57b5725f54da49341ae1bcaf6f6a4_2659047.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/394a7ae86a4f256205576f36edf07e1692bc9fe2_2198067.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/3cb11096cd1db35fa1565b6b34ad5be4e14dffaa_2677977.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/489368d27371e464ca4d09c611e51df6949aab88_2407380.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/4d365627d4d50828a449e1cdbecab8ff899a5ea4_2675557.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/5361fb8ba8d6915465097055387a33d645176ad7_2677644.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/53835d6e52cc94adac31e83adbb6b9809c135a7f_2677255.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/5890ac353772f19d0978a17234d8b920bd234847_2508397.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/60d5a4e2b8a33437427920d45b7b4d759ed368de_2087885.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/60f37fa37adff27da653b456e6fb33ea1e39b429_2450637.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/64b44937ecc9ebb543e502d3ef5cf445964e9fbb_2678923.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/65727e11f4ad31f54bed8825c7245a0a62cdbed4_1806569.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/688ef40551502c9ac6a051860af3f96a67fa9a91_2494615.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/6c132927d3b480e0620e33523c8950d5305c53a5_1889850.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/6cc725893b3af06f0a3b3278a36695bffe9de299_2334482.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/71cd93bbed5b6461e6ba5abd1b178f9bbb4c7638_2214868.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/7493cd13b1f37307a1955ed5a8f300d80788e26e_2228349.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/793a6d642a9fef7de4ff6c4640dc8e857a28d44a_2350014.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/7a422572991ee39e8b0d1f008683f677e0985d5d_2294277.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/7d98ed23d96e78b12cde2d5997eb0773d72e9598_2678140.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/7ecf53a87afcc7fdd3583eabdcf01cb4e6d03638_2421717.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/829b845a50cb275e268ef7484dade3139725f83d_2281787.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/900101ad5930feaf36b2ffe4b0885c79d820d5ee_2676082.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/9844101d3a3d08d3ceabd7ba12e70a80c9abaf09_2268902.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/9afc0ef0e7281171525221a8d549d0a5efa66dbd_2393577.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/a794d298e49e63266eb3b2dc717e423b7875ea48_2612914.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/a86d668d228c2e2335498998e19ec295646b2f6a_2676309.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/aba4122951e4da82c5509b79f7afb9d55868afda_2678367.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/b3f17b6bd2f765c8c067c5bdfd991b5bff377b86_2678723.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/b7031ca33b64f054330f736a2cf14c4a080c20a3_2679116.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/b9e7ef9a044ce628c676b57172d3159e2fd32287_2675156.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/bbe4675da00f9bd4b760a4154685b8332ffaa202_1871405.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/bc50847b301b93187dae180c51896b64790deb75_2567642.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/bf4dc1816116ccc7216ab6c5adf0c0194592ed7e_2364589.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/bf4f53bd00e6568d32d0850645a523c719569b64_2628161.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/c1015b2e7ec5b59fdcf128f2f982b4770ab1f6e1_2523346.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/c33fbe6e0ff19f2cb051f6f9398125bb3f7bb41d_2538917.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/c7137ae68b9f9adce55d468af3a4b41a0d054268_2674977.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/ccaca72e3175b57477fd2b14eecd4e16c8bb7c71_2582285.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/cd6a95051407dcbd7c0c81eb673d4c1ef20d8b8e_2321584.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/d0dbdd8789490519fde9432530d7d05b0f0c921f_2677446.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/d12060e6dedc6065c4b9e35e111dc85b38eb5d61_2015586.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/d5ec2d31ea76b296735d42f0f7f0d36b0b308277_2465017.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/d9ba47d76abdebd78f0b00a2335f43f3da9cb3f2_2679703.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/dde418ca213d4fcc748af4ab9893140604b5c35f_2378404.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/de433ab14ecff2e124b504b99225c10520778cff_2675333.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/ecbdd56f876d951b22ff94dfc564eb35b236f85d_2676872.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/f063c5e78f4eb1b82ee185b3d31d75a5fba8b902_2179482.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/f1379f9b89d7d3dd71188458c79aa582656563ba_2678532.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/f30544e4b2f72739681e52c74cc7784432ae8a53_2436873.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/f4b7a01b4ceb0af56928b5ef5206761a148b853a_2674779.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/facc8d7b50876a0d569413cd09cc958d9fa2a124_2676665.fix +dump/test-vectors/syscall/fixtures/try_find_program_address/fcf25f0fd5d1174ed9be1926096c4f373a890c78_2681303.fix diff --git a/src/flamenco/vm/syscall/fd_vm_syscall_pda.c b/src/flamenco/vm/syscall/fd_vm_syscall_pda.c index 7fce9890e8..ff74ae76e8 100644 --- a/src/flamenco/vm/syscall/fd_vm_syscall_pda.c +++ b/src/flamenco/vm/syscall/fd_vm_syscall_pda.c @@ -165,7 +165,7 @@ fd_vm_syscall_sol_create_program_address( /**/ void * _vm, } /* fd_vm_syscall_sol_try_find_program_address is the entrypoint for the sol_try_find_program_address syscall: -https://github.com/solana-labs/solana/blob/2afde1b028ed4593da5b6c735729d8994c4bfac6/programs/bpf_loader/src/syscalls/mod.rs#L727 +https://github.com/anza-xyz/agave/blob/v2.1.1/programs/bpf_loader/src/syscalls/mod.rs#L791 This syscall creates a valid program derived address, searching for a valid ed25519 curve point by iterating through 255 possible bump seeds. @@ -201,7 +201,6 @@ fd_vm_syscall_sol_try_find_program_address( void * _vm, To maintain CU conformance at a fuzzing level, we should perform the CU deduction only if our adjacent preflight checks do not fail. If they do at some point in the derivation, no extra CUs will be charged. */ - ulong owed_cus = 0UL; for( ulong i=0UL; i<255UL; i++ ) { bump_seed[0] = (uchar)(255UL - i); @@ -212,13 +211,11 @@ fd_vm_syscall_sol_try_find_program_address( void * _vm, int err = 0; fd_pubkey_t * out_haddr = FD_VM_MEM_HADDR_ST_( vm, out_vaddr, FD_VM_ALIGN_RUST_U8, sizeof(fd_pubkey_t), &err ); if( FD_UNLIKELY( 0 != err ) ) { - FD_VM_CU_UPDATE( vm, owed_cus ); *_ret = 0UL; return err; } uchar * out_bump_seed_haddr = FD_VM_MEM_HADDR_ST_( vm, out_bump_seed_vaddr, FD_VM_ALIGN_RUST_U8, 1UL, &err ); if( FD_UNLIKELY( 0 != err ) ) { - FD_VM_CU_UPDATE( vm, owed_cus ); *_ret = 0UL; return err; } @@ -229,19 +226,15 @@ fd_vm_syscall_sol_try_find_program_address( void * _vm, memcpy( out_haddr, derived, sizeof(fd_pubkey_t) ); *out_bump_seed_haddr = (uchar)*bump_seed; - FD_VM_CU_UPDATE( vm, owed_cus ); - *_ret = 0UL; return FD_VM_SUCCESS; } else if( FD_UNLIKELY( err!=FD_VM_ERR_INVALID_PDA ) ) { return err; } - owed_cus = fd_ulong_sat_add( owed_cus, FD_VM_CREATE_PROGRAM_ADDRESS_UNITS ); + FD_VM_CU_UPDATE( vm, FD_VM_CREATE_PROGRAM_ADDRESS_UNITS ); } - FD_VM_CU_UPDATE( vm, owed_cus ); - *_ret = 1UL; return FD_VM_SUCCESS; }