Skip to content

Commit f1f000d

Browse files
authored
Merge branch 'main' into custom-l1-price
2 parents a618cfd + 8882bd0 commit f1f000d

File tree

9 files changed

+249
-47
lines changed

9 files changed

+249
-47
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ categories = ["cryptography"]
1111
publish = false # We don't want to publish our binaries.
1212

1313
[dependencies]
14+
zkevm_opcode_defs = { git = "https://github.com/matter-labs/era-zkevm_opcode_defs.git", branch = "v1.5.0" }
1415
zksync_basic_types = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e10bbdd1e863962552f37e768ae6af649353e4ea" }
1516
zksync_node_fee_model = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e10bbdd1e863962552f37e768ae6af649353e4ea" }
1617
multivm = { git = "https://github.com/matter-labs/zksync-era.git", rev = "e10bbdd1e863962552f37e768ae6af649353e4ea" }

README.md

+29-9
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@ Please note that `era-test-node` is still in its **alpha** stage. Some features
4646

4747
## 📥 Installation & Setup
4848

49+
### Using the installation script
50+
51+
1. Download the installation script and mark as executable:
52+
```bash
53+
curl --proto '=https' -sSf https://raw.githubusercontent.com/matter-labs/era-test-node/main/scripts/install.sh > install.sh
54+
chmod +x install.sh
55+
```
56+
57+
2. Run the script with `sudo` (version can optionally be specified via the `--version` argument):
58+
```bash
59+
sudo ./install.sh
60+
```
61+
62+
3. Start the node:
63+
```bash
64+
era_test_node run
65+
```
66+
67+
### Manually
68+
4969
1. Download `era-test-node` from latest [Release](https://github.com/matter-labs/era-test-node/releases/latest)
5070

5171
2. Extract the binary and mark as executable:
@@ -68,7 +88,7 @@ Please note that `era-test-node` is still in its **alpha** stage. Some features
6888

6989
## 📄 System Contracts
7090

71-
The system contract within the node can be specified via the `--dev-system-contracts` option.
91+
The system contract within the node can be specified via the `--dev-system-contracts` option.
7292
It can take one of the following options:
7393
* `built-in`: Use the compiled built-in contracts
7494
* `built-in-no-verify`: Use the compiled built-in contracts, but without signature verification
@@ -91,7 +111,7 @@ The logging can be configured during runtime via the [`config_setLogLevel`](./SU
91111
## 📃 Caching
92112

93113
The node will cache certain network request by default to disk in the `.cache` directory. Alternatively the caching can be disabled or set to in-memory only
94-
via the `--cache=none|memory|disk` parameter.
114+
via the `--cache=none|memory|disk` parameter.
95115

96116
```bash
97117
era_test_node --cache=none run
@@ -159,7 +179,7 @@ Payer: 0x4eaf936c172b5e5511959167e8ab4f7031113ca3
159179
Gas - Limit: 2_487_330 | Used: 969_330 | Refunded: 1_518_000
160180
Use --show-gas-details flag or call config_setShowGasDetails to display more info
161181

162-
==== Console logs:
182+
==== Console logs:
163183

164184
==== 22 call traces. Use --show-calls flag or call config_setShowCalls to display more info.
165185
Call(Normal) 0x4eaf936c172b5e5511959167e8ab4f7031113ca3 validateTransaction(bytes32, bytes32, tuple) 1830339
@@ -171,16 +191,16 @@ Use --show-gas-details flag or call config_setShowGasDetails to display more inf
171191

172192
You can use the following options to get more granular information during transaction processing:
173193

174-
- `--show-storage-logs <SHOW_STORAGE_LOGS>`: Show storage log information.
175-
[default: none]
194+
- `--show-storage-logs <SHOW_STORAGE_LOGS>`: Show storage log information.
195+
[default: none]
176196
[possible values: none, read, paid, write, all]
177197

178-
- `--show-vm-details <SHOW_VM_DETAILS>`: Show VM details information.
179-
[default: none]
198+
- `--show-vm-details <SHOW_VM_DETAILS>`: Show VM details information.
199+
[default: none]
180200
[possible values: none, all]
181201

182-
- `--show-gas-details <SHOW_GAS_DETAILS>`: Show Gas details information.
183-
[default: none]
202+
- `--show-gas-details <SHOW_GAS_DETAILS>`: Show Gas details information.
203+
[default: none]
184204
[possible values: none, all]
185205

186206
Example:

e2e-tests/test/hardhat-apis.test.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from "chai";
22
import { Wallet } from "zksync-web3";
3-
import { deployContract, getTestProvider } from "../helpers/utils";
3+
import { deployContract, expectThrowsAsync, getTestProvider } from "../helpers/utils";
44
import { RichAccounts } from "../helpers/constants";
55
import { ethers } from "hardhat";
66
import { Deployer } from "@matterlabs/hardhat-zksync-deploy";
@@ -118,6 +118,24 @@ describe("hardhat_setCode", function () {
118118
expect(BigNumber.from(result).toNumber()).to.eq(5);
119119
});
120120

121+
it("Should reject invalid code", async function () {
122+
const action = async () => {
123+
// Arrange
124+
const wallet = new Wallet(RichAccounts[0].PrivateKey);
125+
const deployer = new Deployer(hre, wallet);
126+
127+
const address = "0x1000000000000000000000000000000000001111";
128+
const artifact = await deployer.loadArtifact("Return5");
129+
const contractCode = [...ethers.utils.arrayify(artifact.deployedBytecode)];
130+
const shortCode = contractCode.slice(0, contractCode.length - 1);
131+
132+
// Act
133+
await provider.send("hardhat_setCode", [address, shortCode]);
134+
};
135+
136+
await expectThrowsAsync(action, "bytes must be divisible by 32");
137+
});
138+
121139
it("Should update code with a different smart contract", async function () {
122140
// Arrange
123141
const wallet = new Wallet(RichAccounts[0].PrivateKey);

scripts/install.sh

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
ERA_TEST_NODE_REPO="https://github.com/matter-labs/era-test-node"
6+
7+
function script_usage() {
8+
cat << EOF
9+
Era Test Node Installer v0.1.0
10+
11+
USAGE:
12+
-h | --help Display help information
13+
-v | --version Downloads a specific version of Era Test Node (default: latest release)
14+
-d | --destination The path to the folder where the binary will be installed (default: /usr/local/bin)
15+
EOF
16+
}
17+
18+
function parse_args() {
19+
version=$(get_latest_version)
20+
destination="/usr/local/bin"
21+
22+
while [[ $# -gt 0 ]]; do
23+
arg="$1"
24+
shift
25+
case $arg in
26+
-h | --help)
27+
script_usage
28+
exit 0
29+
;;
30+
-v | --version)
31+
version="$1"
32+
shift
33+
;;
34+
-d | --destination)
35+
destination="$1"
36+
shift
37+
;;
38+
*)
39+
echo "Invalid argument was provided: $arg"
40+
exit 1
41+
;;
42+
esac
43+
done
44+
}
45+
46+
function main() {
47+
parse_args "$@"
48+
49+
echo "Running install script for Era Test Node..."
50+
51+
get_os_info
52+
download_binary
53+
prepare_binary
54+
55+
echo "Era Test Node has been successfully installed!"
56+
}
57+
58+
function prepare_binary() {
59+
echo "Preparing binary..."
60+
61+
tar xz -f "$file_name"
62+
rm "$file_name"
63+
mv era_test_node "$destination/era_test_node"
64+
chmod +x "$destination/era_test_node"
65+
66+
echo "Succesfully prepared binary!"
67+
}
68+
69+
function download_binary() {
70+
file_name="era_test_node-$version-$architecture-$os.tar.gz"
71+
url="$ERA_TEST_NODE_REPO/releases/download/$version/$file_name"
72+
73+
echo "Downloading Era Test Node binary from: $url..."
74+
wget $url
75+
76+
echo "Successfully downloaded Era Test Node Binary!"
77+
}
78+
79+
function get_os_info() {
80+
unamestr="$(uname)"
81+
case "$unamestr" in
82+
"Linux")
83+
os="unknown-linux-gnu"
84+
arch=$(lscpu | awk '/Architecture:/{print $2}')
85+
;;
86+
"Darwin")
87+
os="apple-darwin"
88+
arch=$(arch)
89+
;;
90+
*)
91+
echo "ERROR: Era Test Node only supports Linux and MacOS! Detected OS: $unamestr"
92+
exit 1
93+
;;
94+
esac
95+
96+
case "$arch" in
97+
"x86_64")
98+
architecture="x86_64"
99+
;;
100+
"arm64")
101+
architecture="aarch64"
102+
;;
103+
*)
104+
echo "ERROR: Unsupported architecture detected!"
105+
exit 1
106+
;;
107+
esac
108+
109+
echo "Operating system: $os"
110+
echo "Architecture: $architecture"
111+
}
112+
113+
function get_latest_version() {
114+
echo v$(curl --proto '=https' -sSf https://raw.githubusercontent.com/matter-labs/era-test-node/main/Cargo.toml | \
115+
grep "version" -m 1 | \
116+
awk '{print $3}' | \
117+
sed 's/"//g')
118+
}
119+
120+
main "$@"

src/node/hardhat.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
fork::ForkSource,
66
namespaces::{HardhatNamespaceT, RpcResult},
77
node::InMemoryNode,
8-
utils::{into_jsrpc_error, IntoBoxedFuture},
8+
utils::{into_jsrpc_error, into_jsrpc_error_message, IntoBoxedFuture},
99
};
1010

1111
impl<S: ForkSource + std::fmt::Debug + Clone + Send + Sync + 'static> HardhatNamespaceT
@@ -60,7 +60,7 @@ impl<S: ForkSource + std::fmt::Debug + Clone + Send + Sync + 'static> HardhatNam
6060
self.set_code(address, code)
6161
.map_err(|err| {
6262
tracing::error!("failed setting code: {:?}", err);
63-
into_jsrpc_error(Web3Error::InternalError(err))
63+
into_jsrpc_error_message(err.to_string())
6464
})
6565
.into_boxed_future()
6666
}

src/node/in_memory.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -1544,11 +1544,17 @@ impl<S: ForkSource + std::fmt::Debug + Clone> InMemoryNode<S> {
15441544
..Default::default()
15451545
};
15461546

1547-
let bytecodes: HashMap<U256, Vec<U256>> = vm
1548-
.get_last_tx_compressed_bytecodes()
1549-
.iter()
1550-
.map(|b| bytecode_to_factory_dep(b.original.clone()))
1551-
.collect();
1547+
let mut bytecodes = HashMap::new();
1548+
for b in vm.get_last_tx_compressed_bytecodes().iter() {
1549+
let hashcode = match bytecode_to_factory_dep(b.original.clone()) {
1550+
Ok(hc) => hc,
1551+
Err(error) => {
1552+
tracing::error!("{}", format!("cannot convert bytecode: {}", error).on_red());
1553+
return Err(error.to_string());
1554+
}
1555+
};
1556+
bytecodes.insert(hashcode.0, hashcode.1);
1557+
}
15521558
if execute_bootloader {
15531559
vm.execute(VmExecutionMode::Bootloader);
15541560
}

src/node/in_memory_ext.rs

+18-17
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,10 @@ impl<S: ForkSource + std::fmt::Debug + Clone + Send + Sync + 'static> InMemoryNo
9696
self.get_inner()
9797
.write()
9898
.map_err(|err| anyhow!("failed acquiring lock: {:?}", err))
99-
.map(|mut writer| {
100-
utils::mine_empty_blocks(&mut writer, 1, 1000);
99+
.and_then(|mut writer| {
100+
utils::mine_empty_blocks(&mut writer, 1, 1000)?;
101101
tracing::info!("👷 Mined block #{}", writer.current_miniblock);
102-
"0x0".to_string()
102+
Ok("0x0".to_string())
103103
})
104104
}
105105

@@ -260,7 +260,7 @@ impl<S: ForkSource + std::fmt::Debug + Clone + Send + Sync + 'static> InMemoryNo
260260
"Number of blocks must be greater than 0".to_string(),
261261
));
262262
}
263-
utils::mine_empty_blocks(&mut writer, num_blocks.as_u64(), interval_ms.as_u64());
263+
utils::mine_empty_blocks(&mut writer, num_blocks.as_u64(), interval_ms.as_u64())?;
264264
tracing::info!("👷 Mined {} blocks", num_blocks);
265265

266266
Ok(true)
@@ -304,22 +304,23 @@ impl<S: ForkSource + std::fmt::Debug + Clone + Send + Sync + 'static> InMemoryNo
304304
self.get_inner()
305305
.write()
306306
.map_err(|err| anyhow!("failed acquiring lock: {:?}", err))
307-
.map(|mut writer| {
307+
.and_then(|mut writer| {
308308
let code_key = get_code_key(&address);
309309
tracing::info!("set code for address {address:#x}");
310-
let (hash, code) = bytecode_to_factory_dep(code);
311-
let hash = u256_to_h256(hash);
312-
writer.fork_storage.store_factory_dep(
313-
hash,
314-
code.iter()
315-
.flat_map(|entry| {
316-
let mut bytes = vec![0u8; 32];
317-
entry.to_big_endian(&mut bytes);
318-
bytes.to_vec()
319-
})
320-
.collect(),
321-
);
310+
let hashcode = bytecode_to_factory_dep(code)?;
311+
let hash = u256_to_h256(hashcode.0);
312+
let code = hashcode
313+
.1
314+
.iter()
315+
.flat_map(|entry| {
316+
let mut bytes = vec![0u8; 32];
317+
entry.to_big_endian(&mut bytes);
318+
bytes.to_vec()
319+
})
320+
.collect();
321+
writer.fork_storage.store_factory_dep(hash, code);
322322
writer.fork_storage.set_value(code_key, hash);
323+
Ok(())
323324
})
324325
}
325326
}

0 commit comments

Comments
 (0)