Skip to content
Business logic Audit finding Intermediate

Title: Front-running Leads to Denial of Service and Unauthorized Referral Farming in Creation Functions.

The Factory contract's creation functions accept signed parameters without binding them to the caller, so anyone can reuse a valid signature. An attacker can front-run a legitimate transaction, deploy the contract first at the deterministic address, and cause the victim's transaction to revert, while also inserting their own referral code in the produce function.

Belong

Originally disclosed on Immunefi

57327 sc medium title front running leads to denial of service and unauthorized referral farming in creation functions

Description

Brief / Intro

The Factory contract's creation functions (produce, produceCreditToken, and deployVestingWallet) are vulnerable to front-running. An attacker observing the mempool can intercept valid, signed parameters intended for these functions and submit their own transaction using those parameters first. This preempts the legitimate user's transaction, causing it to fail due to a deterministic address collision (salt reuse). This results in a Denial of Service (DoS) for the user. Additionally, for the produce function, the attacker can insert their own referral code, enabling unauthorized referral farming.


Vulnerability Details

The core issue lies in how signatures are validated for the creation functions within the Factory contract. Functions like produce, produceCreditToken, and deployVestingWallet rely on parameters (AccessTokenInfo, ERC1155Info, VestingWalletInfo) that include a signature generated by the authorized signerAddress. This signature correctly verifies that the parameters themselves were approved by the signer.

However, the functions do not validate that the transaction sender (msg.sender) is authorized to use these signed parameters or is the intended recipient/creator associated with the payload. They only check the signature's validity against the signerAddress.

The factory uses LibClone.cloneDeterministic or LibClone.deployDeterministicERC1967, which employ CREATE2. The address of the new contract is deterministically calculated based on the deployer's address (address(this) which is the factory), a salt, and the creation code hash. The salt used in these functions is derived from parameters within the signed payload (e.g., keccak256(abi.encode(name, symbol)) for produce and produceCreditToken).

An attacker (e.g., a block builder or someone monitoring the mempool) can execute the following sequence:

{% stepper %} {% step %}

Observe

Identify a pending transaction calling produce, produceCreditToken, or deployVestingWallet with valid signed parameters. {% endstep %}

{% step %}

Copy

Extract the signed parameters (accessTokenInfo, creditTokenInfo, or vestingWalletInfo including the signature field) from the observed transaction's calldata. {% endstep %}

{% step %}

Front-run

Submit their own transaction calling the same factory function with the copied parameters. For produce, the attacker can also substitute their own referralCode. Make it execute before the victim's transaction (e.g., higher gas price). {% endstep %}

{% step %}

Success (Attacker)

The attacker's transaction succeeds because the signature is valid (it was signed by the signerAddress for the given parameters) and the deterministic address has not been created yet. The contract is deployed at the predicted address. In the case of produce, the attacker's referral code is associated with the creation. {% endstep %}

{% step %}

Failure (Victim)

The legitimate user's transaction later executes but fails. The CREATE2 operation reverts because the contract at the deterministic address (derived from the same salt) already exists, leading to errors like Factory.TokenAlreadyExists or Factory.VestingWalletAlreadyExists. This results in a Denial of Service (DoS) for the user. {% endstep %} {% endstepper %}

The included proof of concept demonstrates this clearly for the produce function: attacker successfully calls produce using valid signed parameters intended for a victim and an attacker-controlled referral code. The victim's subsequent call with the same signed parameters reverts.

Link to Proof of Concept

https://gist.github.com/emilesean/81f3b8e2336d7f43018f97a238a1d115


Proof of Concept

Solidity
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import {Test, console} from "forge-std/Test.sol";

// Source Imports
import {AccessTokenInfo, ERC1155Info, NftMetadata, VestingWalletInfo} from "contracts/v2/Structures.sol";
import {Escrow} from "contracts/v2/periphery/Escrow.sol";
import {RoyaltiesReceiverV2} from "contracts/v2/periphery/RoyaltiesReceiverV2.sol";
import {Staking} from "contracts/v2/periphery/Staking.sol";
import {VestingWalletExtended} from "contracts/v2/periphery/VestingWalletExtended.sol";
import {BelongCheckIn} from "contracts/v2/platform/BelongCheckIn.sol";
import {Factory} from "contracts/v2/platform/Factory.sol";
import {AccessToken} from "contracts/v2/tokens/AccessToken.sol";
import {CreditToken} from "contracts/v2/tokens/CreditToken.sol";
import {Helper} from "contracts/v2/utils/Helper.sol";
import {SignatureVerifier} from "contracts/v2/utils/SignatureVerifier.sol";
import {Initializable} from "solady/src/utils/Initializable.sol";

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {ERC20Permit} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";

contract MyToken is ERC20, Ownable, ERC20Permit {
    constructor(address initialOwner) ERC20("MyToken", "MTK") Ownable(initialOwner) ERC20Permit("MyToken") {}

    function mint(address to, uint256 amount) public onlyOwner {
        _mint(to, amount);
    }
}

