diff --git a/Hansen.md b/Hansen.md index b59ad2f..cb91f28 100644 --- a/Hansen.md +++ b/Hansen.md @@ -12,6 +12,20 @@ timezone: Asia/Shanghai +### 2024.09.26 + +分两个链 :StarkEx 企业服务, StarkNet 通用服务 +starknet 不兼容evm,而是cvm + - Warp:将 Solidity 转译为 Cairo 语言的转译器 + - Kakarot:一个用 Cairo 语言编写的 zkEVM +三个特性: +- 工作原理:StarkNet 有五个组成部分。分别是在 StarkNet 上的 Prover(证明者),Sequencer(排序器)和全节点;以及部署在以太坊上的验证者(Verifier)和核心状态合约(StarkNet Core)。 +- 账户抽象:StarkNet 实现了原生账户抽象 +- 证明系统:STARK 证明 相比 SNARK 有更多创新,更安全 + +StarkNet 有一些原生的创新应用,分别是全链游戏、合约钱包和链上 AI + + ### 2024.09.25 简单看一下 cario 语言的 基本语法 diff --git a/MartinYeung5.md b/MartinYeung5.md index 19f00cd..2740aa4 100644 --- a/MartinYeung5.md +++ b/MartinYeung5.md @@ -291,5 +291,66 @@ To declare your contract, execute: 正常會出現以下錯誤訊息: ![alt text](https://github.com/MartinYeung5/starknet/blob/main/MartinYeung5/20240925_5.png?raw=true) +### 2024.09.26 +應該要先做設置Account: +https://docs.starknet.io/quick-start/set-up-an-account/ +* starkli --version +* mkdir -p ~/.starkli-wallets/deployer + +在執行下一步前,必須要有Wallet +Argent X or Braavos wallet +https://braavos.app/download-braavos-wallet/ + +測試用: +siren thought depart stem cycle lazy reunion spatial shock local six there + +account address:0x07bf212a91454ec1f129a8f4a29054211dc013f73bbbe50374426a41ce0a68ea +private: +0x0364fb6a326af3224b7fffd73731cd99f81e2c655eb84996ec66736c2cc6fd51 +public: +0x44c91132de72543b5b92eae7875876f281d4706fc57b95c277ad7ced13aa4e + +* starkli signer keystore from-key ~/.starkli-wallets/deployer/keystore.json +1. 需要輸入private key +2. 需要輸入密碼 (自設) + +去新增STARKNET_KEYSTORE +https://docs.starknet.io/quick-start/environment-setup/#setting_up_starkli_environment_variables + +更新.env + +* starkli declare target/dev/my_contract_hello.contract_class.json +都是有錯誤訊息 +Error: account config file not found +![alt text](https://github.com/MartinYeung5/starknet/blob/main/MartinYeung5/20240925_9.png?raw=true) + +starkli account fetch 0x07bf212a91454ec1f129a8f4a29054211dc013f73bbbe50374426a41ce0a68ea --output ~/.starkli-wallets/deployer/account.json --rpc https://starknet-sepolia.g.alchemy.com/starknet/version/rpc/v0_7/xx + +get faucet: +https://starknet-faucet.vercel.app/ + + +starkli account fetch 0x07bf212a91454ec1f129a8f4a29054211dc013f73bbbe50374426a41ce0a68ea --output ~/.starkli-wallets/deployer/account.json + +* starkli declare target/dev/my_contract_hello.contract_class.json +都是有錯誤訊息 +Error: account config file not found +![alt text](https://github.com/MartinYeung5/starknet/blob/main/MartinYeung5/20240925_10.png?raw=true) + +### 2024.09.27 +starkli account fetch 0x07bf212a91454ec1f129a8f4a29054211dc013f73bbbe50374426a41ce0a68ea --output ~/.starkli-wallets/deployer/account.json --rpc https://starknet-sepolia.g.alchemy.com/starknet/version/rpc/v0_7/x + +* 關鍵點: Braavos wallet 需要先deploy + +成功: +![alt text](https://github.com/MartinYeung5/starknet/blob/main/MartinYeung5/20240925_11.png?raw=true) + +檢查: +* cat ~/.starkli-wallets/deployer/account.json +![alt text](https://github.com/MartinYeung5/starknet/blob/main/MartinYeung5/20240925_12.png?raw=true) + +* starkli account deploy ~/.starkli-wallets/deployer/account.json +但我的wallet已經deployed,因為Braavos wallet的已經在錢包上deployed +![alt text](https://github.com/MartinYeung5/starknet/blob/main/MartinYeung5/20240925_13.png?raw=true) diff --git a/README.md b/README.md index ab6e7a7..19badc8 100644 --- a/README.md +++ b/README.md @@ -111,19 +111,19 @@ Starknet 残酷共学是由 LXDAO、Starknet Astro、AAStar 联合发起,旨 | Name | 9.18 | 9.19 | 9.20 | 9.21 | 9.22 | 9.23 | 9.24 | 9.25 | 9.26 | 9.27 | 9.28 | 9.29 | 9.30 | 10.01 | 10.02 | 10.03 | 10.04 | 10.05 | 10.06 | 10.07 | 10.08 | | ------------- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | | Ache | ⭕️ | ⭕️ | ❌ | | | | | | | | | | | | | | | | | | | -| geyu | ⭕️ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | | | -| aliyan404 | ✅ | ✅ | ✅ | ⭕️ | ✅ | ✅ | ⭕️ | | | | | | | | | | | | | | | -| Hansen | ✅ | ✅ | ⭕️ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | | -| Reign | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | | -| qiaopengjun | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | | -| Ric-Li-C | ✅ | ⭕️ | ⭕️ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | | -| River | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | | -| awaqawaqawaq | ✅ | ✅ | ✅ | ⭕️ | ⭕️ | ✅ | ✅ | ✅ | | | | | | | | | | | | | | -| phipupt | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | | -| MartinYeung5 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | | +| geyu | ⭕️ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ⭕️ | ⭕️ | | | | | | | | | | | | | +| aliyan404 | ✅ | ✅ | ✅ | ⭕️ | ✅ | ✅ | ⭕️ | ⭕️ | ❌ | | | | | | | | | | | | | +| Hansen | ✅ | ✅ | ⭕️ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | +| Reign | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | +| qiaopengjun | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | +| Ric-Li-C | ✅ | ⭕️ | ⭕️ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | +| River | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | +| awaqawaqawaq | ✅ | ✅ | ✅ | ⭕️ | ⭕️ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | +| phipupt | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | +| MartinYeung5 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | | | | | | | | | | | | | dethan3 | ✅ | ⭕️ | ✅ | ⭕️ | ❌ | | | | | | | | | | | | | | | | | | Cavn | ✅ | ✅ | ⭕️ | ⭕️ | ❌ | | | | | | | | | | | | | | | | | -| Ellen | ✅ | ⭕️ | ⭕️ | ✅ | ✅ | ✅ | ⭕️ | | | | | | | | | | | | | | | +| Ellen | ✅ | ⭕️ | ⭕️ | ✅ | ✅ | ✅ | ⭕️ | ⭕️ | ❌ | | | | | | | | | | | | | @@ -239,6 +239,19 @@ Starknet 残酷共学是由 LXDAO、Starknet Astro、AAStar 联合发起,旨 + + + + + + + + + + + + + diff --git a/Reign.md b/Reign.md index 5091792..8f3d64a 100644 --- a/Reign.md +++ b/Reign.md @@ -334,7 +334,74 @@ This guide helps set up essential Starknet development tools. ``` - Verify installation with `katana --version`. +### 2024.09.26 +### Summary of Scarb: The Package Manager +**Scarb** is Cairo’s package manager designed for both Cairo and Starknet projects. It simplifies development by handling dependencies, compiling code, and integrating with tools like Foundry. + +#### **Scarb Workflow** +1. **Initialize** a project with `scarb new`, generating a `Scarb.toml` file and a basic project structure. +2. **Add Code** to the `src` directory. +3. **Add Dependencies** via `scarb add`. +4. **Compile** the project using `scarb build`, converting it into Sierra code, the intermediate layer between Cairo and CASM. + +#### **Cairo Project Structure** +- Projects follow a modular structure where each package has a `Scarb.toml` manifest file and a `src/lib.cairo` file. +- Packages can include external libraries and modules, which are declared in the `Scarb.toml` file. + +Example project structure: +``` +my_package/ +├── src/ +│ ├── lib.cairo +├── Scarb.toml +``` + +#### **Building and Adding Dependencies** +- **Build** projects using `scarb build`, which generates the compiled Sierra code. +- **Add dependencies** by editing `Scarb.toml` or using `scarb add`. Dependencies can be hosted on GitHub or other sources and pinned to specific commits for consistency. + +#### **Components (since version 2.3.0)** +Components in Scarb allow for reusable modular add-ons that extend contracts without rewriting logic. For instance, ownership functionality can be separated into a component and plugged into various contracts. + +#### **Example of Adding a Component** +A typical Starknet contract can use components like `ownable_component` for ownership management, ensuring reusable and cleaner contract design. + +#### **Key Commands:** +- `scarb new `: Initialize a new project. +- `scarb build`: Compile Cairo code into Sierra. +- `scarb add `: Add a dependency from a Git repository. +- `scarb clean`: Remove build artifacts. + +#### **Conclusion** +Scarb is a powerful tool in the Cairo ecosystem, helping developers efficiently manage packages, dependencies, and code. With more experience, developers can fully leverage its capabilities to enhance their Starknet projects. Components, in particular, make it easier to build modular, reusable contract logic. + +### 2024.09.27 + +**Katana: A Local Node for Starknet Development** + +**Katana** is a tool developed by the Dojo team to aid in local development for Starknet. It allows developers to run a local Starknet environment for testing and interacting with smart contracts without needing to rely on public testnets. This local node is highly beneficial for fast, iterative contract development and debugging. + +### Features of Katana: +- **Local Development & Testing**: Katana provides a local node, making it easier to test contracts, similar to the starknet-devnet (a public testnet maintained by Shard Labs). +- **Contract Interaction**: It enables developers to deploy and interact with contracts in a local setting. Examples of contract interaction using Katana can be found in resources like *The Cairo Book*. +- **RPC Integration**: Katana supports Remote Procedure Calls (RPC), allowing communication between nodes and making it possible to interact with your local node via tools like Infura or Alchemy. + +### Getting Started with Katana: +1. **Installation**: Katana can be installed using the `dojoup` installer with the following commands: + ```bash + curl -L https://install.dojoengine.org | bash + dojoup + ``` + After installation, verify it using `katana --version`. + +2. **Starting a Local Node**: Launch a local Starknet node with specific parameters such as the number of accounts and seed: + ```bash + katana --accounts 3 --seed 0 + ``` + This creates prefunded accounts for testing, with output displaying their addresses, private and public keys, and the URL for the JSON-RPC server (e.g., `http://0.0.0.0:5050`). + +3. **Persistence**: The local node does not store data permanently, meaning all information is erased after the node stops. To stop the node, simply use `Ctrl+C`. diff --git a/River.md b/River.md index 72435fc..02a4bfa 100644 --- a/River.md +++ b/River.md @@ -826,10 +826,59 @@ fn main() { } ~~~ +`Felt252Dict`允许“重写”任何键对应的值。 + 当实例化`Felt252Dict`后,所有的键关联的值被实例化为0。意味着如果读取一个不存在的数据则会返回0,而不是错误或者未定义的值。也意味着无法从字典中删除数据。 +### 2024.09.26 + +##### 字典底层结构 + +`Cairo`使用Entry列表来实现`Felt252Dict`。每个Entry表示一条可以进行读取、更新、写入操作的记录。 + +Entry结构包含三个值: + +1. `key`:用于识别字典的键值对 +2. `previous_value`:表示`key`的前一个值 +3. `new_value`:表示`key`更新的值 + +如果使用高级结构来实现`Felt252Dict`, 可以定义`Array>`,`Entry`的结构可以是: + +~~~rust +struct Entry { + key: felt252, + previous_value: T, + new_value: T, +} +~~~ + +每一次与`Felt252Dict`交互,就会注册一个新的`Entry`: + +1. `get`操作将注册一个状态未改变的entry,然后`previous_value`和`new_value`存储为同一个值。 +2. `insert`操作将注册一个新的`Entry`,`new_value`为写入的值,`previous_value`则是写入操作之前的值,如果是第一次写入,则为0。 + +使用Entry列表展示了为何不存在重写,仅仅是在每次与`Felt252Dict`交互创建一个新的内存单元。 + +🌰例子:分别更新字典balance的'Alex'和'Maria'两个值: + +~~~rust +balances.insert('Alex', 100_u64); +balances.insert('Maria', 50_u64); +balances.insert('Alex', 200_u64); +balances.get('Maria'); +~~~ + +上面的操作将产生如下entry列表: +| key | previous | new | +| :---: | :------: | :--: | +| Alex | 0 | 100 | +| Maria | 0 | 50 | +| Alex | 100 | 200 | +| Maria | 50 | 50 | +这种实现方式意味着每次读取或者写入操作,都会遍历整个entry列表来查找与`key`相同的最近的那个entry。一旦找到对应的entry,它的`new_value`会被提取出来,并添加到新的entry的`previous_value`中。 +与常规语言不同,`Cairo`的目的之一是使用STARK证明系统生成计算完整性的证明。这意味着需要验证程序的执行是正确的,并且在`Cairo`限制的范围内。其中一个边界检查包括“**字典压缩**”(dictionary squashing),它需要每个条目的旧值和新值的信息。 diff --git a/awaqawaqawaq.md b/awaqawaqawaq.md index 199d8db..cd0d32a 100644 --- a/awaqawaqawaq.md +++ b/awaqawaqawaq.md @@ -129,4 +129,23 @@ StarkNet's tokenomics . - panic() ### 2024.9.25 #### 因为之前没有接触过Rust,所以对Rust的语法和特性感觉理解困难,观看了 [https://www.bilibili.com/video/BV1hjh1emEAY/?spm_id_from=333.337.search-card.all.click&vd_source=1356c9c3725643abb61fbb2c32756c84] 对所有权、借用规则、引用、生命周期 有了一定了解 + +### 2024.9.26 +- Cairo 中的每一个值都有一个 所有者(owner)。 +值在任一时刻有且只有一个所有者。 +当所有者(变量)离开作用域,这个值将被丢弃。 +如果一个值的所有权没有被 转移(move),它不能离开作用域。 +- 借用(ref) + - 借用(borrowing)允许你访问一个值而不取得其所有权。 + - 借用分为 可变借用(mutable borrow)和 不可变借用(immutable borrow)。 + - 可变借用允许你修改值,而不可变借用则不允许。 + - 在任一时刻,一个值只能有一个可变借用,或者任意数量的不可变借用。 + - 借用必须显式地声明,并且不能超过值的所有权生命周期。 + - 借用必须在使用前声明,并且不能在声明后使用。 +- copy drop + - #[derive(Copy, Drop)] + - 实现 Drop 特性的类型被允许没被 Move 就超出范围 + - 实现 Copy 特性的类型不被 Move 语义约束 +- 在 Cairo 中,快照是某一时刻值的不可变视图。你可以将一个值的快照传递给函数,同时保留原始值的所有权。 +- 使用 @ 操作符创建 x 的快照,使用 desnap 操作符 * 将快照转换回普通值 diff --git a/phipupt.md b/phipupt.md index 6dad631..52841a1 100644 --- a/phipupt.md +++ b/phipupt.md @@ -105,12 +105,24 @@ starknet-devnet-rs 使用 ``` cargo install starknet-devnet ``` + 运行节点: ``` -starknet-devnet-rs +starknet-devnet +``` + +加载环境变量 +``` +SEED=10 starknet-devnet +``` + +从文件加载配置 +``` +source .my-env-file && starknet-devnet ``` RPC 调用(获取账户余额): +``` curl -X POST --data '{ "jsonrpc": "2.0", "id": "1", @@ -120,20 +132,64 @@ curl -X POST --data '{ "unit": "WEI", "block_tag": "latest" } -}' http://127.0.0.1:5050/rpc - +}' http://127.0.0.1:5050/ +``` ### 2024.09.25 今天正式开始学习 Cairo。 -Cairo 是第一个用于创建可证明程序的图灵完备语言,适用于一般计算。Cairo 还引入了 Sierra,这是一种新的中间表示,确保每次 Cairo 运行都可以被证明。 +Cairo 是第一个用于创建可证明程序的图灵完备语言,适用于一般计算。Cario 由 Rust 编写。Cairo 还引入了 Sierra,这是一种新的中间表示,确保每次 Cairo 运行都可以被证明。 -Scarb 是 Cairo 的包管理器。 +Cairo 不仅仅是为区块链开发者而设。作为一种通用编程语言,它可以用于任何计算,这些计算可以在一台计算机上进行证明,并在其他硬件要求较低的机器上进行验证 + +1. 准备工作 + - 安装 Scarb(Cairo构建工具和包管理器) + - [安装 VSCode 扩展](https://marketplace.visualstudio.com/items?itemName=starkware.cairo1) + + +2. 参考 + - [Cairo 语言官网](https://www.cairo-lang.org/) + + +### 2024.09.26 + +Scarb:Cairo构建工具和包管理器 + +1. 安装 + 建议通过 asdf 安装 Scarb,这是一个可以按项目管理多个语言运行时版本的 CLI 工具 + + asdf 安装: + ``` + git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.1 + . "$HOME/.asdf/asdf.sh" + ``` + + 使用 asdf 安装 scarb: + ``` + asdf plugin add scarb + ``` + + 安装特定版本 scarb: + ``` + asdf install scarb 2.8.1 + ``` + +2. 使用 + 使用 Scarb 创建项目: + ``` + scarb new hello_world + ``` + + 其他命令: + - `scarb build` + - `scarb test` + - `scarb cairo-run` + - `scarb fmt` + + +3. 参考 +- [Scarb 官方文档](https://docs.swmansion.com/scarb/docs.html) -使用 Scarb 创建项目: -``` -scarb new hello_world -``` diff --git a/qiaopengjun.md b/qiaopengjun.md index c2c9070..d1c6277 100644 --- a/qiaopengjun.md +++ b/qiaopengjun.md @@ -567,13 +567,22 @@ mod tests { // 当我们使用简单类型 (u8 u16 u32) 时, 不需要关注所有权类型,只有报错的时候才关注 // 当遇到所有权的时候,不想改变则使用 @ Span 快照类型 修改则使用 ref 要求是可变的变量 使用 mut - - ``` ### 2024.09.26 -笔记内容 + +Transactions +transaction 是由你的钱包发起的,可以是智能手机或笔记本电脑中的钱包 +你签署一笔交易,并将其发送到Starknet 上 +接受该交易的 Starknet 节点称为 Sequencer 排序器 +目前 Starknet 只有一个排序器,它具有类似内存池的功能 +接收你的交易,并在实际执行交易前进行一些基本的交易验证 +由于Starknet 智能合约实际上时 Cairo 程序,因此必须在Cairo 虚拟机上执行 +交易从内存池发送到Cairo虚拟机,一旦执行完成,该执行的 trace 会发送到证明器,我们称其为 SHARP +被称为 SHARP的原因是它不只是给 Starknet 使用,也给STARKEx 使用 +`SHARP· 中的证明模块创建了有效性证明,确保其计算的完整性 +交易执行的结果,有效性证明会发送到以太坊上一个名为验证器的智能合约,如果验证器认为此证明正确,则该执行结果就是正确的。 ### 2024.09.27