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

fix: Tests & Certora ci #62

Merged
merged 8 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"optimistic_loop": true,
"packages": [
"openzeppelin-contracts=lib/openzeppelin-contracts",
"solidity-utils=lib/solidity-utils/src"
"solidity-utils/=lib/aave-helpers/lib/solidity-utils/src"
],
"process": "emv",
"prover_args": [
Expand All @@ -22,4 +22,4 @@
"solc": "solc8.19",
//"rule_sanity": "advanced",
"verify": "CrossChainControllerWithEmergencyModeHarness:security/certora/specs/CrossChainControllerWithEmergencyMode.spec"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
],
"link": [],
"packages": [
"@aave/core-v3/=lib/aave-address-book/lib/aave-v3-core",
"@aave/core-v3/=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-core",
"@openzeppelin/=lib/openzeppelin-contracts",
"aave-address-book/=lib/aave-address-book/src",
"aave-v3-core/=lib/aave-address-book/lib/aave-v3-core",
"forge-std/=lib/forge-std/src",
"aave-address-book/=lib/aave-helpers/lib/aave-address-book/src",
"aave-v3-core/=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-core",
"forge-std/=lib/aave-helpers/lib/forge-std/src",
"nitro-contracts/=lib/nitro-contracts/src",
"openzeppelin-contracts/=lib/openzeppelin-contracts",
"solidity-utils/=lib/solidity-utils/src"
"solidity-utils/=lib/aave-helpers/lib/solidity-utils/src"
],
"verify": "CrossChainForwarderHarness:security/certora/specs/CrossChainForwarder-envelopRetry.spec",
"solc": "solc8.19",
Expand Down
10 changes: 5 additions & 5 deletions security/certora/confs/verifyCrossChainForwarder-invariants.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
],
"link": [],
"packages": [
"@aave/core-v3/=lib/aave-address-book/lib/aave-v3-core",
"@aave/core-v3/=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-core",
"@openzeppelin/=lib/openzeppelin-contracts",
"aave-address-book/=lib/aave-address-book/src",
"aave-v3-core/=lib/aave-address-book/lib/aave-v3-core",
"forge-std/=lib/forge-std/src",
"aave-address-book/=lib/aave-helpers/lib/aave-address-book/src",
"aave-v3-core/=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-core",
"forge-std/=lib/aave-helpers/lib/forge-std/src",
"nitro-contracts/=lib/nitro-contracts/src",
"openzeppelin-contracts/=lib/openzeppelin-contracts",
"solidity-utils/=lib/solidity-utils/src"
"solidity-utils/=lib/aave-helpers/lib/solidity-utils/src"
],
"verify": "CrossChainForwarderHarness:security/certora/specs/invariants.spec",
"solc": "solc8.19",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
],
"link": [],
"packages": [
"@aave/core-v3/=lib/aave-address-book/lib/aave-v3-core",
"@aave/core-v3/=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-core",
"@openzeppelin/=lib/openzeppelin-contracts",
"aave-address-book/=lib/aave-address-book/src",
"aave-v3-core/=lib/aave-address-book/lib/aave-v3-core",
"forge-std/=lib/forge-std/src",
"aave-address-book/=lib/aave-helpers/lib/aave-address-book/src",
"aave-v3-core/=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-core",
"forge-std/=lib/aave-helpers/lib/forge-std/src",
"nitro-contracts/=lib/nitro-contracts/src",
"openzeppelin-contracts/=lib/openzeppelin-contracts",
"solidity-utils/=lib/solidity-utils/src"
"solidity-utils/=lib/aave-helpers/lib/solidity-utils/src"
],
"verify": "CrossChainForwarderHarness:security/certora/specs/CrossChainForwarder-newEnvelope.spec",
"solc": "solc8.19",
Expand Down
10 changes: 5 additions & 5 deletions security/certora/confs/verifyCrossChainForwarder-sanity.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
],
"link": [],
"packages": [
"@aave/core-v3/=lib/aave-address-book/lib/aave-v3-core",
"@aave/core-v3/=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-core",
"@openzeppelin/=lib/openzeppelin-contracts",
"aave-address-book/=lib/aave-address-book/src",
"aave-v3-core/=lib/aave-address-book/lib/aave-v3-core",
"forge-std/=lib/forge-std/src",
"aave-address-book/=lib/aave-helpers/lib/aave-address-book/src",
"aave-v3-core/=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-core",
"forge-std/=lib/aave-helpers/lib/forge-std/src",
"nitro-contracts/=lib/nitro-contracts/src",
"openzeppelin-contracts/=lib/openzeppelin-contracts",
"solidity-utils/=lib/solidity-utils/src"
"solidity-utils/=lib/aave-helpers/lib/solidity-utils/src"
],
"verify": "CrossChainForwarderHarness:security/certora/specs/CrossChainForwarder-sanity.spec",
"solc": "solc8.19",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
],
"link": [],
"packages": [
"@aave/core-v3/=lib/aave-address-book/lib/aave-v3-core",
"@aave/core-v3/=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-core",
"@openzeppelin/=lib/openzeppelin-contracts",
"aave-address-book/=lib/aave-address-book/src",
"aave-v3-core/=lib/aave-address-book/lib/aave-v3-core",
"forge-std/=lib/forge-std/src",
"aave-address-book/=lib/aave-helpers/lib/aave-address-book/src",
"aave-v3-core/=lib/aave-helpers/lib/aave-address-book/lib/aave-v3-core",
"forge-std/=lib/aave-helpers/lib/forge-std/src",
"nitro-contracts/=lib/nitro-contracts/src",
"openzeppelin-contracts/=lib/openzeppelin-contracts",
"solidity-utils/=lib/solidity-utils/src"
"solidity-utils/=lib/aave-helpers/lib/solidity-utils/src"
],
"verify": "CrossChainForwarderHarness:security/certora/specs/CrossChainForwarder-simpleRules.spec",
"solc": "solc8.19",
Expand Down
4 changes: 2 additions & 2 deletions security/certora/confs/verifyCrossChainReceiver.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"optimistic_loop": true,
"packages": [
"openzeppelin-contracts=lib/openzeppelin-contracts",
"solidity-utils=lib/solidity-utils/src"
"solidity-utils=lib/aave-helpers/lib/solidity-utils/src"
],
"process": "emv",
"prover_args": [
Expand All @@ -23,4 +23,4 @@
"solc": "solc8.19",
// "rule_sanity": "advanced",
"verify": "CrossChainReceiverHarness:security/certora/specs/CrossChainReceiver.spec"
}
}
25 changes: 21 additions & 4 deletions tests/BaseCCForwarder.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.0;
import '../src/contracts/CrossChainForwarder.sol';
import './BaseTest.sol';
import {FailingAdapter} from './mocks/FailingAdapter.sol';
import {SuccessAdapter} from './mocks/SuccessAdapter.sol';