contract Belong is Test {
    // Implementations
    Escrow public escrow;
    RoyaltiesReceiverV2 public royaltiesReceiverV2;
    Staking public staking;
    VestingWalletExtended public vestingWalletExtended;
    BelongCheckIn public belongCheckIn;
    Factory public factoryImplementation;
    Factory public factory; // Proxy instance
    AccessToken public accessToken;
    CreditToken public creditToken;
    MyToken public myToken;

    // Factory Config
    Factory.FactoryParameters private factoryParams;
    Factory.RoyaltiesParameters private royaltiesParams;
    Factory.Implementations private implementations;
    AccessTokenInfo private accessTokenInfo;
    NftMetadata private nftMetadata;
    uint16[5] private percentages;

    // CreditToken Config
    ERC1155Info private creditTokenInfo;
    address private defaultAdmin = makeAddr("defaultAdmin");
    address private manager = makeAddr("manager");
    address private minter = makeAddr("minter");
    address private burner = makeAddr("burner");

    // VestingWallet Config
    VestingWalletInfo private vestingWalletInfo;

    // Users
    address private alice; // Platform Signer / Owner
    uint256 private alicePk;
    address private bob = makeAddr("bob"); // Legitimate User
    address private attacker1 = makeAddr("attacker1"); // Controls referral code
    address private attacker2 = makeAddr("attacker2"); // Front-runner

    function setUp() public {
        // Deploy Implementation Contracts
        escrow = new Escrow();
        royaltiesReceiverV2 = new RoyaltiesReceiverV2();
        staking = new Staking();
        vestingWalletExtended = new VestingWalletExtended();
        belongCheckIn = new BelongCheckIn();
        accessToken = new AccessToken();
        creditToken = new CreditToken();
        factoryImplementation = new Factory();
        myToken = new MyToken(address(this));

        // Label Addresses
        (alice, alicePk) = makeAddrAndKey("alice");
        vm.label(alice, "Alice (Signer)");
        vm.label(bob, "Bob (User)");
        vm.label(attacker1, "Attacker1 (Referral)");
        vm.label(attacker2, "Attacker2 (Frontrunner)");
        vm.label(address(this), "TestContract"); // Label the test contract itself

        // Deploy Factory Proxy
        factory = Factory(
            address(new TransparentUpgradeableProxy(address(factoryImplementation), address(this), bytes("")))
        );

        // Configure Factory Parameters
        factoryParams = Factory.FactoryParameters({
            platformAddress: alice, // Example platform address
            signerAddress: alice, // Alice is the authorized signer
            defaultPaymentCurrency: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE, // ETH
            platformCommission: 100, // 1%
            maxArraySize: 10,
            transferValidator: address(0) // No validator initially
        });

        royaltiesParams = Factory.RoyaltiesParameters({amountToCreator: 8000, amountToPlatform: 2000}); // 80% / 20% split

        implementations = Factory.Implementations({
            accessToken: address(accessToken),
            creditToken: address(creditToken),
            royaltiesReceiver: address(royaltiesReceiverV2),
            vestingWallet: address(vestingWalletExtended)
        });

        percentages = [0, 500, 1500, 3000, 5000]; // Example referral percentages
    }

    /*
     * @custom: Title: Front-running Leads to Denial of Service and Unauthorized Referral Farming in Creation Functions.
     * @custom: Description: Creation functions (`produce`, `produceCreditToken`, `deployVestingWallet`) are susceptible to front-running.
     * An attacker observing the mempool can intercept a legitimate user's transaction intended for one of these functions.
     * They copy the valid, signed parameters (`accessTokenInfo`, `creditTokenInfo`, `vestingWalletInfo`) provided by the platform signer.
     * The attacker then submits their *own* transaction calling the *same* function with the *stolen parameters*, executing *before* the user's transaction.
     * For the `produce` function, the attacker can substitute their own referral code into the call.
     * This attack succeeds because the signature only verifies the parameters' integrity against the signer, not the transaction sender (`msg.sender`).
     * The attacker's transaction successfully creates the contract at the deterministic address (derived from the salt).
     * Consequently, the legitimate user's original transaction fails due to a salt collision (`TokenAlreadyExists` or `VestingWalletAlreadyExists` error), resulting in a Denial of Service (DoS).
     * In the specific case of `produce`, the attacker also illegitimately farms referral rewards associated with the creation.
     * @custom: Severity: Medium. The vulnerability allows an attacker to cause a Denial of Service (DoS) for legitimate users by exploiting the deterministic address generation (salt collision).
     * For the `produce` function, it additionally enables unauthorized referral farming, adding a profit motive to the griefing attack.
     * @custom: Location: [Factory.sol#L230](https://github.com/belongnet/checkin-contracts/blob/6b78ead6186c49cfec2787522460ddd516579a6b/contracts/v2/platform/Factory.sol#L230) (`produce`)
     * @custom: Location: [Factory.sol#L302](https://github.com/belongnet/checkin-contracts/blob/6b78ead6186c49cfec2787522460ddd516579a6b/contracts/v2/platform/Factory.sol#L302) (`produceCreditToken`)
     * @custom: Location: [Factory.sol#L339](https://github.com/belongnet/checkin-contracts/blob/6b78ead6186c49cfec2787522460ddd516579a6b/contracts/v2/platform/Factory.sol#L339) (`deployVestingWallet`)
     * @custom: Count: 3
     * @custom: Remediation: Enhance access control. Consider including `msg.sender` in the signed message hash for these functions, or add explicit checks within the functions to ensure `msg.sender` matches an authorized address derived from the signed payload (e.g., the intended creator or beneficiary).
     */

    function test_produce_FrontRunningLeadingToDOS() public {
        // Initialize the factory
        factory.initialize(factoryParams, royaltiesParams, implementations, percentages);

        // Define NFT metadata for the collection Bob wants to create
        nftMetadata = NftMetadata({name: "Belong", symbol: "BLG"});

        // Prepare base AccessTokenInfo (without signature)
        accessTokenInfo = AccessTokenInfo({
            paymentToken: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE, // ETH
            feeNumerator: uint96(0), // No royalties for this example
            transferable: true,
            maxTotalSupply: uint256(10_000),
            mintPrice: 1 ether,
            whitelistMintPrice: 1 ether,
            collectionExpire: uint256(0), // No expiration
            metadata: nftMetadata,
            contractURI: "ipfs://example",
            signature: bytes("") // Placeholder
        });

        // Generate the hash that Alice (platform signer) would sign
        bytes32 hash = keccak256(
            abi.encodePacked(
                accessTokenInfo.metadata.name,
                accessTokenInfo.metadata.symbol,
                accessTokenInfo.contractURI,
                accessTokenInfo.feeNumerator,
                block.chainid
            )
        );

        // Simulate Alice signing the hash
        (uint8 v, bytes32 r, bytes32 s) = vm.sign(alicePk, hash);
        bytes memory validSignature = abi.encodePacked(r, s, v);

        // Update AccessTokenInfo with the valid signature Bob would receive
        accessTokenInfo.signature = validSignature;

        // --- Attack Scenario ---

        // Step 1: Attacker1 sets up their referral code.
        vm.startPrank(attacker1);
        bytes32 attackerReferralCode = factory.createReferralCode();
        vm.stopPrank();

        // Step 2: Bob gets the valid signed `accessTokenInfo` from Alice.
        // Attacker2 observes Bob's intended transaction (calling `produce` with `accessTokenInfo` and no referral code) in the mempool.
        // Attacker2 copies `accessTokenInfo` and front-runs Bob by calling `produce` first,
        // using Bob's parameters but substituting Attacker1's referral code.
        vm.startPrank(attacker2);
        AccessToken deployedByAttacker = AccessToken(factory.produce(accessTokenInfo, attackerReferralCode));
        vm.stopPrank();
        console.log("AccessToken deployed by Attacker2 at:", address(deployedByAttacker));

        // Step 3: Bob's transaction eventually executes.
        // It reverts with `Factory.TokenAlreadyExists` because the deterministic address derived from the salt (hash of name and symbol)
        // has already been created by Attacker2's front-run transaction.
        // Result: Denial of Service (DoS) for Bob, and successful, unauthorized referral farming credited to Attacker1.
        vm.startPrank(bob);
        vm.expectRevert(Factory.TokenAlreadyExists.selector);
        factory.produce(accessTokenInfo, bytes32("")); // Bob intended to call without a referral code
        vm.stopPrank();

        // Verification (Optional): Check owner of the deployed token and referral user
        assertEq(deployedByAttacker.owner(), attacker2, "Attacker2 should be the owner");
    }
}

