Added support for flatsigs
This commit is contained in:
@@ -35,9 +35,7 @@ abstract contract BaseUtils is
|
||||
|
||||
function _signerCheck(
|
||||
bytes32 _message,
|
||||
bytes32 _r,
|
||||
bytes32 _s,
|
||||
uint8 _v
|
||||
bytes calldata _signature
|
||||
) internal view {
|
||||
if (usedTransactions(_message))
|
||||
revert TxAlreadyUsed();
|
||||
@@ -45,13 +43,11 @@ abstract contract BaseUtils is
|
||||
if (
|
||||
!validBacenSigners(
|
||||
_castAddrToKey(
|
||||
ECDSA.recover(
|
||||
ECDSA.recoverCalldata(
|
||||
ECDSA.toEthSignedMessageHash(
|
||||
_message
|
||||
),
|
||||
_v,
|
||||
_r,
|
||||
_s
|
||||
_signature
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -20,6 +20,12 @@ library DataTypes {
|
||||
uint256[] expiredLocks;
|
||||
}
|
||||
|
||||
struct ReleaseArgs {
|
||||
uint256 lockID;
|
||||
bytes32 pixTimestamp;
|
||||
bytes signature;
|
||||
}
|
||||
|
||||
struct Lock {
|
||||
uint256 counter;
|
||||
uint256 expirationBlock;
|
||||
|
||||
@@ -218,7 +218,7 @@ abstract contract OwnerSettings is
|
||||
assembly {
|
||||
success := staticcall(
|
||||
// gas
|
||||
0x7530,
|
||||
gas(),
|
||||
// address
|
||||
sload(reputation.slot),
|
||||
// argsOffset
|
||||
|
||||
@@ -15,26 +15,43 @@ library ECDSA {
|
||||
0x7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0;
|
||||
|
||||
/// @dev Recovers the signer's address from a message digest `hash`,
|
||||
/// and the signature defined by `v`, `r`, `s`.
|
||||
function recover(
|
||||
/// and the `signature`.
|
||||
///
|
||||
/// This function does NOT accept EIP-2098 short form signatures.
|
||||
/// Use `recover(bytes32 hash, bytes32 r, bytes32 vs)` for EIP-2098
|
||||
/// short form signatures instead.
|
||||
function recoverCalldata(
|
||||
bytes32 hash,
|
||||
uint8 v,
|
||||
bytes32 r,
|
||||
bytes32 s
|
||||
bytes calldata signature
|
||||
) internal view returns (address result) {
|
||||
/// @solidity memory-safe-assembly
|
||||
assembly {
|
||||
// Copy the free memory pointer so that we can restore it later.
|
||||
let m := mload(0x40)
|
||||
// Directly copy `r` and `s` from the calldata.
|
||||
calldatacopy(0x40, signature.offset, 0x40)
|
||||
// Store the `hash` in the scratch space.
|
||||
mstore(0x00, hash)
|
||||
mstore(0x20, and(v, 0xff))
|
||||
mstore(0x40, r)
|
||||
mstore(0x60, s)
|
||||
// Compute `v` and store it in the scratch space.
|
||||
mstore(
|
||||
0x20,
|
||||
byte(
|
||||
0,
|
||||
calldataload(add(signature.offset, 0x40))
|
||||
)
|
||||
)
|
||||
pop(
|
||||
staticcall(
|
||||
gas(), // Amount of gas left for the transaction.
|
||||
// If `s` in lower half order, such that the signature is not malleable.
|
||||
lt(s, add(_MALLEABILITY_THRESHOLD, 1)), // Address of `ecrecover`.
|
||||
and(
|
||||
// If the signature is exactly 65 bytes in length.
|
||||
eq(signature.length, 65),
|
||||
// If `s` in lower half order, such that the signature is not malleable.
|
||||
lt(
|
||||
mload(0x60),
|
||||
add(_MALLEABILITY_THRESHOLD, 1)
|
||||
)
|
||||
), // Address of `ecrecover`.
|
||||
0x00, // Start of input.
|
||||
0x80, // Size of input.
|
||||
0x00, // Start of output.
|
||||
|
||||
@@ -20,6 +20,7 @@ contract P2PIX is BaseUtils {
|
||||
|
||||
using DT for DT.DepositArgs;
|
||||
using DT for DT.LockArgs;
|
||||
using DT for DT.ReleaseArgs;
|
||||
using DT for DT.Lock;
|
||||
using DT for DT.LockStatus;
|
||||
|
||||
@@ -206,13 +207,9 @@ contract P2PIX is BaseUtils {
|
||||
/// - `release` caller gets accrued with `l.relayerPremium` as userRecord credit;
|
||||
/// @dev Function sighash: 0x4e1389ed.
|
||||
function release(
|
||||
uint256 lockID,
|
||||
bytes32 pixTimestamp,
|
||||
bytes32 r,
|
||||
bytes32 s,
|
||||
uint8 v
|
||||
DT.ReleaseArgs calldata args
|
||||
) public nonReentrant {
|
||||
DT.Lock storage l = mapLocks[lockID];
|
||||
DT.Lock storage l = mapLocks[args.lockID];
|
||||
|
||||
if (l.amount == 0) revert AlreadyReleased();
|
||||
if (l.expirationBlock < block.number)
|
||||
@@ -222,11 +219,11 @@ contract P2PIX is BaseUtils {
|
||||
abi.encodePacked(
|
||||
l.pixTarget,
|
||||
l.amount,
|
||||
pixTimestamp
|
||||
args.pixTimestamp
|
||||
)
|
||||
);
|
||||
|
||||
_signerCheck(message, r, s, v);
|
||||
_signerCheck(message, args.signature);
|
||||
|
||||
ERC20 t = ERC20(l.token);
|
||||
|
||||
@@ -254,7 +251,7 @@ contract P2PIX is BaseUtils {
|
||||
lockAmount
|
||||
);
|
||||
|
||||
emit LockReleased(l.buyerAddress, lockID, lockAmount);
|
||||
emit LockReleased(l.buyerAddress, args.lockID, lockAmount);
|
||||
}
|
||||
|
||||
/// @notice Unlocks expired locks.
|
||||
|
||||
Reference in New Issue
Block a user