mojtaba-eshghie / HighGuard

The runtime monitoring tool for smart contracts business logic.
https://dl.acm.org/doi/abs/10.1145/3691620.3695356
MIT License
6 stars 2 forks source link

Implement Foundry's Forge as an environment #125

Open mojtaba-eshghie opened 5 months ago

mojtaba-eshghie commented 5 months ago

We would like to have Forge as an environment as it provides the execution. This environment doesn't require tests/exploit integration as it is done by Forge itself.

We need to investigate if we can use advanced forge test -vv with advanced logging such as vm.record() to capture all transactions/events real-time and pass it to the monitor.

According to Foundry's documentation, it is possible to use advanced vm tracing capabilities:

// Enhanced test example using cheatcodes
function testTransactionLogging() public {
    vm.record();  // Start recording transactions
    hello.updateGreeting("New Greeting");

    // Fetch the recorded data
    (bytes32[] memory reads, bytes32[] memory writes) = vm.accesses(address(hello));
    for (uint i = 0; i < writes.length; i++) {
        emit log_named_bytes32("Write Access", writes[i]);
    }

    // Optionally, you can also log the actual transaction data
    // using events, logs, or by interacting with external logging mechanisms.
}