Skip to content

Commit

Permalink
feat: account nonce discrepancies tests (#654)
Browse files Browse the repository at this point in the history
* chore: add tests

Signed-off-by: nikolay <[email protected]>

* chore: activate test suite

Signed-off-by: nikolay <[email protected]>

* chore: resolve comments

Signed-off-by: nikolay <[email protected]>

* chore: remove .only

Signed-off-by: nikolay <[email protected]>

* chore: add ci run

Signed-off-by: nikolay <[email protected]>

* chore: use gas price instead of max fee per gas

Signed-off-by: nikolay <[email protected]>

* chore: disable tests

Signed-off-by: nikolay <[email protected]>

* chore: fix ci

Signed-off-by: nikolay <[email protected]>

* chore: fix name

Signed-off-by: nikolay <[email protected]>

---------

Signed-off-by: nikolay <[email protected]>
  • Loading branch information
natanasow authored Feb 2, 2024
1 parent 1be6eee commit ed677b7
Show file tree
Hide file tree
Showing 10 changed files with 690 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/solidity-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ jobs:
with:
testfilter: '@yulequiv'

Discrepancies:
if: ${{ inputs.filterTagOverride == ''}}
name: Discrepancies Suites
uses: ./.github/workflows/test-workflow.yml
with:
testfilter: '@discrepancies'

OpenZeppelinEquiv:
if: ${{ inputs.filterTagOverride == ''}}
name: OpenZeppelin Equivalence
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "InternalCallee",
"sourceName": "contracts/discrepancies/nonce/InternalCallee.sol",
"abi": [
{
"inputs": [],
"name": "externalFunction",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "factorySample",
"outputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "revertWithRevertReason",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [],
"name": "revertWithoutRevertReason",
"outputs": [
{
"internalType": "bool",
"name": "",
"type": "bool"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address payable",
"name": "_addr",
"type": "address"
}
],
"name": "selfdestruct",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
],
"bytecode": "0x60806040526000805534801561001457600080fd5b50610255806100246000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c806311f95f6f1461005c5780633a32b54914610079578063b3943ef81461008f578063cfc72007146100af578063ff489d31146100c4575b600080fd5b6100646100cc565b60405190151581526020015b60405180910390f35b61008161010a565b604051908152602001610070565b610097610124565b6040516001600160a01b039091168152602001610070565b6100c26100bd36600461016c565b610154565b005b610064600080fd5b60405162461bcd60e51b815260206004820152600c60248201526b2932bb32b93a2932b0b9b7b760a11b604482015260009060640160405180910390fd5b6000806000815461011a9061019c565b9182905550919050565b600060405161013290610160565b604051809103906000f08015801561014e573d6000803e3d6000fd5b50905090565b806001600160a01b0316ff5b605c806101c483390190565b60006020828403121561017e57600080fd5b81356001600160a01b038116811461019557600080fd5b9392505050565b6000600182016101bc57634e487b7160e01b600052601160045260246000fd5b506001019056fe6080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea2646970667358221220f6481075743730bdd3ce0fb7af3dd2b6506d5d84da4b52715906bac6a1105c9c64736f6c63430008140033a2646970667358221220fb4786cf966a2373184c8f6b1a628112b295bc3f9c837d44585ae5a78c4f7d2b64736f6c63430008140033",
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100575760003560e01c806311f95f6f1461005c5780633a32b54914610079578063b3943ef81461008f578063cfc72007146100af578063ff489d31146100c4575b600080fd5b6100646100cc565b60405190151581526020015b60405180910390f35b61008161010a565b604051908152602001610070565b610097610124565b6040516001600160a01b039091168152602001610070565b6100c26100bd36600461016c565b610154565b005b610064600080fd5b60405162461bcd60e51b815260206004820152600c60248201526b2932bb32b93a2932b0b9b7b760a11b604482015260009060640160405180910390fd5b6000806000815461011a9061019c565b9182905550919050565b600060405161013290610160565b604051809103906000f08015801561014e573d6000803e3d6000fd5b50905090565b806001600160a01b0316ff5b605c806101c483390190565b60006020828403121561017e57600080fd5b81356001600160a01b038116811461019557600080fd5b9392505050565b6000600182016101bc57634e487b7160e01b600052601160045260246000fd5b506001019056fe6080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea2646970667358221220f6481075743730bdd3ce0fb7af3dd2b6506d5d84da4b52715906bac6a1105c9c64736f6c63430008140033a2646970667358221220fb4786cf966a2373184c8f6b1a628112b295bc3f9c837d44585ae5a78c4f7d2b64736f6c63430008140033",
"linkReferences": {},
"deployedLinkReferences": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "Sample",
"sourceName": "contracts/discrepancies/nonce/InternalCallee.sol",
"abi": [],
"bytecode": "0x6080604052348015600f57600080fd5b50603f80601d6000396000f3fe6080604052600080fdfea2646970667358221220f6481075743730bdd3ce0fb7af3dd2b6506d5d84da4b52715906bac6a1105c9c64736f6c63430008140033",
"deployedBytecode": "0x6080604052600080fdfea2646970667358221220f6481075743730bdd3ce0fb7af3dd2b6506d5d84da4b52715906bac6a1105c9c64736f6c63430008140033",
"linkReferences": {},
"deployedLinkReferences": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "InternalCaller",
"sourceName": "contracts/discrepancies/nonce/InternalCaller.sol",
"abi": [
{
"inputs": [],
"stateMutability": "payable",
"type": "constructor"
},
{
"stateMutability": "payable",
"type": "fallback"
},
{
"inputs": [
{
"internalType": "address",
"name": "_addr",
"type": "address"
}
],
"name": "callExternalFunction",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_addr",
"type": "address"
}
],
"name": "callNonExisting",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_addr",
"type": "address"
}
],
"name": "callRevertWithRevertReason",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_addr",
"type": "address"
}
],
"name": "callRevertWithoutRevertReason",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_addr",
"type": "address"
}
],
"name": "callWithValueTo",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_addr",
"type": "address"
}
],
"name": "delegateCallExternalFunction",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address payable",
"name": "_addr",
"type": "address"
}
],
"name": "selfdestruct",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address payable",
"name": "_addr",
"type": "address"
}
],
"name": "sendTo",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_addr",
"type": "address"
}
],
"name": "staticCallExternalFunction",
"outputs": [
{
"internalType": "uint256",
"name": "",
"type": "uint256"
}
],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "_addr",
"type": "address"
}
],
"name": "staticCallNonExisting",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [
{
"internalType": "address payable",
"name": "_addr",
"type": "address"
}
],
"name": "transferTo",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"stateMutability": "payable",
"type": "receive"
}
],
"bytecode": "0x60806040526106e4806100136000396000f3fe6080604052600436106100a75760003560e01c8063a03fa7e31161006e578063cfc720071161004b578063cfc72007146101c2578063dd731395146101e2578063e6d252451461020257005b8063a03fa7e314610162578063a6a3a30014610182578063cc19f13f146101a257005b80632da1b130146100b05780633e657d0a146100d05780637a223a77146100f05780637ec86f891461011057806390f18d831461013057005b366100ae57005b005b3480156100bc57600080fd5b506100ae6100cb366004610642565b610222565b3480156100dc57600080fd5b506100ae6100eb366004610642565b610277565b3480156100fc57600080fd5b506100ae61010b366004610642565b61030b565b34801561011c57600080fd5b506100ae61012b366004610642565b610384565b34801561013c57600080fd5b5061015061014b366004610642565b6103c2565b60405190815260200160405180910390f35b34801561016e57600080fd5b506100ae61017d366004610642565b610484565b34801561018e57600080fd5b5061015061019d366004610642565b6104ba565b3480156101ae57600080fd5b506100ae6101bd366004610642565b61053b565b3480156101ce57600080fd5b506100ae6101dd366004610642565b610579565b3480156101ee57600080fd5b506101506101fd366004610642565b610585565b34801561020e57600080fd5b506100ae61021d366004610642565b610606565b6040516001600160a01b03821690600190600081818185875af1925050503d806000811461026c576040519150601f19603f3d011682016040523d82523d6000602084013e610271565b606091505b50505050565b60408051600481526024810182526020810180516001600160e01b03167fff489d310000000000000000000000000000000000000000000000000000000017905290516001600160a01b038316916102ce91610666565b6000604051808303816000865af19150503d806000811461026c576040519150601f19603f3d011682016040523d82523d6000602084013e610271565b60408051600481526024810182526020810180516001600160e01b031663477387d160e01b17905290516001600160a01b0383169161034991610666565b600060405180830381855afa9150503d806000811461026c576040519150601f19603f3d011682016040523d82523d6000602084013e610271565b60408051600481526024810182526020810180516001600160e01b03166311f95f6f60e01b17905290516001600160a01b038316916102ce91610666565b60408051600481526024810182526020810180516001600160e01b0316633a32b54960e01b1790529051600091829182916001600160a01b038616916104089190610666565b6000604051808303816000865af19150503d8060008114610445576040519150601f19603f3d011682016040523d82523d6000602084013e61044a565b606091505b509150915081801561045d575060008151115b61046857600061047c565b8080602001905181019061047c9190610695565b949350505050565b6040516001600160a01b0382169060009060019082818181858883f193505050501580156104b6573d6000803e3d6000fd5b5050565b60408051600481526024810182526020810180516001600160e01b0316633a32b54960e01b1790529051600091829182916001600160a01b038616916105009190610666565b600060405180830381855afa9150503d8060008114610445576040519150601f19603f3d011682016040523d82523d6000602084013e61044a565b60408051600481526024810182526020810180516001600160e01b031663477387d160e01b17905290516001600160a01b038316916102ce91610666565b806001600160a01b0316ff5b60408051600481526024810182526020810180516001600160e01b0316633a32b54960e01b1790529051600091829182916001600160a01b038616916105cb9190610666565b600060405180830381855af49150503d8060008114610445576040519150601f19603f3d011682016040523d82523d6000602084013e61044a565b6040516001600160a01b0382169060009060019082818181858883f1505050505050565b6001600160a01b038116811461063f57600080fd5b50565b60006020828403121561065457600080fd5b813561065f8161062a565b9392505050565b6000825160005b81811015610687576020818601810151858301520161066d565b506000920191825250919050565b6000602082840312156106a757600080fd5b505191905056fea264697066735822122088d9b7e35f9ff2ccecb253bb28ae4d233b88037dcef75d7df49a7cc80d0e613764736f6c63430008140033",
"deployedBytecode": "0x6080604052600436106100a75760003560e01c8063a03fa7e31161006e578063cfc720071161004b578063cfc72007146101c2578063dd731395146101e2578063e6d252451461020257005b8063a03fa7e314610162578063a6a3a30014610182578063cc19f13f146101a257005b80632da1b130146100b05780633e657d0a146100d05780637a223a77146100f05780637ec86f891461011057806390f18d831461013057005b366100ae57005b005b3480156100bc57600080fd5b506100ae6100cb366004610642565b610222565b3480156100dc57600080fd5b506100ae6100eb366004610642565b610277565b3480156100fc57600080fd5b506100ae61010b366004610642565b61030b565b34801561011c57600080fd5b506100ae61012b366004610642565b610384565b34801561013c57600080fd5b5061015061014b366004610642565b6103c2565b60405190815260200160405180910390f35b34801561016e57600080fd5b506100ae61017d366004610642565b610484565b34801561018e57600080fd5b5061015061019d366004610642565b6104ba565b3480156101ae57600080fd5b506100ae6101bd366004610642565b61053b565b3480156101ce57600080fd5b506100ae6101dd366004610642565b610579565b3480156101ee57600080fd5b506101506101fd366004610642565b610585565b34801561020e57600080fd5b506100ae61021d366004610642565b610606565b6040516001600160a01b03821690600190600081818185875af1925050503d806000811461026c576040519150601f19603f3d011682016040523d82523d6000602084013e610271565b606091505b50505050565b60408051600481526024810182526020810180516001600160e01b03167fff489d310000000000000000000000000000000000000000000000000000000017905290516001600160a01b038316916102ce91610666565b6000604051808303816000865af19150503d806000811461026c576040519150601f19603f3d011682016040523d82523d6000602084013e610271565b60408051600481526024810182526020810180516001600160e01b031663477387d160e01b17905290516001600160a01b0383169161034991610666565b600060405180830381855afa9150503d806000811461026c576040519150601f19603f3d011682016040523d82523d6000602084013e610271565b60408051600481526024810182526020810180516001600160e01b03166311f95f6f60e01b17905290516001600160a01b038316916102ce91610666565b60408051600481526024810182526020810180516001600160e01b0316633a32b54960e01b1790529051600091829182916001600160a01b038616916104089190610666565b6000604051808303816000865af19150503d8060008114610445576040519150601f19603f3d011682016040523d82523d6000602084013e61044a565b606091505b509150915081801561045d575060008151115b61046857600061047c565b8080602001905181019061047c9190610695565b949350505050565b6040516001600160a01b0382169060009060019082818181858883f193505050501580156104b6573d6000803e3d6000fd5b5050565b60408051600481526024810182526020810180516001600160e01b0316633a32b54960e01b1790529051600091829182916001600160a01b038616916105009190610666565b600060405180830381855afa9150503d8060008114610445576040519150601f19603f3d011682016040523d82523d6000602084013e61044a565b60408051600481526024810182526020810180516001600160e01b031663477387d160e01b17905290516001600160a01b038316916102ce91610666565b806001600160a01b0316ff5b60408051600481526024810182526020810180516001600160e01b0316633a32b54960e01b1790529051600091829182916001600160a01b038616916105cb9190610666565b600060405180830381855af49150503d8060008114610445576040519150601f19603f3d011682016040523d82523d6000602084013e61044a565b6040516001600160a01b0382169060009060019082818181858883f1505050505050565b6001600160a01b038116811461063f57600080fd5b50565b60006020828403121561065457600080fd5b813561065f8161062a565b9392505050565b6000825160005b81811015610687576020818601810151858301520161066d565b506000920191825250919050565b6000602082840312156106a757600080fd5b505191905056fea264697066735822122088d9b7e35f9ff2ccecb253bb28ae4d233b88037dcef75d7df49a7cc80d0e613764736f6c63430008140033",
"linkReferences": {},
"deployedLinkReferences": {}
}
28 changes: 28 additions & 0 deletions contracts/discrepancies/nonce/InternalCallee.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

