Skip to content

Commit

Permalink
update storage namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
jtriley-eth committed Feb 20, 2024
1 parent 5c0e4d3 commit eb29ebf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
10 changes: 5 additions & 5 deletions src/mods/BribeMod.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ contract BribeMod {
/// @dev directives:
/// 01. move nonce from storage to memory
/// 02. return nonce
/// @dev the nonce slot is defined as `keccak256("EtherDeckMk2.Nonce") - 1`
/// @dev the nonce slot is defined as `keccak256("EtherDeckMk2.BribeMod.nonce") - 1`
/// @return nonce the nonce of the runner
function nonce() external view returns (uint256) {
assembly {
mstore(0x00, sload(0x51448ae5f8e845d125c02858a227e28c25f218a7e0050dff756ebd4ae4439c98))
mstore(0x00, sload(0x35cc143ea48486ca62296c4e48389c5f5abbd342fc1b39ad2da3d145f4b0d6bb))

return(0x00, 0x20)
}
Expand Down Expand Up @@ -70,7 +70,7 @@ contract BribeMod {
/// 15. if success, return with returndata
/// 16. else, revert with revertdata
/// @dev sighash is `keccak256(abi.encode(payload, target, callvalue, bribe, nonce))`
/// @dev the nonce slot is defined as `keccak256("EtherDeckMk2.Nonce") - 1`
/// @dev the nonce slot is defined as `keccak256("EtherDeckMk2.BribeMod.nonce") - 1`
/// @param target the call target address
/// @param payload the call payload
/// @param sigdata the ecrecover signature data
Expand All @@ -95,13 +95,13 @@ contract BribeMod {

mstore(add(0x40, payload.length), bribe)

let nonce := sload(0x51448ae5f8e845d125c02858a227e28c25f218a7e0050dff756ebd4ae4439c98)
let nonce := sload(0x35cc143ea48486ca62296c4e48389c5f5abbd342fc1b39ad2da3d145f4b0d6bb)

mstore(add(0x60, payload.length), nonce)

success := and(success, eq(keccak256(0x00, add(0x80, payload.length)), calldataload(sigdata.offset)))

sstore(0x51448ae5f8e845d125c02858a227e28c25f218a7e0050dff756ebd4ae4439c98, add(nonce, 0x01))
sstore(0x35cc143ea48486ca62296c4e48389c5f5abbd342fc1b39ad2da3d145f4b0d6bb, add(nonce, 0x01))

success := and(success, call(gas(), caller(), bribe, 0x00, 0x00, 0x00, 0x00))

Expand Down
14 changes: 7 additions & 7 deletions src/mods/FlashMod.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contract FlashMod {
/// 02. store token in memory
/// 03. store flash fee slot index in memory
/// 04. store the flash fee factor in storage at the slot hash
/// @dev flash fee slot index is defined as `keccak256("EtherDeckMk2.FlashFeeSlotIndex") - 1`
/// @dev flash fee slot index is defined as `keccak256("EtherDeckMk2.FlashMod.flashFeeFactor") - 1`
/// @param token the token to flash
/// @param factor the flash fee factor in `1 / 10_000`
function setFlashFeeFactor(address token, uint256 factor) external {
Expand All @@ -26,7 +26,7 @@ contract FlashMod {

mstore(0x00, token)

mstore(0x20, 0xf1eb8105a4a1127cc7c1f140012e33366c72dd5143314d8de5d93f0cd7b10318)
mstore(0x20, 0xb03bc4f1379300f4f940d278a38ba81c82232501ae1614184a0ce60133d2e677)

sstore(keccak256(0x00, 0x40), factor)
}
Expand All @@ -47,7 +47,7 @@ contract FlashMod {
assembly {
mstore(0x00, token)

mstore(0x20, 0xf1eb8105a4a1127cc7c1f140012e33366c72dd5143314d8de5d93f0cd7b10318)
mstore(0x20, 0xb03bc4f1379300f4f940d278a38ba81c82232501ae1614184a0ce60133d2e677)

let success := iszero(iszero(sload(keccak256(0x00, 0x40))))

Expand All @@ -72,14 +72,14 @@ contract FlashMod {
/// 05. if fee is zero or fee multiplication step overflows, revert
/// 06. finish fee computation, store in memory
/// 07. return flash fee
/// @dev flash fee slot index is defined as `keccak256("EtherDeckMk2.FlashFeeSlotIndex") - 1`
/// @dev flash fee slot index is defined as `keccak256("EtherDeckMk2.FlashMod.flashFeeFactor") - 1`
/// @param token the token to flash
/// @param amount the amount for which to compute the flash fee
function flashFee(address token, uint256 amount) external view returns (uint256) {
assembly {
mstore(0x00, token)

mstore(0x20, 0xf1eb8105a4a1127cc7c1f140012e33366c72dd5143314d8de5d93f0cd7b10318)
mstore(0x20, 0xb03bc4f1379300f4f940d278a38ba81c82232501ae1614184a0ce60133d2e677)

let factor := sload(keccak256(0x00, 0x40))

Expand Down Expand Up @@ -130,7 +130,7 @@ contract FlashMod {
/// 29. store one (true) in memory
/// 30. if success, return true
/// 31. else, revert
/// @dev flash fee slot index is defined as `keccak256("EtherDeckMk2.FlashFeeSlotIndex") - 1`
/// @dev flash fee slot index is defined as `keccak256("EtherDeckMk2.FlashMod.flashFeeFactor") - 1`
/// @dev onFlashLoan return value is defined as `keccak256("ERC3156FlashBorrower.onFlashLoan")`
/// @param receiver the receiver of the flash
/// @param token the token to flash
Expand All @@ -155,7 +155,7 @@ contract FlashMod {

mstore(0x24, token)

mstore(0x44, 0xf1eb8105a4a1127cc7c1f140012e33366c72dd5143314d8de5d93f0cd7b10318)
mstore(0x44, 0xb03bc4f1379300f4f940d278a38ba81c82232501ae1614184a0ce60133d2e677)

let factor := sload(keccak256(0x24, 0x40))

Expand Down
16 changes: 8 additions & 8 deletions src/mods/FlatlineMod.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ contract FlatlineMod {
/// 01. check if caller is runner; revert if not
/// 02. bitpack receiver, interval, and current timestamp into value
/// 03. store value in flatline slot
/// @dev flatline slot is defined as `keccak256("EtherDeckMk2.FlatlineSlot") - 1`
/// @dev flatline slot is defined as `keccak256("EtherDeckMk2.Flatline.contingency") - 1`
/// @dev flatline value is defined as `receiver_u160 . interval_u32 . lastUpdate_u64`
/// @dev setting the interval to zero will disable the contingency
/// @param receiver the address to receive the contingency
Expand All @@ -24,7 +24,7 @@ contract FlatlineMod {

let value := or(timestamp(), or(shl(0x40, interval), shl(0x60, receiver)))

sstore(0x2baf74cad7040289b2b1fedcfd3140834838fbbf2e2d05fd8eb72bdb1660b9d0, value)
sstore(0x08c143f31a8b0ea787fb1fb8e637c8434eafb594d63cf7d1b812d10091c0603c, value)
}
}

Expand All @@ -34,17 +34,17 @@ contract FlatlineMod {
/// 02. load value from flatline slot; cache as value
/// 03. mask lastUpdate from value, set to current timestamp; cache as value
/// 04. store value in flatline slot
/// @dev flatline slot is defined as `keccak256("EtherDeckMk2.FlatlineSlot") - 1`
/// @dev flatline slot is defined as `keccak256("EtherDeckMk2.Flatline.contingency") - 1`
/// @dev flatline value is defined as `receiver_u160 . interval_u32 . lastUpdate_u64`
function checkIn() external {
assembly {
if iszero(eq(caller(), sload(runner.slot))) { revert(0x00, 0x00) }

let value := sload(0x2baf74cad7040289b2b1fedcfd3140834838fbbf2e2d05fd8eb72bdb1660b9d0)
let value := sload(0x08c143f31a8b0ea787fb1fb8e637c8434eafb594d63cf7d1b812d10091c0603c)

value := or(and(value, not(0xffffffffffffffff)), timestamp())

sstore(0x2baf74cad7040289b2b1fedcfd3140834838fbbf2e2d05fd8eb72bdb1660b9d0, value)
sstore(0x08c143f31a8b0ea787fb1fb8e637c8434eafb594d63cf7d1b812d10091c0603c, value)
}
}

Expand All @@ -56,11 +56,11 @@ contract FlatlineMod {
/// 04. check if an interval has passed since last update and that interval is nonzero; revert if not
/// 05. store receiver to runner slot
/// 05. clear flatline slot
/// @dev flatline slot is defined as `keccak256("EtherDeckMk2.FlatlineSlot") - 1`
/// @dev flatline slot is defined as `keccak256("EtherDeckMk2.Flatline.contingency") - 1`
/// @dev flatline value is defined as `receiver_u160 . interval_u32 . lastUpdate_u64`
function contingency() external {
assembly {
let value := sload(0x2baf74cad7040289b2b1fedcfd3140834838fbbf2e2d05fd8eb72bdb1660b9d0)
let value := sload(0x08c143f31a8b0ea787fb1fb8e637c8434eafb594d63cf7d1b812d10091c0603c)

let lastUpdate := and(value, 0xffffffffffffffff)

Expand All @@ -70,7 +70,7 @@ contract FlatlineMod {

sstore(runner.slot, shr(0x60, value))

sstore(0x2baf74cad7040289b2b1fedcfd3140834838fbbf2e2d05fd8eb72bdb1660b9d0, 0x00)
sstore(0x08c143f31a8b0ea787fb1fb8e637c8434eafb594d63cf7d1b812d10091c0603c, 0x00)
}
}
}
6 changes: 3 additions & 3 deletions src/mods/TwoStepTransitionMod.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ contract TwoStepTransitionMod {
/// @dev directives:
/// 01. if caller is not runner, revert
/// 02. store newRunner in newRunner slot
/// @dev newRunner slot is defined as `keccak256("EtherDeckMk2.NewRunner") - 1`
/// @dev newRunner slot is defined as `keccak256("EtherDeckMk2.TwoStepTransitionMod.newRunner") - 1`
function startRunnerTransition(address newRunner) external {
assembly {
if iszero(eq(caller(), sload(runner.slot))) { revert(0x00, 0x00) }

sstore(0x91575d7bad3e5965f801b4ac5f4d48ffddfc86e1a6f2ba31dc5a35148e00e041, newRunner)
sstore(0x1135fd56f406be55915358ca5fba26244b149720a5a3d009d6554ab509882baa, newRunner)
}
}

Expand All @@ -28,7 +28,7 @@ contract TwoStepTransitionMod {
/// 03. store newRunner in runner slot
function acceptRunnerTransition() external {
assembly {
let newRunner := sload(0x91575d7bad3e5965f801b4ac5f4d48ffddfc86e1a6f2ba31dc5a35148e00e041)
let newRunner := sload(0x1135fd56f406be55915358ca5fba26244b149720a5a3d009d6554ab509882baa)

if iszero(eq(newRunner, caller())) { revert(0x00, 0x00) }

Expand Down

0 comments on commit eb29ebf

Please sign in to comment.