The Upgrade function first transfers the tokens to the new contract, then calls Contract.Migrate() to upgrade the contract. Contract.Migrate() migrates everything in the persistent storage of the current contract to the new contract when executed. For Migrate() method, it will only transfer the contract storages when the target contract has not been deployed yet.
Specifically, one can frontrun the deployment of the new contract so the migration won’t transfer the storages to the new contract. Though what an attacker can do still depends on the new contract, this might not be the operator’s expectation.
Recommendation
Check whether the contract already exists before calling Contract.Migrate(). And transfer the tokens after the contract migration has succeeded.
Description
There is a lack of sanity check in the
Upgrade()
method of FlamingoSwapPairContract which might lead to unwanted behaviour.The
Upgrade
function first transfers the tokens to the new contract, then callsContract.Migrate()
to upgrade the contract.Contract.Migrate()
migrates everything in the persistent storage of the current contract to the new contract when executed. ForMigrate()
method, it will only transfer the contract storages when the target contract has not been deployed yet.Specifically, one can frontrun the deployment of the new contract so the migration won’t transfer the storages to the new contract. Though what an attacker can do still depends on the new contract, this might not be the operator’s expectation.
Recommendation
Check whether the contract already exists before calling
Contract.Migrate()
. And transfer the tokens after the contract migration has succeeded.