3

I have the following function for batching multiple calls, which returns the result (success or not) and the return data for each corresponding call.

function callBatch(bytes[] calldata calls) public returns (bool[] memory, bytes[] memory) {
    bool[] memory successes = new bool[](calls.length);
    bytes[] memory results = new bytes[](calls.length);

    for (uint256 i; i < calls.length; i++) {
        (successes[i], results[i]) = address(this).delegatecall(calls[i]);
        if (!successes[i]) {
            revert();
        }
    }
    return (successes, results);
}

This function is located in Diamond contract, so address(this).delegatecall(..) triggers the local fallback, propagating the call to the actual function implementation.

In my case, the callBatch function is called with only one call A, which doesn't fail and emits an event E. As you can see, the batch function will fail in case any of the calls fail. Now I want to make the function not fail at all and just return the results:

function callBatch(bytes[] calldata calls) public returns (bool[] memory, bytes[] memory) {
    bool[] memory successes = new bool[](calls.length);
    bytes[] memory results = new bytes[](calls.length);

    for (uint256 i; i < calls.length; i++) {
        (successes[i], results[i]) = address(this).delegatecall(calls[i]);
        // if (!successes[i]) {
        //     revert();
        // }
    }
    return (successes, results);
}

Now, calling the function with the same data and the same contract state still shows that the call was successful (successes[0] == 1), it even outputs the expected result (results[0]). But for some reason, there is no the event anymore and the storage wasn't updated as expected.

Again, just to make it clear, the contract state is always the same before the function is called (because I re-deploy it each time).

What could cause this behaviour?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.