NEAR Protocol · Rust · Sharding · Receipt Execution

NEAR Smart Contract Audit

Quick Answer

  • NEAR contracts are written in Rust (or AssemblyScript) with asynchronous cross-contract execution via receipts — not same-frame like EVM. The primary audit concerns: cross-shard callback state consistency (NEAR's equivalent of reentrancy), access key privilege management, Borsh deserialization correctness, and gas attachment logic.
  • Aurora ($21M, May 2022) — an Ethereum-compatible layer running on NEAR — lost funds via a NEAR-side rainbow bridge contract that incorrectly verified cross-chain transfer proofs. NEAR-side bridge contracts require the same scrutiny as Ethereum bridge contracts.
  • NEAR's human-readable account names (like `protocol.near`) enable phishing via lookalike names — contracts must not rely on user-supplied destination addresses without verification. Free first scan, results in 60 seconds.

NEAR's sharded, receipt-based execution model eliminates same-frame reentrancy but introduces cross-shard callback state management as a critical audit surface — state must remain consistent even when cross-shard calls fail.

Audit Your NEAR Contract Now

Cross-shard callback safety, access key management, Borsh deserialization, Rust security — free first scan.

NEAR Vulnerability Classes

VulnerabilitySeverityDescriptionExample
Cross-Shard Call Reentrancy (Receipt Callbacks)CriticalNEAR's sharded architecture executes cross-contract calls asynchronously via receipts — not in the same transaction frame as EVM external calls. A contract that calls another contract on a different shard and handles the callback must properly manage intermediate state. If state is updated before the callback resolves, a failed cross-shard call may leave state inconsistent, causing balance discrepancies or double-withdrawals.A NEAR contract that sends tokens to a user on shard B and marks the withdrawal as 'completed' before the cross-shard receipt is processed — if the cross-shard call fails, the local state shows completed but tokens were never transferred.
Access Key Privilege EscalationCriticalNEAR's access key model allows contracts to grant function call access keys with specific method and allowance restrictions. If a contract creates function call keys with too-broad method permissions or NEAR token allowances, or fails to revoke keys after use, an attacker with the key can call any permitted method — including those that drain funds or transfer ownership.A protocol that creates a function call key with `allowedMethods: null` (all methods permitted) for a worker account — the worker account, or an attacker who compromises it, can call any contract method including admin functions.
Borsh Deserialization VulnerabilitiesHighNEAR contracts serialize/deserialize state using Borsh (Binary Object Representation Serializer for Hashing). Incorrect Borsh schema definitions — wrong field ordering, missing fields, or type mismatches — can cause silent deserialization failures where a malicious input decodes to unexpected values. Unlike JSON's error-on-unknown-fields behavior, Borsh is length-prefixed and may silently accept malformed data.A NEAR contract struct that adds a new field but doesn't migrate existing stored data — when the contract reads old state with the new struct definition, Borsh reads a different number of bytes than expected, interpreting subsequent bytes as different fields.
Gas Attachment and Refund ManipulationHighNEAR requires contracts to attach gas explicitly to cross-contract calls. Incorrect gas attachment — too little (call panics with out-of-gas), or the gas refund routing — can be exploited. If a contract panics after a cross-shard call but the refund callback is not properly handled, the NEAR token refund may be misdirected or lost.A NEAR contract that makes a cross-contract call with insufficient gas — the cross-contract call panics with `GasExceeded`, but the callback panic leaves the local state in an intermediate position with locked funds and no recovery path.
Human-Readable Account Name PhishingMediumNEAR uses human-readable account names (like `uniswap.near`, `token.berryclub.near`) instead of hex addresses. Attackers create visually similar account names (`uni5wap.near`, `token.berrrc1ub.near`) to phish users who copy-paste account names from untrusted sources. Contracts that accept user-supplied destination account names without verification can send funds to attacker-controlled lookalike accounts.A user-facing NEAR transfer function that accepts `destination` as a string parameter — a social engineering attack tricks a user into calling with `uni5wap.near` instead of `uniswap.near`, sending funds to the attacker's account.

NEAR Audit — FAQs

How is NEAR's execution model different from Ethereum for smart contract security?
NEAR uses a sharded architecture with asynchronous cross-contract calls via receipts. Unlike Ethereum, where a cross-contract call executes in the same transaction frame (enabling reentrancy), NEAR cross-contract calls are asynchronous — they create a receipt that executes in a future block. This eliminates classic same-frame reentrancy but introduces a different challenge: contracts must manage intermediate state between the initial call and the callback. State must be consistent even if the cross-shard call fails. NEAR also uses Rust (or AssemblyScript) rather than Solidity — bringing Rust's memory safety to contracts, at the cost of different vulnerability patterns around serialization and ownership.
What is NEAR's access key model and how can it be misused?
NEAR accounts have two types of access keys: full access keys (can sign any transaction including sending NEAR and deploying contracts) and function call keys (restricted to specific contract methods and NEAR token allowances). This is more granular than Ethereum's single-key account model. Function call keys are designed for delegating limited access to specific contract interactions without granting full account control. Security risks: (1) keys with too-broad method permissions; (2) keys with excessively large NEAR allowances; (3) keys that are never revoked after their intended use; (4) applications that store function call key secrets insecurely.
What are the notable NEAR ecosystem exploits?
The most significant NEAR ecosystem hack was the Ronin Bridge exploit — though Ronin itself is Ethereum-based, the attacker used compromised validator keys in a pattern common to cross-chain bridges in NEAR's ecosystem as well. More directly relevant: the Aurora exploit ($21M, May 2022) — Aurora is an Ethereum-compatible layer running on NEAR, and the hack targeted Aurora's NEP-141 token bridge. The vulnerability was in a NEAR-side contract that handled rainbow bridge transfer proofs incorrectly, allowing an attacker to prove a false bridge deposit. This demonstrates that NEAR-side contracts in cross-chain bridges require the same high-scrutiny audit as Ethereum bridge contracts.
Does NEAR's sharding affect smart contract security?
NEAR's Nightshade sharding splits the network into shards, each processing a subset of accounts. Cross-shard transactions are handled via receipt routing. For smart contract security: (1) contracts can be deployed on any shard, and a contract on shard A calling a contract on shard B is asynchronous; (2) state on different shards is not atomically consistent — cross-shard operations require careful callback design; (3) the gas costs for cross-shard calls are higher than same-shard calls. For DeFi contracts that operate across multiple contracts on different shards, the callback-based architecture requires careful state management to prevent inconsistencies.
How much does a NEAR smart contract audit cost?
NEAR contract audits in Rust are typically priced at $10k–$60k depending on complexity — similar to Solana audits. The Rust language's memory safety reduces certain vulnerability classes, but Borsh deserialization bugs, cross-shard callback design, and access key management require deep NEAR expertise. Key NEAR auditors include BlockSec, Ottersec, and Halborn. SmartContractAuditor.ai analyzes NEAR contracts for known vulnerability patterns — free for the first scan.
Written by Duron Epps, Founder of SmartContractAuditor.ai · Last updated July 2026