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

Legacymarket audit fixes #2133

Merged
merged 50 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
a60a474
fixes from audit
dbeal-eth Jun 29, 2023
c961a2a
fix msg sender should be target on migrate func
dbeal-eth Jul 13, 2023
a5a9183
Merge branch 'develop' into legacymarket-audit-fixes
barrasso Aug 14, 2023
fcf3d6f
Merge remote-tracking branch 'origin/develop' into legacymarket-audit…
dbeal-eth Aug 15, 2023
e35affe
feedback
dbeal-eth Aug 15, 2023
6ea1fbb
Merge branch 'legacymarket-audit-fixes' of https://github.com/Synthet…
dbeal-eth Aug 15, 2023
f479a9a
Merge branch 'develop' into legacymarket-audit-fixes
barrasso Feb 8, 2024
3f1d2a2
fix lint
barrasso Feb 8, 2024
877bf10
fix tests
barrasso Feb 9, 2024
209fd0b
Merge branch 'develop' into legacymarket-audit-fixes
barrasso Feb 9, 2024
40b9925
Fix Liquidator unit tests
barrasso Feb 16, 2024
96da286
fix unit tests
barrasso Feb 16, 2024
299e31f
fix fork tests
barrasso Feb 16, 2024
5775edc
fix int dual tests
barrasso Feb 16, 2024
51dcca5
fix fork
barrasso Feb 20, 2024
943b9ad
update optimism commit hash for ops tool
barrasso Feb 21, 2024
7021b1d
update op commit hash
barrasso Feb 21, 2024
308cb43
add node 18.17.1 op commit hash
barrasso Feb 21, 2024
2c6f319
update commit hash
barrasso Feb 21, 2024
f1faa31
update configure reward escrow script and op commit hash
barrasso Feb 28, 2024
b9766e1
Update docker-node image
barrasso Feb 29, 2024
214db6e
revert package-lock.json
barrasso Feb 29, 2024
22ec001
Merge branch 'develop' into legacymarket-audit-fixes
barrasso Feb 29, 2024
9e2a856
revert op commit change
barrasso Feb 29, 2024
5e21373
run npm i
barrasso Feb 29, 2024
d1be527
Update job-header-machine.yml machine image tag
barrasso Feb 29, 2024
d196e9b
install node version 18.19
barrasso Feb 29, 2024
81c9564
fix config
barrasso Feb 29, 2024
7e1d521
fix config 2
barrasso Feb 29, 2024
1c2e386
fix ci lint
barrasso Feb 29, 2024
5d78548
use op commit hash when upgraded to node 18
barrasso Feb 29, 2024
1d14c88
use op commit hash after upgraded to node 18
barrasso Feb 29, 2024
4a87b3f
Add install pnpm step
barrasso Feb 29, 2024
e25e97e
update pnpm options
barrasso Feb 29, 2024
0b29e20
add install cmd
barrasso Feb 29, 2024
53c382d
remove sh -c
barrasso Feb 29, 2024
60366f0
Use commandSync
barrasso Mar 1, 2024
ee01bfa
revert to sync
barrasso Mar 1, 2024
26521cd
update pnpm commands
barrasso Mar 5, 2024
1fec5df
update ci image tag and revert task-ops
barrasso Mar 5, 2024
2783827
use optimism v1.7.0 tag
barrasso Mar 5, 2024
b61eb0a
pull docker node instead of building
barrasso Mar 5, 2024
e73ab96
remove gcloud command
barrasso Mar 5, 2024
54b27ff
update _start func and remove build step from ci
barrasso Mar 5, 2024
79b0ed3
port mapping
barrasso Mar 5, 2024
a439588
Update ops task and circleci config
barrasso Mar 5, 2024
b7d33d4
log node version
barrasso Mar 5, 2024
87be523
update task-ops.js
barrasso Mar 5, 2024
91b1962
revert stuff
barrasso Mar 5, 2024
4e144eb
Merge branch 'develop' into legacymarket-audit-fixes
barrasso Mar 5, 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 .circleci/config.template.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# DO NOT EDIT MANUALLY! instead run `npm run build:ci`
# autogenerated by `.circleci/pack.js` from contents of `jobs` .yml files
version: 2.1
orbs:
orbs:
rust: circleci/[email protected]
commands:
{{> commands}}
Expand Down
36 changes: 18 additions & 18 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# DO NOT EDIT MANUALLY! instead run `npm run build:ci`
# autogenerated by `.circleci/pack.js` from contents of `jobs` .yml files
version: 2.1
orbs:
orbs:
rust: circleci/[email protected]
commands:
cmd-wait-for-port:
Expand All @@ -18,7 +18,7 @@ jobs:
job-audit:
working_directory: ~/repo
docker:
- image: synthetixio/docker-sec-tools:16.17-ubuntu
- image: synthetixio/docker-sec-tools:18.19-ubuntu
steps:
- checkout
- run:
Expand All @@ -32,7 +32,7 @@ jobs:
job-cannon:
working_directory: ~/repo
machine:
image: ubuntu-2204:2022.04.1
image: ubuntu-2204:current
docker_layer_caching: true
environment:
foundry_cache_version: "1"
Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:
job-fork-tests-ovm:
working_directory: ~/repo
docker:
- image: synthetixio/docker-node:16.17-ubuntu
- image: synthetixio/docker-node:18.19-ubuntu
resource_class: large
steps:
- checkout
Expand All @@ -123,7 +123,7 @@ jobs:
job-fork-tests:
working_directory: ~/repo
docker:
- image: synthetixio/docker-node:16.17-ubuntu
- image: synthetixio/docker-node:18.19-ubuntu
resource_class: large
steps:
- checkout
Expand All @@ -150,7 +150,7 @@ jobs:
job-integration-tests:
working_directory: ~/repo
machine:
image: ubuntu-2204:2022.04.1
image: ubuntu-2204:current
docker_layer_caching: true
environment:
foundry_cache_version: "1"
Expand Down Expand Up @@ -248,7 +248,7 @@ jobs:
job-lint:
working_directory: ~/repo
docker:
- image: synthetixio/docker-node:16.17-ubuntu
- image: synthetixio/docker-node:18.19-ubuntu
steps:
- checkout
- attach_workspace:
Expand All @@ -257,7 +257,7 @@ jobs:
job-pack-browser:
working_directory: ~/repo
docker:
- image: synthetixio/docker-node:16.17-ubuntu
- image: synthetixio/docker-node:18.19-ubuntu
steps:
- checkout
- attach_workspace:
Expand All @@ -268,7 +268,7 @@ jobs:
job-prepare:
working_directory: ~/repo
docker:
- image: synthetixio/docker-node:16.17-ubuntu
- image: synthetixio/docker-node:18.19-ubuntu
steps:
- run:
name: Set node & npm versions
Expand Down Expand Up @@ -299,7 +299,7 @@ jobs:
job-simulate-release:
working_directory: ~/repo
docker:
- image: synthetixio/docker-node:16.17-ubuntu
- image: synthetixio/docker-node:18.19-ubuntu
steps:
- checkout
- attach_workspace:
Expand All @@ -323,7 +323,7 @@ jobs:
job-static-analysis:
working_directory: ~/repo
docker:
- image: synthetixio/docker-node:16.17-ubuntu
- image: synthetixio/docker-node:18.19-ubuntu
steps:
- checkout
- attach_workspace:
Expand All @@ -340,7 +340,7 @@ jobs:
job-test-deploy-script:
working_directory: ~/repo
machine:
image: ubuntu-2204:2022.04.1
image: ubuntu-2204:current
docker_layer_caching: true
environment:
foundry_cache_version: "1"
Expand Down Expand Up @@ -393,7 +393,7 @@ jobs:
job-unit-tests-coverage-report:
working_directory: ~/repo
docker:
- image: synthetixio/docker-sec-tools:16.17-ubuntu
- image: synthetixio/docker-sec-tools:18.19-ubuntu
steps:
- checkout
- attach_workspace:
Expand All @@ -406,7 +406,7 @@ jobs:
job-unit-tests-coverage:
working_directory: ~/repo
docker:
- image: synthetixio/docker-node:16.17-ubuntu
- image: synthetixio/docker-node:18.19-ubuntu
resource_class: large
parallelism: 8
steps:
Expand All @@ -433,7 +433,7 @@ jobs:
job-unit-tests-gas-report:
working_directory: ~/repo
docker:
- image: synthetixio/docker-node:16.17-ubuntu
- image: synthetixio/docker-node:18.19-ubuntu
steps:
- checkout
- attach_workspace:
Expand All @@ -451,7 +451,7 @@ jobs:
job-unit-tests:
working_directory: ~/repo
docker:
- image: synthetixio/docker-node:16.17-ubuntu
- image: synthetixio/docker-node:18.19-ubuntu
resource_class: large
parallelism: 8
steps:
Expand Down Expand Up @@ -484,7 +484,7 @@ jobs:
job-validate-deployments:
working_directory: ~/repo
docker:
- image: synthetixio/docker-node:16.17-ubuntu
- image: synthetixio/docker-node:18.19-ubuntu
steps:
- checkout
- attach_workspace:
Expand All @@ -500,7 +500,7 @@ jobs:
job-validate-etherscan:
working_directory: ~/repo
docker:
- image: synthetixio/docker-node:16.17-ubuntu
- image: synthetixio/docker-node:18.19-ubuntu
parameters:
network:
type: string
Expand Down
2 changes: 1 addition & 1 deletion .circleci/src/snippets/job-header-machine.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
working_directory: ~/repo
machine:
image: ubuntu-2204:2022.04.1
image: ubuntu-2204:current
docker_layer_caching: true
environment:
foundry_cache_version: "1"
2 changes: 1 addition & 1 deletion .circleci/src/snippets/job-header-node.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
working_directory: ~/repo
docker:
- image: synthetixio/docker-node:16.17-ubuntu
- image: synthetixio/docker-node:18.19-ubuntu
2 changes: 1 addition & 1 deletion .circleci/src/snippets/job-header-sec-tools.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
working_directory: ~/repo
docker:
- image: synthetixio/docker-sec-tools:16.17-ubuntu
- image: synthetixio/docker-sec-tools:18.19-ubuntu
2 changes: 1 addition & 1 deletion .github/workflows/slither-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest

