Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8056c87
refactor: update withheld amount maintenance
kupermind Jun 23, 2025
80c47a4
chore: correcting number of optimizations in forge
kupermind Jun 23, 2025
b7ccf4d
test: adding test
kupermind Jun 23, 2025
4d543af
chore: linters
kupermind Jun 23, 2025
d5dfddc
doc: internal audit 7
Jun 23, 2025
da3d8e9
refactor: addressing internal audit
kupermind Jun 23, 2025
2c4d96d
test: correcting test
kupermind Jun 23, 2025
fd4aea0
doc: adding up-to-date diagram
kupermind Jun 23, 2025
cd5a0a9
doc: adding up-to-date diagram
kupermind Jun 23, 2025
e38d964
doc: adding up-to-date diagram
kupermind Jun 23, 2025
1555832
refactor: account for withheld amount update flag
kupermind Jun 23, 2025
f36648a
refactor: total amount correction
kupermind Jun 23, 2025
a71476d
chore: comment
kupermind Jun 23, 2025
87bac92
tes: test correction
kupermind Jun 23, 2025
c1ba5f6
tes: test correction
kupermind Jun 23, 2025
96621e5
Merge pull request #217 from valory-xyz/refactor_target_dispenser
kupermind Jun 23, 2025
ceb931c
doc: updating flowchart
kupermind Jun 23, 2025
6cbc6d2
Update README.md
mariapiamo Jun 23, 2025
d4de5d2
chore: syncing on mainnet name in globals
kupermind Jun 24, 2025
998b668
Merge pull request #215 from valory-xyz/v1.3.3-internal-audit
kupermind Jun 24, 2025
e885e71
Merge pull request #214 from valory-xyz/update_withheld_amount_tests
kupermind Jun 24, 2025
adc82db
doc: re-audit 1.3.3
Jun 25, 2025
368b741
Merge pull request #218 from valory-xyz/v1.3.3-internal-audit
kupermind Jun 25, 2025
dec034b
chore: Addressing internal audit 2
kupermind Jun 25, 2025
513a2fc
refactor: no revert
kupermind Jun 25, 2025
1e272d6
Merge pull request #219 from valory-xyz/address_internal_audit2
kupermind Jun 25, 2025
82b4e18
Merge pull request #216 from valory-xyz/address_internal_audit
kupermind Jun 25, 2025
cb47f9d
chore: static audit update
kupermind Jun 25, 2025
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 .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
out
node_modules
.env
coverage
Expand Down
1 change: 1 addition & 0 deletions audits/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ An internal audit with a focus on PoAA Staking fixing after C4A is located in th

