Skip to content

Commit 6de01c6

Browse files
fix: add staker address to DEPOSIT typehash (#424)
This provides additional signature replay protection for the `StrategyManager.depositIntoStrategyWithSignature` method Specifically, it addresses the issue outlined in https://mirror.xyz/curiousapple.eth/pFqAdW2LiJ-6S4sg_u1z08k4vK6BCJ33LcyXpnNb8yU where some ERC1271 wallets might be vulnerable to "replays" of signatures While the theoretical "damage" would be ~zero (allowing someone to deposit and credit the deposit to a user), adding this field to the typehash seems to be best practice, at least.
1 parent 7511559 commit 6de01c6

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

src/contracts/core/StrategyManager.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ contract StrategyManager is
146146
require(expiry >= block.timestamp, "StrategyManager.depositIntoStrategyWithSignature: signature expired");
147147
// calculate struct hash, then increment `staker`'s nonce
148148
uint256 nonce = nonces[staker];
149-
bytes32 structHash = keccak256(abi.encode(DEPOSIT_TYPEHASH, strategy, token, amount, nonce, expiry));
149+
bytes32 structHash = keccak256(abi.encode(DEPOSIT_TYPEHASH, staker, strategy, token, amount, nonce, expiry));
150150
unchecked {
151151
nonces[staker] = nonce + 1;
152152
}

src/contracts/core/StrategyManagerStorage.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ abstract contract StrategyManagerStorage is IStrategyManager {
1919
keccak256("EIP712Domain(string name,uint256 chainId,address verifyingContract)");
2020
/// @notice The EIP-712 typehash for the deposit struct used by the contract
2121
bytes32 public constant DEPOSIT_TYPEHASH =
22-
keccak256("Deposit(address strategy,address token,uint256 amount,uint256 nonce,uint256 expiry)");
22+
keccak256("Deposit(address staker,address strategy,address token,uint256 amount,uint256 nonce,uint256 expiry)");
2323
// maximum length of dynamic arrays in `stakerStrategyList` mapping, for sanity's sake
2424
uint8 internal constant MAX_STAKER_STRATEGY_LIST_LENGTH = 32;
2525

src/test/integration/User.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ contract User_AltMethods is User {
432432
// Get signature
433433
uint256 nonceBefore = strategyManager.nonces(address(this));
434434
bytes32 structHash = keccak256(
435-
abi.encode(strategyManager.DEPOSIT_TYPEHASH(), strat, underlyingToken, tokenBalance, nonceBefore, expiry)
435+
abi.encode(strategyManager.DEPOSIT_TYPEHASH(), address(this), strat, underlyingToken, tokenBalance, nonceBefore, expiry)
436436
);
437437
bytes32 digestHash = keccak256(abi.encodePacked("\x19\x01", strategyManager.domainSeparator(), structHash));
438438
bytes memory signature = bytes(abi.encodePacked(digestHash)); // dummy sig data

src/test/unit/StrategyManagerUnit.t.sol

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ contract StrategyManagerUnitTests is EigenLayerUnitTestSetup, IStrategyManagerEv
153153

154154
{
155155
bytes32 structHash = keccak256(
156-
abi.encode(strategyManager.DEPOSIT_TYPEHASH(), dummyStrat, dummyToken, amount, nonceBefore, expiry)
156+
abi.encode(strategyManager.DEPOSIT_TYPEHASH(), staker, dummyStrat, dummyToken, amount, nonceBefore, expiry)
157157
);
158158
bytes32 digestHash = keccak256(abi.encodePacked("\x19\x01", strategyManager.domainSeparator(), structHash));
159159

@@ -511,7 +511,7 @@ contract StrategyManagerUnitTests_depositIntoStrategyWithSignature is StrategyMa
511511

512512
{
513513
bytes32 structHash = keccak256(
514-
abi.encode(strategyManager.DEPOSIT_TYPEHASH(), strategy, token, amount, nonceBefore, expiry)
514+
abi.encode(strategyManager.DEPOSIT_TYPEHASH(), staker, strategy, token, amount, nonceBefore, expiry)
515515
);
516516
bytes32 digestHash = keccak256(abi.encodePacked("\x19\x01", strategyManager.domainSeparator(), structHash));
517517

@@ -582,7 +582,7 @@ contract StrategyManagerUnitTests_depositIntoStrategyWithSignature is StrategyMa
582582

583583
{
584584
bytes32 structHash = keccak256(
585-
abi.encode(strategyManager.DEPOSIT_TYPEHASH(), strategy, token, amount, nonceBefore, expiry)
585+
abi.encode(strategyManager.DEPOSIT_TYPEHASH(), staker, strategy, token, amount, nonceBefore, expiry)
586586
);
587587
bytes32 digestHash = keccak256(abi.encodePacked("\x19\x01", strategyManager.domainSeparator(), structHash));
588588

@@ -638,7 +638,7 @@ contract StrategyManagerUnitTests_depositIntoStrategyWithSignature is StrategyMa
638638

639639
{
640640
bytes32 structHash = keccak256(
641-
abi.encode(strategyManager.DEPOSIT_TYPEHASH(), dummyStrat, revertToken, amount, nonceBefore, expiry)
641+
abi.encode(strategyManager.DEPOSIT_TYPEHASH(), staker, dummyStrat, revertToken, amount, nonceBefore, expiry)
642642
);
643643
bytes32 digestHash = keccak256(abi.encodePacked("\x19\x01", strategyManager.domainSeparator(), structHash));
644644

@@ -713,7 +713,7 @@ contract StrategyManagerUnitTests_depositIntoStrategyWithSignature is StrategyMa
713713

714714
{
715715
bytes32 structHash = keccak256(
716-
abi.encode(strategyManager.DEPOSIT_TYPEHASH(), strategy, token, amount, nonceBefore, expiry)
716+
abi.encode(strategyManager.DEPOSIT_TYPEHASH(), staker, strategy, token, amount, nonceBefore, expiry)
717717
);
718718
bytes32 digestHash = keccak256(abi.encodePacked("\x19\x01", strategyManager.domainSeparator(), structHash));
719719

@@ -753,7 +753,7 @@ contract StrategyManagerUnitTests_depositIntoStrategyWithSignature is StrategyMa
753753

754754
{
755755
bytes32 structHash = keccak256(
756-
abi.encode(strategyManager.DEPOSIT_TYPEHASH(), strategy, token, amount, nonceBefore, expiry)
756+
abi.encode(strategyManager.DEPOSIT_TYPEHASH(), staker, strategy, token, amount, nonceBefore, expiry)
757757
);
758758
bytes32 digestHash = keccak256(abi.encodePacked("\x19\x01", strategyManager.domainSeparator(), structHash));
759759

0 commit comments

Comments
 (0)