Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Rollbackable fields private #209

Merged
merged 69 commits into from
Sep 5, 2024
Merged
Changes from 1 commit
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
5de8afb
Derive partial-eq for VmState
MarcosNicolau Aug 13, 2024
59470a7
Add initial gas param for VmState new
MarcosNicolau Aug 13, 2024
26c2b18
Update era-compiler-tester branch
MarcosNicolau Aug 13, 2024
e5cb98b
fix test bytecode_publishing
juan518munoz Aug 14, 2024
f0dce41
Store changes for get_used_contracts tests
MarcosNicolau Aug 14, 2024
c862649
adapt to zksync-era tests
juan518munoz Aug 16, 2024
bbac76d
Remove hash_map from Storage trait
MarcosNicolau Aug 16, 2024
5ca9edf
Fix increment_tx_number not cleaning transient_storage
MarcosNicolau Aug 20, 2024
01c6eb6
Fix decommit opcode
MarcosNicolau Aug 20, 2024
be5024f
Various far_call fixes
MarcosNicolau Aug 20, 2024
cdfcd92
Add stipend param to frame and decrease it in panics and reverts
MarcosNicolau Aug 20, 2024
5be7e35
Add no refund storage_read for far_call decommit_code_hash
MarcosNicolau Aug 20, 2024
29c184a
Remove rollbacks from main context
MarcosNicolau Aug 20, 2024
679d38d
Reimplement vec snapshots
MarcosNicolau Aug 20, 2024
1c9a4b2
Add external snapshot(whole vm)
MarcosNicolau Aug 20, 2024
f6f2829
Add storage cache and util functio to get storage changes from initial
MarcosNicolau Aug 20, 2024
8747004
Refactor state pub fields
MarcosNicolau Aug 20, 2024
2a28162
Add new function to get storage changes from snapshot or initial
MarcosNicolau Aug 20, 2024
6509f4a
Merge branch 'main' into zksync-era-integration-tests
MarcosNicolau Aug 20, 2024
41db1b5
Update zksync-era submodule
MarcosNicolau Aug 20, 2024
fe7a666
Update era-compiler-tester submodule
MarcosNicolau Aug 20, 2024
18c5199
Address clippy warnings
MarcosNicolau Aug 20, 2024
897eb16
More clippy warnings
MarcosNicolau Aug 20, 2024
4efc066
Update zksync-era submodule
MarcosNicolau Aug 20, 2024
b512b31
ci: add submodule step for era
fkrause98 Aug 20, 2024
b4c8773
initial commit
juan518munoz Aug 20, 2024
a5700ea
Address review comments
MarcosNicolau Aug 20, 2024
c30ea73
Add cache to storage_read
MarcosNicolau Aug 21, 2024
cd451dd
Update zksync-era submodule
MarcosNicolau Aug 22, 2024
d0c59af
Add full tracers implementation
MarcosNicolau Aug 22, 2024
855d043
Refactor how the vm handles tracers
MarcosNicolau Aug 22, 2024
439f68e
Update era-compiler-tester submodule
MarcosNicolau Aug 22, 2024
e5ab604
Update zksync-era submodule
MarcosNicolau Aug 22, 2024
6d1682e
Address clippy warnings
MarcosNicolau Aug 22, 2024
0cc8684
Add default function in Tracer trait
MarcosNicolau Aug 23, 2024
081d615
Address clippy warnings
MarcosNicolau Aug 23, 2024
6068375
merge branch 'zksync-era-integration-tests'
juan518munoz Aug 26, 2024
ee97d09
Address review comments
MarcosNicolau Aug 26, 2024
5baf370
Add docs to state
MarcosNicolau Aug 26, 2024
75434eb
Address review comments
MarcosNicolau Aug 26, 2024
66d412c
Remove optional from run with tracers
MarcosNicolau Aug 26, 2024
291e4c1
Update era-compiler-tester submodule
MarcosNicolau Aug 26, 2024
02e8a90
Update era-compiler-tester submodule
MarcosNicolau Aug 26, 2024
ed3784c
Address clippy warnings
MarcosNicolau Aug 26, 2024
aea62fe
Fix storage_read
MarcosNicolau Aug 26, 2024
e6b1c19
Merge remote-tracking branch 'origin' into zksync-era-integration-tests
MarcosNicolau Aug 26, 2024
0385534
Merge branch 'zksync-era-tests' into implement-tracers
MarcosNicolau Aug 26, 2024
caad06d
Merge branch 'zksync-era-integration-tests' into implement-tracers
MarcosNicolau Aug 26, 2024
c06ce65
Merge branch 'main' into implement-tracers
MarcosNicolau Aug 28, 2024
f5dfd2a
merge branch 'main'
juan518munoz Aug 28, 2024
b444373
update zksync era submodule
juan518munoz Aug 28, 2024
fc2855a
Implement statistics (#213)
MarcosNicolau Aug 29, 2024
c36cf47
Merge branch 'main' into implement-tracers
MarcosNicolau Aug 29, 2024
5de6b4d
Update zksync-era submodule
MarcosNicolau Aug 29, 2024
adc3c0e
Move storage param to vm run
MarcosNicolau Aug 30, 2024
c1ab599
Merge branch 'main' into zk_server_compatibility
gianbelinche Sep 3, 2024
05c6bb9
Update zksync era submodule
gianbelinche Sep 3, 2024
beb8ef0
Update compiler tester submodule
gianbelinche Sep 3, 2024
264c0d0
Lint
gianbelinche Sep 3, 2024
5ba2e42
Merge branch 'zk_server_compatibility' into era_vm_rollbackable_priv_…
gianbelinche Sep 3, 2024
d9f581f
Remove print
gianbelinche Sep 3, 2024
1e6167a
Update zksync era submodule
gianbelinche Sep 3, 2024
2a213dc
Add heap size optimization
gianbelinche Sep 4, 2024
a44f3b8
Update submodules
gianbelinche Sep 4, 2024
c4dab0e
Address comments
gianbelinche Sep 4, 2024
80cf4c3
Merge branch 'zk_server_compatibility' into era_vm_rollbackable_priv_…
gianbelinche Sep 4, 2024
7f4d603
Merge branch 'main' into era_vm_rollbackable_priv_fields
gianbelinche Sep 4, 2024
274fa7e
Lint
gianbelinche Sep 4, 2024
9abd7fa
Update submodule
gianbelinche Sep 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'main' into implement-tracers
  • Loading branch information
MarcosNicolau committed Aug 29, 2024
commit c36cf4712de7913c1e7a6e1212ec75a8fc525a5f
18 changes: 12 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -552,10 +552,10 @@ jobs:
- name: Checkout sources
uses: actions/checkout@v4

- name: Zksync-era dependencies
- name: Zksync-era + perf dependencies
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: clang clang-tools build-essential librocksdb-dev
packages: clang clang-tools build-essential librocksdb-dev linux-tools-common linux-tools-generic linux-perf
version: 1.0

- name: Setup nodejs + yarn
@@ -585,25 +585,31 @@ jobs:
chmod +x solc
sudo cp solc /usr/bin/solc

- name: Build benchmark contracts
working-directory: ${{ github.workspace }}
run: make bench-setup

- name: Fetch toolchain version from zksync-era
- name: Fetch toolchain version from zksync-era + set zksync home
run: |
cd ${{ github.workspace }}/zksync-era
echo "ERA_TOOLCHAIN=$(head ./rust-toolchain)" >> $GITHUB_ENV
echo "ZKSYNC_HOME=${{ github.workspace }}/zksync-era" >> $GITHUB_ENV

- name: Rustup toolchain install
uses: dtolnay/rust-toolchain@nightly
with:
toolchain: ${{ env.ERA_TOOLCHAIN }}

- name: Build benchmark contracts
working-directory: ${{ github.workspace }}
run: make bench-setup

- uses: Swatinem/rust-cache@v2
with:
workspaces: |
${{ github.workspace }}/zksync-era/core/tests/vm-benchmark

- uses: taiki-e/install-action@v2
with:
tool: flamegraph

- name: Check zksync-era benchmarks & era_vm build correctly
run: |
cd ${{ github.workspace }}/zksync-era
70 changes: 69 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
.PHONY: clean lint test deps submodules era-test
.PHONY: clean lint test deps submodules bench flamegraph era-test build-bench-contracts %.sol
.SILENT: %.sol

LLVM_PATH?=$(shell pwd)/era-compiler-tester/target-llvm/target-final/
ZKSYNC_ROOT=$(shell realpath ./zksync-era)
ZKSYNC_L1_CONTRACTS=$(ZKSYNC_ROOT)/contracts/l1-contracts/artifacts
ZKSYNC_L2_CONTRACTS=$(ZKSYNC_ROOT)/contracts/l2-contracts/artifacts-zk
ZKSYNC_SYS_CONTRACTS=$(ZKSYNC_ROOT)/contracts/system-contracts/artifacts-zk
ZKSYNC_BOOTLOADER_CONTRACT=$(ZKSYNC_ROOT)/contracts/system-contracts/bootloader/build/artifacts
ZKSYNC_BENCH_TEST_DATA=$(ZKSYNC_ROOT)/etc/contracts-test-data/artifacts-zk
ZKSYNC_BENCH_CONTRACTS=$(ZKSYNC_ROOT)/core/tests/vm-benchmark/deployment_benchmarks
BENCH_SOURCES=$(shell realpath ./deployment_benchmarks_sources)


clean:
rm -rf ./db
@@ -27,5 +37,63 @@ test: deps
ci-test:
export LLVM_SYS_170_PREFIX=$(LLVM_PATH) && $(MAKE) test

# Build the given set of zksync era contracts,
# this can be: l1, l2 or system contracts.
# These are needed for benchmarking.
define build_zk_contracts
cd $(ZKSYNC_ROOT)/contracts && \
yarn install --frozen-lockfile && \
$(1)
endef

$(ZKSYNC_L1_CONTRACTS):
$(call build_zk_contracts, yarn l1 build)

$(ZKSYNC_L2_CONTRACTS):
$(call build_zk_contracts, yarn l2 build)

$(ZKSYNC_SYS_CONTRACTS):
$(call build_zk_contracts, yarn sc build:system-contracts)

$(ZKSYNC_BOOTLOADER_CONTRACT):
$(call build_zk_contracts, yarn sc build:bootloader)

$(ZKSYNC_BENCH_TEST_DATA):
touch $(ZKSYNC_ROOT)/etc/contracts-test-data
cd $(ZKSYNC_ROOT)/etc/contracts-test-data && yarn install --frozen-lockfile && yarn build

# Steps:
# 1 - cd
# 2 - Take the given CONTRACT.sol and get its byte code
# 3 - Parse the output
# 4 - Redirect the hexstring to a CONTRACT (mind the extension-less name) to
# a file insie the contract benchmarks folder.
%.sol:
echo "Building benchmark contract: $@"
cd $(BENCH_SOURCES) && \
zksolc --bin $@ | grep -oE '0x[0-9a-fA-F]+' > $(ZKSYNC_BENCH_CONTRACTS)/$(basename $@)

build_bench_contracts: fibonacci_rec.sol send.sol


# Compile contracts and fetch submodules for the benches.
# If you get any 'missing file' errors whil running cargo bench, this is probably what you must run.
bench-setup: submodules build_bench_contracts $(ZKSYNC_BENCH_TEST_DATA) $(ZKSYNC_SYS_CONTRACTS) $(ZKSYNC_BOOTLOADER_CONTRACT) $(ZKSYNC_L1_CONTRACTS) $(ZKSYNC_L2_CONTRACTS)

bench:
cd $(ZKSYNC_ROOT) && cargo bench --bench criterion "$(lambda|fast_vm|legacy)/(fibonacci|send)"

check-flamegraph:
cd $(ZKSYNC_ROOT) && CARGO_PROFILE_BENCH_DEBUG=2 cargo flamegraph --root --bench criterion -- --bench --profile-time 5 "$lambda/fibonacci_rec^"

bench-base:
cd $(ZKSYNC_ROOT) && cargo bench --bench criterion -- --save-baseline bench_base lambda 1>bench-compare.txt

bench-compare:
cd $(ZKSYNC_ROOT) && cargo bench --bench criterion -- --baseline bench_base lambda 1>bench-compare.txt

clean-contracts:
rm -rfv $(ZKSYNC_BENCH_TEST_DATA) $(ZKSYNC_SYS_CONTRACTS) $(ZKSYNC_BOOTLOADER_CONTRACT) $(ZKSYNC_L1_CONTRACTS) $(ZKSYNC_L2_CONTRACTS)

era-test: submodules
cd ./zksync-era/core/lib/multivm && cargo t era_vm
55 changes: 55 additions & 0 deletions bench_results.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import re
import sys

def convert_to_ms(value, unit):
if unit == 'µs':
return value / 1000
elif unit == 'ms':
return value
elif unit == 's':
return value * 1000
else:
raise ValueError(f"Unknown time unit: {unit}")

def parse_benchmark_file(file_path):
machines = {}
pattern = r'(\w+)/\w+\s+time:\s+\[\d+(?:\.\d+)?\s(\w+)\s(\d+(?:\.\d+)?)\s(\w+)\s\d+(?:\.\d+)?\s(\w+)\]'

with open(file_path, 'r') as file:
content = file.read()
# Clean the file content
cleaned_content = re.sub(r'\n(\s+)time:', ' time:', content)
for line in cleaned_content.split('\n'):
match = re.match(pattern, line)
if match:
machine, lower_unit, mid_time, mid_unit, upper_unit = match.groups()
# Convert mid_time to milliseconds
mid_time_ms = convert_to_ms(float(mid_time), mid_unit)
machines[machine] = machines.get(machine, 0) + mid_time_ms

return machines

def main():
if len(sys.argv) != 2:
print("Usage: results.py <path-to-file>")
return
file_path = sys.argv[1]
results = parse_benchmark_file(file_path)

for machine, total_time in results.items():
print(f"Total {machine} time: {total_time:.3f} ms")

if not "lambda" in results:
return

print("")

if "legacy" in results:
lambda_vs_legacy = round(results["lambda"] / results["legacy"], 1)
print(f"lambda_vm took x{lambda_vs_legacy} more than legacy_vm")
if "fast" in results:
lambda_vs_fast = round(results["lambda"] / results["fast"], 1)
print(f"lambda_vm took x{lambda_vs_fast} more than fast_vm")

if __name__ == "__main__":
main()
22 changes: 22 additions & 0 deletions deployment_benchmarks_sources/factorial_it.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
pragma solidity ^0.8.0;

contract benchmark {
uint256 value;
constructor() {
value = fac(57);
}

function get_calculation() public view returns (uint256) {
return value;
}

function fac(uint n) internal pure returns(uint256) {
uint256 r = 1;
for (uint256 k = 2; k <= n; k++) {
r = k * r;
}

return r;
}
}

20 changes: 20 additions & 0 deletions deployment_benchmarks_sources/factorial_rec.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
pragma solidity ^0.8.0;

contract benchmark {
uint256 value;
constructor() {
value = fac(57);
}

function get_calculation() public view returns (uint256) {
return value;
}

function fac(uint256 n) internal returns (uint256) {
if (n <= 1) {
return 1;
}
return n * fac(n - 1);
}
}

26 changes: 26 additions & 0 deletions deployment_benchmarks_sources/fibonacci_it.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
pragma solidity ^0.8.0;

contract benchmark {
uint256 value;
constructor() {
value = fib(370);
}

function get_calculation() public view returns (uint256) {
return value;
}

function fib(uint n) internal pure returns(uint b) {
if (n == 0) {
return 0;
}
uint a = 1;
b = 1;
for (uint i = 2; i < n; i++) {
uint c = a + b;
a = b;
b = c;
}
return b;
}
}
19 changes: 19 additions & 0 deletions deployment_benchmarks_sources/fibonacci_rec.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
pragma solidity ^0.8.0;

contract benchmark {
uint256 value;
constructor() {
value = fib(25);
}

function get_calculation() public view returns (uint256) {
return value;
}

function fib(uint256 n) internal returns (uint256) {
if (n <= 1) {
return n;
}
return fib(n - 1) + fib(n - 2);
}
}
25 changes: 25 additions & 0 deletions deployment_benchmarks_sources/heap_read_write.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pragma solidity ^0.8.0;

contract HeapBenchmark {
constructor() {
uint256 v1 = 0;
uint256 v2 = 0;
uint256 n = 16000;
uint256[] memory array = new uint256[](1);

assembly {
mstore(add(array, sub(n, 1)), 4242)

let j := 0
for {} lt(j, n) {} {
v1 := mload(add(array, mod(mul(j, j), n)))
v2 := mload(add(array, j))
mstore(add(array, j), add(add(v1, v2), 42))
j := add(j, 1)
if gt(j, sub(n, 1)) {
j := 0
}
}
}
}
}
8 changes: 8 additions & 0 deletions deployment_benchmarks_sources/send.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pragma solidity >=0.8.20;

contract Send {
constructor() {
address payable self = payable(msg.sender);
self.call{value: 100};
}
}
You are viewing a condensed version of this merge commit. You can view the full changes here.