Commit da17f609 authored by Maurelian's avatar Maurelian

feat(ctb): Working signature recording

parent 0d9784bf
...@@ -15,12 +15,11 @@ contract LivenessGuard is SignatureDecoder, BaseGuard { ...@@ -15,12 +15,11 @@ contract LivenessGuard is SignatureDecoder, BaseGuard {
} }
/// @notice We just need to satisfy the BaseGuard interfae, but we don't actually need to use this method. /// @notice We just need to satisfy the BaseGuard interfae, but we don't actually need to use this method.
function checkAfterExecution(bytes32 txHash, bool success) external { function checkAfterExecution(bytes32, bool) external pure {
return; return;
} }
/// @notice This checkTransaction implementation records the most recent time which any owner has signed a /// @notice Records the most recent time which any owner has signed a transaction.
/// transaction.
function checkTransaction( function checkTransaction(
address to, address to,
uint256 value, uint256 value,
...@@ -32,7 +31,7 @@ contract LivenessGuard is SignatureDecoder, BaseGuard { ...@@ -32,7 +31,7 @@ contract LivenessGuard is SignatureDecoder, BaseGuard {
address gasToken, address gasToken,
address payable refundReceiver, address payable refundReceiver,
bytes memory signatures, bytes memory signatures,
address msgSender address
) )
external external
{ {
...@@ -43,7 +42,7 @@ contract LivenessGuard is SignatureDecoder, BaseGuard { ...@@ -43,7 +42,7 @@ contract LivenessGuard is SignatureDecoder, BaseGuard {
} }
// This is a bit of a hack, maybe just replicate the functionality here rather than calling home // This is a bit of a hack, maybe just replicate the functionality here rather than calling home
bytes memory txHashData = Safe(payable(msg.sender)).encodeTransactionData( bytes32 txHash = Safe(payable(msg.sender)).getTransactionHash(
// Transaction info // Transaction info
to, to,
value, value,
...@@ -56,23 +55,22 @@ contract LivenessGuard is SignatureDecoder, BaseGuard { ...@@ -56,23 +55,22 @@ contract LivenessGuard is SignatureDecoder, BaseGuard {
gasToken, gasToken,
refundReceiver, refundReceiver,
// Signature info // Signature info
Safe(payable(msg.sender)).nonce() // check that this works
); );
address[] memory signers = _getNSigners(keccak256(txHashData), signatures); address[] memory signers = _getNSigners(txHash, signatures);
for (uint256 i = 0; i < signers.length; i++) { for (uint256 i = 0; i < signers.length; i++) {
lastSigned[signers[i]] = block.timestamp; lastSigned[signers[i]] = block.timestamp;
} }
} }
function _getNSigners(bytes32 dataHash, bytes memory signatures) internal returns (address[] memory _owners) { /// @notice Exctract the signers from a set of signatures.
uint256 numSignatures = signatures.length / 65; // division OK? function _getNSigners(bytes32 dataHash, bytes memory signatures) internal pure returns (address[] memory _owners) {
uint256 numSignatures = signatures.length / 65;
_owners = new address[](numSignatures); _owners = new address[](numSignatures);
// The following code is extracted from the Safe.checkNSignatures() method. It removes the signature validation /// The following code is extracted from the Safe.checkNSignatures() method. It removes the signature
// code, /// validation code, and keeps only the parsing code necessary to extract the owner addresses from the
// and keeps only the parsing code necessary to extract the owner addresses from the signatures. /// signatures. We do not double check if the owner derived from a signature is valid. As this is handled
// We do not double check if the owner derived from a signature is valid. As tHis is handled in /// in the final require statement of Safe.checkNSignatures().
// the final require statement of Safe.checkNSignatures().
address currentOwner; address currentOwner;
uint8 v; uint8 v;
bytes32 r; bytes32 r;
......
...@@ -27,7 +27,7 @@ contract LivnessGuard_TestInit is Test, SafeTestTools { ...@@ -27,7 +27,7 @@ contract LivnessGuard_TestInit is Test, SafeTestTools {
function setUp() public { function setUp() public {
safeInstance = _setupSafe(); safeInstance = _setupSafe();
livenessGuard = new LivenessGuard(safeInstance.safe); livenessGuard = new LivenessGuard(safeInstance.safe);
safeInstance.enableModule(address(livenessGuard)); safeInstance.setGuard(address(livenessGuard));
} }
} }
...@@ -37,7 +37,6 @@ contract LivnessGuard_TestCheckTx is LivnessGuard_TestInit { ...@@ -37,7 +37,6 @@ contract LivnessGuard_TestCheckTx is LivnessGuard_TestInit {
function test_checkTransaction_succeeds() external { function test_checkTransaction_succeeds() external {
safeInstance.execTransaction({ to: address(1111), value: 0, data: hex"abba" }); safeInstance.execTransaction({ to: address(1111), value: 0, data: hex"abba" });
// bug signers need to be sorted from low to high
for (uint256 i; i < safeInstance.owners.length; i++) { for (uint256 i; i < safeInstance.owners.length; i++) {
assertEq(livenessGuard.lastSigned(safeInstance.owners[i]), block.timestamp); assertEq(livenessGuard.lastSigned(safeInstance.owners[i]), block.timestamp);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment