Skip to content

Commit e81a74b

Browse files
ArvoleararitkulovaHrom131
authored
New libs and clean up (#156)
* Added bitcoin libs (#153) * added bitcoin libs * renamed BitcoinHelper to EndianConverter * refactored natspec * review fixes coverage 100% * BtcTxParser -> TxParser * updated readme * refactored tests for txParser * fixed parseBlockHeader LE numbers * refactored endianConverter * added bytes to bytes conversion in EndianConverter * cleaned headers data for tests * review fixes * package json fix * refactored parseCuint in TxParser * refactored naming in EndianConverter * natspec EndianConverter * removed convertion function from bytes to uint and vice versa * covereage for EndianConverter * refactored _reverseUint128 in EndianConverter * fixed pragma solidity * Update ERC7947 interface (#154) * Update ERC7947 interface * Fix unit tests * typo * added check for insertion attack in TxMerkleProof; added isBitcoinTransaction and parseCuintMemory to TxParser * utilized addHexPrefix * TxMerkleProof now uses txIndex to calculate hashing directions * fixed typo * consistency in codestyle * updated version to 3.2.0 * removed unused test case * removed excess comment * fixed natspec * refactored helpers * added reference for insertion attack * update readme --------- Co-authored-by: Oleh Komendant <44612825+Hrom131@users.noreply.github.com> Co-authored-by: Artem Chystiakov <artem.ch31@gmail.com> * remove some contracts * removed compilation for pragma solidity 0.7.6 * removed bignumber.js from dependencies * Update AAccountRecovery contract * update changelog, revert version --------- Co-authored-by: Yuliia Aritkulova <94910987+aritkulova@users.noreply.github.com> Co-authored-by: Oleh Komendant <44612825+Hrom131@users.noreply.github.com> Co-authored-by: Oleh Komendant <oleg02kom@gmail.com>
1 parent 34dead4 commit e81a74b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3530
-2068
lines changed

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Changelog
22

3+
## [minor]
4+
5+
Added several new libs to work with Bitcoin:
6+
7+
- `BlockHeader` to parse and format Bitcoin block headers.
8+
- `TxMerkleProof` to verify the inclusion of a Bitcoin transaction in a block.
9+
- `TxParser` to parse and format Bitcoin transactions.
10+
- `EndianConverter` to convert between little-endian and big-endian formats.
11+
12+
Removed rarely used, legacy libs and contracts:
13+
14+
- `SetHelper`.
15+
- `UniswapV2Oracle`.
16+
- `UniswapV3Oracle`.
17+
318
## [none]
419

5-
- Improved package publishing process
20+
- Improved package publishing process.

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@ contracts
4545
├── libs
4646
│ ├── arrays
4747
│ │ ├── ArrayHelper — "Common functions to work with arrays"
48-
│ │ ├── Paginator — "Return array slices from view function"
49-
│ │ └── SetHelper — "Array abstraction over sets"
48+
│ │ └── Paginator — "Return array slices from view function"
49+
│ ├── bitcoin
50+
│ │ ├── BlockHeader — "Parse and format Bitcoin block headers"
51+
│ │ ├── TxMerkleProof — "Verify transaction inclusion in Bitcoin block"
52+
│ │ └── TxParser — "Parse and format Bitcoin transactions"
5053
│ ├── bn
5154
│ │ └── U512 — "A hyperoptimized uint512 implementation"
5255
│ ├── crypto
@@ -67,15 +70,13 @@ contracts
6770
│ │ └── Vector — "A pushable memory array"
6871
│ ├── utils
6972
│ │ ├── DecimalsConverter — "Simplify interaction with ERC-20 decimals"
73+
│ │ ├── EndianConverter — "Convert between little-endian and big-endian formats"
7074
│ │ ├── MemoryUtils — "Functions for memory manipulation"
7175
│ │ ├── ReturnDataProxy — "Bypass extra returndata copy when returning data"
7276
│ │ └── Typecaster — "Cast between various Solidity types"
7377
│ └── zkp
7478
│ ├── Groth16VerifierHelper — "Simplify integration with Groth16 proofs"
7579
│ └── PlonkVerifierHelper — "Simplify integration with Plonk proofs"
76-
├── oracles
77-
│ ├── AUniswapV2Oracle — "Uniswap V2 oracle with custom TWAP"
78-
│ └── UniswapV3Oracle — "Uniswap V3 oracle with a clean interface"
7980
├── proxy
8081
│ └── adminable
8182
│ ├── AdminableProxy — "A slight modification of a transparent proxy"

contracts/access/AMultiOwnable.sol

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.21;
33

4-
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
54
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
5+
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
66

7-
import {SetHelper} from "../libs/arrays/SetHelper.sol";
87
import {TypeCaster} from "../libs/utils/TypeCaster.sol";
98
import {IMultiOwnable} from "../interfaces/access/IMultiOwnable.sol";
109

@@ -24,7 +23,6 @@ import {IMultiOwnable} from "../interfaces/access/IMultiOwnable.sol";
2423
abstract contract AMultiOwnable is IMultiOwnable, Initializable {
2524
using EnumerableSet for EnumerableSet.AddressSet;
2625
using TypeCaster for address;
27-
using SetHelper for EnumerableSet.AddressSet;
2826

2927
struct AMultiOwnableStorage {
3028
EnumerableSet.AddressSet owners;
@@ -113,7 +111,9 @@ abstract contract AMultiOwnable is IMultiOwnable, Initializable {
113111
function _addOwners(address[] memory newOwners_) private {
114112
AMultiOwnableStorage storage $ = _getAMultiOwnableStorage();
115113

116-
$.owners.add(newOwners_);
114+
for (uint256 i = 0; i < newOwners_.length; ++i) {
115+
$.owners.add(newOwners_[i]);
116+
}
117117

118118
if ($.owners.contains(address(0))) revert InvalidOwner();
119119

@@ -132,7 +132,9 @@ abstract contract AMultiOwnable is IMultiOwnable, Initializable {
132132
function _removeOwners(address[] memory oldOwners_) private {
133133
AMultiOwnableStorage storage $ = _getAMultiOwnableStorage();
134134

135-
$.owners.remove(oldOwners_);
135+
for (uint256 i = 0; i < oldOwners_.length; ++i) {
136+
$.owners.remove(oldOwners_[i]);
137+
}
136138

137139
emit OwnersRemoved(oldOwners_);
138140
}

contracts/access/ARBAC.sol

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Ini
66
import {IRBAC} from "../interfaces/access/IRBAC.sol";
77

88
import {TypeCaster} from "../libs/utils/TypeCaster.sol";
9-
import {SetHelper} from "../libs/arrays/SetHelper.sol";
109
import {DynamicSet} from "../libs/data-structures/DynamicSet.sol";
1110

1211
/**
@@ -32,7 +31,6 @@ import {DynamicSet} from "../libs/data-structures/DynamicSet.sol";
3231
*/
3332
abstract contract ARBAC is IRBAC, Initializable {
3433
using DynamicSet for DynamicSet.StringSet;
35-
using SetHelper for DynamicSet.StringSet;
3634
using TypeCaster for string;
3735

3836
struct ARBACStorage {
@@ -234,7 +232,9 @@ abstract contract ARBAC is IRBAC, Initializable {
234232
function _grantRoles(address to_, string[] memory rolesToGrant_) internal {
235233
ARBACStorage storage $ = _getARBACStorage();
236234

237-
$.userRoles[to_].add(rolesToGrant_);
235+
for (uint256 i = 0; i < rolesToGrant_.length; ++i) {
236+
$.userRoles[to_].add(rolesToGrant_[i]);
237+
}
238238

239239
emit GrantedRoles(to_, rolesToGrant_);
240240
}
@@ -247,7 +247,9 @@ abstract contract ARBAC is IRBAC, Initializable {
247247
function _revokeRoles(address from_, string[] memory rolesToRevoke_) internal {
248248
ARBACStorage storage $ = _getARBACStorage();
249249

250-
$.userRoles[from_].remove(rolesToRevoke_);
250+
for (uint256 i = 0; i < rolesToRevoke_.length; ++i) {
251+
$.userRoles[from_].remove(rolesToRevoke_[i]);
252+
}
251253

252254
emit RevokedRoles(from_, rolesToRevoke_);
253255
}
@@ -272,7 +274,10 @@ abstract contract ARBAC is IRBAC, Initializable {
272274
resourceToAdd_
273275
];
274276

275-
_permissions.add(permissionsToAdd_);
277+
for (uint256 i = 0; i < permissionsToAdd_.length; ++i) {
278+
_permissions.add(permissionsToAdd_[i]);
279+
}
280+
276281
_resources.add(resourceToAdd_);
277282

278283
emit AddedPermissions(role_, resourceToAdd_, permissionsToAdd_, allowed_);
@@ -298,7 +303,9 @@ abstract contract ARBAC is IRBAC, Initializable {
298303
resourceToRemove_
299304
];
300305

301-
_permissions.remove(permissionsToRemove_);
306+
for (uint256 i = 0; i < permissionsToRemove_.length; ++i) {
307+
_permissions.remove(permissionsToRemove_[i]);
308+
}
302309

303310
if (_permissions.length() == 0) {
304311
_resources.remove(resourceToRemove_);

contracts/access/extensions/ARBACGroupable.sol

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pragma solidity ^0.8.21;
44
import {IRBACGroupable} from "../../interfaces/access/extensions/IRBACGroupable.sol";
55

66
import {DynamicSet} from "../../libs/data-structures/DynamicSet.sol";
7-
import {SetHelper} from "../../libs/arrays/SetHelper.sol";
87

98
import {ARBAC} from "../ARBAC.sol";
109

@@ -24,7 +23,6 @@ import {ARBAC} from "../ARBAC.sol";
2423
*/
2524
abstract contract ARBACGroupable is IRBACGroupable, ARBAC {
2625
using DynamicSet for DynamicSet.StringSet;
27-
using SetHelper for DynamicSet.StringSet;
2826

2927
struct ARBACGroupableStorage {
3028
uint256 defaultGroupEnabled;
@@ -211,7 +209,9 @@ abstract contract ARBACGroupable is IRBACGroupable, ARBAC {
211209
function _addUserToGroups(address who_, string[] memory groupsToAddTo_) internal {
212210
ARBACGroupableStorage storage $ = _getARBACGroupableStorage();
213211

214-
$.userGroups[who_].add(groupsToAddTo_);
212+
for (uint256 i = 0; i < groupsToAddTo_.length; ++i) {
213+
$.userGroups[who_].add(groupsToAddTo_[i]);
214+
}
215215

216216
emit AddedToGroups(who_, groupsToAddTo_);
217217
}
@@ -224,7 +224,9 @@ abstract contract ARBACGroupable is IRBACGroupable, ARBAC {
224224
function _removeUserFromGroups(address who_, string[] memory groupsToRemoveFrom_) internal {
225225
ARBACGroupableStorage storage $ = _getARBACGroupableStorage();
226226

227-
$.userGroups[who_].remove(groupsToRemoveFrom_);
227+
for (uint256 i = 0; i < groupsToRemoveFrom_.length; ++i) {
228+
$.userGroups[who_].remove(groupsToRemoveFrom_[i]);
229+
}
228230

229231
emit RemovedFromGroups(who_, groupsToRemoveFrom_);
230232
}
@@ -237,7 +239,9 @@ abstract contract ARBACGroupable is IRBACGroupable, ARBAC {
237239
function _grantGroupRoles(string memory groupTo_, string[] memory rolesToGrant_) internal {
238240
ARBACGroupableStorage storage $ = _getARBACGroupableStorage();
239241

240-
$.groupRoles[groupTo_].add(rolesToGrant_);
242+
for (uint256 i = 0; i < rolesToGrant_.length; ++i) {
243+
$.groupRoles[groupTo_].add(rolesToGrant_[i]);
244+
}
241245

242246
emit GrantedGroupRoles(groupTo_, rolesToGrant_);
243247
}
@@ -250,7 +254,9 @@ abstract contract ARBACGroupable is IRBACGroupable, ARBAC {
250254
function _revokeGroupRoles(string memory groupFrom_, string[] memory rolesToRevoke_) internal {
251255
ARBACGroupableStorage storage $ = _getARBACGroupableStorage();
252256

253-
$.groupRoles[groupFrom_].remove(rolesToRevoke_);
257+
for (uint256 i = 0; i < rolesToRevoke_.length; ++i) {
258+
$.groupRoles[groupFrom_].remove(rolesToRevoke_[i]);
259+
}
254260

255261
emit RevokedGroupRoles(groupFrom_, rolesToRevoke_);
256262
}

contracts/account-abstraction/AAccountRecovery.sol

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,31 @@ abstract contract AAccountRecovery is IAccountRecovery {
7676
/**
7777
* @notice Should be called in the `addRecoveryProvider` function
7878
*/
79-
function _addRecoveryProvider(address provider_, bytes memory recoveryData_) internal virtual {
79+
function _addRecoveryProvider(
80+
address provider_,
81+
bytes memory recoveryData_,
82+
uint256 value_
83+
) internal virtual {
8084
if (provider_ == address(0)) revert ZeroAddress();
8185

8286
AAccountRecoveryStorage storage $ = _getAAccountRecoveryStorage();
8387

8488
if (!$.recoveryProviders.add(provider_)) revert ProviderAlreadyAdded(provider_);
8589

86-
IRecoveryProvider(provider_).subscribe(recoveryData_);
90+
IRecoveryProvider(provider_).subscribe{value: value_}(recoveryData_);
8791

8892
emit RecoveryProviderAdded(provider_);
8993
}
9094

9195
/**
9296
* @notice Should be called in the `removeRecoveryProvider` function
9397
*/
94-
function _removeRecoveryProvider(address provider_) internal virtual {
98+
function _removeRecoveryProvider(address provider_, uint256 value_) internal virtual {
9599
AAccountRecoveryStorage storage $ = _getAAccountRecoveryStorage();
96100

97101
if (!$.recoveryProviders.remove(provider_)) revert ProviderNotRegistered(provider_);
98102

99-
IRecoveryProvider(provider_).unsubscribe();
103+
IRecoveryProvider(provider_).unsubscribe{value: value_}();
100104

101105
emit RecoveryProviderRemoved(provider_);
102106
}

contracts/finance/staking/AStaking.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.21;
33

4+
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
45
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
56
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
6-
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
77

88
import {AValueDistributor} from "./AValueDistributor.sol";
99

0 commit comments

Comments
 (0)