Added support for flatsigs

This commit is contained in:
PedroCailleret 2023-05-22 07:43:47 -03:00
parent 26a495246e
commit 631c1d5dfb
32 changed files with 214 additions and 205 deletions

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/3d12978eb8a70621f317c36179381ad8.json" "buildInfo": "../../build-info/811e76435f5423608b4f8fda7811bf8e.json"
} }

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../../build-info/3d12978eb8a70621f317c36179381ad8.json" "buildInfo": "../../../build-info/811e76435f5423608b4f8fda7811bf8e.json"
} }

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../../build-info/3d12978eb8a70621f317c36179381ad8.json" "buildInfo": "../../../build-info/811e76435f5423608b4f8fda7811bf8e.json"
} }

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../../build-info/3d12978eb8a70621f317c36179381ad8.json" "buildInfo": "../../../build-info/811e76435f5423608b4f8fda7811bf8e.json"
} }

View File

@ -3,8 +3,8 @@
"contractName": "DataTypes", "contractName": "DataTypes",
"sourceName": "contracts/core/DataTypes.sol", "sourceName": "contracts/core/DataTypes.sol",
"abi": [], "abi": [],
"bytecode": "0x60808060405234601757603a9081601d823930815050f35b600080fdfe600080fdfea26469706673582212201904685203adfcebeda9a1444d5381c24a37e2895e8a7dff26bd8d5af2fafcbc64736f6c63430008130033", "bytecode": "0x60808060405234601757603a9081601d823930815050f35b600080fdfe600080fdfea2646970667358221220cd1f7ebb936fcf31afe01a797870de94db3214655afaa1cb621785aa86bd86e964736f6c63430008130033",
"deployedBytecode": "0x600080fdfea26469706673582212201904685203adfcebeda9a1444d5381c24a37e2895e8a7dff26bd8d5af2fafcbc64736f6c63430008130033", "deployedBytecode": "0x600080fdfea2646970667358221220cd1f7ebb936fcf31afe01a797870de94db3214655afaa1cb621785aa86bd86e964736f6c63430008130033",
"linkReferences": {}, "linkReferences": {},
"deployedLinkReferences": {} "deployedLinkReferences": {}
} }

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../../build-info/3d12978eb8a70621f317c36179381ad8.json" "buildInfo": "../../../build-info/811e76435f5423608b4f8fda7811bf8e.json"
} }

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../../build-info/3d12978eb8a70621f317c36179381ad8.json" "buildInfo": "../../../build-info/811e76435f5423608b4f8fda7811bf8e.json"
} }

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/3d12978eb8a70621f317c36179381ad8.json" "buildInfo": "../../../../build-info/811e76435f5423608b4f8fda7811bf8e.json"
} }

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/3d12978eb8a70621f317c36179381ad8.json" "buildInfo": "../../../../build-info/811e76435f5423608b4f8fda7811bf8e.json"
} }

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/3d12978eb8a70621f317c36179381ad8.json" "buildInfo": "../../../../build-info/811e76435f5423608b4f8fda7811bf8e.json"
} }

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/3d12978eb8a70621f317c36179381ad8.json" "buildInfo": "../../../../build-info/811e76435f5423608b4f8fda7811bf8e.json"
} }

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/3d12978eb8a70621f317c36179381ad8.json" "buildInfo": "../../../../build-info/811e76435f5423608b4f8fda7811bf8e.json"
} }

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/3d12978eb8a70621f317c36179381ad8.json" "buildInfo": "../../../../build-info/811e76435f5423608b4f8fda7811bf8e.json"
} }

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/3d12978eb8a70621f317c36179381ad8.json" "buildInfo": "../../../../build-info/811e76435f5423608b4f8fda7811bf8e.json"
} }

View File