container:
image: synthetixio/docker-sec-tools:16.17-ubuntu
image: synthetixio/docker-sec-tools:18.19-ubuntu

steps:
- name: Checkout
Expand Down
6 changes: 6 additions & 0 deletions contracts/BaseRewardEscrowV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ contract BaseRewardEscrowV2 is Owned, IRewardEscrowV2, LimitedSetup(8 weeks), Mi

/* Mapping of nominated address to recieve account merging */
mapping(address => address) public nominatedReceiver;
mapping(address => bool) public permittedEscrowCreators;

/* Max escrow duration */
uint public max_duration = 2 * 52 weeks; // Default max 2 years duration
Expand Down Expand Up @@ -307,6 +308,10 @@ contract BaseRewardEscrowV2 is Owned, IRewardEscrowV2, LimitedSetup(8 weeks), Mi
synthetixERC20().transfer(transferTo, amount);
}

function setPermittedEscrowCreator(address creator, bool permitted) external onlyOwner {
permittedEscrowCreators[creator] = permitted;
}

/**
* @notice Create an escrow entry to lock SNX for a given duration in seconds
* @dev This call expects that the depositor (msg.sender) has already approved the Reward escrow contract
Expand All @@ -318,6 +323,7 @@ contract BaseRewardEscrowV2 is Owned, IRewardEscrowV2, LimitedSetup(8 weeks), Mi
uint256 duration
) external {
require(beneficiary != address(0), "Cannot create escrow with address(0)");
require(permittedEscrowCreators[msg.sender], "Only permitted escrow creators can create escrow entries");

/* Transfer SNX from msg.sender */
require(synthetixERC20().transferFrom(msg.sender, address(this), deposit), "token transfer failed");
Expand Down
18 changes: 6 additions & 12 deletions contracts/BaseSynthetix.sol
Original file line number Diff line number Diff line change
Expand Up @@ -449,34 +449,28 @@ contract BaseSynthetix is IERC20, ExternStateToken, MixinResolver, ISynthetix {
return success;
}

