Skip to content

Commit 671faa5

Browse files
committed
feat: agg-mode example contract
1 parent 1b69227 commit 671faa5

4 files changed

Lines changed: 124 additions & 0 deletions

File tree

examples/L2/contracts/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
## Foundry
2+
3+
**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**
4+
5+
Foundry consists of:
6+
7+
- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
8+
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
9+
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
10+
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.
11+
12+
## Documentation
13+
14+
https://book.getfoundry.sh/
15+
16+
## Usage
17+
18+
### Build
19+
20+
```shell
21+
$ forge build
22+
```
23+
24+
### Test
25+
26+
```shell
27+
$ forge test
28+
```
29+
30+
### Format
31+
32+
```shell
33+
$ forge fmt
34+
```
35+
36+
### Gas Snapshots
37+
38+
```shell
39+
$ forge snapshot
40+
```
41+
42+
### Anvil
43+
44+
```shell
45+
$ anvil
46+
```
47+
48+
### Deploy
49+
50+
```shell
51+
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
52+
```
53+
54+
### Cast
55+
56+
```shell
57+
$ cast <subcommand>
58+
```
59+
60+
### Help
61+
62+
```shell
63+
$ forge --help
64+
$ anvil --help
65+
$ cast --help
66+
```

examples/L2/contracts/foundry.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[profile.default]
2+
src = "src"
3+
out = "out"
4+
libs = ["lib"]
5+
6+
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.13;
3+
4+
import {Script, console} from "forge-std/Script.sol";
5+
import {StateTransition} from "../src/StateTransition.sol";
6+
7+
contract StateTransitionDeployer is Script {
8+
StateTransition public stateTransitionContract;
9+
10+
function setUp() public {}
11+
12+
function run(address _alignedProofAggregationService) public returns (address) {
13+
vm.startBroadcast();
14+
15+
stateTransitionContract = new StateTransition(_alignedProofAggregationService);
16+
17+
vm.stopBroadcast();
18+
19+
return address(stateTransitionContract);
20+
}
21+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.13;
3+
4+
contract StateTransition {
5+
event StateUpdated(bytes32)
6+
7+
bytes32 public PROGRAM_ID = 0x00;
8+
bytes32 public stateRoot;
9+
address public alignedProofAggregator;
10+
11+
constructor(address _alignedProofAggregator) {
12+
alignedProofAggregator = _alignedProofAggregator;
13+
}
14+
15+
function updateState(bytes publicInputs, bytes32[] merkleProof) public {
16+
bytes memory callData = abi.encodeWithSignature(
17+
"verifyProofInclusion(bytes32[],bytes32,bytes)", merkleProof, programId, publicInputs
18+
);
19+
(bool callResult, bytes memory response) = alignedProofAggregator.staticcall(callData);
20+
require(callWasSuccessful, "static_call failed");
21+
22+
bool proofVerified = abi.decode(response, (bool));
23+
require(proofVerified, "proof not verified in aligned");
24+
25+
(prevStateRoot, newStateRoot) = abi.decode(publicInputs, (bytes32, UserStateUpdate[]));
26+
require(prevStateRoot == stateRoot);
27+
stateRoot = newStateRoot;
28+
29+
emit StateUpdated(stateRoot);
30+
}
31+
}

0 commit comments

Comments
 (0)