Remediation

{% hint style="info" %} Enhance access control for creation functions. Options include:

  • Include msg.sender in the signed message hash so signatures are bound to the intended caller (e.g., signer signs hash that includes intended creator address).
  • Verify within the function that msg.sender matches an intended creator/beneficiary derived from the signed payload (explicit check).
  • Alternatively, incorporate a nonce or ephemeral value tied to the intended caller into the signed payload to prevent reuse by others. These changes prevent an attacker from reusing signed parameters seen in the mempool. {% endhint %}

The original report as published on Immunefi. Images and videos are our own copies; raw HTML is shown as text. View it on Immunefi.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 7 min read.

Context

Belong is a platform whose smart contracts are split into a platform layer and a periphery layer. The target of this report is the Factory contract at contracts/v2/platform/Factory.sol, which is responsible for creating the platform's core objects: access tokens, credit tokens and vesting wallets.

The three creation functions examined here are produce, produceCreditToken and deployVestingWallet. Each takes a struct of parameters (AccessTokenInfo, ERC1155Info and VestingWalletInfo respectively) that carries a signature field. That signature is produced off-chain by an authorised signerAddress and is meant to prove that the platform approved the parameters. The factory then deploys the new contract with LibClone.cloneDeterministic or LibClone.deployDeterministicERC1967, both of which use CREATE2, so the resulting address is a function of the factory's own address, a salt and the creation code hash. The salt is derived from fields inside the signed payload, for example keccak256(abi.encode(name, symbol)) for produce and produceCreditToken.