/**
* @notice allows for migration from v2x to v3 when an account has pending escrow entries
*/
function revokeAllEscrow(address account) external systemActive {
address legacyMarketAddress = resolver.getAddress(CONTRACT_V3_LEGACYMARKET);
require(msg.sender == legacyMarketAddress, "Only LegacyMarket can revoke escrow");
rewardEscrowV2().revokeFrom(account, legacyMarketAddress, rewardEscrowV2().totalEscrowedAccountBalance(account), 0);
}

function migrateAccountBalances(address account)
external
systemActive
returns (uint totalEscrowRevoked, uint totalLiquidBalance)
{
address debtMigratorOnEthereum = resolver.getAddress(CONTRACT_DEBT_MIGRATOR_ON_ETHEREUM);
require(msg.sender == debtMigratorOnEthereum, "Only L1 DebtMigrator");
require(
msg.sender == debtMigratorOnEthereum || msg.sender == resolver.getAddress(CONTRACT_V3_LEGACYMARKET),
"Only L1 DebtMigrator or LegacyMarket"
);

// get their liquid SNX balance and transfer it to the migrator contract
totalLiquidBalance = tokenState.balanceOf(account);
if (totalLiquidBalance > 0) {
bool succeeded = _transferByProxy(account, debtMigratorOnEthereum, totalLiquidBalance);
bool succeeded = _transferByProxy(account, msg.sender, totalLiquidBalance);
require(succeeded, "snx transfer failed");
}

// get their escrowed SNX balance and revoke it all
totalEscrowRevoked = rewardEscrowV2().totalEscrowedAccountBalance(account);
if (totalEscrowRevoked > 0) {
rewardEscrowV2().revokeFrom(account, debtMigratorOnEthereum, totalEscrowRevoked, 0);
rewardEscrowV2().revokeFrom(account, msg.sender, totalEscrowRevoked, 0);
}
}

