Ackee-Blockchain / trident

Rust-based framework to Fuzz Solana programs, designed to help you ship secure code.
https://ackee.xyz/trident/docs/latest/
MIT License
209 stars 19 forks source link

Additional anchor types #115

Closed Ikrk closed 8 months ago

Ikrk commented 9 months ago

Added support for all Anchor types. Now, any context structure supported by Anchor 0.29.0 should be correctly parsed and the appropriate snapshot structs generated correctly.

Before this change, the parsing was done "manually". Now however we are using the parser directly from Anchor that has been exposed in Anchor 0.29.0 when using the idl-build feature flag. The types Interface and InterfaceAccount were not tested.

Also, this PR changes the way how the snapshot accounts are constructed. Now only the explicitly optional accounts and the accounts that have the init or close constraints are wrapped into the Option type. That make the work with accounts within the check methods easier because it is not necessary to always verify if there is Some account.

Finally, this PR modularized the implementation within the snapshot_generator.rs file to make it more readable.

Ikrk commented 9 months ago

The accounts snapshots code generation was changed and the tests do not pass anymore. I will correct it next week.

lukacan commented 9 months ago

When used on fuzz_example3, the freshly generated account_snapshots.rs contains an error for "escrow_pda_authority". The account is expected to be:

However, the code is generated as: let escrow_pda_authority = accounts_iter .next() .ok_or(FuzzingError::NotEnoughAccounts)?;

where escrow_pdaauthority has type Option<AccountInfo<'>>

lukacan commented 8 months ago

I made some additional testing today and so far I found another issues:

EDIT: I was further testing account types based on anchor_lang::accounts for Anchor 0.28.0, and my suggestions/observations:

Ikrk commented 8 months ago

Finally I have made following modifications:

lukacan commented 8 months ago

Good job ! I did some testing and it looks like everything generates correctly.