Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/909 proxy delegatecall #1003

Merged
merged 34 commits into from
Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
81ab74f
Validates in Proxy.sol if address is a contract,implements #909
Sep 12, 2019
05a79bb
adapting to the same code format
Sep 15, 2019
600647c
adding Warning to avoid using the isContract function from a constructor
Sep 15, 2019
25d36c4
Merge pull request #1 from celo-org/master
r00ted199 Sep 15, 2019
333c102
Merge branch 'master' into feature/909-proxy-delegatecall
Sep 15, 2019
0cb2519
adding timeout
Sep 16, 2019
db37486
applying address contract check to fallback function
Sep 17, 2019
23f512b
commenting circleci protocol timeout
Sep 17, 2019
4863833
linting and small changes to improve the code reading
Sep 17, 2019
3f34dd6
Merge pull request #2 from celo-org/master
r00ted199 Sep 19, 2019
2568f85
Merge branch 'master' into feature/909-proxy-delegatecall
Sep 19, 2019
b1fdbd0
fixing e2e transfer test with new gas estimates
Sep 19, 2019
eb3f125
adding details about how to execute this e2e test in local
Sep 19, 2019
8089220
fixing accounts doc issue
Sep 19, 2019
78f627a
moving isContract check to _setImplementation
Sep 19, 2019
7bf1b03
Merge pull request #3 from celo-org/master
r00ted199 Sep 20, 2019
fdde8ba
Merge branch 'master' into feature/909-proxy-delegatecall
Sep 20, 2019
4d26ae3
adds the validation of is a contract address before executing call or…
Sep 20, 2019
44d8570
style nits
Sep 21, 2019
2038095
Merge branch 'master' into feature/909-proxy-delegatecall
r00ted199 Sep 21, 2019
a65fed6
Merge branch 'master' into feature/909-proxy-delegatecall
r00ted199 Sep 23, 2019
2a6052a
Merge pull request #4 from celo-org/master
r00ted199 Sep 24, 2019
96945ed
Merge branch 'master' into feature/909-proxy-delegatecall
Sep 24, 2019
9d53836
fixing conflict and doing check if dataLength > 0
Sep 24, 2019
45c2a9a
Merge branch 'feature/909-proxy-delegatecall' of https://github.com/r…
Sep 24, 2019
58bc4ae
fixing conflict
Sep 24, 2019
ab8d380
Merge pull request #5 from celo-org/master
r00ted199 Sep 24, 2019
def8fdd
Merge branch 'master' into feature/909-proxy-delegatecall
Sep 24, 2019
f7d98bf
simple text replacement
Sep 25, 2019
24de378
Merge branch 'feature/909-proxy-delegatecall' of https://github.com/r…
Sep 25, 2019
3809b07
Merge branch 'master' into feature/909-proxy-delegatecall
m-chrzan Sep 26, 2019
e974897
Merge branch 'master' into feature/909-proxy-delegatecall
timmoreton Sep 28, 2019
755026a
Merge branch 'master' into feature/909-proxy-delegatecall
m-chrzan Sep 30, 2019
f5f63bb
Merge branch 'master' into feature/909-proxy-delegatecall
Sep 30, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ jobs:
./scripts/ci_check_if_test_should_run_v2.sh ${FILES_TO_CHECK}
- run:
name: test
no_output_timeout: 20m
# Flaky tests - run them twice
command: yarn --cwd packages/protocol test:coverage || yarn --cwd packages/protocol test:coverage
- store_artifacts:
Expand Down
17 changes: 17 additions & 0 deletions packages/protocol/contracts/common/Proxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ contract Proxy {
payable
onlyOwner
{
require(isContract(implementation), "Invalid contract address");
_setImplementation(implementation);
bool success;
bytes memory returnValue;
Expand Down Expand Up @@ -138,4 +139,20 @@ contract Proxy {
}
emit OwnerSet(newOwner);
}


/**
* @dev isContract detect whether the address is
* a contract address or externally owned account (EOA)
* WARNING: Calling this function from a constructor will return 0
* independently if the address given as parameter is a contract or EOA
* @return true if it is a contract address
*/
function isContract(address addr) public view returns (bool) {
uint size;
/* solium-disable-next-line security/no-inline-assembly */
assembly { size := extcodesize(addr) }
return size > 0;
}

}
7 changes: 7 additions & 0 deletions packages/protocol/test/common/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ contract('Proxy', (accounts: string[]) => {
assert.equal(events[0].event, 'ImplementationSet')
})

it('should not allow to call a non contract address', async () =>
assertRevert(
proxy._setAndInitializeImplementation(accounts[1], initializeData(42), {
from: accounts[1],
})
))

it('should not allow a non-owner to set an implementation', async () =>
assertRevert(
proxy._setAndInitializeImplementation(hasInitializer.address, initializeData(42), {
Expand Down