Skip to content
Business logic Audit finding Intermediate

Initialization bypasses the "max 2 weeks" guard for min_upgrade_delay

The contract's initialization function does not enforce the two-week maximum on the minimum upgrade delay that the setter enforces. An attacker or careless deployer could set an arbitrarily large delay at creation, effectively locking the upgrade path.

Folks Finance: Wormhole NTT on Algorand

Originally disclosed on Immunefi

Informational View original

57300 sc insight initialization bypasses the max 2 weeks guard for min upgrade delay

Submitted on Oct 25th 2025 at 04:39:57 UTC by @Afriauditor for Audit Comp | Folks Finance: Wormhole NTT on Algorand

Description

Brief / Intro

NttManager.py inherits the Upgradeable contract. In Upgradeable, admins are constrained to set a maximum minimum-upgrade delay of two weeks enforced in the setter via:

assert min_upgrade_delay <= self.max_for_min_upgrade_delay(), "Delay exceeds maximum allowed"

The code comments explicitly state this cap “prevents setting get_active_min_upgrade_delay() so large that upgrades become effectively impossible.” However, this constraint is not enforced at initialization: NttManager.create(...) forwards the provided min_upgrade_delay to Upgradeable.create(...), which does not validate the value. As a result, an arbitrarily large delay can be locked in at genesis.

Vulnerability Details

  • NttManager.create(..., min_upgrade_delay) → calls Upgradeable.create(self, min_upgrade_delay).
  • Upgradeable.create(min_upgrade_delay) stores delay_1 = min_upgrade_delay without the two-week cap check.
  • All future scheduling operations must satisfy:

timestamp >= Global.latest_timestamp + get_active_min_upgrade_delay()

  • If the initial min_upgrade_delay is set to an extremely large value at creation, the system effectively prevents timely scheduling of:
    • contract upgrades, and
    • future reductions to the delay itself,

contradicting the safety intent documented in the code.

Impact Details

A large min_upgrade_delay at deployment effectively locks the contract’s upgrade path.

References

Proof of Concept

Add the following test to NttManger.test.ts to demonstrate that create accepts a delay greater than two weeks and stores it unbounded:

{% code title="NttManger.test.ts" %}

TypeScript
test("create uses provided min_upgrade_delay even if > 2 weeks", async () => {
  const HUGE_DELAY = 20n * SECONDS_IN_DAY; // set to 20 days which is over over 2 weeks
  const { appClient } = await factory.deploy({
    createParams: {
      sender: creator,
      method: "create",
      args: [nttTokenAppId, SOURCE_CHAIN_ID, THRESHOLD, HUGE_DELAY],
      extraFee: (1000).microAlgos(),
    },
  });

  // read this instance's state
  expect(await appClient.state.global.minUpgradeDelay()).toEqual({
    delay_0: 0n,
    delay_1: HUGE_DELAY,   // proves no clamp at create-time
    timestamp: 0n,
  });
  expect(await appClient.getActiveMinUpgradeDelay()).toEqual(HUGE_DELAY);
});

{% endcode %}

Notes

No fixes or mitigation steps are included in this report.

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

Context

Folks Finance runs a Wormhole Native Token Transfer (NTT) deployment on Algorand, and the contracts under review live in the algorand-ntt-contracts repository. The specific file in scope is the NTT manager contract:

Text
ntt_contracts/ntt_manager/NttManager.py

NttManager.py inherits from an Upgradeable contract. Upgradeable is the piece that governs how upgrades are scheduled: it holds a minimum upgrade delay, and every future scheduling operation has to satisfy a timestamp constraint built from that delay. The delay is meant to be adjustable by admins, but only within a ceiling. The setter enforces that ceiling with an assertion, and the code comments explain the intent: the cap exists so that get_active_min_upgrade_delay() cannot be set so large that upgrades become effectively impossible.

The report is filed as an Insight, with the impact category "Contract fails to deliver promised returns, but doesn't lose value".

Setup

The report does not describe any accounts, roles, tooling versions or deployment preconditions beyond what the proof of concept needs. The PoC is a TypeScript test added to NttManger.test.ts (spelled that way in the report), and it uses a factory.deploy helper with a createParams object, a creator sender, an nttTokenAppId, a SOURCE_CHAIN_ID, a THRESHOLD, and a SECONDS_IN_DAY constant. These come from the existing test harness; the report does not document how they are defined.