The report is filed under the griefing impact category: no profit motive is required for the attacker, but users or the protocol are damaged. For produce the author argues there is also a profit motive, in the form of referral rewards.

Setup

The proof of concept is a Foundry test (forge-std/Test.sol, pragma solidity ^0.8.13) that deploys the full set of implementation contracts and a TransparentUpgradeableProxy in front of the Factory implementation. The roles are:

Name Role
alice Platform signer and owner, holds alicePk
bob Legitimate user
attacker1 Controls a referral code
attacker2 The front-runner

The factory is initialised with FactoryParameters where signerAddress is alice, defaultPaymentCurrency is the ETH sentinel [redacted], platformCommission is 100, maxArraySize is 10 and transferValidator is address(0). Royalties are split amountToCreator: 8000, amountToPlatform: 2000. Referral percentages are [0, 500, 1500, 3000, 5000].

The NFT metadata Bob wants is NftMetadata({name: "Belong", symbol: "BLG"}), and the AccessTokenInfo is built with mintPrice: 1 ether, whitelistMintPrice: 1 ether, maxTotalSupply: uint256(10_000), transferable: true, feeNumerator: uint96(0), collectionExpire: uint256(0) and contractURI: "ipfs://example".

The precondition for the whole attack is that a pending transaction calling one of the three creation functions with valid signed parameters is visible in the mempool.

Finding it

The author's observation is that the signature check covers the parameters but not the caller. The factory verifies that the struct was signed by signerAddress; it never verifies that msg.sender is the user the payload was intended for, nor that msg.sender is the intended creator or beneficiary. Because the salt is taken from the signed payload itself, two calls with the same payload target the same CREATE2 address. Whoever gets mined first wins the address, and the second call reverts.

That combination turns a public mempool into a race that anyone can win, and for produce the attacker can additionally substitute their own referral code.

Exploitation

The report lays the attack out as a five-step sequence.

Step 1: Observe

Identify a pending transaction calling produce, produceCreditToken or deployVestingWallet with valid signed parameters. A block builder or anyone monitoring the mempool can do this.

Step 2: Copy

Extract the signed parameters (accessTokenInfo, creditTokenInfo or vestingWalletInfo, including the signature field) from the observed transaction's calldata.

Step 3: Front-run

Submit your own transaction calling the same factory function with the copied parameters, and make it execute before the victim's transaction, for example with a higher gas price. For produce, the attacker can also substitute their own referralCode.

Step 4: Success (attacker)

The attacker's transaction succeeds because the signature is valid for those parameters and the deterministic address has not been created yet. The contract is deployed at the predicted address. For produce, the attacker's referral code is now associated with the creation.

Step 5: Failure (victim)

The legitimate user's transaction executes later and fails. The CREATE2 operation reverts because a contract already exists at the deterministic address derived from the same salt, producing errors such as Factory.TokenAlreadyExists or Factory.VestingWalletAlreadyExists. That is the denial of service.

The proof of concept demonstrates the produce path end to end. The test first initialises the factory, then builds the AccessTokenInfo with an empty signature placeholder and computes the hash Alice would sign:

Solidity
bytes32 hash = keccak256(
    abi.encodePacked(
        accessTokenInfo.metadata.name,
        accessTokenInfo.metadata.symbol,
        accessTokenInfo.contractURI,
        accessTokenInfo.feeNumerator,
        block.chainid
    )
);

Alice's key signs that hash and the result is packed into the struct:

Solidity
(uint8 v, bytes32 r, bytes32 s) = vm.sign(alicePk, hash);
bytes memory validSignature = abi.encodePacked(r, s, v);

accessTokenInfo.signature = validSignature;

With the signed payload in hand, the attack runs in three moves. First, attacker1 registers a referral code:

Solidity
vm.startPrank(attacker1);
bytes32 attackerReferralCode = factory.createReferralCode();
vm.stopPrank();

Second, attacker2 front-runs Bob by calling produce with Bob's signed accessTokenInfo but with attacker1's referral code:

Solidity
vm.startPrank(attacker2);
AccessToken deployedByAttacker = AccessToken(factory.produce(accessTokenInfo, attackerReferralCode));
vm.stopPrank();
console.log("AccessToken deployed by Attacker2 at:", address(deployedByAttacker));

Third, Bob's own transaction runs and reverts, because the deterministic address derived from the salt (the hash of name and symbol) is already taken:

Solidity
vm.startPrank(bob);
vm.expectRevert(Factory.TokenAlreadyExists.selector);
factory.produce(accessTokenInfo, bytes32("")); // Bob intended to call without a referral code
vm.stopPrank();

The test closes with an assertion that the deployed token belongs to the front-runner:

Solidity
assertEq(deployedByAttacker.owner(), attacker2, "Attacker2 should be the owner");

So the outcome is a denial of service for Bob plus referral credit for attacker1, all from a payload that was legitimately signed by the platform.

Root cause

