Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
linghuccc committed Sep 27, 2024
2 parents c91521d + ffbd058 commit fdb223d
Show file tree
Hide file tree
Showing 8 changed files with 311 additions and 23 deletions.
14 changes: 14 additions & 0 deletions Hansen.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ timezone: Asia/Shanghai

<!-- Content_START -->

### 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 语言的 基本语法

Expand Down
61 changes: 61 additions & 0 deletions MartinYeung5.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

<!-- Content_END -->
35 changes: 24 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 || ⭕️ | ⭕️ |||| ⭕️ | ⭕️ | | | | | | | | | | | | | |
<!-- END_COMMIT_TABLE -->


Expand Down Expand Up @@ -239,6 +239,19 @@ Starknet 残酷共学是由 LXDAO、Starknet Astro、AAStar 联合发起,旨



















Expand Down
67 changes: 67 additions & 0 deletions Reign.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <project_name>`: Initialize a new project.
- `scarb build`: Compile Cairo code into Sierra.
- `scarb add <dependency>`: 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`.

<!-- Content_END -->
49 changes: 49 additions & 0 deletions River.md
Original file line number Diff line number Diff line change
Expand Up @@ -826,10 +826,59 @@ fn main() {
}
~~~
`Felt252Dict<T>`允许“重写”任何键对应的值。
当实例化`Felt252Dict<T>`后,所有的键关联的值被实例化为0。意味着如果读取一个不存在的数据则会返回0,而不是错误或者未定义的值。也意味着无法从字典中删除数据。
### 2024.09.26
##### 字典底层结构
`Cairo`使用Entry列表来实现`Felt252Dict<T>`。每个Entry表示一条可以进行读取、更新、写入操作的记录。
Entry结构包含三个值:
1. `key`:用于识别字典的键值对
2. `previous_value`:表示`key`的前一个值
3. `new_value`:表示`key`更新的值
如果使用高级结构来实现`Felt252Dict<T>`, 可以定义`Array<Entry<T>>`,`Entry<T>`的结构可以是:
~~~rust
struct Entry<T> {
key: felt252,
previous_value: T,
new_value: T,
}
~~~
每一次与`Felt252Dict<T>`交互,就会注册一个新的`Entry<T>`:
1. `get`操作将注册一个状态未改变的entry,然后`previous_value`和`new_value`存储为同一个值。
2. `insert`操作将注册一个新的`Entry<T>`,`new_value`为写入的值,`previous_value`则是写入操作之前的值,如果是第一次写入,则为0。
使用Entry列表展示了为何不存在重写,仅仅是在每次与`Felt252Dict<T>`交互创建一个新的内存单元。
🌰例子:分别更新字典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),它需要每个条目的旧值和新值的信息。
<!-- Content_END -->
19 changes: 19 additions & 0 deletions awaqawaqawaq.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 操作符 * 将快照转换回普通值
<!-- Content_END -->
74 changes: 65 additions & 9 deletions phipupt.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
```

<!-- Content_END -->
Loading

0 comments on commit fdb223d

Please sign in to comment.