An internal audit with a focus on tokenimics inflation update is located in this folder: [internal audit 6](https://github.com/valory-xyz/autonolas-tokenomics/blob/main/audits/internal6).

An internal audit with a focus on WithheldAmount fixing in PoAA Staking is located in this folder: [internal audit 7](https://github.com/valory-xyz/autonolas-tokenomics/blob/main/audits/internal7).

### External audit
Final audit reports are listed in their historical order:
Expand Down
20 changes: 20 additions & 0 deletions audits/internal7/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Internal audit of autonolas-tokenomics
The review has been performed based on the contract code in the following repository:<br>
`https://github.com/valory-xyz/autonolas-tokenomics` <br>
commit: `4d543af4efefea0380a1c5b1d79f5e574b4c26f0` or `tag: v1.3.3-pre-internal-audit`<br>

## Objectives
The audit focused on WithheldAmount fix in TargetDispenserL2 contract

## Issue
### Medium. Logical issue
```
This is not a bug in the current code.
However, the essence of the fix is ​​in conflict with this:
function syncWithheldAmount(bytes memory bridgePayload) external payable {}
In the current code, anyone can execute it.
It zeroid withheldAmount = amount - normalizedAmount;
They need to be given equal rights (OwnerOnly).
To discussion!
```
[]
19 changes: 19 additions & 0 deletions contracts/staking/DefaultTargetDispenserL2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ abstract contract DefaultTargetDispenserL2 is IBridgeErrors {
event AmountWithheld(address indexed target, uint256 amount);
event StakingRequestQueued(bytes32 indexed queueHash, address indexed target, uint256 amount,
bytes32 indexed batchHash, uint256 olasBalance, uint256 paused);
event StakingMaintenanceDataProcessed(bytes data);
event MessagePosted(uint256 indexed sequence, address indexed messageSender, uint256 amount,
bytes32 indexed batchHash);
event MessageReceived(address indexed sender, uint256 chainId, bytes data);
event WithheldAmountUpdated(uint256 amount);
event Drain(address indexed owner, uint256 amount);
event TargetDispenserPaused();
event TargetDispenserUnpaused();
Expand Down Expand Up @@ -335,6 +337,8 @@ abstract contract DefaultTargetDispenserL2 is IBridgeErrors {

// Process the data
_processData(data);

emit StakingMaintenanceDataProcessed(data);
}

/// @dev Syncs withheld token amount with L1.
Expand Down Expand Up @@ -397,6 +401,21 @@ abstract contract DefaultTargetDispenserL2 is IBridgeErrors {
_locked = 1;
}

/// @dev Updates withheld amount manually by the DAO in order to account for `processDataMaintenance()` amounts.
/// @notice The amount here must correspond to the exact withheldAmount minus the accumulation of all the previous
/// unique amounts deposited via `processDataMaintenance()` function execution.
/// @param amount Updated withheld amount.
function updateWithheldAmountMaintenance(uint256 amount) external {
// Check the contract ownership
if (msg.sender != owner) {
revert OwnerOnly(msg.sender, owner);
}

withheldAmount = amount;

emit WithheldAmountUpdated(amount);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introducing function described in the WD.


/// @dev Pause the contract.
function pause() external {
// Check for the contract ownership
Expand Down
17 changes: 17 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[profile.default]
#solc = "0.8.30"
auto_detect_solc = true
src = "contracts"
out = "out"
libs = ["lib"]
optimizer = true
optimizer_runs = 100
evm_version = "prague"

remappings = [
"canonical-weth=node_modules/canonical-weth",
"@gnosis.pm=node_modules/@gnosis.pm",
"@prb=node_modules/@prb",
"@uniswap=node_modules/@uniswap",
"wormhole-solidity-sdk=node_modules/wormhole-solidity-sdk",
]
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"eslint": "^8.57.0",
"solhint": "^5.0.3",
"ethers": "^5.7.2",
"hardhat": "^2.24.0",
"hardhat": "^2.24.3",
"hardhat-contract-sizer": "^2.10.0",
"hardhat-deploy": "^0.11.43",
"hardhat-deploy-ethers": "^0.3.0-beta.13",
Expand Down
30 changes: 30 additions & 0 deletions test/StakingBridging.js
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,36 @@ describe("StakingBridging", async () => {
arbitrumTargetDispenserL2.unpause()
).to.be.revertedWithCustomError(arbitrumTargetDispenserL2, "OwnerOnly");
});

it("Migrate functionality on L2 with the withheld amount recovery", async function () {
// Pause the deposit processor
await arbitrumTargetDispenserL2.pause();

// Deposit some OLAS to the contract
await olas.mint(arbitrumTargetDispenserL2.address, defaultAmount);

// Update withheldAmount by the DAO
await arbitrumTargetDispenserL2.updateWithheldAmountMaintenance(defaultAmount);

// Deploy another contract
const ArbitrumTargetDispenserL2 = await ethers.getContractFactory("ArbitrumTargetDispenserL2");
const bridgedRelayerDeAliased = await bridgeRelayer.l1ToL2AliasedSender();
const newArbitrumTargetDispenserL2 = await ArbitrumTargetDispenserL2.deploy(olas.address,
stakingProxyFactory.address, bridgeRelayer.address, bridgedRelayerDeAliased, chainId);
await newArbitrumTargetDispenserL2.deployed();

// Initial withheld amount is zero
expect(await olas.balanceOf(newArbitrumTargetDispenserL2.address)).to.equal(0);

// Migrate the contract to a new one
await arbitrumTargetDispenserL2.migrate(newArbitrumTargetDispenserL2.address);

// Update withheldAmount by the DAO
const withheldAmount = await olas.balanceOf(newArbitrumTargetDispenserL2.address);
await newArbitrumTargetDispenserL2.updateWithheldAmountMaintenance(withheldAmount);

expect(await olas.balanceOf(newArbitrumTargetDispenserL2.address)).to.equal(withheldAmount);
});
});

context("Gnosis", async function () {
Expand Down
104 changes: 52 additions & 52 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -730,53 +730,53 @@
"@nodelib/fs.scandir" "2.1.5"
fastq "^1.6.0"

"@nomicfoundation/edr-darwin-arm64@0.11.0":
version "0.11.0"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-darwin-arm64/-/edr-darwin-arm64-0.11.0.tgz#fa791451c5ce2acf6634143bca9fe8f1b5c66603"
integrity sha512-aYTVdcSs27XG7ayTzvZ4Yn9z/ABSaUwicrtrYK2NR8IH0ik4N4bWzo/qH8rax6rewVLbHUkGyGYnsy5ZN4iiMw==

"@nomicfoundation/edr-darwin-x64@0.11.0":
version "0.11.0"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-darwin-x64/-/edr-darwin-x64-0.11.0.tgz#b1aaf0bfb331f6d136a92cbe31f184e2209e7a4f"
integrity sha512-RxX7UYgvJrfcyT/uHUn44Nsy1XaoW+Q1khKMdHKxeW7BrgIi+Lz+siz3bX5vhSoAnKilDPhIVLrnC8zxQhjR2A==

"@nomicfoundation/edr-linux-arm64-gnu@0.11.0":
version "0.11.0"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-arm64-gnu/-/edr-linux-arm64-gnu-0.11.0.tgz#fef6763c5d42bb68b4fc95df45c4745a0e31df93"
integrity sha512-J0j+rs0s11FuSipt/ymqrFmpJ7c0FSz1/+FohCIlUXDxFv//+1R/8lkGPjEYFmy8DPpk/iO8mcpqHTGckREbqA==

"@nomicfoundation/edr-linux-arm64-musl@0.11.0":
version "0.11.0"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-arm64-musl/-/edr-linux-arm64-musl-0.11.0.tgz#ef89d5d2aefc1f8d4f7c699c59b8897a645d33eb"
integrity sha512-4r32zkGMN7WT/CMEuW0VjbuEdIeCskHNDMW4SSgQSJOE/N9L1KSLJCSsAbPD3aYE+e4WRDTyOwmuLjeUTcLZKQ==

"@nomicfoundation/edr-linux-x64-gnu@0.11.0":
version "0.11.0"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-x64-gnu/-/edr-linux-x64-gnu-0.11.0.tgz#97432126110aa805b761d4743ab158698cae6d66"
integrity sha512-SmdncQHLYtVNWLIMyGaY6LpAfamzTDe3fxjkirmJv3CWR5tcEyC6LMui/GsIVnJzXeNJBXAzwl8hTUAxHTM6kQ==

"@nomicfoundation/edr-linux-x64-musl@0.11.0":
version "0.11.0"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-x64-musl/-/edr-linux-x64-musl-0.11.0.tgz#7605fddbada22dfdd14b15f4ac562014d9c82332"
integrity sha512-w6hUqpn/trwiH6SRuRGysj37LsQVCX5XDCA3Xi81sbOaLhbHrNvK9TXWyZmcuzbdTKQQW6VNywcSxDdOiChcJg==

"@nomicfoundation/edr-win32-x64-msvc@0.11.0":
version "0.11.0"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-win32-x64-msvc/-/edr-win32-x64-msvc-0.11.0.tgz#6766175f3ec47bfbda0429ca00fed4ae5632a3c4"
integrity sha512-BLmULjRKoH9BsX+c4Na2ypV7NGeJ+M6Zpqj/faPOwleVscDdSr/IhriyPaXCe8dyfwbge7lWsbekiADtPSnB2Q==

"@nomicfoundation/edr@^0.11.0":
version "0.11.0"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr/-/edr-0.11.0.tgz#d8b0ba4dfd7d93b9c54762e72eb9cd4e8244ce46"
integrity sha512-36WERf8ldvyHR6UAbcYsa+vpbW7tCrJGBwF4gXSsb8+STj1n66Hz85Y/O7B9+8AauX3PhglvV5dKl91tk43mWw==
dependencies:
"@nomicfoundation/edr-darwin-arm64" "0.11.0"
"@nomicfoundation/edr-darwin-x64" "0.11.0"
"@nomicfoundation/edr-linux-arm64-gnu" "0.11.0"
"@nomicfoundation/edr-linux-arm64-musl" "0.11.0"
"@nomicfoundation/edr-linux-x64-gnu" "0.11.0"
"@nomicfoundation/edr-linux-x64-musl" "0.11.0"
"@nomicfoundation/edr-win32-x64-msvc" "0.11.0"
"@nomicfoundation/edr-darwin-arm64@0.11.1":
version "0.11.1"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-darwin-arm64/-/edr-darwin-arm64-0.11.1.tgz#70b9187fbd046e8c0911f1e5a97b7ad13701a686"
integrity sha512-vjca7gkl1o0yYqMjwxQpMEtdsb20nWHBnnxDO8ZBCTD5IwfYT5LiMxFaJo8NUJ7ODIRkF/zuEtAF3W7+ZlC5RA==

"@nomicfoundation/edr-darwin-x64@0.11.1":
version "0.11.1"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-darwin-x64/-/edr-darwin-x64-0.11.1.tgz#e59298fa126057eab6f34cdf9c8bcc4839b81873"
integrity sha512-0aGStHq9XePXX9UqdU1w60HGO9AfYCgkNEir5sBpntU5E0TvZEK6jwyYr667+s90n2mihdeP97QSA0O/6PT6PA==

"@nomicfoundation/edr-linux-arm64-gnu@0.11.1":
version "0.11.1"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-arm64-gnu/-/edr-linux-arm64-gnu-0.11.1.tgz#bd2a7c835a2cbc25fe149f5d4e0f3c6832dfdf7b"
integrity sha512-OWhCETc03PVdtzatW/c2tpOPx+GxlBfBaLmMuGRD1soAr1nMOmg2WZAlo4i6Up9fkQYl+paiYMMFVat1meaMvQ==

"@nomicfoundation/edr-linux-arm64-musl@0.11.1":
version "0.11.1"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-arm64-musl/-/edr-linux-arm64-musl-0.11.1.tgz#e3ecc8ea5862e594e43bdea1cc54c5e68c272567"
integrity sha512-p0qvtIvDA2eZ8pQ5XUKnWdW1IrwFzSrjyrO88oYx6Lkw8nYwf2JEeETo5o5W84DDfimfoBGP7RWPTPcTBKCaLQ==

"@nomicfoundation/edr-linux-x64-gnu@0.11.1":
version "0.11.1"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-x64-gnu/-/edr-linux-x64-gnu-0.11.1.tgz#e900dc3ae97368ee5dd1a7918a3098b56399b450"
integrity sha512-V4Us7Q0E8kng3O/czd5GRcxmZxWX+USgqz9yQ3o7DVq7FP96idaKvtcbMQp64tjHf2zNtX2y77sGzgbVau7Bww==

"@nomicfoundation/edr-linux-x64-musl@0.11.1":
version "0.11.1"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-linux-x64-musl/-/edr-linux-x64-musl-0.11.1.tgz#52374d0d4389b7edad871b6a35ac301c963e4a8d"
integrity sha512-lCSXsF10Kjjvs5duGbM6pi1WciWHXFNWkMgDAY4pg6ZRIy4gh+uGC6CONMfP4BDZwfrALo2p6+LwyotrJEqpyg==

"@nomicfoundation/edr-win32-x64-msvc@0.11.1":
version "0.11.1"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr-win32-x64-msvc/-/edr-win32-x64-msvc-0.11.1.tgz#7d3b7d541d902ea5385a1bb4385522625007863b"
integrity sha512-sNSmmRTURAd1sdKuyO5tqrFiJvHHVPZLM4HB53F21makGoyInFGhejdo3qZrkoinM8k0ewEJDbUp0YuMEgMOhQ==

"@nomicfoundation/edr@^0.11.1":
version "0.11.1"
resolved "https://registry.yarnpkg.com/@nomicfoundation/edr/-/edr-0.11.1.tgz#c645a8984a02cd1797f772298c46ee12bfbe9ebc"
integrity sha512-P97XwcD9DdMMZm9aqw89+mzqzlKmqzSPM3feBES2WVRm5/LOiBYorhpeAX+ANj0X8532SKgxoZK/CN5OWv9vZA==
dependencies:
"@nomicfoundation/edr-darwin-arm64" "0.11.1"
"@nomicfoundation/edr-darwin-x64" "0.11.1"
"@nomicfoundation/edr-linux-arm64-gnu" "0.11.1"
"@nomicfoundation/edr-linux-arm64-musl" "0.11.1"
"@nomicfoundation/edr-linux-x64-gnu" "0.11.1"
"@nomicfoundation/edr-linux-x64-musl" "0.11.1"
"@nomicfoundation/edr-win32-x64-msvc" "0.11.1"

"@nomicfoundation/hardhat-chai-matchers@^1.0.6":
version "1.0.6"
Expand Down Expand Up @@ -2963,14 +2963,14 @@ hardhat-tracer@^2.8.1:
debug "^4.3.4"
ethers "^5.6.1"

hardhat@^2.24.0:
version "2.24.0"
resolved "https://registry.yarnpkg.com/hardhat/-/hardhat-2.24.0.tgz#33dbe8c3972c2d2db6206966e19466571a937932"
integrity sha512-wDkD5GPmttYv21MR7tGDkyQ22tO2V86OEV8pA7NcXWYUpibe8XZ2EanXCeRHO61vwEx0f7/M+NqrhJwasaNMJg==
hardhat@^2.24.3:
version "2.25.0"
resolved "https://registry.yarnpkg.com/hardhat/-/hardhat-2.25.0.tgz#473bf07b62a0ea30cf003e4585f71a0ffc70c739"
integrity sha512-yBiA74Yj3VnTRj7lhnn8GalvBdvsMOqTKRrRATSy/2v0VIR2hR0Jcnmfn4aQBLtGAnr3Q2c8CxL0g3LYegUp+g==
dependencies:
"@ethereumjs/util" "^9.1.0"
"@ethersproject/abi" "^5.1.2"
"@nomicfoundation/edr" "^0.11.0"
"@nomicfoundation/edr" "^0.11.1"
"@nomicfoundation/solidity-analyzer" "^0.1.0"
"@sentry/node" "^5.18.1"
"@types/bn.js" "^5.1.0"
Expand Down
Loading