DSS 2026 — Beyond the EVM: What Auditing NEAR Taught Me About Ecosystem-Specific Security Nemveer Source video: https://www.youtube.com/watch?v=kQvw1G_wXzY Automatic captions — not human-reviewed. Complete spoken-audio coverage is unverified. Source language tag: en (English). Source export SHA256: 6643fe823de81853d6bdf3dc89b360a6bc7efcc61c0aedb6e7ceaf6776ce405d [0:00] Nice. [0:01] So, yeah, I'm Nambir. I'm a security [0:04] researcher at Sartora. [0:06] Earlier this year, we had audited a [0:08] lending protocol on the near block [0:10] chain. [0:11] And we found several issues there. And [0:13] some of those issue had nothing to do [0:16] with the [0:17] near chain. [0:19] Some of those issues had nothing to do [0:21] with the landing logic. It came from the [0:23] chain itself. It came [0:26] because of not considering all the [0:28] scenarios unable by the execution model [0:30] of the chain. [0:31] So today I will be showing [0:33] a couple of such example and what it [0:36] taught me about the things that we take [0:39] for granted. What it taught me about the [0:41] assumptions that we may bring from the [0:44] past chain we had audited to the new [0:47] chain and which not might always hold [0:49] there. [0:50] So let's get started. Let's first look [0:52] at the simplest borrow function. This is [0:55] something that we have all seen. We have [0:57] all audited simple borrow function three [0:59] line. [1:01] Check the limit, pay the borrower and [1:03] update the debt. Limit is the something [1:05] that the collateral allows the users to [1:08] borrow. [1:09] Looks pretty simple, right? Check, pay [1:12] and update the debt. [1:14] What could go wrong here? [1:17] My question is [1:18] can anything run between these two [1:20] lines? [1:21] I'm not talking about the re-entrancy. [1:23] Just assume for the sake of this that [1:24] the token contract is safe. [1:27] Can anything run between these two line [1:29] in this and in that case? [1:33] Well, most of us are right that on the [1:35] Ethereum nothing can run between the two [1:37] lines because one transaction, one block [1:40] and it's done. [1:42] But on the near the answer is yes. And [1:46] that gap essentially enabled several [1:49] attack vectors that caused some findings [1:51] to this protocol. [1:53] So [1:54] let's [1:56] in order to understand that let's first [1:58] see that how these three [2:00] are modeled for the near. Please [2:02] remember this three lines and we will [2:04] see that how this are actually executed [2:06] on the near. [2:07] So near is a shaded blockchain. [2:09] Everything runs in shard. One shard [2:11] doesn't share any knowledge with the [2:12] other shards. So the cross contract call [2:15] your contract is making might actually [2:17] live on the other shards. [2:19] So calling another contract doesn't [2:21] always happen right away. [2:24] It's async. One transaction can actually [2:27] span across multiple blocks. So if in [2:30] our example [2:32] uh [2:33] after checking the limit the lending [2:35] contract actually asked the token [2:37] contract [2:39] to pay the borrower. [2:41] But the lending contract ends right [2:43] there. [2:44] The check is done. [2:46] The request to transfer is sent. All of [2:48] it is saved and that is block N. [2:51] Each of these boxes are called receipt [2:53] and inside a particular receipt [2:56] everything is atomic. [2:58] Then in a later block the transfer would [3:00] attempt to pay the borrower. It might [3:02] work. It might fail and then in a later [3:05] block [3:07] if the transfer was successful the [3:08] callback would come back to the lending [3:10] contract and the debt would be updated. [3:12] So [3:14] one borrow transaction spanned across [3:16] three multiple blocks. [3:18] Inside a particular receipt everything [3:20] is atomic but across the receipt [3:22] not at all. [3:25] Whatever the state changes that has been [3:27] saved by block N [3:29] stays saved even if the later transfer [3:32] fails. [3:33] And this is not something uh [3:36] this is not the case with the Ethereum [3:37] or the any other chain we know because [3:40] one transaction, one block and it's [3:43] done. But in the near it is possible. [3:47] And also [3:48] uh [3:49] the interesting thing is that [3:52] anyone can come while the transfer is in [3:54] the air and call any functionality of [3:57] the lending protocol [3:59] even while the first borrow transaction [4:01] is not completed fully. [4:04] So this is also the interesting thing, [4:06] and let's keep this mind, and let's see [4:09] our first example. [4:11] Let's meet Sam. [4:13] Sam has provided 100 collateral [4:16] to the lending protocol with the [4:18] with the collateral factor of the 80% he [4:21] is allowed to borrow 80. He puts forward [4:23] a request to borrow 80, so the check [4:25] would be 0 + 80, and it it it's well [4:28] below the limit, and the check passes. [4:30] So the lending contract asks the token [4:32] contract to please pay Sam. [4:35] But [4:37] while the transfer is in the air, and [4:39] while the callback hasn't executed yet [4:42] and the debt is not updated, Sam comes [4:45] again and asks [4:46] the lending contract for the 80 again. [4:50] So my question is what debt does the [4:52] second request see? [4:55] The answer is zero [4:57] because the first request callback [5:00] hasn't executed yet, the debt is not [5:02] updated. [5:04] So the second request check would also [5:06] pass. The two transaction two transfer [5:09] goes through, two callbacks would come [5:11] back. The first would write 80, the [5:13] second would write 160, and the Sam has [5:15] essentially borrowed 160 against the [5:17] collateral of 100. [5:19] And that's a bad debt. [5:21] So [5:23] pretty interesting, but [5:25] how to fix it? And the solution is again [5:27] very simple that we we [5:30] we should count the seat when the ticket [5:32] is sold and not while the passenger on [5:34] boards. So the moment Sam requests a [5:36] transfer, we have to reserve that [5:39] amount. So our updated check would be [5:41] existing debt plus the newly [5:45] the reserved in air and the new amount [5:47] requested, and that should be below the [5:49] limit. So with this updated check, when [5:51] Sam comes with his second request, our [5:53] check would be 80 + 80, which is 160, [5:56] which is above the limit, and his second [5:58] request would be refused, and we are [6:00] saved from the issues. So this [6:03] this issue was about the timing the same [6:06] made two consecutive request to bypass [6:08] the limit. Now let's see one another [6:10] interesting [6:12] scenario [6:13] that is enabled by the near execution [6:15] model. [6:16] In order to understand that let's first [6:20] know how what is the storage rule on the [6:22] near. On near blockchain the user have [6:25] to pay for the storage that they are [6:26] going to use. So for example if I want [6:29] to hold a token [6:31] I need to register in the token [6:33] contract. I need to pay for it. It's [6:35] it's like a bank that if I don't have a [6:38] bank account in a particular bank no one [6:40] would be able to transfer me money in [6:42] that bank. So for example consider Dario [6:46] he is everything right in the landing [6:48] contract. There's a plenty of cap. There [6:50] is no debt. Collateral is enough but and [6:53] he wants to borrow 80 of the borrow [6:55] asset but it doesn't have any [6:58] token account in the borrow asset. [7:01] So is is his borrow request would be [7:03] refused because it doesn't have an [7:05] account there. [7:07] This is not something that we always [7:09] think on the Ethereum because we always [7:11] assume that the ERC 20 transfer to any [7:13] address would always be successful [7:15] because on Ethereum [7:17] every address has account on every bank. [7:20] So this is except it is a contract and [7:23] we have a revert in the receive [7:24] function. [7:27] But on the near it is very much possible [7:29] to refuse the transfer to ourselves. [7:33] But why would someone do that? Why would [7:34] someone make a transfer to himself [7:37] revert? [7:39] Let's let's understand that with the [7:40] example. [7:42] So for example as I said Dario has [7:44] everything right in the landing [7:45] contract. He wants to borrow 80 and the [7:48] check easily passes [7:50] but the landing contract does very [7:52] sensible thing here. He puts aside a 80 [7:56] in order to not promise the same amount [7:58] to some other user. [8:00] So the free liquidity would be 20 if the [8:04] initial free liquidity is 100 and if we [8:07] are promising 80 to the Dario [8:10] the fee would be 20. [8:12] So as I said, the chat passes and the [8:15] lending contract asks the token contract [8:17] to pay to the Dario, but while that [8:20] transfer is in the air [8:22] Maya comes to the lending contract. Maya [8:24] is a legit user. He asks the token [8:26] contract to to please borrow borrow me [8:29] 30. But since the contract is only 20, [8:32] Maya's request would be refused. And [8:34] when the transfer tries to execute [8:37] Dario's transfer, [8:39] it would fail as well because Dario [8:41] doesn't have any account on the token [8:44] contract. So Maya's request is refused. [8:47] Dario's request is refused as well. [8:50] So Dario [8:52] could do it repeatedly. [8:54] Dario could essentially [8:58] consume [9:00] the pool's liquidity with nothing but [9:02] the gas. [9:04] Dario can [9:05] DOS any legit user from borrowing. He [9:08] could prevent all the suppliers for from [9:10] earning [9:11] any yield. [9:13] And what's the cost to the Dario? Just [9:16] the gas. [9:17] So let's see how how to fix this. [9:20] Again, the fix is very simple. The [9:22] moment the request was initiated, we [9:25] charge [9:27] we we start charging interest from the [9:30] block and only. So even if the later [9:32] transfer fails, [9:35] the Dario has to [9:36] pay interest for the amount of time the [9:39] transfer was in the air. So if the Dario [9:43] now wants to DOS the other user and the [9:45] lending protocol, he would not only have [9:47] to pay the gas but also the interest. [9:50] So [9:51] if you notice, there were two things [9:53] that needed to be seen here. The [9:56] the first was the storage rule on the [9:59] near and also the call model on the [10:01] near. Those those two things combined [10:04] enabled this attack. So let's just [10:07] let's just bring everything together and [10:10] again ask our [10:12] question, our assumptions. That three [10:14] lines were same, but the guarantee it [10:17] provides differs across the chain. [10:20] I earlier I never used to check those [10:23] assumptions because I always used to [10:24] believe that nothing runs between my [10:26] lines. The transfer fails and everything [10:29] before it automatically undoes because [10:31] the revert takes the whole transaction [10:32] downs with it and a transfer to a user [10:35] who has an account would always be [10:36] successful. And all of these hold true [10:39] on the Ethereum. But let's see what [10:41] about Solana. [10:42] On Solana first two holds, but third [10:45] doesn't hold because you need to have a [10:47] token account on the token program. [10:50] And on near [10:52] none of these holds. [10:54] So under questioning our assumptions and [10:57] learning about the ecosystem is always [11:00] beneficial because knowing the language [11:03] you could just read the code, but [11:05] knowing the chain would find the bug. So [11:07] with this new learning [11:10] I always [11:12] try to question my assumptions. I always [11:14] try to spend first few hours learning [11:16] the ecosystem [11:18] and doing some of these steps that draw [11:21] one full function call, ask who controls [11:24] each step and taste the weight. [11:26] So yeah, [11:29] please understand the ecosystem you are [11:31] auditing. It would be [11:33] it would tell you where to look for the [11:35] bugs. And yeah, at last [11:38] again that's my question. Can anything [11:40] learn between line two and three? [11:43] And it really depends on on which chain [11:47] you are standing. [11:49] So yeah, that was my time. [11:52] Thank you so much for the listening.