The signature validates the parameters and nothing else. The creation functions check the signature against signerAddress but do not bind it to msg.sender, and they do not check that the caller is the intended recipient or creator associated with the payload. Because the salt is derived from signed fields such as keccak256(abi.encode(name, symbol)), the target address is fixed by the payload, so any second use of the same payload collides. The signature therefore verifies the parameters but does nothing against reuse by a different caller.

Impact

For all three functions, an attacker who sees a pending signed creation can take the address first and make the legitimate user's transaction revert with Factory.TokenAlreadyExists or Factory.VestingWalletAlreadyExists. That is a denial of service against that user's creation.

For produce specifically, the attacker can also attach their own referral code, which the report describes as unauthorised referral farming and as adding a profit motive to what would otherwise be pure griefing. The report rates the issue Medium.

Fix

The report recommends strengthening access control on the creation functions, with three options:

  1. Include msg.sender in the signed message hash, so a signature is bound to the intended caller (the signer signs a hash that includes the intended creator address).
  2. Verify inside the function that msg.sender matches an intended creator or beneficiary derived from the signed payload, as an explicit check.
  3. Incorporate a nonce or ephemeral value tied to the intended caller into the signed payload, so it cannot be reused by anyone else.

Any of these prevents an attacker from reusing signed parameters seen in the mempool.

Variants to test

  • Other signed-parameter creation functions. Look for any factory function that takes a struct with a signature field and deploys with CREATE2. A positive result is that a second caller can reuse the same signed struct and either take the deterministic address or revert the original caller.
  • Referral or attribution fields outside the signature. Check whether fields such as a referral code, beneficiary or recipient are excluded from the signed hash. A positive result is that you can change them while the signature still verifies.
  • Salt derived from signed payload fields. Where the salt is keccak256 of name and symbol or similar, two identical payloads always collide. A positive result is a reproducible AlreadyExists revert on the second call.
  • Nonce or ephemeral value handling. If a nonce is present, check whether it is bound to the caller or merely to the payload. A positive result is that the nonce can be consumed by a different address than the one it was issued for.

Hunting notes

This class of bug hides in factories and registries that accept off-chain signatures over deployment parameters. During recon, look for CREATE2 usage (cloneDeterministic, deployDeterministicERC1967) combined with a signature check, and read the signed hash carefully to see which fields it covers. If the hash omits the caller, the recipient or any attribution field, the payload is replayable by anyone who sees it. The signal is a struct with a signature member whose hash omits msg.sender.

To show impact, reproduce the race in a test: sign a payload as the legitimate signer, have one address consume it, then have the intended user call with the same payload and show the revert. Asserting ownership of the deployed contract by the front-runner, as this proof of concept does, makes the griefing and the referral capture concrete.

Written with AI from the full original report and checked against it passage by passage; anything it could not back up was removed or toned down. The original is the record. 16 min read.

What happened, in plain words

Belong is a platform built on smart contracts, which are small programs that live on a blockchain. The blockchain is a shared public ledger: anyone can read it, and anyone can send it instructions in the form of transactions. A transaction is a request to run a piece of code, and it is only final once it has been included in a block, which is a bundle of transactions that the network agrees on.

Belong's contracts are split into two groups. The platform layer holds the central machinery, and the periphery layer holds supporting pieces. This report is about one contract in the platform layer, called Factory, stored at contracts/v2/platform/Factory.sol. A factory, in programming, is a piece of code whose job is to create other pieces of code. This one creates the platform's core objects: access tokens, credit tokens and vesting wallets. An access token here is a token that gives access to a collection; a credit token is a token used for credits; a vesting wallet is a wallet that releases funds gradually over time. You do not need to know the fine detail of each to follow the bug.

The three creation functions examined here are produce, produceCreditToken and deployVestingWallet. A function is a named block of code you can call. Each of these three takes a bundle of settings, called a struct, which is simply a group of related values packed together. The structs are named AccessTokenInfo, ERC1155Info and VestingWalletInfo. Each of them carries a field called signature.

A signature, in this context, is a cryptographic stamp. The platform holds a secret key, and with it produces a short string of characters that anyone can check against the matching public key. If the check passes, you know the holder of the secret key approved exactly the data that was signed, and that the data has not been altered. The key here belongs to an address called signerAddress. The signature is made off-chain, meaning outside the blockchain, by the platform's own systems, and then travels inside the transaction. Its purpose is to prove that the platform approved the parameters.

To actually create the new contract, the factory uses LibClone.cloneDeterministic or LibClone.deployDeterministicERC1967. Both rely on an Ethereum feature called CREATE2. Normally, the address of a newly created contract is hard to predict. CREATE2 makes it predictable: the address is calculated from the address of the contract doing the creating (here the factory itself), a value called a salt, and a hash of the code being deployed. A hash is a fingerprint: a fixed-length string computed from data, where any change to the data produces a completely different fingerprint. The salt is a value mixed into that calculation to make different deployments land at different addresses. In this factory, the salt is derived from fields inside the signed payload, for example keccak256(abi.encode(name, symbol)) for produce and produceCreditToken. keccak256 is the hashing function used, and abi.encode is the standard way of turning values into a byte string before hashing.

