Skip to content

Commit 57bde16

Browse files
committed
add fuzz and mocks, fix security findings
1 parent 6227e1a commit 57bde16

7 files changed

Lines changed: 866 additions & 7 deletions

File tree

foundry.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@ remappings = [
88
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/"
99
]
1010

11+
# Use: forge coverage --no-match-coverage "test/mocks/" to exclude mocks
12+
1113
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

report.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Aderyn Analysis Report
2+
3+
This report was generated by [Aderyn](https://github.com/Cyfrin/aderyn), a static analysis tool built by [Cyfrin](https://cyfrin.io), a blockchain security company. This report is not a substitute for manual audit or security review. It should not be relied upon for any purpose other than to assist in the identification of potential security vulnerabilities.
4+
# Table of Contents
5+
6+
- [Summary](#summary)
7+
- [Files Summary](#files-summary)
8+
- [Files Details](#files-details)
9+
- [Issue Summary](#issue-summary)
10+
- [Low Issues](#low-issues)
11+
- [L-1: Centralization Risk for trusted owners](#l-1-centralization-risk-for-trusted-owners)
12+
13+
14+
# Summary
15+
16+
## Files Summary
17+
18+
| Key | Value |
19+
| --- | --- |
20+
| .sol Files | 1 |
21+
| Total nSLOC | 84 |
22+
23+
24+
## Files Details
25+
26+
| Filepath | nSLOC |
27+
| --- | --- |
28+
| src/LimitOrderBook.sol | 84 |
29+
| **Total** | **84** |
30+
31+
32+
## Issue Summary
33+
34+
| Category | No. of Issues |
35+
| --- | --- |
36+
| High | 0 |
37+
| Low | 1 |
38+
39+
40+
# Low Issues
41+
42+
## L-1: Centralization Risk for trusted owners
43+
44+
Contracts have owners with privileged rights to perform admin tasks and need to be trusted to not perform malicious updates or drain funds.
45+
46+
<details><summary>4 Found Instances</summary>
47+
48+
49+
- Found in src/LimitOrderBook.sol [Line: 14](src/LimitOrderBook.sol#L14)
50+
51+
```solidity
52+
contract LimitOrderBook is Ownable, ReentrancyGuard {
53+
```
54+
55+
- Found in src/LimitOrderBook.sol [Line: 155](src/LimitOrderBook.sol#L155)
56+
57+
```solidity
58+
function authorizeExecutor(address executor) external onlyOwner {
59+
```
60+
61+
- Found in src/LimitOrderBook.sol [Line: 164](src/LimitOrderBook.sol#L164)
62+
63+
```solidity
64+
function revokeExecutor(address executor) external onlyOwner {
65+
```
66+
67+
- Found in src/LimitOrderBook.sol [Line: 173](src/LimitOrderBook.sol#L173)
68+
69+
```solidity
70+
function setExecutorAuthRequired(bool requireAuth) external onlyOwner {
71+
```
72+
73+
</details>
74+
75+
76+

src/LimitOrderBook.sol

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT
2-
pragma solidity ^0.8.25;
2+
pragma solidity 0.8.25;
33

44
import "@openzeppelin/contracts/access/Ownable.sol";
55
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
@@ -21,7 +21,6 @@ contract LimitOrderBook is Ownable, ReentrancyGuard {
2121
error LimitOrderBook_OrderNotFound();
2222
error LimitOrderBook_NotOrderOwner();
2323
error LimitOrderBook_OrderAlreadyExecuted();
24-
error LimitOrderBook_OrderNotExecutable();
2524
error LimitOrderBook_UnauthorizedExecutor();
2625

2726
/*//////////////////////////////////////////////////////////////
@@ -49,11 +48,12 @@ contract LimitOrderBook is Ownable, ReentrancyGuard {
4948
EVENTS
5049
//////////////////////////////////////////////////////////////*/
5150

52-
event OrderPlaced(uint256 indexed orderId, address indexed user, uint256 price, uint256 amount);
51+
event OrderPlaced(uint256 indexed orderId, address indexed user, uint256 indexed price, uint256 amount);
5352
event OrderExecuted(uint256 indexed orderId);
5453
event OrderCancelled(uint256 indexed orderId);
5554
event ExecutorAuthorized(address indexed executor);
5655
event ExecutorRevoked(address indexed executor);
56+
event ExecutorAuthRequirementChanged(bool indexed requireAuth);
5757

5858
/*//////////////////////////////////////////////////////////////
5959
MODIFIERS
@@ -74,6 +74,8 @@ contract LimitOrderBook is Ownable, ReentrancyGuard {
7474
//////////////////////////////////////////////////////////////*/
7575

7676
constructor(address initialOwner) Ownable(initialOwner) {
77+
// Explicitly initialize state variables
78+
s_nextOrderId = 0;
7779
// Initially, allow anyone to execute (can be changed later)
7880
// This supports the permissionless bot execution model
7981
s_authorizedExecutors[address(0)] = true; // Flag to indicate permissionless execution
@@ -171,6 +173,7 @@ contract LimitOrderBook is Ownable, ReentrancyGuard {
171173
function setExecutorAuthRequired(bool requireAuth) external onlyOwner {
172174
// Use address(0) as a flag for whether auth is required
173175
s_authorizedExecutors[address(0)] = !requireAuth;
176+
emit ExecutorAuthRequirementChanged(requireAuth);
174177
}
175178

176179
/*//////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)