Expand Down
2 changes: 0 additions & 2 deletions contracts/interfaces/ISynthetix.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,5 @@ interface ISynthetix {

function burnSecondary(address account, uint amount) external;

function revokeAllEscrow(address account) external;

function migrateAccountBalances(address account) external returns (uint totalEscrowRevoked, uint totalLiquidBalance);
}
33 changes: 0 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions publish/src/commands/deploy/configure-reward-escrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ module.exports = async ({ addressOf, deployer, runStep }) => {
// Synthetix,
RewardEscrowV2Storage,
RewardEscrowV2Frozen,
LiquidatorRewards,
DebtMigratorOnOptimism,
} = deployer.deployedContracts;

// SIP-252 rewards escrow migration
Expand Down Expand Up @@ -102,4 +104,30 @@ module.exports = async ({ addressOf, deployer, runStep }) => {
writeArg: addressOf(RewardEscrowV2),
comment: 'Ensure the RewardsDistribution can read the RewardEscrowV2 address',
});

if (DebtMigratorOnOptimism) {
await runStep({
contract: 'RewardEscrowV2',
target: RewardEscrowV2,
read: 'permittedEscrowCreators',
readArg: addressOf(DebtMigratorOnOptimism),
expected: input => input,
write: 'setPermittedEscrowCreator',
writeArg: [addressOf(DebtMigratorOnOptimism), true],
comment: 'Allow escrow entry creation by DebtMigratorOnOptimism',
});
}

if (RewardEscrowV2.permittedEscrowCreators) {
await runStep({
contract: 'RewardEscrowV2',
target: RewardEscrowV2,
read: 'permittedEscrowCreators',
readArg: addressOf(LiquidatorRewards),
expected: input => input,
write: 'setPermittedEscrowCreator',
writeArg: [addressOf(LiquidatorRewards), true],
comment: 'Allow escrow entry creation by LiquidatorRewards',
});
}
};
16 changes: 1 addition & 15 deletions test/contracts/BaseSynthetix.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ contract('BaseSynthetix', async accounts => {
'mint',
'mintSecondary',
'mintSecondaryRewards',
'revokeAllEscrow',
'settle',
'transfer',
'transferFrom',
Expand Down Expand Up @@ -617,6 +616,7 @@ contract('BaseSynthetix', async accounts => {
beforeEach(async () => {
// give the account some balance to test with
await baseSynthetixProxy.transfer(account3, toUnit('200'), { from: owner });
await rewardEscrowV2.setPermittedEscrowCreator(owner, true, { from: owner });
await rewardEscrowV2.createEscrowEntry(account3, toUnit('100'), 1, { from: owner });

assert.bnEqual(await baseSynthetixImpl.collateral(account3), toUnit('300'));
Expand All @@ -643,20 +643,6 @@ contract('BaseSynthetix', async accounts => {
});
});

// SIP-299
describe('revokeAllEscrow', () => {
it('restricted to legacy market', async () => {
await addressResolver.importAddresses(['LegacyMarket'].map(toBytes32), [account2], {
from: owner,
});
await rewardEscrowV2.createEscrowEntry(account1, toUnit('100'), 1, { from: owner });
await assert.revert(
baseSynthetixImpl.revokeAllEscrow(account1, { from: owner }),
'Only LegacyMarket can revoke escrow'
);
});
});

it('should transfer when legacy market address is non-zero', async () => {
await addressResolver.importAddresses(['LegacyMarket'].map(toBytes32), [account2], {
from: owner,
Expand Down
Loading
Loading