contract Sample {}

contract InternalCallee {
uint calledTimes = 0;

function factorySample() external returns (address) {
return address(new Sample());
}

function externalFunction() external returns (uint) {
return ++calledTimes;
}

function revertWithRevertReason() public returns (bool) {
revert("RevertReason");
}

function revertWithoutRevertReason() public returns (bool) {
revert();
}

function selfdestruct(address payable _addr) external {
selfdestruct(_addr);
}
}
57 changes: 57 additions & 0 deletions contracts/discrepancies/nonce/InternalCaller.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;

contract InternalCaller {
constructor() payable {}

function callNonExisting(address _addr) external {
_addr.call(abi.encodeWithSignature("nonExisting()"));
}

function staticCallNonExisting(address _addr) external {
_addr.staticcall(abi.encodeWithSignature("nonExisting()"));
}

function staticCallExternalFunction(address _addr) external returns (uint) {
(bool success, bytes memory result) = _addr.staticcall(abi.encodeWithSignature("externalFunction()"));
return success && result.length > 0 ? abi.decode(result, (uint)) : 0;
}

function delegateCallExternalFunction(address _addr) external returns (uint) {
(bool success, bytes memory result) = _addr.delegatecall(abi.encodeWithSignature("externalFunction()"));
return success && result.length > 0 ? abi.decode(result, (uint)) : 0;
}

function callExternalFunction(address _addr) external returns (uint) {
(bool success, bytes memory result) = _addr.call(abi.encodeWithSignature("externalFunction()"));
return success && result.length > 0 ? abi.decode(result, (uint)) : 0;
}

function callRevertWithRevertReason(address _addr) external {
_addr.call(abi.encodeWithSignature("revertWithRevertReason()"));
}

function callRevertWithoutRevertReason(address _addr) external {
_addr.call(abi.encodeWithSignature("revertWithoutRevertReason()"));
}

function sendTo(address payable _addr) external {
_addr.send(1);
}

function transferTo(address payable _addr) external {
_addr.transfer(1);
}

function callWithValueTo(address _addr) external {
_addr.call{value : 1}("");
}

function selfdestruct(address payable _addr) external {
selfdestruct(_addr);
}

receive() external payable {}

fallback() external payable {}
}
2 changes: 2 additions & 0 deletions test/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ const Contract = {
ExampleGovernor: 'ExampleGovernor',
ExampleTokenVote: 'ExampleTokenVote',
Purchase: 'Purchase',
InternalCallee: 'InternalCallee',
InternalCaller: 'InternalCaller'
};

const CALL_EXCEPTION = 'CALL_EXCEPTION';
Expand Down
Loading

0 comments on commit ed677b7

Please sign in to comment.