Finding it

The researcher compared two paths that both end up setting the minimum upgrade delay:

  1. The admin setter, which is guarded by the two-week cap.
  2. The initialisation path, which is not.

The setter's guard is:

Text
assert min_upgrade_delay <= self.max_for_min_upgrade_delay(), "Delay exceeds maximum allowed"

The comments around it state that this cap "prevents setting get_active_min_upgrade_delay() so large that upgrades become effectively impossible." That is the documented safety intent.

The initialisation path does not carry the same check. NttManager.create(...) forwards the supplied min_upgrade_delay to Upgradeable.create(...), and Upgradeable.create(...) stores it without validating it against the cap. So a value that the setter would reject can be locked in at genesis.

Exploitation

Step 1: trace the initialisation path

The report lays out the call chain:

  • NttManager.create(..., min_upgrade_delay) calls Upgradeable.create(self, min_upgrade_delay).
  • Upgradeable.create(min_upgrade_delay) stores delay_1 = min_upgrade_delay without the two-week cap check.

Step 2: understand what the stored delay controls

All future scheduling operations must satisfy:

Text
timestamp >= Global.latest_timestamp + get_active_min_upgrade_delay()

Because the stored delay feeds directly into that expression, an extremely large value set at creation pushes every valid scheduling timestamp far into the future.

Step 3: demonstrate it with a test

The researcher adds the following test to NttManger.test.ts:

TypeScript
test("create uses provided min_upgrade_delay even if > 2 weeks", async () => {
  const HUGE_DELAY = 20n * SECONDS_IN_DAY; // set to 20 days which is over over 2 weeks
  const { appClient } = await factory.deploy({
    createParams: {
      sender: creator,
      method: "create",
      args: [nttTokenAppId, SOURCE_CHAIN_ID, THRESHOLD, HUGE_DELAY],
      extraFee: (1000).microAlgos(),
    },
  });

  // read this instance's state
  expect(await appClient.state.global.minUpgradeDelay()).toEqual({
    delay_0: 0n,
    delay_1: HUGE_DELAY,   // proves no clamp at create-time
    timestamp: 0n,
  });
  expect(await appClient.getActiveMinUpgradeDelay()).toEqual(HUGE_DELAY);
});

The test deploys a fresh instance through factory.deploy, passing HUGE_DELAY (20 days, described in the comment as over two weeks) as the fourth argument to create. It then reads the instance's global state. The minUpgradeDelay() value comes back with delay_0 of 0n, delay_1 equal to HUGE_DELAY, and timestamp of 0n, which shows the value was stored as supplied with no clamp at create time. The follow-up assertion on getActiveMinUpgradeDelay() returns HUGE_DELAY, confirming the active delay is the oversized value.

Root cause

The two-week ceiling is enforced in the admin setter but not in the initialisation path. Upgradeable.create(...) writes delay_1 = min_upgrade_delay directly, so the invariant that the setter protects does not hold for contracts created with an oversized value. The existing defence, the assertion in the setter, never runs during creation, which is why it does not stop this.

Impact

With an extremely large min_upgrade_delay fixed at creation, the system effectively prevents timely scheduling of two things:

  • contract upgrades, and
  • future reductions to the delay itself.

In the report's words, a large min_upgrade_delay at deployment effectively locks the contract's upgrade path. This contradicts the safety intent documented in the code. The report classifies the impact as the contract failing to deliver promised returns without loss of value, and it does not describe any path by which an attacker profits or funds are lost.

Fix

The report includes no fixes or mitigation steps.

Variants to test

  • Check every other entry point that writes the delay field, not just the setter and create. A positive result is any write path that reaches delay_1 without the cap assertion.
  • Look for upgradeable or configurable contracts where a guarded setter and an unguarded constructor or initialiser both write the same parameter. A positive result is a deployment that stores a value the setter would reject.
  • Test boundary values around the cap (exactly at the maximum, one unit above) on both paths. A positive result is the setter rejecting a value that creation accepts.

Hunting notes

This kind of bug hides where the same state variable has more than one writer: an admin setter with validation, and an initialiser without it. During review, list every assignment to the variable and compare the guards on each. The signal is a comment or assertion that documents a safety invariant, combined with an initialisation path that bypasses it. The report shows impact by deploying with a value above the documented cap and reading back the stored and active delay, which demonstrates the invariant break directly rather than arguing it abstractly.

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