The report is filed under the griefing impact category. Griefing means causing damage to users or to the protocol without necessarily making money from it. For produce, the author argues there is also a profit motive, in the form of referral rewards. A referral code is a short identifier that credits whoever owns it when a new creation uses it, a bit like a coupon code that pays the person who handed it out.

Setup

The proof of concept is a Foundry test. Foundry is a toolkit for writing and running tests against smart contracts on your own machine, without touching the real network. The test imports forge-std/Test.sol, a helper library that gives tests useful tools, and declares pragma solidity ^0.8.13, which states the version of the Solidity language the file expects.

The test deploys the full set of implementation contracts and a TransparentUpgradeableProxy in front of the Factory implementation. A proxy is a contract that sits in front of another and forwards calls to it; it lets the team replace the code behind a fixed address later. The roles in the test are:

Name Role
alice Platform signer and owner, holds alicePk
bob Legitimate user
attacker1 Controls a referral code
attacker2 The front-runner

alicePk is Alice's private key, the secret used to make signatures. The test keeps it so it can sign on Alice's behalf.

The factory is initialised with FactoryParameters where signerAddress is alice, defaultPaymentCurrency is the ETH sentinel [redacted], platformCommission is 100, maxArraySize is 10 and transferValidator is address(0). A sentinel is a special placeholder value that stands for something else; here that long address is the conventional way of saying "native ETH" rather than a token contract. address(0) means no address at all, so no validator is set. Royalties are split amountToCreator: 8000, amountToPlatform: 2000, which is a way of expressing an 80/20 split in basis points, where 10000 represents 100 percent. Referral percentages are [0, 500, 1500, 3000, 5000].

The NFT metadata Bob wants is NftMetadata({name: "Belong", symbol: "BLG"}). NFT stands for non-fungible token, a unique digital item on a blockchain; metadata is the descriptive information attached to it, such as its name and ticker symbol. The AccessTokenInfo is built with mintPrice: 1 ether, whitelistMintPrice: 1 ether, maxTotalSupply: uint256(10_000), transferable: true, feeNumerator: uint96(0), collectionExpire: uint256(0) and contractURI: "ipfs://example". In short: one ether to mint, the same for whitelisted buyers, at most ten thousand tokens, transferable, no royalty fee, no expiry, and a link to off-chain metadata stored on IPFS, a distributed file system.

The precondition for the whole attack is that a pending transaction calling one of the three creation functions with valid signed parameters is visible in the mempool. The mempool is the waiting room of a blockchain: transactions that have been broadcast but not yet included in a block. It is public, so anyone can look inside it.

Finding it

The author's observation is that the signature check covers the parameters but not the caller. The factory verifies that the struct was signed by signerAddress; it never verifies that msg.sender is the user the payload was intended for, nor that msg.sender is the intended creator or beneficiary. msg.sender is the address that sent the current call, the equivalent of the return address on an envelope. Because the salt is taken from the signed payload itself, two calls with the same payload target the same CREATE2 address. Whoever gets mined first wins the address, and the second call reverts. To revert means to abort and undo everything the call did, like a shop refusing a sale and handing your money back.

That combination turns a public mempool into a race that anyone can win, and for produce the attacker can additionally substitute their own referral code. Think of a signed permission slip for a named event: the slip proves the organiser approved the event, but it does not say who may hand it in, so the first person at the desk gets the ticket.

Exploitation

The report lays the attack out as a five-step sequence.

Step 1: Observe

Identify a pending transaction calling produce, produceCreditToken or deployVestingWallet with valid signed parameters. A block builder or anyone monitoring the mempool can do this. A block builder is the party that assembles transactions into the next block, so it sees pending transactions before they are final.

Step 2: Copy

Extract the signed parameters (accessTokenInfo, creditTokenInfo or vestingWalletInfo, including the signature field) from the observed transaction's calldata. Calldata is the raw data attached to a transaction: the function to call and the arguments to pass. It is visible to anyone watching.

Step 3: Front-run

Submit your own transaction calling the same factory function with the copied parameters, and make it execute before the victim's transaction, for example with a higher gas price. Gas is the fee paid to have a transaction processed; paying more makes it more attractive to include sooner. Front-running means getting your transaction in ahead of someone else's after seeing theirs. For produce, the attacker can also substitute their own referralCode.

Step 4: Success (attacker)

The attacker's transaction succeeds because the signature is valid for those parameters and the deterministic address has not been created yet. The contract is deployed at the predicted address. For produce, the attacker's referral code is now associated with the creation.

Step 5: Failure (victim)

The legitimate user's transaction executes later and fails. The CREATE2 operation reverts because a contract already exists at the deterministic address derived from the same salt, producing errors such as Factory.TokenAlreadyExists or Factory.VestingWalletAlreadyExists. That is the denial of service. Denial of service means making a legitimate action impossible for its intended user, like occupying the only parking space so the person who booked it cannot park.

The proof of concept demonstrates the produce path end to end. The test first initialises the factory, then builds the AccessTokenInfo with an empty signature placeholder and computes the hash Alice would sign:

Solidity
bytes32 hash = keccak256(
    abi.encodePacked(
        accessTokenInfo.metadata.name,
        accessTokenInfo.metadata.symbol,
        accessTokenInfo.contractURI,
        accessTokenInfo.feeNumerator,
        block.chainid
    )
);

Line by line: bytes32 hash declares a variable that will hold a 32-byte fingerprint. keccak256(...) computes that fingerprint from whatever is inside the brackets. abi.encodePacked(...) glues the listed values together into one byte string, without padding between them. The values glued together are the collection's name, its symbol, its contract URI, its fee numerator and block.chainid, which is the identifier of the blockchain network the code is running on. The chain ID is the identifier of the blockchain network the code is running on. The result is the exact message the platform signer is asked to approve.

Alice's key signs that hash and the result is packed into the struct:

Solidity
(uint8 v, bytes32 r, bytes32 s) = vm.sign(alicePk, hash);
bytes memory validSignature = abi.encodePacked(r, s, v);

accessTokenInfo.signature = validSignature;

Line by line: vm.sign(alicePk, hash) asks the test tool to sign the hash with Alice's private key. The result comes back as three pieces, v, r and s, which together are the standard representation of an Ethereum signature. abi.encodePacked(r, s, v) glues those three pieces into one byte string in the order r, s, v. accessTokenInfo.signature = validSignature stores that byte string in the struct's signature field, so the payload now carries a stamp the factory will accept. This mirrors what the platform does in real life before handing the payload to a user.

With the signed payload in hand, the attack runs in three moves. First, attacker1 registers a referral code:

Solidity
vm.startPrank(attacker1);
bytes32 attackerReferralCode = factory.createReferralCode();
vm.stopPrank();

Line by line: vm.startPrank(attacker1) tells the test tool to make all following calls as if they came from attacker1's address. factory.createReferralCode() calls the factory to create a new referral code and returns it. bytes32 attackerReferralCode stores that returned code in a variable. vm.stopPrank() ends the impersonation, so later calls come from whoever the test says next. The step is needed because the attacker wants the referral reward to land on a code they control.

Second, attacker2 front-runs Bob by calling produce with Bob's signed accessTokenInfo but with attacker1's referral code:

Solidity
vm.startPrank(attacker2);
AccessToken deployedByAttacker = AccessToken(factory.produce(accessTokenInfo, attackerReferralCode));
vm.stopPrank();
console.log("AccessToken deployed by Attacker2 at:", address(deployedByAttacker));

Line by line: the test again impersonates an address, this time attacker2, the front-runner. factory.produce(accessTokenInfo, attackerReferralCode) calls the creation function with Bob's signed settings and the attacker's referral code. The factory checks the signature, finds it valid, and deploys the new access token. The returned address is wrapped as an AccessToken and stored in deployedByAttacker. vm.stopPrank() ends the impersonation. console.log(...) prints the address of the deployed token so the test output shows where it landed. This is the heart of the attack: the signature is genuine, but the caller is not the person it was meant for, and the referral code was swapped.

Third, Bob's own transaction runs and reverts, because the deterministic address derived from the salt (the hash of name and symbol) is already taken:

Solidity
vm.startPrank(bob);
vm.expectRevert(Factory.TokenAlreadyExists.selector);
factory.produce(accessTokenInfo, bytes32("")); // Bob intended to call without a referral code
vm.stopPrank();

Line by line: the test impersonates bob. vm.expectRevert(Factory.TokenAlreadyExists.selector) tells the test tool that the very next call is expected to fail with that specific error; .selector is the short identifier of the error type. factory.produce(accessTokenInfo, bytes32("")) is Bob's call, using the same signed settings and an empty referral code, which is what he intended. Because the address for those settings has already been filled by the attacker's transaction, the call reverts with TokenAlreadyExists, and the test passes only because the revert happened as expected. vm.stopPrank() ends the impersonation.

The test closes with an assertion that the deployed token belongs to the front-runner:

Solidity
assertEq(deployedByAttacker.owner(), attacker2, "Attacker2 should be the owner");

Line by line: deployedByAttacker.owner() asks the deployed token who its owner is. assertEq(...) checks that this equals attacker2. The last argument is a message shown if the check fails. This confirms that the front-runner, not Bob, ended up owning the creation.

So the outcome is a denial of service for Bob plus referral credit for attacker1, all from a payload that was legitimately signed by the platform.

Root cause

The signature validates the parameters and nothing else. The creation functions check the signature against signerAddress but do not bind it to msg.sender, and they do not check that the caller is the intended recipient or creator associated with the payload. Because the salt is derived from signed fields such as keccak256(abi.encode(name, symbol)), the target address is fixed by the payload, so any second use of the same payload collides. The signature therefore verifies the parameters but does nothing against reuse by a different caller. Replay here means using the same signed message a second time, from a different sender, and having it accepted again.

Impact

For all three functions, an attacker who sees a pending signed creation can take the address first and make the legitimate user's transaction revert with Factory.TokenAlreadyExists or Factory.VestingWalletAlreadyExists. That is a denial of service against that user's creation.

