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

Gas usage comparisson between P256Verify precompile implementations (benchmark) #180

Open
wants to merge 51 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
49a89da
Add test contracts
ilitteri Nov 1, 2023
8bbe8ab
Add compiler module
ilitteri Nov 1, 2023
88dd6ca
Add local_wallet to utils
ilitteri Nov 1, 2023
4e62bd6
Update deps
ilitteri Nov 1, 2023
8390379
Add integration tests
ilitteri Nov 1, 2023
5af4ae5
Add compiler module to lib
ilitteri Nov 1, 2023
ee74e5b
cargo fmt
ilitteri Nov 1, 2023
b239b76
Update deps
ilitteri Nov 1, 2023
7201ab4
Remove log usage
ilitteri Nov 1, 2023
51b3955
Fix tests
ilitteri Nov 1, 2023
2f9092a
Add comment explaining where we got the calldata from
jrchatruc Nov 1, 2023
b039c79
clippy
jrchatruc Nov 1, 2023
5d5f243
Add cheaper modexp version
ilitteri Nov 2, 2023
26904fd
Update integration tests
ilitteri Nov 2, 2023
79ae22a
Add clean cmd in Makefile
ilitteri Nov 2, 2023
e62dd8b
Update era-test-node commit
ilitteri Nov 2, 2023
f8950d6
cargo fmt
ilitteri Nov 2, 2023
7c456fb
Add new verifier test
jrchatruc Nov 2, 2023
076f772
Fix 1 limb modexp tests
ilitteri Nov 2, 2023
035faa8
Update cheap modexp
ilitteri Nov 2, 2023
73fbe5e
Update era-test-node commit
ilitteri Nov 2, 2023
230c131
Update era-test-node commit
ilitteri Nov 2, 2023
992e904
Update Verifier's vk with a test one
ilitteri Nov 3, 2023
cc94578
write_verifier_gas_result on new verifier
ilitteri Nov 3, 2023
c8f3a22
Update run cmd
ilitteri Nov 3, 2023
a9574e0
Add comments to tests
ilitteri Nov 3, 2023
4af0fd7
Ignore new_verifier_fails
ilitteri Nov 3, 2023
b02728b
cargo fmt & clippy
ilitteri Nov 3, 2023
40dfb83
Add P256 verifier contracts
ilitteri Nov 3, 2023
e9ddab2
Add p256verify bench
ilitteri Nov 3, 2023
25599c7
Change modexp precompile to switch to the simple implementation if ev…
jrchatruc Nov 3, 2023
18ed01b
Go back to call modexp
ilitteri Nov 3, 2023
264409c
Implement naive compile_zkvyper
ilitteri Nov 3, 2023
dad7224
Merge branch 'add_verifier_integration_test' of github.com:lambdaclas…
ilitteri Nov 3, 2023
6679b99
Add vyper implementation to bench
ilitteri Nov 3, 2023
d9f20df
Add benches report
ilitteri Nov 6, 2023
9beb478
Finish benchmark setup
ilitteri Nov 6, 2023
53331f7
Generate calldata vector
ilitteri Nov 6, 2023
606f03c
Cargo fmt
ilitteri Nov 6, 2023
bb7debb
Add calldata vector generation for benches
ilitteri Nov 6, 2023
42e06ca
Merge branch 'main' of github.com:lambdaclass/zksync_era_precompiles …
ilitteri Nov 6, 2023
cda0c25
Fix table
ilitteri Nov 6, 2023
db36740
Fix clippy
ilitteri Nov 7, 2023
0b134ec
Remove precompile
ilitteri Nov 7, 2023
ed29922
Add report to list
ilitteri Nov 7, 2023
052fdf4
Update compilers paths
ilitteri Nov 7, 2023
942d3fd
Update Makefile
ilitteri Nov 7, 2023
971972b
Update Makefile
ilitteri Nov 7, 2023
6b68b89
Revert "Update compilers paths"
ilitteri Nov 8, 2023
e1cbaf1
Update makefile
ilitteri Nov 8, 2023
4fe861b
Merge branch 'main' of github.com:lambdaclass/zksync_era_precompiles …
ilitteri Nov 8, 2023
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
16 changes: 15 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: setup update run test docs
.PHONY: setup update run test docs clean compilers get-zksolc get-zkvyper get-vyper benches

setup:
git submodule update --init && \
Expand Down Expand Up @@ -29,3 +29,17 @@ docs:

clean:
rm submodules/era-test-node/src/deps/contracts/*.yul.zbin submodules/era-test-node/etc/system-contracts/contracts/precompiles/*.yul

compilers: get-zksolc get-zkvyper get-vyper

get-zksolc:
wget 'https://github.com/matter-labs/zksolc-bin/raw/main/macosx-arm64/zksolc-macosx-arm64-v1.3.14' -O ~/Library/Application\ Support/eth-compilers/zksolc

get-zkvyper:
wget 'https://github.com/matter-labs/zkvyper-bin/blob/main/macosx-arm64/zkvyper-macosx-arm64-v1.3.13' -O ~/Library/Application\ Support/eth-compilers/zkvyper

get-vyper:
wget 'https://github.com/vyperlang/vyper/releases/download/v0.3.10/vyper.0.3.10+commit.91361694.darwin' -O ~/Library/Application\ Support/eth-compilers/vyper

benches:
make test PRECOMPILE=p256verify_bench
1,568 changes: 1,568 additions & 0 deletions assets/benches_calldata.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions precompiles/Modexp.yul
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,10 @@ object "ModExp" {
let limbsExpLen, misalignment := bigIntLimbs(expLen)
let limbsModLen, misalignment := bigIntLimbs(modLen)

if and(and(eq(limbsBaseLen, 1), eq(limbsExpLen, 1)), eq(limbsModLen, 1)) {
oneLimbImplementation()
}

let ptrBaseLimbs
parseCalldata(basePtr, baseLen, ptrBaseLimbs)

Expand Down
34 changes: 33 additions & 1 deletion scripts/p256verify_daimo_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def write_test_suit(test_suit_data, test_file: io.TextIOWrapper):
for test_case in test_suit_data:
write_test_case("P256VERIFTY_PRECOMPILE_ADDRESS", test_case, test_file)

def main():
def write_daimo_tests():
test_case_data = []
for test_path in TESTS_PATHS:
with open(test_path, "r") as entry_file:
Expand Down Expand Up @@ -89,5 +89,37 @@ def main():

write_test_suit(test_case_data, open("tests/tests/p256verify_daimo_tests.rs", "w"))

def gen_valid_test_cases_calldata():
test_cases_calldata = []
for test_path in TESTS_PATHS:
with open(test_path, "r") as entry_file:
data = json.load(entry_file)
i = 0
for test_case in data:
hash = test_case["hash"]
r = test_case["r"]
s = test_case["s"]
x = test_case["x"]
y = test_case["y"]

calldata = hash + r + s + x + y

if "wycheproof" in entry_file.name:
comment = test_case["comment"]
valid = test_case["valid"]
name = f"wycheproof_{i}_{'should_fail' if not valid else 'should_pass'}"
i += 1
else:
name = "_".join(test_case["comment"].split(" "))
valid = True
comment = None
if valid:
test_cases_calldata.append(calldata)
with open("assets/benches_calldata.json", "w") as benches_calldata:
json.dump(test_cases_calldata, benches_calldata)

def main():
gen_valid_test_cases_calldata()

if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ fn main() {
"p256verify".to_string(),
"secp256k1verify".to_string(),
"verifier".to_string(),
"p256verify_benches_report".to_string(),
];
precompiles_report_list
.into_iter()
Expand Down
Loading