contract BaseCCForwarderTest is BaseTest, CrossChainForwarder {
address internal constant CROSS_CHAIN_CONTROLLER = address(123029525691); // can be hardcoded as its not consequential to testing
Expand Down Expand Up @@ -65,6 +66,12 @@ contract BaseCCForwarderTest is BaseTest, CrossChainForwarder {
return address(new FailingAdapter(trustedRemotes));
}

function _deploySuccessAdapter() internal returns (address) {
SuccessAdapter.TrustedRemotesConfig[]
memory trustedRemotes = new SuccessAdapter.TrustedRemotesConfig[](0);
return address(new SuccessAdapter(trustedRemotes));
}

modifier enableBridgeAdaptersForPath(
uint256 destinationChainId,
uint256 numberOfAdapters,
Expand All @@ -79,7 +86,7 @@ contract BaseCCForwarderTest is BaseTest, CrossChainForwarder {
adaptersType == AdapterSuccessType.ALL_SUCCESS ||
(adaptersType == AdapterSuccessType.SOME_SUCCESS && i % 2 == 0)
) {
currentChainBridgeAdapter = address(uint160(uint(keccak256(abi.encodePacked(i)))));
currentChainBridgeAdapter = _deploySuccessAdapter();
_adapterSuccess[currentChainBridgeAdapter] = true;
} else {
currentChainBridgeAdapter = _deployFailingAdapter();
Expand All @@ -89,8 +96,10 @@ contract BaseCCForwarderTest is BaseTest, CrossChainForwarder {
uint160(uint(keccak256(abi.encodePacked(i + numberOfAdapters + 1))))
);

bytes
memory empty = hex'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
bytes memory returnData = _adapterSuccess[currentChainBridgeAdapter]
? bytes('')
? empty
: abi.encodeWithSignature('Error(string)', 'error message');

UsedAdapter memory usedBridgeAdapter = UsedAdapter({
Expand Down Expand Up @@ -174,11 +183,19 @@ contract BaseCCForwarderTest is BaseTest, CrossChainForwarder {

function _testForwardMessage(ExtendedTransaction memory extendedTx) internal {
_mockAdaptersForwardMessage(extendedTx.envelope.destinationChainId);
vm.expectEmit(true, true, true, true);
emit EnvelopeRegistered(extendedTx.envelopeId, extendedTx.envelope);
bool successEmitted;

UsedAdapter[] memory usedAdapters = _currentlyUsedAdaptersByChain[
extendedTx.envelope.destinationChainId
];

for (uint256 i = 0; i < usedAdapters.length; i++) {
if (usedAdapters[i].success == true && !successEmitted) {
vm.expectEmit(true, true, true, true);
emit EnvelopeRegistered(extendedTx.envelopeId, extendedTx.envelope);
successEmitted = true;
}
}
for (uint256 i = 0; i < usedAdapters.length; i++) {
vm.expectEmit(true, true, true, true);
emit TransactionForwardingAttempted(
Expand Down
57 changes: 1 addition & 56 deletions tests/CrossChainForwarder.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -430,17 +430,6 @@ contract CrossChainForwarderTest is BaseTest {
})
)
);
vm.expectCall(
address(lzAdapter),
0,
abi.encodeWithSelector(
LayerZeroAdapter.forwardMessage.selector,
DESTINATION_BRIDGE_ADAPTER,
0,
extendedTx.envelope.destinationChainId,
extendedTx.transactionEncoded
)
);
vm.expectEmit(true, true, false, true);
emit EnvelopeRegistered(extendedTx.envelopeId, extendedTx.envelope);
(bytes32 returnedEnvelopeId, bytes32 returnedTransactionId) = crossChainForwarder
Expand Down Expand Up @@ -472,17 +461,6 @@ contract CrossChainForwarderTest is BaseTest {
);

hoax(extendedTx.envelope.origin);
vm.expectCall(
address(lzAdapter),
0,
abi.encodeWithSelector(
LayerZeroAdapter.forwardMessage.selector,
DESTINATION_BRIDGE_ADAPTER,
0,
extendedTx.envelope.destinationChainId,
extendedTx.transactionEncoded
)
);
vm.expectEmit(true, true, false, true);
emit EnvelopeRegistered(extendedTx.envelopeId, extendedTx.envelope);
(bytes32 returnedEnvelopeId, bytes32 returnedTransactionId) = crossChainForwarder
Expand Down Expand Up @@ -561,17 +539,7 @@ contract CrossChainForwarderTest is BaseTest {
})
)
);
vm.expectCall(
address(lzAdapter),
0,
abi.encodeWithSelector(
LayerZeroAdapter.forwardMessage.selector,
DESTINATION_BRIDGE_ADAPTER,
0,
extendedTx.envelope.destinationChainId,
extendedTx.transactionEncoded
)
);

vm.expectEmit(true, true, false, true);
emit EnvelopeRegistered(extendedTx.envelopeId, extendedTx.envelope);
(bytes32 returnedEnvelopeId, bytes32 returnedTransactionId) = crossChainForwarder
Expand Down Expand Up @@ -600,17 +568,6 @@ contract CrossChainForwarderTest is BaseTest {
);

hoax(GUARDIAN);
vm.expectCall(
address(lzAdapter),
0,
abi.encodeWithSelector(
LayerZeroAdapter.forwardMessage.selector,
DESTINATION_BRIDGE_ADAPTER,
0,
extendedTx.envelope.destinationChainId,
extendedTxOnRetry.transactionEncoded
)
);
crossChainForwarder.retryEnvelope(extendedTx.envelope, 0);

assertTrue(crossChainForwarder.isTransactionForwarded(extendedTxOnRetry.transaction));
Expand Down Expand Up @@ -670,18 +627,6 @@ contract CrossChainForwarderTest is BaseTest {
).encode();

hoax(GUARDIAN);
vm.expectCall(
address(lzAdapter),
0,
abi.encodeWithSelector(
LayerZeroAdapter.forwardMessage.selector,
DESTINATION_BRIDGE_ADAPTER,
0,
extendedTx.envelope.destinationChainId,
transactionOnRetry.data
)
);

crossChainForwarder.retryEnvelope(extendedTx.envelope, 0);

assertTrue(crossChainForwarder.isEnvelopeRegistered(extendedTx.envelope));
Expand Down
53 changes: 26 additions & 27 deletions tests/Forwarder.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ contract ForwarderTest is BaseCCForwarderTest {
_validateRetryTransactionWhenAdaptersNotUnique(extendedTx);
}

// ----------- validations -----------------------
// ----------- validations ----------------------
function _validateRetryTransactionWhenAllAdaptersFail(
ExtendedTransaction memory extendedTx
) internal {
Expand Down Expand Up @@ -348,52 +348,51 @@ contract ForwarderTest is BaseCCForwarderTest {
j++
) {
if (
_currentlyUsedAdaptersByChain[extendedTx.envelope.destinationChainId][j].success == false
_currentlyUsedAdaptersByChain[extendedTx.envelope.destinationChainId][j].success == true
) {
failedAdaptersCounter++;
}
}

address[] memory bridgeAdaptersToRetry = new address[](failedAdaptersCounter);
ICrossChainForwarder.ChainIdBridgeConfig[]
memory bridgeAdaptersToRetryConfig = new ICrossChainForwarder.ChainIdBridgeConfig[](
failedAdaptersCounter
);

uint256 index = 0;
for (
uint256 k = 0;
k < _currentlyUsedAdaptersByChain[extendedTx.envelope.destinationChainId].length;
k++
) {
if (
_currentlyUsedAdaptersByChain[extendedTx.envelope.destinationChainId][k].success == false
_currentlyUsedAdaptersByChain[extendedTx.envelope.destinationChainId][k].success == true
) {
bridgeAdaptersToRetry[index++] = _currentlyUsedAdaptersByChain[
bridgeAdaptersToRetry[index] = _currentlyUsedAdaptersByChain[
extendedTx.envelope.destinationChainId
][k].bridgeAdapterConfig.currentChainBridgeAdapter;
_adapterSuccess[
_currentlyUsedAdaptersByChain[extendedTx.envelope.destinationChainId][k]
.bridgeAdapterConfig
.currentChainBridgeAdapter
] = true;
bridgeAdaptersToRetryConfig[index] = _currentlyUsedAdaptersByChain[
extendedTx.envelope.destinationChainId
][k].bridgeAdapterConfig;
index++;
}
}

_mockAdaptersForwardMessage(extendedTx.envelope.destinationChainId);

UsedAdapter[] memory usedAdapters = _currentlyUsedAdaptersByChain[
extendedTx.envelope.destinationChainId
];
for (uint256 i = 0; i < usedAdapters.length; i++) {
if (usedAdapters[i].success == false) {
vm.expectEmit(true, true, true, true);
emit TransactionForwardingAttempted(
extendedTx.transactionId,
extendedTx.envelopeId,
extendedTx.transactionEncoded,
extendedTx.envelope.destinationChainId,
usedAdapters[i].bridgeAdapterConfig.currentChainBridgeAdapter,
usedAdapters[i].bridgeAdapterConfig.destinationBridgeAdapter,
true,
bytes('')
);
}
for (uint256 i = 0; i < bridgeAdaptersToRetryConfig.length; i++) {
vm.expectEmit(true, true, true, true);
emit TransactionForwardingAttempted(
extendedTx.transactionId,
extendedTx.envelopeId,
extendedTx.transactionEncoded,
extendedTx.envelope.destinationChainId,
bridgeAdaptersToRetryConfig[i].currentChainBridgeAdapter,
bridgeAdaptersToRetryConfig[i].destinationBridgeAdapter,
true,
hex'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
);
}
this.retryTransaction(extendedTx.transactionEncoded, GAS_LIMIT, bridgeAdaptersToRetry);
}
Expand All @@ -419,7 +418,7 @@ contract ForwarderTest is BaseCCForwarderTest {
usedAdapters[i].bridgeAdapterConfig.currentChainBridgeAdapter,
usedAdapters[i].bridgeAdapterConfig.destinationBridgeAdapter,
usedAdapters[i].success,
usedAdapters[i].returnData
hex'00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'
);
}
bytes32 transactionId = this.retryEnvelope(extendedTx.envelope, GAS_LIMIT);
Expand Down
Loading
Loading