@ -9,8 +9,8 @@
"type": "error" "type": "error"
} }
], ],
"bytecode": "0x60808060405234601757603a9081601d823930815050f35b600080fdfe600080fdfea26469706673582212201f6fe8a460e1235bb7e19365d8e3cc56b718d44f5db82f5fa3c90d3c7da59ebf64736f6c63430008130033", "bytecode": "0x60808060405234601757603a9081601d823930815050f35b600080fdfe600080fdfea26469706673582212209602e77b0002730843efd4bf0aab444a6a8daeade7f7f10052351ae288f5aa5264736f6c63430008130033",
"deployedBytecode": "0x600080fdfea26469706673582212201f6fe8a460e1235bb7e19365d8e3cc56b718d44f5db82f5fa3c90d3c7da59ebf64736f6c63430008130033", "deployedBytecode": "0x600080fdfea26469706673582212209602e77b0002730843efd4bf0aab444a6a8daeade7f7f10052351ae288f5aa5264736f6c63430008130033",
"linkReferences": {}, "linkReferences": {},
"deployedLinkReferences": {} "deployedLinkReferences": {}
} }

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/3d12978eb8a70621f317c36179381ad8.json" "buildInfo": "../../../../build-info/811e76435f5423608b4f8fda7811bf8e.json"
} }

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/3d12978eb8a70621f317c36179381ad8.json" "buildInfo": "../../../../build-info/811e76435f5423608b4f8fda7811bf8e.json"
} }

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/3d12978eb8a70621f317c36179381ad8.json" "buildInfo": "../../../../build-info/811e76435f5423608b4f8fda7811bf8e.json"
} }

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../../../build-info/3d12978eb8a70621f317c36179381ad8.json" "buildInfo": "../../../../build-info/811e76435f5423608b4f8fda7811bf8e.json"
} }

View File

@ -1,4 +1,4 @@
{ {
"_format": "hh-sol-dbg-1", "_format": "hh-sol-dbg-1",
"buildInfo": "../../build-info/3d12978eb8a70621f317c36179381ad8.json" "buildInfo": "../../build-info/811e76435f5423608b4f8fda7811bf8e.json"
} }

File diff suppressed because one or more lines are too long

View File

