Skip to content

Commit

Permalink
fix: use unchecked at safe places to reduce bytecode size
Browse files Browse the repository at this point in the history
  • Loading branch information
xenide committed Jan 8, 2025
1 parent 1732564 commit b45664a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
solc = "0.8.28"
evm_version = "cancun"
via_ir = true
bytecode_hash = "none"
bytecode_hash = "ipfs"
optimizer_runs = 1_000_000
gas_limit = "18446744073709551615"
libs = ['lib']
Expand Down
6 changes: 3 additions & 3 deletions script/optimized-deployer-meta
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"constant_product_hash": "0xddd075b1901512190892da217db5c4d266a6831226e14669e690aeb663dd9cf3",
"factory_hash": "0x87b0f73fafcf4bb41e013c8423dc679f6885527007d6c3f1e1834a670cbaadc5",
"stable_hash": "0xa52a6e20c3811c44bda8bc9f7988dd62da3c611711900f85d465b64bf97066af"
"constant_product_hash": "0x174b1bf04c1051e9d50d64a3c3b35666a4473b5994955635039d64ef9da69e97",
"factory_hash": "0x03107ee57e3054504c8ec584092f9d955bec0cbd1225fa1a8fb090a2084335aa",
"stable_hash": "0xf4d1335e5817123c66d1e76ef6f1fb5a767ef362f9005e0be256d01176994096"
}
6 changes: 3 additions & 3 deletions script/unoptimized-deployer-meta
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"constant_product_hash": "0x903212fc8445706a81c9527fb7fdbb940f030132904209befdddbc617d8bbc47",
"factory_hash": "0x09a9ce1ed77c95be4842dddd771939e048b8bfe2837863be3a2766b1c13ea5a2",
"stable_hash": "0x54471d136002bf755956dcaefd3f0450ba1596532ca57cc84f6c9d774002f4d3"
"constant_product_hash": "0x4cca74e4aab53779dc7f4f91ab12a3460cc34bae518a286b4ecd7fd16c0f193c",
"factory_hash": "0xc5e6cd61c86f3ff115d416548099141eb8fa9ede05aebf8f748e14f0b2cecfb4",
"stable_hash": "0x9fefafb4b596813d280a5fdeee37fc998c79303f69e4a638c7244e29bd1e1ad7"
}
6 changes: 3 additions & 3 deletions src/ReservoirDeployer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ contract ReservoirDeployer {
uint256 public step = 0;

// Bytecode hashes.
bytes32 public constant FACTORY_HASH = bytes32(0x87b0f73fafcf4bb41e013c8423dc679f6885527007d6c3f1e1834a670cbaadc5);
bytes32 public constant FACTORY_HASH = bytes32(0x03107ee57e3054504c8ec584092f9d955bec0cbd1225fa1a8fb090a2084335aa);
bytes32 public constant CONSTANT_PRODUCT_HASH =
bytes32(0xddd075b1901512190892da217db5c4d266a6831226e14669e690aeb663dd9cf3);
bytes32 public constant STABLE_HASH = bytes32(0xa52a6e20c3811c44bda8bc9f7988dd62da3c611711900f85d465b64bf97066af);
bytes32(0x174b1bf04c1051e9d50d64a3c3b35666a4473b5994955635039d64ef9da69e97);
bytes32 public constant STABLE_HASH = bytes32(0xf4d1335e5817123c66d1e76ef6f1fb5a767ef362f9005e0be256d01176994096);

// Deployment addresses.
GenericFactory public factory;
Expand Down
9 changes: 7 additions & 2 deletions src/curve/stable/StablePair.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ contract StablePair is ReservoirPair {
function rampA(uint64 aFutureARaw, uint64 aFutureATime) external onlyFactory {
require(aFutureARaw >= StableMath.MIN_A && aFutureARaw <= StableMath.MAX_A, InvalidA());

uint64 lFutureAPrecise = aFutureARaw * uint64(StableMath.A_PRECISION);
uint64 lFutureAPrecise;
unchecked {
lFutureAPrecise = aFutureARaw * uint64(StableMath.A_PRECISION);
}

uint256 duration = aFutureATime - block.timestamp;
require(duration >= StableMath.MIN_RAMP_TIME, InvalidDuration());
Expand Down Expand Up @@ -368,7 +371,9 @@ contract StablePair is ReservoirPair {

/// @dev number of coins in the pool multiplied by A precise
function _getNA() internal view returns (uint256) {
return 2 * _getCurrentAPrecise();
unchecked {
return 2 * _getCurrentAPrecise();
}
}

function getCurrentA() external view returns (uint64) {
Expand Down

0 comments on commit b45664a

Please sign in to comment.