What happened, in plain words

Folks Finance runs a piece of software on a blockchain called Algorand. That software is a set of smart contracts, which are programs that live on the blockchain and run automatically. The contracts in question handle a system called Wormhole Native Token Transfer (NTT), which moves tokens between blockchains. The code lives in a public repository called algorand-ntt-contracts, and the file under review is the manager contract:

Text
ntt_contracts/ntt_manager/NttManager.py

One part of this manager contract deals with upgrades. An upgrade is a change to the program itself, and blockchains usually make upgrades wait a minimum amount of time so that people have a chance to react. That waiting period is called the minimum upgrade delay. The contract lets administrators change this delay, but only up to a ceiling of two weeks. The code that changes the delay checks the ceiling and refuses anything larger.

The researcher found that the check only happens when an administrator changes the delay later on. When the contract is first created, the delay is set without any check at all. So whoever creates the contract can set a delay far larger than two weeks, and the contract will accept it. Once that oversized delay is stored, upgrades and even future reductions of the delay itself become practically impossible, because every scheduling action has to wait for that delay to pass first.

The report is filed as an Insight, which is a low-key category for observations that are worth knowing but are not a direct theft or loss. The stated impact category is "Contract fails to deliver promised returns, but doesn't lose value".

Background concepts you need first

Before the details make sense, here are the ideas the report leans on.

  • Smart contract: a program stored on a blockchain. Once deployed, it runs as written, and anyone can call its functions. Think of it as a vending machine that is bolted to the ground: the rules are fixed in advance and the machine does exactly what its code says.
  • Blockchain: a shared ledger that many computers keep in sync. Algorand is one such blockchain.
  • Upgrade: replacing or changing the logic of a deployed contract. Because contracts often hold money, upgrades are usually delayed on purpose so users can see them coming.
  • Minimum upgrade delay: the shortest amount of time that must pass before a scheduled upgrade can take effect. It is a safety brake.
  • Setter: a function that changes a stored value. In everyday terms, it is the dial on a machine that an administrator is allowed to turn.
  • Initialisation (or creation): the one-time setup that runs when a contract is first deployed. Think of it as filling in the machine's settings on the day it is installed.
  • Assertion: a line of code that checks a condition and stops execution if the condition is false. It is like a bouncer at a door who refuses entry when the rule is broken.
  • Invariant: a rule that is supposed to hold at all times. Here the invariant is "the minimum upgrade delay is never larger than two weeks".
  • Genesis: the moment a contract is first created, before anything else has happened.
  • Timestamp: a point in time, usually measured in seconds since some starting point.
  • Test harness: the surrounding code and helpers that let a developer run a contract in a simulated environment and check its behaviour.

The setup

The report does not describe any accounts, roles, tooling versions or deployment preconditions beyond what the proof of concept needs. The proof of concept is a TypeScript test added to a file called NttManger.test.ts (spelled that way in the report). TypeScript is a programming language that compiles to JavaScript, and tests written in it are run by a test runner to check that code behaves as expected.

The test uses a helper called factory.deploy with a createParams object, a creator sender, an nttTokenAppId, a SOURCE_CHAIN_ID, a THRESHOLD, and a SECONDS_IN_DAY constant. These come from the existing test harness; the report does not document how they are defined. In plain terms, the test harness already knows how to spin up a fresh copy of the contract, and the test just supplies the settings for that fresh copy.

Finding it

The researcher compared two paths that both end up setting the minimum upgrade delay:

  1. The admin setter, which is guarded by the two-week cap.
  2. The initialisation path, which is not.

The setter's guard is:

Text
assert min_upgrade_delay <= self.max_for_min_upgrade_delay(), "Delay exceeds maximum allowed"

This line says: if the requested delay is larger than the maximum allowed, stop with the message "Delay exceeds maximum allowed". The comments around it state that this cap "prevents setting get_active_min_upgrade_delay() so large that upgrades become effectively impossible." That is the documented safety intent: the cap exists so that nobody can turn the brake so tight that the machine can never move again.

