soroban-examples icon indicating copy to clipboard operation
soroban-examples copied to clipboard

fuzzing example: fuzz_target_2 Config::setup is wrong

Open brson opened this issue 2 years ago • 2 comments

This example uses snapshots to reset the environment, but the way it initializes the first environment should not be recommended:

    fn setup() -> Env {
        let snapshot = {
            let init_ledger = LedgerInfo {
                protocol_version: 1,
                sequence_number: 10,
                timestamp: 12345,
                network_id: Default::default(),
                base_reserve: 10,
                min_temp_entry_ttl: u32::MAX,
                min_persistent_entry_ttl: u32::MAX,
                max_entry_ttl: u32::MAX,
            };

            LedgerSnapshot::from(init_ledger, None)
        };

        let env = Env::from_snapshot(snapshot);
        env.mock_all_auths();

        env
    }

Instead of calling Env::default it creates a snapshot from scratch and converts that to an env. This fails to do a bunch of initialization that Env::default does for the testutils config, and also configures the initial snapshot with strange values for ttl etc.

Instead, the initial snapshot should be created with Env::default, subsequent time advances can still use snapshots to destroy and reconstruct the env.

brson avatar Oct 31 '23 22:10 brson

There are additional revisions to be made to the fuzzing examples and I will get back to them soon.

brson avatar Oct 31 '23 22:10 brson

Using snapshots to destroy and recreate the environment may not be a good idea at all since Env::from_snapshot doesn't do the same test setup that Env::default does.

brson avatar Oct 31 '23 22:10 brson