Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,6 @@ Then, the test suite can be run with:
pnpm run test
```

#### Address Mismatch

Many of the contracts (e.g. callbacks) require a specific address prefix or have a deterministic address. If tests are failing for this reason, the cause is usually one of:

- The code of a callback contract has been changed
- This requires re-generating the salt for the contract. See the [test_salts.sh](/script/salts/test/test_salts.sh) script.
- There has been a change to the dependencies under `/lib` or `/dependencies`. The dependencies affect the build output, so any changes will affect the bytecode generated by the Solidity compiler.
- If the change was inadvertent, this can be fixed by running `pnpm install` to reset the changes.
- If the change to dependencies and invalidation of salts is expected, then new salts must be generated. In some cases (such as Uniswap V2 and V3 factories), the new addresses must be recorded in the `Constants.sol` file.

### Format

Combines `forge fmt` and `solhint`
Expand Down
10 changes: 5 additions & 5 deletions deployments/.berachain-v1.0.3.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"deployments.BatchAuctionHouse": "0xBA0000907c7812AEC8F7e9e27AefF4Ea7565A8bA",
"deployments.BatchCatalogue": "0x30c356DFBAc808BC62c860A9B285f024b40dF1fc",
"deployments.auctionModules.EncryptedMarginalPrice": "0x053219a03D5Bb08B8EeC2BB9743F723b312A1cE3",
"deployments.auctionModules.FixedPriceBatch": "0xe6c04Ce6ca70eeE60bEc40E2e6e62958D91E02CC",
"deployments.derivativeModules.BatchLinearVesting": "0xE292cF4e316191CbFEbD74909356DF3cd9455e96"
"deployments.BatchAuctionHouse": "0xBA0000907c7812AEC8F7e9e27AefF4Ea7565A8bA",
"deployments.BatchCatalogue": "0x30c356DFBAc808BC62c860A9B285f024b40dF1fc",
"deployments.auctionModules.EncryptedMarginalPrice": "0x053219a03D5Bb08B8EeC2BB9743F723b312A1cE3",
"deployments.auctionModules.FixedPriceBatch": "0xe6c04Ce6ca70eeE60bEc40E2e6e62958D91E02CC",
"deployments.derivativeModules.BatchLinearVesting": "0xE292cF4e316191CbFEbD74909356DF3cd9455e96"
}
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ forge-std = "1.9.1"
solmate = "6.8.0"
solady = "0.0.124"
"@openzeppelin-contracts" = "4.9.2"
clones-with-immutable-args = { version = "1.1.1", git = "git@github.com:wighawag/clones-with-immutable-args.git", rev = "f5ca191afea933d50a36d101009b5644dc28bc99" }
clones-with-immutable-args = { version = "1.1.1", git = "https://github.com/wighawag/clones-with-immutable-args.git", rev = "f5ca191afea933d50a36d101009b5644dc28bc99" }
3 changes: 3 additions & 0 deletions script/deploy/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
# RPC_URL: URL for the RPC node. Should be specified in .env.
# VERIFIER_URL: URL for the Etherscan API verifier. Should be specified when used on an unsupported chain.

# Exit on error
set -e

# Iterate through named arguments
# Source: https://unix.stackexchange.com/a/388038
while [ $# -gt 0 ]; do
Expand Down
3 changes: 3 additions & 0 deletions script/deploy/write_deployment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# ./write_deployment.sh <key> <value>
# Updates the env.json file with the key-value pair

# Exit on error
set -e

# Get command-line arguments
KEY=$1
VALUE=$2
Expand Down
3 changes: 3 additions & 0 deletions script/install.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

# Exit on error
set -e

# echo ""
# echo "*** Setting up submodules"
# git submodule init
Expand Down
3 changes: 3 additions & 0 deletions script/publish.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

# Exit on error
set -e

# This script is used to release a new version of the package. It will:
# - Validate that the working directory is clean
# - Validate the version number argument
Expand Down
20 changes: 0 additions & 20 deletions script/salts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,6 @@ This document provides instructions on how to generate and use salts for CREATE2

## Tasks

### Generating Test Salts

Many of the tests use salts to deploy callbacks at addresses with a specific prefix. Changes to the state variables in the test contract can require the re-generation of the salt. To do so, perform the following:

```bash
./script/salts/test/test_salts.sh --saltKey <SALT_KEY>
```

For example, if re-generating salts for the `MockCallback` contract, make the following call:

```bash
./script/salts/test/test_salts.sh --saltKey MockCallback
```

The resulting salts will be written to the `./script/salts/salts.json` file, which the test cases will read from.

Notes:

- When re-generating salts, ensure that any git submodule changes are either reverted or committed. For example, if switching from a branch with a particular submodule to a branch in which that submodule is not present, the submodule changes will not be automatically reverted. This will cause changes in the generated bytecode and in turn, the salt. The submodule changes must be reverted and the salts generated afterwards.

### Generating AuctionHouse Salts

For aesthetic reasons, the AuctionHouse contracts may need to be deployed at deterministic addresses.
Expand Down
60 changes: 50 additions & 10 deletions script/salts/WithSalts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,18 @@ contract WithSalts is Script {
}

function _getBytecodePath(
string memory name_
string memory name_,
bytes32 bytecodeHash_
) internal pure returns (string memory) {
return string.concat(_getBytecodeDirectory(), "/", name_, ".bin");
return string.concat(
_getBytecodeDirectory(), "/", name_, "-", vm.toString(bytecodeHash_), ".bin"
);
}

function _createBytecodeDirectory() internal {
// Create the bytecode folder if it doesn't exist
if (!vm.isDir(_getBytecodeDirectory())) {
console2.log("Creating bytecode directory");

string[] memory inputs = new string[](2);
inputs[0] = "mkdir";
inputs[1] = _BYTECODE_DIR;

vm.ffi(inputs);
vm.createDir(_getBytecodeDirectory(), true);
}
}

Expand All @@ -44,12 +41,55 @@ contract WithSalts is Script {
bytes memory bytecode = abi.encodePacked(creationCode_, contractArgs_);
bytecodeHash = keccak256(bytecode);

bytecodePath = _getBytecodePath(contractName_);
bytecodePath = _getBytecodePath(contractName_, bytecodeHash);

// Don't write the bytecode if it already exists
if (vm.isFile(bytecodePath)) {
console2.log("Skipping bytecode write for ", contractName_);
return (bytecodePath, bytecodeHash);
}

_createBytecodeDirectory();
vm.writeFile(bytecodePath, vm.toString(bytecode));

return (bytecodePath, bytecodeHash);
}

function _generateSalt(
string memory contractName_,
bytes memory creationCode_,
bytes memory contractArgs_,
string memory prefix_
) internal returns (bytes32) {
// Write the bytecode
(string memory bytecodePath, bytes32 bytecodeHash) =
_writeBytecode(contractName_, creationCode_, contractArgs_);

// Call the salts script to generate and return the salt
string[] memory inputs = new string[](9);
inputs[0] = "./script/salts/generate_salt.sh";
inputs[1] = "--bytecodeFile";
inputs[2] = bytecodePath;
inputs[3] = "--bytecodeHash";
inputs[4] = vm.toString(bytecodeHash);
inputs[5] = "--prefix";
inputs[6] = prefix_;

bytes memory output = vm.ffi(inputs);
console2.log("Salt generated for", contractName_, "with prefix", prefix_);
console2.logBytes32(bytes32(output));

return bytes32(output);
}

function _getTestSalt(
string memory contractName_,
bytes memory creationCode_,
bytes memory contractArgs_
) internal returns (bytes32) {
return _getSalt(string.concat("Test_", contractName_), creationCode_, contractArgs_);
}

/// @notice Gets the salt for a given key
/// @dev If the key is not found, the function will return `bytes32(0)`.
///
Expand Down
60 changes: 60 additions & 0 deletions script/salts/generate_salt.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

# Usage:
# ./generate_salt.sh --bytecode <bytecode file> --prefix <prefix> --bytecodeHash <bytecode hash> [--deployer <deployer>]

# Exit on error
set -e

# Iterate through named arguments
# Source: https://unix.stackexchange.com/a/388038
while [ $# -gt 0 ]; do
if [[ $1 == *"--"* ]]; then
v="${1/--/}"
declare $v="$2"
fi

shift
done

# Check if bytecodeFile is set
if [ -z "$bytecodeFile" ]
then
echo "No bytecode file specified. Provide the relative path after the command."
exit 1
fi

# Check if bytecodeFile exists
if [ ! -f "$bytecodeFile" ]
then
echo "Bytecode file ($bytecodeFile) not found. Provide the correct relative path after the command."
exit 1
fi

# Check if prefix is set
if [ -z "$prefix" ]
then
echo "No prefix specified. Provide the prefix after the bytecode file."
exit 1
fi

# Check if bytecodeHash is set
if [ -z "$bytecodeHash" ]
then
echo "No args hash specified. Provide the args hash after the salt key."
exit 1
fi

DEPLOYER_FLAG=""
if [ ! -z "$deployer" ]
then
DEPLOYER_FLAG="--deployer $deployer"
fi

# Generate salt using cast create2
output=$(cast create2 --case-sensitive --starts-with $prefix --init-code $(cat $bytecodeFile) $DEPLOYER_FLAG)

# Get the first salt (as cast will often return the same salt multiple times)
salt=$(echo "$output" | grep 'Salt: ' | head -n 1 | awk -F' ' '{print $2}')

echo "$salt"
20 changes: 0 additions & 20 deletions script/salts/salts.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,5 @@
"0xcad29ef747f1a7ad12c1e5e715ac675f8534c0d3682dfddfa39287ae7b7d7f01": "0x761de87b1ea43dc2f84665b59b2ce8498c1a09458e3a89751578be7c72811114",
"0xf7e1693ed561ec566275117c8ea944263f9f801df4d4c61e4a934b7152f36dcc": "0x0b3e7731b05ed1f6d2cbbc4e64b503b8582801ae807ee756b3472916ec29c6fb",
"0xf877dc218ee7538ffb3ad6f8fd1b4694cbb6f38d9e0b7a4d9a19ace3c24830a2": "0xad2a1f39589d55fd4fb667bda19d168106901d33100bb9c50fc57b1735024bcd"
},
"Test_MockCallback": {
"0x122b7366cd1ef2d5b4e5301e1905912ec0fe8b73e77aee436d38421a86d15313": "0x0a9151c7b46dc91425f2a34eb6b2fb33ee191550a9165830ae27877b3f4ca221",
"0x31839cd002be9d58c711006d802d11286e56601f846dda258f2e3a3d6312e9d5": "0x413ec56e5cda12c513a637af386dc614c6d8d4cd3332147aa3c1e8a384357a78",
"0x3906ecd77f3b4704ca6c6d5a06ecf7039c68312b200ade661f6d2a28098049e1": "0xe9927b53dc310098994a46e7f6c2cd5104b776f99b91115eece80ec5f8acebe8",
"0x525f9fb7cb93f53509d24ec2f82f9d832e21209c45978e2e315915d6ff8c6a7f": "0xe900d098e9a5d9bb11ba2a3667b6b1eeae83814fe553bb76e514cf5b3fa7a2ac",
"0x54a5ad7b0937b5a5876975ca86a146047356b10210457afbbe77c13e6f5dd954": "0x8c917d14c4e8991eb770603f76c7a2ee6ec9938465f1b8e3c4bc144066179dac",
"0x6205fbf29817ca90fa2498c5b1187af9359d49f9386e35ba328382bcaa131cc3": "0x360e652e5304ee51b6e45d13472e12154037096162a58739e9407aae45926f01",
"0x678385a33025444b4cc1bb4114e4f2b91518f7b62874b3dc9c42cc273c353cb9": "0x55c1bb8e1768f6374b0d715192f3a4623af7018e5c4ccfae641766ff58ef6f53",
"0x780f4d36b46e5c008598b23b91a1a33d3a6d9a009ab4e7d1ec6c4fd0b96ae27e": "0x2e795045262fbbed80e54de0ee9a59506de844b46ffdcbf2fbfe6d2cb7bf6247",
"0x7dceb7e223c0a4949e5e2af68c3896c5549e9d942a7c0a2f82de4b4f1048467f": "0x384c9eafa40ee73af86d2d4fafdfd1ee31e06696f2c23a0c1d18b0e8785b6ce1",
"0x7fdc727348e9937fdf4d1ce371e33669ccd01a66514298047926c8cf38059721": "0x67567fd2ac4f9e05bda2cd306f73bb75aec8f0ce6ea6a60f00665b3ba7440b62",
"0x804b4adedbf071a753a22b7f14d78b78c9417097e5826cae690132d4b0d1598b": "0x8bb2239f825595560b0a31bb2bf07b18cd578df9dfb500b00c386eac3fd8b609",
"0x97c630af696c3e707d37a9df6f374aa2de8cbad3b57d70fd716c420aff85ee21": "0x32dbea5832194b7fa3c189f428b3abd9be5dc93d536c7799e7dbe122f0b9da89",
"0xb7e994be576e566138244c31d8ed1a61a2c2326f7850970f250734441540ba47": "0x3c1a8efebca923e4a1cdc651c554d06a3548e7929d0c7971866bf59b7d6571b3",
"0xb8efc6c465a7b9a95be1d788850dc2fc5372dc35032c8128b1ffec136000ed33": "0xb31bd2f0dada0bf7ceae9b37708c9329967684b9b73b7cc4a99027477b46b132",
"0xbc04d3cb883befcd89fc74569e56a84bf7adb63ae3864cbd1c11314d21c1355a": "0x4783fc51f9862eb57357966692ae70dd540e68ea0848903b77500534194b7f1c",
"0xc0c056f15966bf95b1fe024d064fdf5dc1ff953912a563bc162ff480bb29829d": "0x2eaeb172f8893ca0778cc5470e73f871ffc45825607e7fc37e15db3c369898a8",
"0xc51d6c63ad7dee6c11da98be8f32ac5ca7df37533c82928856a61da22d2e15dd": "0x19ce56b3efb04248482e4368f2063c9ea6f0ca1cedaced0737fa06ece52c43e1",
"0xdf57220126314faa7501d1bf9080691a765b85dcd73ddbc413ad43a5981beb82": "0x4be72c05d6c702b486af22bf4f9a29e0c0c466b036fee37355e9e7fb7c67b66d"
}
}
Loading
Loading