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
3 changes: 2 additions & 1 deletion script/BatchCallAndSponsor.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ contract BatchCallAndSponsorScript is Script {
for (uint256 i = 0; i < calls.length; i++) {
encodedCalls = abi.encodePacked(encodedCalls, calls[i].to, calls[i].value, calls[i].data);
}
bytes32 digest = keccak256(abi.encodePacked(BatchCallAndSponsor(ALICE_ADDRESS).nonce(), encodedCalls));
bytes32 digest =
keccak256(abi.encodePacked(block.chainid, BatchCallAndSponsor(ALICE_ADDRESS).nonce(), encodedCalls));
(uint8 v, bytes32 r, bytes32 s) = vm.sign(ALICE_PK, MessageHashUtils.toEthSignedMessageHash(digest));
bytes memory signature = abi.encodePacked(r, s, v);

Expand Down
3 changes: 2 additions & 1 deletion src/BatchCallAndSponsor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
* 2. Directly by the smart account: When the account itself (i.e. address(this)) calls the function, no signature is required.
*
* Replay protection is achieved by using a nonce that is included in the signed message.
* Cross chain replay protection is achieved by using the chainid in the signed message.
*/
contract BatchCallAndSponsor {
using ECDSA for bytes32;
Expand Down Expand Up @@ -51,7 +52,7 @@ contract BatchCallAndSponsor {
for (uint256 i = 0; i < calls.length; i++) {
encodedCalls = abi.encodePacked(encodedCalls, calls[i].to, calls[i].value, calls[i].data);
}
bytes32 digest = keccak256(abi.encodePacked(nonce, encodedCalls));
bytes32 digest = keccak256(abi.encodePacked(block.chainid, nonce, encodedCalls));

bytes32 ethSignedMessageHash = MessageHashUtils.toEthSignedMessageHash(digest);

Expand Down
5 changes: 3 additions & 2 deletions test/BatchCallAndSponsor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ contract BatchCallAndSponsorTest is Test {
encodedCalls = abi.encodePacked(encodedCalls, calls[i].to, calls[i].value, calls[i].data);
}

bytes32 digest = keccak256(abi.encodePacked(BatchCallAndSponsor(ALICE_ADDRESS).nonce(), encodedCalls));
bytes32 digest =
keccak256(abi.encodePacked(block.chainid, BatchCallAndSponsor(ALICE_ADDRESS).nonce(), encodedCalls));

(uint8 v, bytes32 r, bytes32 s) = vm.sign(ALICE_PK, MessageHashUtils.toEthSignedMessageHash(digest));
bytes memory signature = abi.encodePacked(r, s, v);
Expand Down Expand Up @@ -171,7 +172,7 @@ contract BatchCallAndSponsorTest is Test {
vm.attachDelegation(signedDelegation);

uint256 nonceBefore = BatchCallAndSponsor(ALICE_ADDRESS).nonce();
bytes32 digest = keccak256(abi.encodePacked(nonceBefore, encodedCalls));
bytes32 digest = keccak256(abi.encodePacked(block.chainid, nonceBefore, encodedCalls));
(uint8 v, bytes32 r, bytes32 s) = vm.sign(ALICE_PK, MessageHashUtils.toEthSignedMessageHash(digest));
bytes memory signature = abi.encodePacked(r, s, v);

Expand Down