Skip to content

Commit

Permalink
restrict 10x
Browse files Browse the repository at this point in the history
  • Loading branch information
volovyks committed Feb 18, 2025
1 parent ef3cc41 commit e4e11d2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
3 changes: 2 additions & 1 deletion chain-signatures/contract-eth/contracts/ChainSignatures.sol
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ contract ChainSignatures is AccessControl {
* @param _request The signature request details.
*/
function sign(SignRequest memory _request) external payable {
require(msg.value == signatureDeposit, "Insufficient deposit");
require(msg.value >= signatureDeposit, "Insufficient deposit");
require(msg.value <= signatureDeposit * 10, "Deposit too high");

emit SignatureRequested(
msg.sender,
Expand Down
23 changes: 21 additions & 2 deletions chain-signatures/contract-eth/test/ChainSignatures.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ describe("ChainSignatures", function () {
describe("Changing signatureDeposit", function () {
it("Should change signatureDeposit by setSignatureDeposit", async function () {
const requiredDepositBeforeChange = await chainSignatures.getSignatureDeposit();
const depositExpectedInWei = ethers.parseUnits("50000", "gwei");
const depositExpectedInWei = ethers.parseUnits("50000", "gwei");
expect(requiredDepositBeforeChange).to.equal(depositExpectedInWei);
const depositToSetInWei = ethers.parseUnits("100000", "gwei");
const depositToSetInWei = ethers.parseUnits("100000", "gwei");
await chainSignatures.connect(owner).setSignatureDeposit(depositToSetInWei);
const requiredDepositAfterChange = await chainSignatures.getSignatureDeposit();
expect(requiredDepositAfterChange).to.equal(depositToSetInWei);
Expand Down Expand Up @@ -162,5 +162,24 @@ describe("ChainSignatures", function () {
expect(parsedEvent.args[1]).to.equal(addr2.address);
expect(parsedEvent.args[2]).to.equal(errorMessage);
});

it("Should not accept a signature deposit with 10x of required deposit", async function () {
const payload = ethers.keccak256(ethers.toUtf8Bytes("Test payload"));
const path = "test/path";
const requiredDeposit = await chainSignatures.getSignatureDeposit();

const maxDeposit = requiredDeposit * 10n;
await expect(chainSignatures.connect(addr1).sign({ payload, path, keyVersion: 0, algo: "", dest: "", params: "" }, { value: maxDeposit }))
.to.emit(chainSignatures, "SignatureRequested")
.withArgs(addr1.address, payload, 0, maxDeposit, 31337, path, "", "", "");

const excessiveDeposit = requiredDeposit * 10n + 1n;
await expect(
chainSignatures.connect(addr1).sign(
{ payload, path, keyVersion: 0, algo: "", dest: "", params: "" },
{ value: excessiveDeposit }
)
).to.be.revertedWith("Deposit too high");
});
});
});

0 comments on commit e4e11d2

Please sign in to comment.