Skip to content

Commit

Permalink
add checkPreMigration flag
Browse files Browse the repository at this point in the history
  • Loading branch information
olga24912 committed Jul 24, 2024
1 parent f4ffa6d commit 4098d95
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
19 changes: 14 additions & 5 deletions eth-custodian/contracts/EthCustodianProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,18 @@ contract EthCustodianProxy is

function withdraw(
bytes calldata proofData,
uint64 proofBlockHeight
uint64 proofBlockHeight,
bool checkPreMigration
) external {
if (BlockHeightFromProofExtractor.getBlockHeightFromProof(proofData) > migrationBlockHeight) {
_requireNotPaused(PAUSED_WITHDRAW_POST_MIGRATION);
ethCustodianImpl.withdraw(proofData, proofBlockHeight);
} else {
if (isPreMigration(proofData, checkPreMigration)) {
_requireNotPaused(PAUSED_WITHDRAW_PRE_MIGRATION);
bytes memory postMigrationProducer = ethCustodianImpl.nearProofProducerAccount_();
_writeProofProducerSlot(preMigrationProducerAccount);
ethCustodianImpl.withdraw(proofData, proofBlockHeight);
_writeProofProducerSlot(postMigrationProducer);
} else {
_requireNotPaused(PAUSED_WITHDRAW_POST_MIGRATION);
ethCustodianImpl.withdraw(proofData, proofBlockHeight);
}
}

Expand Down Expand Up @@ -150,6 +151,14 @@ contract EthCustodianProxy is
_pause(flags);
}

function isPreMigration(bytes calldata proofData, bool checkPreMigration) internal view returns(bool) {
if (checkPreMigration) {
return BlockHeightFromProofExtractor.getBlockHeightFromProof(proofData) <= migrationBlockHeight;
}

return false;
}

/**
* @dev Internal function called by the proxy contract to authorize an upgrade to a new implementation address
* using the UUPS proxy upgrade pattern. Overrides the default `_authorizeUpgrade` function from the `UUPSUpgradeable` contract.
Expand Down
16 changes: 8 additions & 8 deletions eth-custodian/test/EthCustodianProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ describe('EthCustodianProxy contract', () => {
await ethCustodianProxy.pauseProxy(PAUSED_WITHDRAW_POST_MIGRATION);
const proof = require('./proof_template_from_testnet.json');

await expect(ethCustodianProxy.withdraw(borshifyOutcomeProof(proof), blockHeightFromProof + 1))
await expect(ethCustodianProxy.withdraw(borshifyOutcomeProof(proof), blockHeightFromProof + 1, true))
.to.be.revertedWith('Pausable: paused');
});

Expand All @@ -153,7 +153,7 @@ describe('EthCustodianProxy contract', () => {
await ethCustodianProxy.pauseProxy(PAUSED_WITHDRAW_PRE_MIGRATION);
const proof = require('./proof_template_from_testnet.json');

await expect(ethCustodianProxy.withdraw(borshifyOutcomeProof(proof), blockHeightFromProof))
await expect(ethCustodianProxy.withdraw(borshifyOutcomeProof(proof), blockHeightFromProof, true))
.to.be.revertedWith('Pausable: paused');
});

Expand All @@ -169,10 +169,10 @@ describe('EthCustodianProxy contract', () => {

const proof = require('./proof_template_from_testnet.json');

await expect(ethCustodianProxy.withdraw(borshifyOutcomeProof(proof), 1099))
await expect(ethCustodianProxy.withdraw(borshifyOutcomeProof(proof), 1099, true))
.to.be.revertedWith('Pausable: paused');

await expect(ethCustodianProxy.withdraw(borshifyOutcomeProof(proof), blockHeightFromProof + 1))
await expect(ethCustodianProxy.withdraw(borshifyOutcomeProof(proof), blockHeightFromProof + 1, true))
.to.be.revertedWith('Pausable: paused');
});
});
Expand Down Expand Up @@ -234,7 +234,7 @@ describe('EthCustodianProxy contract', () => {
await ethers.provider.getBalance(user2.address));

await expect(
ethCustodianProxy.withdraw(borshifyOutcomeProof(postMigrationProof), blockHeightFromProof + 1)
ethCustodianProxy.withdraw(borshifyOutcomeProof(postMigrationProof), blockHeightFromProof + 1, true)
)
.to.emit(ethCustodian, 'Withdrawn')
.withArgs(user2.address, amount);
Expand All @@ -252,7 +252,7 @@ describe('EthCustodianProxy contract', () => {
const balanceBefore = BigInt(await ethers.provider.getBalance(user2.address));

await expect(
ethCustodianProxy.withdraw(borshifyOutcomeProof(proof), blockHeightFromProof + 2)
ethCustodianProxy.withdraw(borshifyOutcomeProof(proof), blockHeightFromProof + 2, true)
)
.to.emit(ethCustodian, 'Withdrawn')
.withArgs(user2.address, amount);
Expand All @@ -268,7 +268,7 @@ describe('EthCustodianProxy contract', () => {
const balanceBefore = BigInt(await ethers.provider.getBalance(user2.address));

await expect(
ethCustodianProxy.withdraw(borshifyOutcomeProof(proof), blockHeightFromProof)
ethCustodianProxy.withdraw(borshifyOutcomeProof(proof), blockHeightFromProof, true)
)
.to.emit(ethCustodian, 'Withdrawn')
.withArgs(user2.address, amount);
Expand All @@ -286,7 +286,7 @@ describe('EthCustodianProxy contract', () => {
const migrationBlock = await ethCustodianProxy.migrationBlockHeight();

await expect(
ethCustodianProxy.withdraw(borshifyOutcomeProof(proof), parseInt(migrationBlock))
ethCustodianProxy.withdraw(borshifyOutcomeProof(proof), parseInt(migrationBlock), true)
)
.to.emit(ethCustodian, 'Withdrawn')
.withArgs(user2.address, amount);
Expand Down

0 comments on commit 4098d95

Please sign in to comment.