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

Implement InvoiceModule.sol integration tests #3

Closed
wants to merge 41 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
199a144
feat(invoice-module): check for non-zero 'Container' code size and up…
gabrielstoica Jul 8, 2024
5fcf4de
test(invoice-module): add basic integration tests structure
gabrielstoica Jul 8, 2024
7d8d28b
feat(invoice-module): check for non-zero 'Container' code size and up…
gabrielstoica Jul 8, 2024
fd38bd8
test: update 'MockModule.sol' to match the new checks
gabrielstoica Jul 8, 2024
98b0618
forge install: v2-core
gabrielstoica Jul 8, 2024
08b70e6
build: install @sablier/v2-core and @prb/math
gabrielstoica Jul 8, 2024
5c422a1
fix(container): return only 'IContainer' interfaceId for ERC-165
gabrielstoica Jul 9, 2024
95c6f55
feat(invoice-module): add Sablier V2 Lockup Linear stream management
gabrielstoica Jul 9, 2024
80589cd
chore(invoice-module): add missing 'OnlyBrokerAdmin' error
gabrielstoica Jul 9, 2024
d4a2e5d
feat: update invoice module types and errors
gabrielstoica Jul 10, 2024
ec845e7
feat(invoice-module): integrate Sablier v2 'LockupStreamCreator' and …
gabrielstoica Jul 10, 2024
d87ce84
test: fix base 'setUp' method to account Sablier v2 streams and small…
gabrielstoica Jul 10, 2024
9187956
chore(invoice-module): use proper types for Sablier v2 integration
gabrielstoica Jul 10, 2024
b5f247a
ci: update 'test.yml' workflow
gabrielstoica Jul 10, 2024
f3b9381
feat(invoice-module): integrate Sablier v2 Tranched streams
gabrielstoica Jul 11, 2024
29724e0
feat(invoice-module): handle stream creationg based on its type
gabrielstoica Jul 11, 2024
d8adafd
refactor(invoice-module): replace 'Frequency' check with the 'payment…
gabrielstoica Jul 11, 2024
f3a6de8
test: fix create invoice helper
gabrielstoica Jul 11, 2024
c44dfa2
feat(invoice-module): update checks, emitted event types and 'Payment…
gabrielstoica Jul 11, 2024
d428de4
test: fix create invoice helper
gabrielstoica Jul 11, 2024
6a7e212
feat(invoice-module): add 'StreamManager' contract to handle stream m…
gabrielstoica Jul 11, 2024
aed6eec
feat: add handlers to cancel, renounce and transfer ownership of a st…
gabrielstoica Jul 11, 2024
43aa8aa
feat(invoice-module): manage Sablier v2 streams through the 'StreamCr…
gabrielstoica Jul 12, 2024
224969f
test: update 'Base.t.sol' to support the new structure of the invoice…
gabrielstoica Jul 12, 2024
14292cb
Merge branch 'invoice-module/stream' of github.com:metadock/contracts…
gabrielstoica Jul 12, 2024
121951c
refactor: merge 'StreamManager' and 'StreamCreator' contracts
gabrielstoica Jul 12, 2024
ec0b928
chore(invoice-module): rename Sablier Lockup contracts
gabrielstoica Jul 12, 2024
42b7090
build: install @nomad-xyz/excessively-safe-call lib
gabrielstoica Jul 15, 2024
b2571b7
refactor: use 'ExcessivelySafeCall' for module call
gabrielstoica Jul 15, 2024
31fe0df
docs: add documentation for invoice module errors
gabrielstoica Jul 15, 2024
7980463
feat(invoice-module): create tranched stream with timestamps, improve…
gabrielstoica Jul 15, 2024
da2270b
test: move integration-related contracts to dedicated container
gabrielstoica Jul 15, 2024
9c274b6
test: fix outdated error in 'execute' unit test and add missing helpe…
gabrielstoica Jul 15, 2024
4633d8d
test: add 'MockNonCompliantContainer' mock contract
gabrielstoica Jul 15, 2024
eb16f28
fix(container): revert with the same error returned by the module con…
gabrielstoica Jul 16, 2024
1860435
test: fix 'execute' test
gabrielstoica Jul 16, 2024
ef946c4
fix(invoice-module): invoice recipient and error renaming
gabrielstoica Jul 16, 2024
78664be
test: switch inheritance on the 'InvoiceModule.t.sol'
gabrielstoica Jul 16, 2024
d0fd422
refactor(invoice-module): calculate 'paymentsLeft' on-chain, add new …
gabrielstoica Jul 16, 2024
aed9882
test: add generic 'InvoiceModule' modifiers and update errors
gabrielstoica Jul 16, 2024
1341a02
test(invoice-module): add 'createInvoice' integration tests
gabrielstoica Jul 16, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Run Forge build
run: |
forge --version
forge build --sizes
forge build
id: build

