Skip to content

Conversation

@ZeroEkkusu
Copy link
Collaborator

@ZeroEkkusu ZeroEkkusu commented Feb 28, 2022

feat(stdError): add lowLevelError

Motivation

Cover INVALID opcode cases, such as trying to directly access an element of an array in another contract that is oob, or when there was an error while decoding the error message (0x).

Showcase with arrays

contract C {
    bool[] public bools;

    constructor() {
        bools.push(true);
    }
}

contract TestC is DSTest {
    function testLowLevelError() public {
        Vm vm = Vm(HEVM_ADDRESS);
        C c = new C();
        // P.S. No, we cannot use `indexOOBError` here
        vm.expectRevert(stdError.lowLevelError);
        c.bools(1);
    }
}

test(stdError): add testExpectEncodeStg

Add a test for encodeStorageError. This was marked as TODO.

/// INSIDE TESTING CONTRACT

function testExpectEncodeStg() public {
    vm.expectRevert(stdError.encodeStorageError);
    test.encodeStgError();
}

/// INSIDE DUMMY CONTRACT

bytes someBytes;

function encodeStgError() public {
    assembly {
        sstore(someBytes.slot, 1)
    }
    bytes memory b = someBytes;
}

@ZeroEkkusu ZeroEkkusu changed the title feat(stdError): add lowLevelError 2 commits: lowLevelError + testExpectEncodeStg Mar 2, 2022
@brockelmore
Copy link
Member

lmk wen ready for review

@ZeroEkkusu
Copy link
Collaborator Author

if it isn't draft, it is ready :)

@brockelmore
Copy link
Member

if it isn't draft, it is ready :)

plz request reviews going forward regardless :)

@ZeroEkkusu
Copy link
Collaborator Author

ZeroEkkusu commented Mar 4, 2022

i can't formally request reviews as a non-collaborator

will @ u in the future, if that's what you meant

Edit: 😳

@ZeroEkkusu ZeroEkkusu requested a review from brockelmore March 4, 2022 18:56
Copy link
Member

@brockelmore brockelmore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm :)

@brockelmore brockelmore merged commit 018b7a5 into foundry-rs:master Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants