Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

max-timeout for expiry #30

Merged
merged 5 commits into from
Jul 14, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/contracts/contracts/TransactionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ contract TransactionManager is ReentrancyGuard, ITransactionManager {
/// @dev Minimum timeout (will be the lowest on the receiving chain)
uint256 public constant MIN_TIMEOUT = 24 hours;

/// @dev Maximum timeout
uint256 public constant MAX_TIMEOUT = 30 days; // 720 hours

constructor(uint256 _chainId) {
chainId = _chainId;
}
Expand Down Expand Up @@ -187,6 +190,9 @@ contract TransactionManager is ReentrancyGuard, ITransactionManager {
// Make sure the expiry is greater than min
require((expiry - block.timestamp) >= MIN_TIMEOUT, "prepare: TIMEOUT_TOO_LOW");

// Make sure the expiry is lower than max
require((expiry - block.timestamp) <= MAX_TIMEOUT, "prepare: TIMEOUT_TOO_HIGH");

// Make sure the hash is not a duplicate
bytes32 digest = keccak256(abi.encode(invariantData));
require(variantTransactionData[digest] == bytes32(0), "prepare: DIGEST_EXISTS");
Expand Down
11 changes: 11 additions & 0 deletions packages/contracts/test/transactionManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,17 @@ describe("TransactionManager", function () {
).to.be.revertedWith("prepare: TIMEOUT_TOO_LOW");
});

it("should revert if expiry is higher than max_timeout", async () => {
const { transaction, record } = await getTransactionData();
const days31 = 31 * 24 * 60 * 60;
const expiry = (Math.floor(Date.now() / 1000) + days31 + 5_000).toString();
await expect(
transactionManager
.connect(user)
.prepare(transaction, record.amount, expiry, EmptyBytes, EmptyBytes, EmptyBytes, { value: record.amount }),
).to.be.revertedWith("prepare: TIMEOUT_TOO_HIGH");
});

it("should revert if param sending and receiving chainId are same", async () => {
const { transaction, record } = await getTransactionData({ sendingChainId: 1337, receivingChainId: 1337 });
await expect(
Expand Down
19 changes: 19 additions & 0 deletions packages/contracts/typechain/TransactionManager.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { TypedEventFilter, TypedEvent, TypedListener } from "./commons";

interface TransactionManagerInterface extends ethers.utils.Interface {
functions: {
"MAX_TIMEOUT()": FunctionFragment;
"MIN_TIMEOUT()": FunctionFragment;
"activeTransactionBlocks(address,uint256)": FunctionFragment;
"addLiquidity(uint256,address,address)": FunctionFragment;
Expand All @@ -35,6 +36,10 @@ interface TransactionManagerInterface extends ethers.utils.Interface {
"variantTransactionData(bytes32)": FunctionFragment;
};

encodeFunctionData(
functionFragment: "MAX_TIMEOUT",
values?: undefined
): string;
encodeFunctionData(
functionFragment: "MIN_TIMEOUT",
values?: undefined
Expand Down Expand Up @@ -135,6 +140,10 @@ interface TransactionManagerInterface extends ethers.utils.Interface {
values: [BytesLike]
): string;

decodeFunctionResult(
functionFragment: "MAX_TIMEOUT",
data: BytesLike
): Result;
decodeFunctionResult(
functionFragment: "MIN_TIMEOUT",
data: BytesLike
Expand Down Expand Up @@ -227,6 +236,8 @@ export class TransactionManager extends BaseContract {
interface: TransactionManagerInterface;

functions: {
MAX_TIMEOUT(overrides?: CallOverrides): Promise<[BigNumber]>;

MIN_TIMEOUT(overrides?: CallOverrides): Promise<[BigNumber]>;

activeTransactionBlocks(
Expand Down Expand Up @@ -335,6 +346,8 @@ export class TransactionManager extends BaseContract {
): Promise<[string]>;
};

MAX_TIMEOUT(overrides?: CallOverrides): Promise<BigNumber>;

MIN_TIMEOUT(overrides?: CallOverrides): Promise<BigNumber>;

activeTransactionBlocks(
Expand Down Expand Up @@ -443,6 +456,8 @@ export class TransactionManager extends BaseContract {
): Promise<string>;

callStatic: {
MAX_TIMEOUT(overrides?: CallOverrides): Promise<BigNumber>;

MIN_TIMEOUT(overrides?: CallOverrides): Promise<BigNumber>;

activeTransactionBlocks(
Expand Down Expand Up @@ -940,6 +955,8 @@ export class TransactionManager extends BaseContract {
};

estimateGas: {
MAX_TIMEOUT(overrides?: CallOverrides): Promise<BigNumber>;

MIN_TIMEOUT(overrides?: CallOverrides): Promise<BigNumber>;

activeTransactionBlocks(
Expand Down Expand Up @@ -1049,6 +1066,8 @@ export class TransactionManager extends BaseContract {
};

populateTransaction: {
MAX_TIMEOUT(overrides?: CallOverrides): Promise<PopulatedTransaction>;

MIN_TIMEOUT(overrides?: CallOverrides): Promise<PopulatedTransaction>;

activeTransactionBlocks(
Expand Down
Loading