- name: Run Forge tests
Expand Down
9 changes: 9 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@
[submodule "lib/openzeppelin-contracts"]
path = lib/openzeppelin-contracts
url = https://github.com/OpenZeppelin/openzeppelin-contracts
[submodule "lib/v2-core"]
path = lib/v2-core
url = https://github.com/sablier-labs/v2-core
[submodule "lib/prb-math"]
path = lib/prb-math
url = https://github.com/PaulRBerg/prb-math
[submodule "lib/nomad-xyz/excessively-safe-call"]
path = lib/nomad-xyz/excessively-safe-call
url = https://github.com/nomad-xyz/ExcessivelySafeCall
26 changes: 26 additions & 0 deletions lib/nomad-xyz/excessively-safe-call/.github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
on: [push]

name: test

jobs:
check:
name: Foundry project
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Run tests @ 0.8.13
run: forge test -vvv --use 0.8.13

- name: Run tests @ 0.7.6
run: forge test -vvv --use 0.7.6

- name: Run snapshot
run: forge snapshot
2 changes: 2 additions & 0 deletions lib/nomad-xyz/excessively-safe-call/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cache/
out/
3 changes: 3 additions & 0 deletions lib/nomad-xyz/excessively-safe-call/.gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lib/ds-test"]
path = lib/ds-test
url = https://github.com/dapphub/ds-test
7 changes: 7 additions & 0 deletions lib/nomad-xyz/excessively-safe-call/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

### Unreleased

### 0.0.1-rc.1

- first release
110 changes: 110 additions & 0 deletions lib/nomad-xyz/excessively-safe-call/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# ExcessivelySafeCall

This solidity library helps you call untrusted contracts safely. Specifically,
it seeks to prevent _all possible_ ways that the callee can maliciously cause
the caller to revert. Most of these revert cases are covered by the use of a
[low-level call](https://solidity-by-example.org/call/). The main difference
with between `address.call()`call and `address.excessivelySafeCall()` is that
a regular solidity call will **automatically** copy bytes to memory without
consideration of gas.

This is to say, a low-level solidity call will copy _any amount of bytes_ to
local memory. When bytes are copied from returndata to memory, the
[memory expansion cost
](https://ethereum.stackexchange.com/questions/92546/what-is-expansion-cost) is
paid. This means that when using a standard solidity call, the callee can
**"returnbomb"** the caller, imposing an arbitrary gas cost. Because this gas is
paid _by the caller_ and _in the caller's context_, it can cause the caller to
run out of gas and halt execution.

To prevent returnbombing, we provide `excessivelySafeCall` and
`excessivelySafeStaticCall`. These behave similarly to solidity's low-level
calls, however, they allow the user to specify a maximum number of bytes to be
copied to local memory. E.g. a user desiring a single return value should
specify a `_maxCopy` of 32 bytes. Refusing to copy large blobs to local memory
effectively prevents the callee from triggering local OOG reversion. We _also_ recommend careful consideration of the gas amount passed to untrusted
callees.

Consider the following contracts:

```solidity
contract BadGuy {
function youveActivateMyTrapCard() external pure returns (bytes memory) {
assembly{
revert(0, 1_000_000)
}
}
}

contract Mark {
function oops(address badGuy) {
bool success;
bytes memory ret;

// Mark pays a lot of gas for this copy 😬😬😬
(success, ret) == badGuy.call(
SOME_GAS,
abi.encodeWithSelector(
BadGuy.youveActivateMyTrapCard.selector
)
);

// Mark may OOG here, preventing local state changes
importantCleanup();
}
}

contract ExcessivelySafeSam {
using ExcessivelySafeCall for address;

// Sam is cool and doesn't get returnbombed
function sunglassesEmoji(address badGuy) {
bool success;
bytes memory ret;

(success, ret) == badGuy.excessivelySafeCall(
SOME_GAS,
32, // <-- the magic. Copy no more than 32 bytes to memory
abi.encodeWithSelector(
BadGuy.youveActivateMyTrapCard.selector
)
);

// Sam can afford to clean up after himself.
importantCleanup();
}
}
```

## When would I use this

`ExcessivelySafeCall` prevents malicious callees from affecting post-execution
cleanup (e.g. state-based replay protection). Given that a dev is unlikely to
hard-code a call to a malicious contract, we expect most danger to come from
dynamic dispatch protocols, where neither the callee nor the code being called
is known to the developer ahead of time.

Dynamic dispatch in solidity is probably _most_ useful for metatransaction
protocols. This includes gas-abstraction relayers, smart contract wallets,
bridges, etc.

Nomad uses excessively safe calls for safe processing of cross-domain messages.
This guarantees that a message recipient cannot interfere with safe operation
of the cross-domain communication channel and message processing layer.

## Interacting with the repo

**To install in your project**:

- install [Foundry](https://github.com/gakonst/foundry)
- `forge install nomad-xyz/ExcessivelySafeCall`

**To run tests**:

- install [Foundry](https://github.com/gakonst/foundry)
- `forge test`

## A note on licensing:

Tests are licensed GPLv3, as they extend the `DSTest` contract. Non-test work
is avialable under user's choice of MIT and Apache2.0.
5 changes: 5 additions & 0 deletions lib/nomad-xyz/excessively-safe-call/foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[profile.default]
src = 'src'
out = 'out'
libs = ['lib']
remappings = ['ds-test/=lib/ds-test/src/']
3 changes: 3 additions & 0 deletions lib/nomad-xyz/excessively-safe-call/lib/ds-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.dapple
/build
/out
Loading