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

SKALE-4983 add limit for message and test #1033

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 20 additions & 0 deletions proxy/contracts/MessageProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ abstract contract MessageProxy is AccessControlEnumerableUpgradeable, IMessagePr

uint256 public gasLimit;

uint256 public messageBytesLength;

/**
* @dev Emitted for every outgoing message to schain.
*/
Expand Down Expand Up @@ -110,6 +112,11 @@ abstract contract MessageProxy is AccessControlEnumerableUpgradeable, IMessagePr
address contractAddress
);

event MessageBytesLengthChanged(
uint256 oldValue,
uint256 newValue
);

/**
* @dev Modifier to make a function callable only if caller is granted with {CHAIN_CONNECTOR_ROLE}.
*/
Expand Down Expand Up @@ -190,6 +197,18 @@ abstract contract MessageProxy is AccessControlEnumerableUpgradeable, IMessagePr
emit ExtraContractRemoved(bytes32(0), extraContract);
}

/**
* @dev Sets messageBytesLength to a new value.
*
* Requirements:
*
* - `msg.sender` must be granted CONSTANT_SETTER_ROLE.
*/
function setMessageBytesLength(uint256 newMessageBytesLength) external override onlyConstantSetter {
emit GasLimitWasChanged(messageBytesLength, newMessageBytesLength);
messageBytesLength = newMessageBytesLength;
}

/**
* @dev Should return length of contract registered by schainHash.
*/
Expand Down Expand Up @@ -289,6 +308,7 @@ abstract contract MessageProxy is AccessControlEnumerableUpgradeable, IMessagePr
virtual
{
require(connectedChains[targetChainHash].inited, "Destination chain is not initialized");
require(data.length <= messageBytesLength, "Message is too long");
_authorizeOutgoingMessageSender(targetChainHash);

emit OutgoingMessage(
Expand Down
1 change: 1 addition & 0 deletions proxy/contracts/mainnet/MessageProxyForMainnet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ contract MessageProxyForMainnet is SkaleManagerClient, MessageProxy, IMessagePro
MessageProxy.initializeMessageProxy(1e6);
headerMessageGasCost = 70000;
messageGasCost = 9000;
messageBytesLength = 1024;
}

/**
Expand Down
1 change: 1 addition & 0 deletions proxy/contracts/schain/MessageProxyForSchain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ contract MessageProxyForSchain is MessageProxy, IMessageProxyForSchainInitialize
true
);
schainHash = keccak256(abi.encodePacked(schainName));
messageBytesLength = 1024;

// In predeployed mode all token managers and community locker
// will be added to registryContracts
Expand Down
25 changes: 25 additions & 0 deletions proxy/test/MessageProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,31 @@ describe("MessageProxy", () => {
outgoingMessagesCounter.should.be.deep.equal(BigNumber.from(1));
});

it("should not post outgoing message with big data", async () => {
const contractAddress = messageProxyForMainnet.address;

const bytesData1024 = "0x0000000000000000000000000000000000000000000000000000000000000000" +
"0000000000000000000000000000000000000000000000000000000000000000".repeat(31);

const bytesData1025 = "0x0000000000000000000000000000000000000000000000000000000000000000" +
"0000000000000000000000000000000000000000000000000000000000000000".repeat(31) +
"00";

await caller
.postOutgoingMessageTester(messageProxyForMainnet.address, schainHash, contractAddress, bytesData1025)
.should.be.rejectedWith("Destination chain is not initialized");

await messageProxyForMainnet.connect(deployer).addConnectedChain(schainName);
await caller
.postOutgoingMessageTester(messageProxyForMainnet.address, schainHash, contractAddress, bytesData1025)
.should.be.rejectedWith("Message is too long");
await caller
.postOutgoingMessageTester(messageProxyForMainnet.address, schainHash, contractAddress, bytesData1024)
const outgoingMessagesCounter = BigNumber.from(
await messageProxyForMainnet.getOutgoingMessagesCounter(schainName));
outgoingMessagesCounter.should.be.deep.equal(BigNumber.from(1));
});

it("should allow schain owner to send message", async () => {
const message = "0xd2";
const schainOwner = user;
Expand Down