Grief on transfers due to vestingStart during vesting
The vesting start setter did not check that the new start was before the vesting end, so an admin could set a start later than the end. This would make the vesting duration underflow and break transfers of vested tokens and the vestsAt view function.
Dravee Follow with hansfriese
Originally disclosed on Code4rena
Submitted by Dravee, also found by hansfriese
contracts/ERC721Vestable.sol#L99-L101 contracts/ERC721Vestable.sol#L44 contracts/ERC721Vestable.sol#L65
Past similar finding with the same severity: https://github.com/code-423n4/2022-05-runes-findings/issues/30
While centralization risk is acknowledged by the team & the C4udit tool: this may lead to loss of functionality (grief).
Proof of concept
There is no requirement for the start time to be before the end time:
File: ERC721Vestable.sol
099: function _setVestingStart(uint48 _newVestingStart) internal virtual {
100: vestingStart = _newVestingStart; //@audit-issue can be set after vesting end
101: }
...
106: function _setVestingEnd(uint48 _newVestingEnd) internal virtual {
107: require(
108: _newVestingEnd > vestingStart,
109: "End must be greater than start"
110: );
111: vestingEnd = _newVestingEnd;
112: }
Changing the start time in such a way (by error) can break the logic of transfer during the vesting period:
ERC721Vestable.sol#_beforeTokenTransfer():
File: ERC721Vestable.sol
31: function _beforeTokenTransfer(
32: address from,
33: address to,
34: uint256 tokenId
35: ) internal virtual override {
36: super._beforeTokenTransfer(from, to, tokenId);
37: uint256 globalId = getGlobalId(tokenId);
38: if (
39: vestingEnabled &&
40: from != address(0) && // minting
41: globalId <= lastVestingGlobalId &&
42: block.timestamp < vestingEnd
43: ) {
44: uint256 vestingDuration = vestingEnd - vestingStart; //@audit Griefing if vestingStart > vestingEnd (possible)
45: uint256 chunk = vestingDuration / lastVestingGlobalId;
46: require(
47: block.timestamp >= (chunk * globalId) + vestingStart,
48: "Not vested"
49: );
50: }
51:
52: }
While less severe, it can also break the following view function:
ERC721Vestable.sol#vestsAt():
65: uint256 vestingDuration = vestingEnd - vestingStart;
Recommended Mitigation Steps
I believe that vestingStart and vestingEnd should be immutable/constants. But in case the sponsor still wants them to be editable: consider adding the following check:
File: ERC721Vestable.sol
099: function _setVestingStart(uint48 _newVestingStart) internal virtual {
+ 100: require(_newVestingStart < vestingEnd, "End must be greater than start");
100: vestingStart = _newVestingStart; //@audit-issue can be set after vesting end
101: }
The process to edit the vesting period would then be to first edit vestingEnd if the new vestingStart is going to be bigger that it.
Alex the Entreprenerd (judge) commented:
Worth flagging, unclear on severity and if the sponsor intended for vesting to be changeable or not.
With the info we have, we know this undefined state can be achieved, so probably valid, but acceptable nofix by sponsor.
msclecram (Forgotten Runiverse) confirmed
Alex the Entreprenerd (judge) commented:
In contrast to other admin findings this one:
- Shows an inconsistency in setters, from a convention that was already followed
- Shows how this inconsistency can cause an issue with the contract, not merely a Admin Privilege
For the reasons above am judging the finding Medium Severity.
msclecram (Forgotten Runiverse) commented:
We updated the code with the next changes:
- We added require for starting time
https://github.com/bisonic-official/plot-contract/commit/ea8abd7faffde4218232e22ba5d8402e37d96878
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the setter for vestingStart lacked the same ordering check that the setter for vestingEnd had, allowing an inconsistent state where start is after end.
Impact
If the start is set after the end, the vesting duration calculation underflows and transfers during vesting revert, and the vestsAt view function also breaks; the team accepted this as a medium-severity admin issue.
What the attacker needed
Admin sets vestingStart after vestingEnd
The fix
The team added a require check on the starting time so it must be before the vesting end, and the finding was fixed.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A smart contract can lock tokens for a period, called vesting, before they can be moved. The code that sets the start of this period did not check it was earlier than the end, so a mistake by the contract owner could make the maths go wrong and stop people moving their tokens.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.