For produce specifically, the attacker can also attach their own referral code, which the report describes as unauthorised referral farming and as adding a profit motive to what would otherwise be pure griefing. Farming, in this sense, means collecting rewards repeatedly or illegitimately. The report rates the issue Medium.

Fix

The report recommends strengthening access control on the creation functions, with three options:

  1. Include msg.sender in the signed message hash, so a signature is bound to the intended caller (the signer signs a hash that includes the intended creator address).
  2. Verify inside the function that msg.sender matches an intended creator or beneficiary derived from the signed payload, as an explicit check.
  3. Incorporate a nonce or ephemeral value tied to the intended caller into the signed payload, so it cannot be reused by anyone else. A nonce is a number used once; an ephemeral value is a temporary value that is not meant to be reused.

Any of these prevents an attacker from reusing signed parameters seen in the mempool.

Variants to test

  • Other signed-parameter creation functions. Look for any factory function that takes a struct with a signature field and deploys with CREATE2. A positive result is that a second caller can reuse the same signed struct and either take the deterministic address or revert the original caller.
  • Referral or attribution fields outside the signature. Check whether fields such as a referral code, beneficiary or recipient are excluded from the signed hash. A positive result is that you can change them while the signature still verifies.
  • Salt derived from signed payload fields. Where the salt is keccak256 of name and symbol or similar, two identical payloads always collide. A positive result is a reproducible AlreadyExists revert on the second call.
  • Nonce or ephemeral value handling. If a nonce is present, check whether it is bound to the caller or merely to the payload. A positive result is that the nonce can be consumed by a different address than the one it was issued for.

Hunting notes

This class of bug hides in factories and registries that accept off-chain signatures over deployment parameters. During recon, look for CREATE2 usage (cloneDeterministic, deployDeterministicERC1967) combined with a signature check, and read the signed hash carefully to see which fields it covers. Recon means the early survey of a target to see what it is made of. If the hash omits the caller, the recipient or any attribution field, the payload is replayable by anyone who sees it. The signal is a struct with a signature member whose hash omits msg.sender.

To show impact, reproduce the race in a test: sign a payload as the legitimate signer, have one address consume it, then have the intended user call with the same payload and show the revert. Asserting ownership of the deployed contract by the front-runner, as this proof of concept does, makes the griefing and the referral capture concrete.

Glossary

  • Access token: in this report, a token that grants access to a collection created by the factory.
  • Address: an identifier on a blockchain, used to send funds or call contracts.
  • Assertion: a check in a test that a value equals what is expected, failing the test if not.
  • Basis points: a way of expressing percentages where 10000 equals 100 percent.
  • Block: a bundle of transactions added to the blockchain together.
  • Block builder: the party that assembles transactions into the next block.
  • Calldata: the raw data attached to a transaction, naming the function and its arguments.
  • CREATE2: an Ethereum feature that makes the address of a newly created contract predictable from the creator, a salt and the code hash.
  • Credit token: in this report, a token used for credits, created by the factory.
  • Denial of service: making a legitimate action impossible for its intended user.
  • Deterministic address: an address that can be calculated in advance from known inputs.
  • Ephemeral value: a temporary value meant to be used once and not reused.
  • Factory: a contract whose job is to create other contracts.
  • Foundry: a toolkit for writing and running smart contract tests locally.
  • Front-running: getting your own transaction in ahead of someone else's after seeing theirs.
  • Function: a named block of code that can be called.
  • Gas: the fee paid to have a transaction processed.
  • Griefing: causing damage to users or a protocol without necessarily profiting.
  • Hash: a fixed-length fingerprint computed from data, changing completely if the data changes.
  • IPFS: a distributed file system used to store files off-chain.
  • Keccak256: the hashing function used to compute fingerprints in this code.
  • Mempool: the public waiting room of pending transactions not yet in a block.
  • Metadata: descriptive information attached to a token, such as name and symbol.
  • msg.sender: the address that sent the current call.
  • NFT: a non-fungible token, a unique digital item on a blockchain.
  • Nonce: a number used once, to stop a message being reused.
  • Off-chain: happening outside the blockchain.
  • Payload: the data carried by a transaction or message.
  • Private key: the secret used to create signatures.
  • Proxy: a contract that forwards calls to another contract behind a fixed address.
  • Referral code: an identifier that credits its owner when used in a creation.
  • Replay: using the same signed message again and having it accepted.
  • Revert: abort a call and undo everything it did.
  • Salt: a value mixed into the CREATE2 calculation to make deployments land at different addresses.
  • Sentinel: a special placeholder value that stands for something else.
  • Signature: a cryptographic stamp proving the holder of a key approved specific data.
  • Smart contract: a small program that lives on a blockchain.
  • Solidity: the programming language used to write these contracts.
  • Struct: a group of related values packed together.
  • Transaction: a request sent to a blockchain to run code or move funds.
  • Vesting wallet: a wallet that releases funds gradually over time.

More from Belong

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.