> For the complete documentation index, see [llms.txt](https://docs.stacks.co/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.stacks.co/learn/zh/transactions/post-conditions.md).

# 后置条件

<div data-with-frame="true"><figure><img src="/files/ea510a0546d15712ff652ba4815b48b47563e75c" alt=""><figcaption></figcaption></figure></div>

{% hint style="info" %}
**构建者资源**

* 如需深入了解后置条件的用法， [请看这里](/post-conditions/overview.md).
* 关于 SIP-005 中概述的后置条件技术规范， [请看这里](https://github.com/stacksgov/sips/blob/main/sips/sip-005/sip-005-blocks-and-transactions.md#transaction-post-conditions).
* 关于 SIP-040 中概述的 Originator 模式和 MAY SEND NFT 条件， [请看这里](https://github.com/stacksgov/sips/blob/main/sips/sip-040/sip-040-post-conds.md).
* 关于 SIP-045 中概述的质押和 PoX 后置条件， [请看这里](https://github.com/stacksgov/sips/blob/main/sips/sip-045/sip-045-pox-5-bitcoin-staking.md).
  {% endhint %}

#### **全局概览**

* 后置条件是约束 *你附加到交易中的* 它们精确定义了哪些资产（STX、SIP-010 代币、NFT）允许转移以及转移多少——并且从 SIP-045 开始，还定义了允许发生哪些质押和 PoX 操作。
* 如果底层智能合约的执行会违反你声明的限制，整个交易就会中止。
* 即使智能合约包含意料之外的逻辑，它也不能移动超出你后置条件允许范围的资产。
* 后置条件由客户端构建，通常由客户端开发者完成。它们是已签名交易的一部分。合约无法修改它们。
* 钱包会解析已签名交易，并在广播前向用户显示所声明的后置条件。

***

### 什么是后置条件？ <a href="#what-are-post-conditions" id="what-are-post-conditions"></a>

后置条件是关于链上交易的断言，必须满足；否则交易将在执行期间中止。换句话说，后置条件充当安全网，允许你指定交易中可以发生哪些状态变化。

**有时，客户端开发者并不是编写底层智能合约的同一个人，可能并不十分熟悉其内部逻辑、嵌套的外部合约调用或边缘情况。** 这套逻辑有助于限制因漏洞或恶意行为而可能对用户及其资产造成的损害。

简单来说，后置条件是一组在用户交易执行前必须满足的条件。后置条件背后的主要目标，是限制因漏洞、故意行为或其他原因而对用户资产造成的损害。

后置条件是 Stacks 协议内置的一项额外安全功能，有助于保护终端用户。它们并不是 Clarity 智能合约的功能，而是在客户端实现，旨在作为防范恶意合约的额外保险。

当用户发起交易时，它们会作为交易的一部分发送，这意味着我们需要在前端实现后置条件。每当你将资产（同质化或非同质化）从一个地址转移到另一个地址时，都应利用后置条件。

后置条件最初只涵盖资产转移——STX、同质化代币和 NFT。从 Stacks 纪元 4.0 开始， [SIP-045](https://github.com/stacksgov/sips/blob/main/sips/sip-045/sip-045-pox-5-bitcoin-staking.md) 它将其扩展到质押：质押后置条件限制某个主体在质押时锁定（或修改）的 STX 数量，而 PoX 后置条件限制某个主体是否执行其他 PoX 操作，例如解除质押。这意味着，用户不仅能免受意外转账的影响，也能免受合约意外更改其质押仓位的影响。

***

> #### *后置条件充当安全网，允许你指定在交易执行期间可以且应该发生哪些状态变化。*


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.stacks.co/learn/zh/transactions/post-conditions.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
