forked from sphinx-labs/sphinx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(pg): calculate correct Sphinx Module address for non-zero salt nonce
- Loading branch information
1 parent
a3546a3
commit c3ad210
Showing
12 changed files
with
261 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sphinx-labs/plugins': patch | ||
--- | ||
|
||
Calculate correct Sphinx Module address for non-zero salt nonce |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { ethers } from 'ethers' | ||
import { getSphinxConstants, remove0x } from '@sphinx-labs/contracts' | ||
|
||
/** | ||
* Writes the initcode and expected addresses of all Sphinx system contracts. This allows us to use | ||
* the contracts in Forge tests. | ||
* | ||
* The output can be written to a file by appending this CLI command with: `> fileName.json`. | ||
* | ||
* NOTE: The generated `SphinxInitCode` contract is for testing purposes only. Including it in the | ||
* production Foundry plugin would *significantly* slow down the user's compilation process if | ||
* they're using Yul (i.e. `viaIR`) with the optimizer enabled. It's not necessary for us to use the | ||
* `SphinxInitCode` contract in the production Foundry plugin because we deploy the Sphinx system | ||
* contracts from TypeScript via the `ensureSphinxAndGnosisSafeDeployed` function. | ||
*/ | ||
const writeConstants = async () => { | ||
const sphinxConstants = getSphinxConstants() | ||
|
||
const contractInfo = sphinxConstants.map( | ||
({ artifact, constructorArgs, expectedAddress }) => { | ||
const { abi, bytecode } = artifact | ||
|
||
const iface = new ethers.Interface(abi) | ||
|
||
const creationCode = bytecode.concat( | ||
remove0x(iface.encodeDeploy(constructorArgs)) | ||
) | ||
|
||
return { creationCode, expectedAddress } | ||
} | ||
) | ||
|
||
const solidityFile = | ||
`// SPDX-License-Identifier: MIT\n` + | ||
`pragma solidity >=0.6.2 <0.9.0;\n\n` + | ||
`struct SphinxContractInfo {\n` + | ||
` bytes creationCode;\n` + | ||
` address expectedAddress;\n` + | ||
`}\n\n` + | ||
`contract SphinxInitCode {\n` + | ||
` function getSphinxContractInfo() public pure returns (SphinxContractInfo[] memory) {\n` + | ||
` SphinxContractInfo[] memory contracts = new SphinxContractInfo[](${contractInfo.length});\n` + | ||
`${contractInfo | ||
.map( | ||
({ creationCode, expectedAddress }, i) => | ||
` contracts[${i}] = SphinxContractInfo(hex"${remove0x( | ||
creationCode | ||
)}", ${expectedAddress});` | ||
) | ||
.join('\n')}\n` + | ||
` return contracts;\n }` + | ||
`\n}` | ||
|
||
process.stdout.write(solidityFile) | ||
} | ||
|
||
writeConstants() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "sphinx-forge-std/Test.sol"; | ||
import { Sphinx } from "../../contracts/foundry/Sphinx.sol"; | ||
import { IGnosisSafe } from "@sphinx-labs/contracts/contracts/foundry/interfaces/IGnosisSafe.sol"; | ||
import { SphinxTestUtils } from "../../contracts/test/SphinxTestUtils.sol"; | ||
|
||
contract Sphinx_Test is Test, Sphinx, SphinxTestUtils { | ||
|
||
function setUp() public { | ||
deploySphinxSystem(); | ||
|
||
sphinxConfig.projectName = "test_project"; | ||
sphinxConfig.owners = [0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266]; | ||
sphinxConfig.threshold = 1; | ||
sphinxConfig.orgId = "test-org-id"; | ||
} | ||
|
||
function test_sphinxModule_success_standard() external { | ||
IGnosisSafe safeProxy = IGnosisSafe(deploySphinxModuleAndGnosisSafe(sphinxConfig)); | ||
|
||
(address[] memory modules, ) = safeProxy.getModulesPaginated(address(0x1), 1); | ||
address sphinxModule = modules[0]; | ||
|
||
address expectedAddress = this.sphinxModule(); | ||
|
||
assertEq(expectedAddress, sphinxModule); | ||
} | ||
|
||
function test_sphinxModule_success_nonZeroSaltNonce() external { | ||
sphinxConfig.saltNonce = 1; | ||
IGnosisSafe safeProxy = IGnosisSafe(deploySphinxModuleAndGnosisSafe(sphinxConfig)); | ||
|
||
(address[] memory modules, ) = safeProxy.getModulesPaginated(address(0x1), 1); | ||
address sphinxModule = modules[0]; | ||
|
||
address expectedAddress = this.sphinxModule(); | ||
|
||
assertEq(expectedAddress, sphinxModule); | ||
} | ||
} |
Oops, something went wrong.