The initialisation path does not carry the same check. NttManager.create(...) forwards the supplied min_upgrade_delay to Upgradeable.create(...), and Upgradeable.create(...) stores it without validating it against the cap. So a value that the setter would reject can be locked in at genesis. In everyday terms: the dial on the front of the machine has a stop that prevents turning it past two weeks, but the factory setting written on the inside of the machine has no such stop, and the factory setting is what the machine actually uses.

Exploitation

Step 1: trace the initialisation path

The report lays out the call chain:

  • NttManager.create(..., min_upgrade_delay) calls Upgradeable.create(self, min_upgrade_delay).
  • Upgradeable.create(min_upgrade_delay) stores delay_1 = min_upgrade_delay without the two-week cap check.

Why this step matters: to show a bug, you first have to show the exact route the value takes from the outside world into storage. Here the route is short. The manager's creation function hands the delay to the upgradeable base contract, and the base contract writes it straight into a field called delay_1. No check sits on that route.

Step 2: understand what the stored delay controls

All future scheduling operations must satisfy:

Text
timestamp >= Global.latest_timestamp + get_active_min_upgrade_delay()

This line says: the time you want to schedule something for must be at least the current time plus the active minimum delay. If the delay is enormous, then the earliest allowed time is pushed enormously far into the future. Because the stored delay feeds directly into that expression, an extremely large value set at creation pushes every valid scheduling timestamp far into the future. That is why the bug matters: it is not just a stored number, it is a number that gates every future action.

Step 3: demonstrate it with a test

The researcher adds the following test to NttManger.test.ts:

TypeScript
test("create uses provided min_upgrade_delay even if > 2 weeks", async () => {
  const HUGE_DELAY = 20n * SECONDS_IN_DAY; // set to 20 days which is over over 2 weeks
  const { appClient } = await factory.deploy({
    createParams: {
      sender: creator,
      method: "create",
      args: [nttTokenAppId, SOURCE_CHAIN_ID, THRESHOLD, HUGE_DELAY],
      extraFee: (1000).microAlgos(),
    },
  });

  // read this instance's state
  expect(await appClient.state.global.minUpgradeDelay()).toEqual({
    delay_0: 0n,
    delay_1: HUGE_DELAY,   // proves no clamp at create-time
    timestamp: 0n,
  });
  expect(await appClient.getActiveMinUpgradeDelay()).toEqual(HUGE_DELAY);
});

