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
45 changes: 45 additions & 0 deletions test/Account.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,49 @@ contract AccountTest is BaseTest {
uint256 keysCount137 = IthacaAccount(eoaAddress).keyCount();
assertEq(keysCount137, 2, "Keys should be added on chain 137");
}

function testContextKeyHash() public {
DelegatedEOA memory d = _randomEIP7702DelegatedEOA();

PassKey memory key = _randomPassKey();
key.k.isSuperAdmin = true;

vm.prank(d.eoa);
d.d.authorize(key.k);

// Orchestrator workflow
vm.prank(d.d.ORCHESTRATOR());
ERC7821.Call[] memory calls = new ERC7821.Call[](1);
calls[0].data = abi.encodeWithSelector(this.targetFunctionContextKeyHash.selector);
calls[0].to = address(this);
calls[0].value = 0;
bytes memory opData = abi.encode(key.keyHash);
bytes memory executionData = abi.encode(calls, opData);
d.d.execute(_ERC7821_BATCH_EXECUTION_MODE, executionData);

assertEq(contextKeyHash, key.keyHash, "Context key hash mismatch orchestrator workflow");

// Reset context key hash
contextKeyHash = bytes32(0);

// Workflow with opData
uint256 nonce = d.d.getNonce(0);
bytes memory signature = _sig(key, d.d.computeDigest(calls, nonce));
opData = abi.encodePacked(nonce, signature);
executionData = abi.encode(calls, opData);
d.d.execute(_ERC7821_BATCH_EXECUTION_MODE, executionData);

assertEq(contextKeyHash, key.keyHash, "Context key hash mismatch orchestrator workflow");

// Reset context key hash
contextKeyHash = bytes32(0);

// Simple workflow without opData (self-execution)
bytes memory emptyOpData;
executionData = abi.encode(calls, emptyOpData);
vm.prank(address(d.d));
d.d.execute(_ERC7821_BATCH_EXECUTION_MODE, executionData);

assertEq(contextKeyHash, bytes32(0), "Context key hash should be zero for self-execution without opData");
}
}
5 changes: 5 additions & 0 deletions test/Base.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ contract BaseTest is SoladyTest {
EIP7702Proxy eip7702Proxy;
TargetFunctionPayload[] targetFunctionPayloads;
Simulator simulator;
bytes32 contextKeyHash;

struct TargetFunctionPayload {
address by;
Expand Down Expand Up @@ -94,6 +95,10 @@ contract BaseTest is SoladyTest {
targetFunctionPayloads.push(TargetFunctionPayload(msg.sender, msg.value, data));
}

function targetFunctionContextKeyHash() public payable {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice pattern!

contextKeyHash = IthacaAccount(payable(msg.sender)).getContextKeyHash();
}

function _setEIP7702Delegation(address eoa) internal {
vm.etch(eoa, abi.encodePacked(hex"ef0100", address(account)));
}
Expand Down
Loading