Skip to content

solidity: Simulated upgrade attack fix - #228

Open
matevz wants to merge 3 commits into
masterfrom
matevz/feature/simulation-attack-fix
Open

solidity: Simulated upgrade attack fix#228
matevz wants to merge 3 commits into
masterfrom
matevz/feature/simulation-attack-fix

Conversation

@matevz

@matevz matevz commented Jul 30, 2026

Copy link
Copy Markdown
Member

Implements #198 (Option 4):

  • adds UPUPSUpgradeable contract that enforces a two-step upgrade
  • updates hardhat deployment tasks
  • updates tests

Tested on Sapphire Testnet with Safe:

$ npx hardhat show 0x91075489Df10f3Ee42ed497aaA4C6c9E94924Ac0 --network sapphire-testnet
=== Accounting Contract Info ===
Proxy address:        0x91075489Df10f3Ee42ed497aaA4C6c9E94924Ac0
Implementation:       0x822414e02851c8fcEE0E39F30EE225F568979514
VERSION:              3
Owner:                0xf1B7dF2E13E01928BAac26b6d4f315008EEE5E25
SiweAuth address:     0x402fF7d748CfD37BEF9b2cCfB208e595FBb39B8c
Withdrawal count:     0
Proposed upgrade:     yes
  New implementation: 0xf01f1B746e50ccee741333eE667B6C34ad473CBa
  Min block number:   18217961

=== Registered Tokens (0) ===

=== AccountingSiweAuth Info ===
Address:              0x402fF7d748CfD37BEF9b2cCfB208e595FBb39B8c
ROFL app ID:          rofl1qqn9xndja7e2pnxhttktmecvwzz0yqwxsquqyxdf
Auth key hash:        0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563

=== EVMSignerAndVerifier Info ===
EVM signing address:  0xcbf2A507A676164b87A93497477cD4dBD1a3393e
Gas tank address:     0xEceC81a8510A1FA8209434564f7ec6faB9E6780a
ROFL app ID:          rofl1qqn9xndja7e2pnxhttktmecvwzz0yqwxsquqyxdf
ROFL signer address:  0x0000000000000000000000000000000000000000
$ npx hardhat show 0x91075489Df10f3Ee42ed497aaA4C6c9E94924Ac0 --network sapphire-testnet
=== Accounting Contract Info ===
Proxy address:        0x91075489Df10f3Ee42ed497aaA4C6c9E94924Ac0
Implementation:       0xf01f1B746e50ccee741333eE667B6C34ad473CBa
VERSION:              4
Owner:                0xf1B7dF2E13E01928BAac26b6d4f315008EEE5E25
SiweAuth address:     0x402fF7d748CfD37BEF9b2cCfB208e595FBb39B8c
Withdrawal count:     0
Proposed upgrade:     none

=== Registered Tokens (0) ===

=== AccountingSiweAuth Info ===
Address:              0x402fF7d748CfD37BEF9b2cCfB208e595FBb39B8c
ROFL app ID:          rofl1qqn9xndja7e2pnxhttktmecvwzz0yqwxsquqyxdf
Auth key hash:        0x290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563

=== EVMSignerAndVerifier Info ===
EVM signing address:  0xcbf2A507A676164b87A93497477cD4dBD1a3393e
Gas tank address:     0xEceC81a8510A1FA8209434564f7ec6faB9E6780a
ROFL app ID:          rofl1qqn9xndja7e2pnxhttktmecvwzz0yqwxsquqyxdf
ROFL signer address:  0x0000000000000000000000000000000000000000

@matevz matevz linked an issue Jul 30, 2026 that may be closed by this pull request
@matevz
matevz force-pushed the matevz/feature/simulation-attack-fix branch from 1c3354c to baa0487 Compare July 30, 2026 14:18
Comment thread solidity/contracts/lib/UPUPSUpgradeable.sol
Comment thread solidity/contracts/Accounting.sol
@matevz
matevz force-pushed the matevz/feature/simulation-attack-fix branch 2 times, most recently from c1e31aa to 02e1ad7 Compare July 31, 2026 09:20
@matevz
matevz force-pushed the matevz/feature/simulation-attack-fix branch from 02e1ad7 to 6d69f84 Compare July 31, 2026 09:28
@matevz matevz changed the title solidity: Simulation attack fix solidity: Simulated upgrade attack fix Jul 31, 2026
@matevz
matevz marked this pull request as ready for review July 31, 2026 11:33
@matevz
matevz requested a review from uniyalabhishek July 31, 2026 11:33
Comment thread solidity/tasks/deploy.ts

console.log(`Deployed new proposed implementation: ${newImplAddress}`);
}
const deployTx = await hre.upgrades.prepareUpgrade(args.address, Accounting, {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

existing proxies report VERSION == 1, and this PR leaves the available version at 1, so the check above returns before this migration runs.

Comment thread solidity/tasks/deploy.ts
if (args.outputSafe) {
const data = Accounting.interface.encodeFunctionData("upgradeToAndCall", [newImplAddress, "0x"]);
if (!args.outputSafe) {
const txProposeUpgrade = await (await current.proposeUpgrade(newImplAddress, 0)).wait();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

existing proxies do not implement proposeUpgrade, so the first migration reverts before UPUPS is installed? I suggest adding a legacy one-step bootstrap path and a test that starts from the master implementation. similarly below at 294.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Simulated upgrade attack on Privana contracts

2 participants