Thanks for pointing that out I need to go update the test cases!
To clarify here is an example. Let’s say you have the following function:
function testPush1() external pure returns(uint256[] memory, uint256[] memory) {
uint256[] memory arr = new uint256[](4);
arr[0] = 0;
arr[1] = 1;
arr[2] = 2;
arr[3] = 3;
mem.push(arr, 4);
uint256[] memory arr2 = new uint256[](1);
arr2[0] = 100;
return (arr, arr2);
}
With internal
and public
functions you receive the same output that looks correct:
arr: [0,1,2,3,4]
arr2: [100]
Here is where I made a mistake in the test cases. I should have written the test function in the following manner (placing mem.push()
after the declaration of arr2
):
function testPush2() external pure returns(uint256[] memory, uint256[] memory) {
uint256[] memory arr = new uint256[](4);
arr[0] = 0;
arr[1] = 1;
arr[2] = 2;
arr[3] = 3;
uint256[] memory arr2 = new uint256[](1);
arr2[0] = 100;
mem.push(arr, 4);
return (arr, arr2);
}
This time you will see that having internal
vs public
will return two different outputs:
**Internal**
arr: [0,1,2,3,4]
arr2: [1,100,64,256]
**Public**
arr: [0,1,2,3,4]
arr2: [100]
What I was attempting to convey is that using an internal function in this case will read the memory location of arr[4]
as the memory location that arr2
should be storing the length of the array. That is why arr2
outputs 4 elements (we pushed 4 to the end of arr
). You can also see that the first two elements are 1 and 100, which is the original declaration of arr2
in memory. This means the EVM is still looking at the old memory location of arr2
because we are jumping inside of the internal function to execute the code. Using delegatecall, we are executing in the context of the original function (testPush2()
). This tells the EVM that we are updating the data associated with these variables in testPush2()
.
The reason why my original test cases still passed is because the EVM learned about the new variables after updating the first array so it did not have to worry about overwriting them.
I hope this example clears things up but let me know if you need any further explanation 