Line by line, in plain words:

  • test("create uses provided min_upgrade_delay even if > 2 weeks", async () => { starts a named test. The name describes what is being checked: that creation accepts a delay larger than two weeks. async means the test can wait for slow operations such as deploying a contract.
  • const HUGE_DELAY = 20n * SECONDS_IN_DAY; builds the oversized value. SECONDS_IN_DAY is a constant from the harness holding the number of seconds in a day. The n suffix marks a big integer literal in TypeScript, used because blockchain numbers can be very large. The comment notes that 20 days is over two weeks.
  • const { appClient } = await factory.deploy({ deploys a fresh copy of the contract and pulls out a handle called appClient for talking to it. await means the test pauses until deployment finishes.
  • createParams: { begins the settings for the creation call.
  • sender: creator, says which account is making the call.
  • method: "create", names the contract function being called.
  • args: [nttTokenAppId, SOURCE_CHAIN_ID, THRESHOLD, HUGE_DELAY], passes the arguments. The fourth argument is the delay, and it is the oversized value.
  • extraFee: (1000).microAlgos(), attaches a small fee, expressed in microAlgos, the smallest unit of the Algorand currency. This is a normal part of sending a transaction on Algorand.
  • }); closes the deployment call.
  • expect(await appClient.state.global.minUpgradeDelay()).toEqual({ reads the contract's stored global state and compares it to an expected object. expect(...).toEqual(...) is the test framework's way of saying "this must equal that".
  • delay_0: 0n, expects one part of the stored delay to be zero.
  • delay_1: HUGE_DELAY, expects the stored delay to be exactly the oversized value. The comment says this proves there is no clamp at create time.
  • timestamp: 0n, expects the stored timestamp to be zero.
  • expect(await appClient.getActiveMinUpgradeDelay()).toEqual(HUGE_DELAY); reads the active delay through the contract's own getter and expects it to be the oversized value too. This confirms the oversized value is not just stored but actually in force.
  • }); closes the test.

The test deploys a fresh instance through factory.deploy, passing HUGE_DELAY (20 days, described in the comment as over two weeks) as the fourth argument to create. It then reads the instance's global state. The minUpgradeDelay() value comes back with delay_0 of 0n, delay_1 equal to HUGE_DELAY, and timestamp of 0n, which shows the value was stored as supplied with no clamp at create time. The follow-up assertion on getActiveMinUpgradeDelay() returns HUGE_DELAY, confirming the active delay is the oversized value.

Why this step matters: a test is a reproducible demonstration. Instead of arguing that the code probably behaves a certain way, the test runs the code and shows the result. Anyone with the repository can run it and see the same outcome.

Root cause

The two-week ceiling is enforced in the admin setter but not in the initialisation path. Upgradeable.create(...) writes delay_1 = min_upgrade_delay directly, so the invariant that the setter protects does not hold for contracts created with an oversized value. The existing defence, the assertion in the setter, never runs during creation, which is why it does not stop this.

In everyday terms: the rule is written on one door but not on the other, and the second door is the one used on installation day.

Impact

With an extremely large min_upgrade_delay fixed at creation, the system effectively prevents timely scheduling of two things:

  • contract upgrades, and
  • future reductions to the delay itself.

In the report's words, a large min_upgrade_delay at deployment effectively locks the contract's upgrade path. This contradicts the safety intent documented in the code. The report classifies the impact as the contract failing to deliver promised returns without loss of value, and it does not describe any path by which an attacker profits or funds are lost.

Why the second point matters: the oversized delay also blocks timely scheduling of reductions to the delay itself.

Fix

The report includes no fixes or mitigation steps.

Variants to test

  • Check every other entry point that writes the delay field, not just the setter and create. A positive result is any write path that reaches delay_1 without the cap assertion.
  • Look for upgradeable or configurable contracts where a guarded setter and an unguarded constructor or initialiser both write the same parameter. A positive result is a deployment that stores a value the setter would reject.
  • Test boundary values around the cap (exactly at the maximum, one unit above) on both paths. A positive result is the setter rejecting a value that creation accepts.

Hunting notes

This kind of bug hides where the same state variable has more than one writer: an admin setter with validation, and an initialiser without it. During review, list every assignment to the variable and compare the guards on each. The signal is a comment or assertion that documents a safety invariant, combined with an initialisation path that bypasses it. The report shows impact by deploying with a value above the documented cap and reading back the stored and active delay, which demonstrates the invariant break directly rather than arguing it abstractly.

Glossary

  • Algorand: a blockchain platform on which the contracts in this report run.
  • Assertion: a code check that halts execution if a condition is false.
  • Blockchain: a shared, replicated ledger maintained by many computers.
  • Call chain: the sequence of function calls that leads from one entry point to another.
  • Cap: an upper limit on a value.
  • Constructor: the code that runs once when an object or contract is created.
  • Contract: see smart contract.
  • Creation (initialisation): the one-time setup that runs when a contract is first deployed.
  • Delay: a waiting period that must pass before something is allowed to happen.
  • Deploy: to publish a contract to a blockchain so it can be used.
  • Factory (test helper): a helper in the test harness that creates fresh contract instances.
  • Genesis: the moment of first creation.
  • Getter: a function that reads a stored value.
  • Global state: the stored data that belongs to a contract as a whole, rather than to a single call.
  • Initialiser: the function that sets up a contract at creation time.
  • Insight: a low-severity report category for observations that are not direct theft or loss.
  • microAlgos: the smallest unit of the Algorand currency.
  • Minimum upgrade delay: the shortest time that must pass before a scheduled upgrade can take effect.
  • NTT (Native Token Transfer): a Wormhole system for moving tokens between blockchains.
  • Proof of concept (PoC): a small, runnable demonstration that a bug is real.
  • Repository: a project's collection of source code and history.
  • Smart contract: a program stored on a blockchain that runs as written.
  • Test harness: the surrounding code and helpers that let tests run a contract in a simulated environment.
  • Timestamp: a point in time, usually measured in seconds.
  • TypeScript: a programming language that compiles to JavaScript, often used for tests.
  • Upgrade: a change to a deployed contract's logic.
  • Upgradeable: a contract designed so its logic can be replaced or changed later.
  • Wormhole: a system for passing messages and tokens between blockchains.

More from Folks Finance: Wormhole NTT on Algorand

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.