Skip to content

Commit 6654484

Browse files
[hebao-v2] Support signature without signatureType (#2627)
* [hebao-v2] Support signature without signatureType * fix * optimize ReentantGuard * feedback * add test * update * add proxy test * revert changes in ReenTrancyGuard * update
1 parent f894f93 commit 6654484

File tree

5 files changed

+155
-31641
lines changed

5 files changed

+155
-31641
lines changed

packages/hebao_v2/contracts/lib/SignatureUtil.sol

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,31 +115,32 @@ library SignatureUtil
115115
return false;
116116
}
117117

118-
uint signatureTypeOffset = signature.length.sub(1);
119-
SignatureType signatureType = SignatureType(signature.toUint8(signatureTypeOffset));
118+
require(signature.length == 65 || signature.length == 66, "INVALID_SIGNATURE_LENGTH");
120119

121-
// Strip off the last byte of the signature by updating the length
122-
assembly {
123-
mstore(signature, signatureTypeOffset)
124-
}
120+
bool trimmed = false;
121+
if (signature.length == 66) {
122+
// Strip off the last byte of the signature by updating the length
123+
assembly {
124+
mstore(signature, 65)
125+
}
125126

126-
if (signatureType == SignatureType.EIP_712) {
127-
success = (signer == recoverECDSASigner(signHash, signature));
128-
} else if (signatureType == SignatureType.ETH_SIGN) {
127+
trimmed = true;
128+
}
129+
130+
success = (signer == recoverECDSASigner(signHash, signature));
131+
if (!success) {
129132
bytes32 hash = keccak256(
130133
abi.encodePacked("\x19Ethereum Signed Message:\n32", signHash)
131134
);
132135
success = (signer == recoverECDSASigner(hash, signature));
133-
} else {
134-
success = false;
135-
}
136-
137-
// Restore the signature length
138-
assembly {
139-
mstore(signature, add(signatureTypeOffset, 1))
140136
}
141137

142-
return success;
138+
if (trimmed) {
139+
// Restore the signature length
140+
assembly {
141+
mstore(signature, 66)
142+
}
143+
}
143144
}
144145

145146
function verifyERC1271Signature(

packages/hebao_v2/hardhat.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ export default {
4040
accounts: loadTestAccounts()
4141
},
4242

43+
optimistic: {
44+
chainId: 420,
45+
url: 'http://127.0.0.1:8545',
46+
gas: 6700000,
47+
accounts: { mnemonic: 'test test test test test test test test test test test junk' }
48+
},
49+
4350
// HttpNetworkConfig
4451
ganache: {
4552
chainId: 31337,

0 commit comments

Comments
 (0)