@ -35,9 +35,7 @@ abstract contract BaseUtils is
function _signerCheck( function _signerCheck(
bytes32 _message, bytes32 _message,
bytes32 _r, bytes calldata _signature
bytes32 _s,
uint8 _v
) internal view { ) internal view {
if (usedTransactions(_message)) if (usedTransactions(_message))
revert TxAlreadyUsed(); revert TxAlreadyUsed();
@ -45,13 +43,11 @@ abstract contract BaseUtils is
if ( if (
!validBacenSigners( !validBacenSigners(
_castAddrToKey( _castAddrToKey(
ECDSA.recover( ECDSA.recoverCalldata(
ECDSA.toEthSignedMessageHash( ECDSA.toEthSignedMessageHash(
_message _message
), ),
_v, _signature
_r,
_s
) )
) )
) )

View File

@ -20,6 +20,12 @@ library DataTypes {
uint256[] expiredLocks; uint256[] expiredLocks;
} }
struct ReleaseArgs {
uint256 lockID;
bytes32 pixTimestamp;
bytes signature;
}
struct Lock { struct Lock {
uint256 counter; uint256 counter;
uint256 expirationBlock; uint256 expirationBlock;

View File

@ -218,7 +218,7 @@ abstract contract OwnerSettings is
assembly { assembly {
success := staticcall( success := staticcall(
// gas // gas
0x7530, gas(),
// address // address
sload(reputation.slot), sload(reputation.slot),
// argsOffset // argsOffset

View File

@ -15,26 +15,43 @@ library ECDSA {
0x7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0; 0x7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0;
/// @dev Recovers the signer's address from a message digest `hash`, /// @dev Recovers the signer's address from a message digest `hash`,
/// and the signature defined by `v`, `r`, `s`. /// and the `signature`.
function recover( ///
/// 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, bytes32 hash,
uint8 v, bytes calldata signature
bytes32 r,
bytes32 s
) internal view returns (address result) { ) internal view returns (address result) {
/// @solidity memory-safe-assembly /// @solidity memory-safe-assembly
assembly { assembly {
// Copy the free memory pointer so that we can restore it later. // Copy the free memory pointer so that we can restore it later.
let m := mload(0x40) 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(0x00, hash)
mstore(0x20, and(v, 0xff)) // Compute `v` and store it in the scratch space.
mstore(0x40, r) mstore(
mstore(0x60, s) 0x20,
byte(
0,
calldataload(add(signature.offset, 0x40))
)
)
pop( pop(
staticcall( staticcall(
gas(), // Amount of gas left for the transaction. gas(), // Amount of gas left for the transaction.
// If `s` in lower half order, such that the signature is not malleable. and(
lt(s, add(_MALLEABILITY_THRESHOLD, 1)), // Address of `ecrecover`. // 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. 0x00, // Start of input.
0x80, // Size of input. 0x80, // Size of input.
0x00, // Start of output. 0x00, // Start of output.

View File

@ -20,6 +20,7 @@ contract P2PIX is BaseUtils {
using DT for DT.DepositArgs; using DT for DT.DepositArgs;
using DT for DT.LockArgs; using DT for DT.LockArgs;
using DT for DT.ReleaseArgs;
using DT for DT.Lock; using DT for DT.Lock;
using DT for DT.LockStatus; using DT for DT.LockStatus;
@ -206,13 +207,9 @@ contract P2PIX is BaseUtils {
/// - `release` caller gets accrued with `l.relayerPremium` as userRecord credit; /// - `release` caller gets accrued with `l.relayerPremium` as userRecord credit;
/// @dev Function sighash: 0x4e1389ed. /// @dev Function sighash: 0x4e1389ed.
function release( function release(
uint256 lockID, DT.ReleaseArgs calldata args
bytes32 pixTimestamp,
bytes32 r,
bytes32 s,
uint8 v
) public nonReentrant { ) public nonReentrant {
DT.Lock storage l = mapLocks[lockID]; DT.Lock storage l = mapLocks[args.lockID];
if (l.amount == 0) revert AlreadyReleased(); if (l.amount == 0) revert AlreadyReleased();
if (l.expirationBlock < block.number) if (l.expirationBlock < block.number)
@ -222,11 +219,11 @@ contract P2PIX is BaseUtils {
abi.encodePacked( abi.encodePacked(
l.pixTarget, l.pixTarget,
l.amount, l.amount,
pixTimestamp args.pixTimestamp
) )
); );
_signerCheck(message, r, s, v); _signerCheck(message, args.signature);
ERC20 t = ERC20(l.token); ERC20 t = ERC20(l.token);
@ -254,7 +251,7 @@ contract P2PIX is BaseUtils {
lockAmount lockAmount
); );
emit LockReleased(l.buyerAddress, lockID, lockAmount); emit LockReleased(l.buyerAddress, args.lockID, lockAmount);
} }
/// @notice Unlocks expired locks. /// @notice Unlocks expired locks.

View File

@ -15,7 +15,7 @@ const _abi = [
]; ];
const _bytecode = const _bytecode =
"0x60808060405234601757603a9081601d823930815050f35b600080fdfe600080fdfea26469706673582212201f6fe8a460e1235bb7e19365d8e3cc56b718d44f5db82f5fa3c90d3c7da59ebf64736f6c63430008130033"; "0x60808060405234601757603a9081601d823930815050f35b600080fdfe600080fdfea26469706673582212209602e77b0002730843efd4bf0aab444a6a8daeade7f7f10052351ae288f5aa5264736f6c63430008130033";
type ECDSAConstructorParams = type ECDSAConstructorParams =
| [signer?: Signer] | [signer?: Signer]

File diff suppressed because one or more lines are too long

View File

@ -71,6 +71,18 @@ export declare namespace DataTypes {
merkleProof: string[]; merkleProof: string[];
expiredLocks: BigNumber[]; expiredLocks: BigNumber[];
}; };
export type ReleaseArgsStruct = {
lockID: PromiseOrValue<BigNumberish>;
pixTimestamp: PromiseOrValue<BytesLike>;
signature: PromiseOrValue<BytesLike>;
};
export type ReleaseArgsStructOutput = [BigNumber, string, string] & {
lockID: BigNumber;
pixTimestamp: string;
signature: string;
};
} }
export interface P2PIXInterface extends utils.Interface { export interface P2PIXInterface extends utils.Interface {
@ -92,7 +104,7 @@ export interface P2PIXInterface extends utils.Interface {
"lockCounter()": FunctionFragment; "lockCounter()": FunctionFragment;
"mapLocks(uint256)": FunctionFragment; "mapLocks(uint256)": FunctionFragment;
"owner()": FunctionFragment; "owner()": FunctionFragment;
"release(uint256,bytes32,bytes32,bytes32,uint8)": FunctionFragment; "release((uint256,bytes32,bytes))": FunctionFragment;
"reputation()": FunctionFragment; "reputation()": FunctionFragment;
"sellerAllowList(address)": FunctionFragment; "sellerAllowList(address)": FunctionFragment;
"setDefaultLockBlocks(uint256)": FunctionFragment; "setDefaultLockBlocks(uint256)": FunctionFragment;
@ -216,13 +228,7 @@ export interface P2PIXInterface extends utils.Interface {
encodeFunctionData(functionFragment: "owner", values?: undefined): string; encodeFunctionData(functionFragment: "owner", values?: undefined): string;
encodeFunctionData( encodeFunctionData(
functionFragment: "release", functionFragment: "release",
values: [ values: [DataTypes.ReleaseArgsStruct]
PromiseOrValue<BigNumberish>,
PromiseOrValue<BytesLike>,
PromiseOrValue<BytesLike>,
PromiseOrValue<BytesLike>,
PromiseOrValue<BigNumberish>
]
): string; ): string;
encodeFunctionData( encodeFunctionData(
functionFragment: "reputation", functionFragment: "reputation",
@ -706,11 +712,7 @@ export interface P2PIX extends BaseContract {
owner(overrides?: CallOverrides): Promise<[string]>; owner(overrides?: CallOverrides): Promise<[string]>;
release( release(
lockID: PromiseOrValue<BigNumberish>, args: DataTypes.ReleaseArgsStruct,
pixTimestamp: PromiseOrValue<BytesLike>,
r: PromiseOrValue<BytesLike>,
s: PromiseOrValue<BytesLike>,
v: PromiseOrValue<BigNumberish>,
overrides?: Overrides & { from?: PromiseOrValue<string> } overrides?: Overrides & { from?: PromiseOrValue<string> }
): Promise<ContractTransaction>; ): Promise<ContractTransaction>;
@ -889,11 +891,7 @@ export interface P2PIX extends BaseContract {
owner(overrides?: CallOverrides): Promise<string>; owner(overrides?: CallOverrides): Promise<string>;
release( release(
lockID: PromiseOrValue<BigNumberish>, args: DataTypes.ReleaseArgsStruct,
pixTimestamp: PromiseOrValue<BytesLike>,
r: PromiseOrValue<BytesLike>,
s: PromiseOrValue<BytesLike>,
v: PromiseOrValue<BigNumberish>,
overrides?: Overrides & { from?: PromiseOrValue<string> } overrides?: Overrides & { from?: PromiseOrValue<string> }
): Promise<ContractTransaction>; ): Promise<ContractTransaction>;
@ -1072,11 +1070,7 @@ export interface P2PIX extends BaseContract {
owner(overrides?: CallOverrides): Promise<string>; owner(overrides?: CallOverrides): Promise<string>;
release( release(
lockID: PromiseOrValue<BigNumberish>, args: DataTypes.ReleaseArgsStruct,
pixTimestamp: PromiseOrValue<BytesLike>,
r: PromiseOrValue<BytesLike>,
s: PromiseOrValue<BytesLike>,
v: PromiseOrValue<BigNumberish>,
overrides?: CallOverrides overrides?: CallOverrides
): Promise<void>; ): Promise<void>;
@ -1367,11 +1361,7 @@ export interface P2PIX extends BaseContract {
owner(overrides?: CallOverrides): Promise<BigNumber>; owner(overrides?: CallOverrides): Promise<BigNumber>;
release( release(
lockID: PromiseOrValue<BigNumberish>, args: DataTypes.ReleaseArgsStruct,
pixTimestamp: PromiseOrValue<BytesLike>,
r: PromiseOrValue<BytesLike>,
s: PromiseOrValue<BytesLike>,
v: PromiseOrValue<BigNumberish>,
overrides?: Overrides & { from?: PromiseOrValue<string> } overrides?: Overrides & { from?: PromiseOrValue<string> }
): Promise<BigNumber>; ): Promise<BigNumber>;
@ -1541,11 +1531,7 @@ export interface P2PIX extends BaseContract {
owner(overrides?: CallOverrides): Promise<PopulatedTransaction>; owner(overrides?: CallOverrides): Promise<PopulatedTransaction>;
release( release(
lockID: PromiseOrValue<BigNumberish>, args: DataTypes.ReleaseArgsStruct,
pixTimestamp: PromiseOrValue<BytesLike>,
r: PromiseOrValue<BytesLike>,
s: PromiseOrValue<BytesLike>,
v: PromiseOrValue<BigNumberish>,
overrides?: Overrides & { from?: PromiseOrValue<string> } overrides?: Overrides & { from?: PromiseOrValue<string> }
): Promise<PopulatedTransaction>; ): Promise<PopulatedTransaction>;

View File

@ -39,6 +39,7 @@ import {
randomSigners, randomSigners,
createDepositArgs, createDepositArgs,
createLockArgs, createLockArgs,
createReleaseArgs
} from "./utils/fixtures"; } from "./utils/fixtures";
describe("P2PIX", () => { describe("P2PIX", () => {
@ -869,7 +870,7 @@ describe("P2PIX", () => {
const flatSig = await acc01.signMessage( const flatSig = await acc01.signMessage(
messageHashBytes, messageHashBytes,
); );
const sig = ethers.utils.splitSignature(flatSig); // const sig = ethers.utils.splitSignature(flatSig);
await erc20.approve(p2pix.address, newPrice); await erc20.approve(p2pix.address, newPrice);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs( createDepositArgs(
@ -894,11 +895,11 @@ describe("P2PIX", () => {
await p2pix await p2pix
.connect(acc01) .connect(acc01)
.release( .release(
1, createReleaseArgs(
ethers.constants.One,
endtoendID, endtoendID,
sig.r, flatSig
sig.s, ),
sig.v,
); );
const tx = await p2pix const tx = await p2pix
.connect(acc01) .connect(acc01)
@ -1267,7 +1268,7 @@ describe("P2PIX", () => {
const flatSig = await acc01.signMessage( const flatSig = await acc01.signMessage(
ethers.utils.arrayify(messageToSign), ethers.utils.arrayify(messageToSign),
); );
const sig = ethers.utils.splitSignature(flatSig); // const sig = ethers.utils.splitSignature(flatSig);
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs( createDepositArgs(
@ -1292,12 +1293,12 @@ describe("P2PIX", () => {
const lockID = ethers.constants.One; const lockID = ethers.constants.One;
await mine(13); await mine(13);
const fail = p2pix.release( const fail = p2pix.release(
lockID, createReleaseArgs(
ethers.constants.HashZero, lockID,
sig.r, ethers.constants.HashZero,
sig.s, flatSig,
sig.v, ),
); );
await expect(fail).to.be.revertedWithCustomError( await expect(fail).to.be.revertedWithCustomError(
p2pix, p2pix,
@ -1314,7 +1315,7 @@ describe("P2PIX", () => {
const flatSig = await acc01.signMessage( const flatSig = await acc01.signMessage(
ethers.utils.arrayify(messageToSign), ethers.utils.arrayify(messageToSign),
); );
const sig = ethers.utils.splitSignature(flatSig); // const sig = ethers.utils.splitSignature(flatSig);
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs( createDepositArgs(
@ -1338,18 +1339,18 @@ describe("P2PIX", () => {
); );
const lockID = ethers.constants.One; const lockID = ethers.constants.One;
await p2pix.release( await p2pix.release(
lockID, createReleaseArgs(
ethers.constants.HashZero, lockID,
sig.r, ethers.constants.HashZero,
sig.s, flatSig
sig.v, ),
); );
const fail = p2pix.release( const fail = p2pix.release(
lockID, createReleaseArgs(
ethers.constants.HashZero, lockID,
sig.r, ethers.constants.HashZero,
sig.s, flatSig,
sig.v, ),
); );
await expect(fail).to.be.revertedWithCustomError( await expect(fail).to.be.revertedWithCustomError(
@ -1366,7 +1367,7 @@ describe("P2PIX", () => {
const flatSig = await owner.signMessage( const flatSig = await owner.signMessage(
ethers.utils.arrayify(messageToSign), ethers.utils.arrayify(messageToSign),
); );
const sig = ethers.utils.splitSignature(flatSig); // const sig = ethers.utils.splitSignature(flatSig);
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs( createDepositArgs(
@ -1392,12 +1393,12 @@ describe("P2PIX", () => {
await p2pix await p2pix
.connect(acc01) .connect(acc01)
.release( .release(
1, createReleaseArgs(
ethers.constants.HashZero, ethers.constants.One,
sig.r, ethers.constants.HashZero,
sig.s, flatSig,
sig.v, ),
); );
await p2pix await p2pix
.connect(acc03) .connect(acc03)
.lock( .lock(
@ -1412,11 +1413,11 @@ describe("P2PIX", () => {
const fail = p2pix const fail = p2pix
.connect(acc01) .connect(acc01)
.release( .release(
2, createReleaseArgs(
ethers.constants.HashZero, ethers.constants.Two,
sig.r, ethers.constants.HashZero,
sig.s, flatSig,
sig.v, ),
); );
await expect(fail).to.be.revertedWithCustomError( await expect(fail).to.be.revertedWithCustomError(
@ -1433,7 +1434,7 @@ describe("P2PIX", () => {
const flatSig = await acc03.signMessage( const flatSig = await acc03.signMessage(
ethers.utils.arrayify(messageToSign), ethers.utils.arrayify(messageToSign),
); );
const sig = ethers.utils.splitSignature(flatSig); // const sig = ethers.utils.splitSignature(flatSig);
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
await p2pix.deposit( await p2pix.deposit(
@ -1459,11 +1460,11 @@ describe("P2PIX", () => {
const fail = p2pix const fail = p2pix
.connect(acc01) .connect(acc01)
.release( .release(
1, createReleaseArgs(
ethers.constants.HashZero, ethers.constants.One,
sig.r, ethers.constants.HashZero,
sig.s, flatSig,
sig.v, ),
); );
await expect(fail).to.be.revertedWithCustomError( await expect(fail).to.be.revertedWithCustomError(
@ -1494,7 +1495,7 @@ describe("P2PIX", () => {
const flatSig = await acc01.signMessage( const flatSig = await acc01.signMessage(
messageHashBytes, messageHashBytes,
); );
const sig = ethers.utils.splitSignature(flatSig); // const sig = ethers.utils.splitSignature(flatSig);
const root = ethers.constants.HashZero; const root = ethers.constants.HashZero;
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
@ -1536,12 +1537,12 @@ describe("P2PIX", () => {
const tx = await p2pix const tx = await p2pix
.connect(acc01) .connect(acc01)
.release( .release(
1, createReleaseArgs(
endtoendID, ethers.constants.One,
sig.r, endtoendID,
sig.s, flatSig,
sig.v, ),
); );
const lockStatus1 = const lockStatus1 =
await p2pix.callStatic.getLocksStatus([1]); await p2pix.callStatic.getLocksStatus([1]);
@ -1650,7 +1651,7 @@ describe("P2PIX", () => {
const flatSig1 = await owner.signMessage( const flatSig1 = await owner.signMessage(
ethers.utils.arrayify(messageToSign1), ethers.utils.arrayify(messageToSign1),
); );
const sig1 = ethers.utils.splitSignature(flatSig1); // const sig1 = ethers.utils.splitSignature(flatSig1);
const messageToSign2 = ethers.utils.solidityKeccak256( const messageToSign2 = ethers.utils.solidityKeccak256(
["bytes32", "uint80", "bytes32"], ["bytes32", "uint80", "bytes32"],
[await p2pix.callStatic.getStr(pixTarget), 50, endtoendID], [await p2pix.callStatic.getStr(pixTarget), 50, endtoendID],
@ -1658,7 +1659,7 @@ describe("P2PIX", () => {
const flatSig2 = await owner.signMessage( const flatSig2 = await owner.signMessage(
ethers.utils.arrayify(messageToSign2), ethers.utils.arrayify(messageToSign2),
); );
const sig2 = ethers.utils.splitSignature(flatSig2); // const sig2 = ethers.utils.splitSignature(flatSig2);
const messageToSign3 = ethers.utils.solidityKeccak256( const messageToSign3 = ethers.utils.solidityKeccak256(
["bytes32", "uint80", "bytes32"], ["bytes32", "uint80", "bytes32"],
[await p2pix.callStatic.getStr(pixTarget), 25, endtoendID], [await p2pix.callStatic.getStr(pixTarget), 25, endtoendID],
@ -1666,7 +1667,7 @@ describe("P2PIX", () => {
const flatSig3 = await owner.signMessage( const flatSig3 = await owner.signMessage(
ethers.utils.arrayify(messageToSign3), ethers.utils.arrayify(messageToSign3),
); );
const sig3 = ethers.utils.splitSignature(flatSig3); // const sig3 = ethers.utils.splitSignature(flatSig3);
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs( createDepositArgs(
@ -1739,33 +1740,33 @@ describe("P2PIX", () => {
const tx = await p2pix const tx = await p2pix
.connect(acc01) .connect(acc01)
.release( .release(
lockID, createReleaseArgs(
endtoendID, lockID,
sig1.r, endtoendID,
sig1.s, flatSig1,
sig1.v, ),
); );
// relayerPremium != 0 && // relayerPremium != 0 &&
// lock's msg.sender != release's msg.sender // lock's msg.sender != release's msg.sender
const tx1 = await p2pix const tx1 = await p2pix
.connect(acc01) .connect(acc01)
.release( .release(
lockID2, createReleaseArgs(
endtoendID, lockID2,
sig2.r, endtoendID,
sig2.s, flatSig2,
sig2.v, ),
); );
// relayerPremium != 0 && // relayerPremium != 0 &&
// lock's msg.sender == release's msg.sender // lock's msg.sender == release's msg.sender
const tx2 = await p2pix const tx2 = await p2pix
.connect(acc03) .connect(acc03)
.release( .release(
createReleaseArgs(
lockID3, lockID3,
endtoendID, endtoendID,
sig3.r, flatSig3,
sig3.s, ),
sig3.v,
); );
const used1 = await p2pix.callStatic.usedTransactions( const used1 = await p2pix.callStatic.usedTransactions(
ethers.utils.arrayify(messageToSign1), ethers.utils.arrayify(messageToSign1),
@ -1909,7 +1910,7 @@ describe("P2PIX", () => {
const flatSig = await acc01.signMessage( const flatSig = await acc01.signMessage(
messageHashBytes, messageHashBytes,
); );
const sig = ethers.utils.splitSignature(flatSig); // const sig = ethers.utils.splitSignature(flatSig);
await erc20.approve(p2pix.address, price); await erc20.approve(p2pix.address, price);
await p2pix.deposit( await p2pix.deposit(
createDepositArgs( createDepositArgs(
@ -1934,12 +1935,12 @@ describe("P2PIX", () => {
const lockID = ethers.constants.One; const lockID = ethers.constants.One;
// await mine(10); // await mine(10);
await p2pix.release( await p2pix.release(
lockID, createReleaseArgs(
endtoendID, lockID,
sig.r, endtoendID,
sig.s, flatSig,
sig.v, ),
); );
const fail = p2pix.unlockExpired([lockID]); const fail = p2pix.unlockExpired([lockID]);
await expect(fail).to.be.revertedWithCustomError( await expect(fail).to.be.revertedWithCustomError(

View File

@ -12,7 +12,7 @@ import {
Reputation, Reputation,
} from "../../src/types"; } from "../../src/types";
import { Call, RepFixture, P2PixAndReputation, DepositArgs, LockArgs } from "./interfaces"; import { Call, RepFixture, P2PixAndReputation, DepositArgs, LockArgs, ReleaseArgs } from "./interfaces";
// exported constants // exported constants
@ -32,6 +32,12 @@ export const createLockArgs = (seller: string, token: string, amount: BigNumber,
expiredLocks, expiredLocks,
}); });
export const createReleaseArgs = (lockID: BigNumber, pixTimestamp: string, signature: string): ReleaseArgs => ({
lockID,
pixTimestamp,
signature,
});
export const getSignerAddrs = ( export const getSignerAddrs = (
amount: number, amount: number,
addrs: SignerWithAddress[], addrs: SignerWithAddress[],

View File

@ -31,6 +31,12 @@ export interface LockArgs {
expiredLocks: BigNumber[]; expiredLocks: BigNumber[];
} }
export interface ReleaseArgs {
lockID: BigNumber;
pixTimestamp: string;
signature: string;
}
export interface Lock { export interface Lock {
counter: BigNumber; counter: BigNumber;
expirationBlock: BigNumber; expirationBlock: BigNumber;