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

[Docs] Everything you need to know about EIP712 on zkSync Era #38

Draft
wants to merge 160 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
160 commits
Select commit Hold shift + click to select a range
8f9b388
Add clippy lints
ilitteri May 12, 2023
1f7f38e
Re-export `ethers-rs`
ilitteri May 12, 2023
d58321a
Add simple CLI for improving development
ilitteri May 12, 2023
94a8753
Update imports
ilitteri May 12, 2023
8a6c44c
Remove `unwrap`s
ilitteri May 12, 2023
d727e45
Add Makefile
ilitteri May 12, 2023
1c8ce09
Fix `README.md`
ilitteri May 12, 2023
51f4edc
Add serde_json as dependency
IAvecilla May 15, 2023
0c5bbc8
Add solc and zksolc compiler binaries
IAvecilla May 15, 2023
e895186
Add new compile module to use zkSolc as compiler
IAvecilla May 15, 2023
88e95b6
Delete compiler binaries from repo
IAvecilla May 15, 2023
7819dfe
Add compilation output struct for serialization
IAvecilla May 16, 2023
e94969b
Add solc and zksolc compiler binaries
IAvecilla May 16, 2023
0e898e2
Update Makefile
ilitteri May 16, 2023
c12b6de
Add `compile` command
ilitteri May 16, 2023
16845eb
cargo fmt
ilitteri May 16, 2023
eda717e
Refactor `ZKProject::compile_zk`
ilitteri May 16, 2023
bb6ef73
`solc` bin is no longer needed
ilitteri May 16, 2023
6430b34
Rename
ilitteri May 16, 2023
d7f8e35
`compile` cmd now returns the compilation output
ilitteri May 16, 2023
fc996c0
Refactor `compile` cmd
ilitteri May 16, 2023
0524036
cargo fmt
ilitteri May 16, 2023
d03d455
Add documentation for `compile` cmd
ilitteri May 17, 2023
5902125
Revert "`solc` bin is no longer needed"
IAvecilla May 17, 2023
c23c6e9
Update deps
ilitteri May 17, 2023
e15f4eb
Change solc compiler path
IAvecilla May 17, 2023
8f50862
Add test
ilitteri May 17, 2023
3061e63
cargo fmt
ilitteri May 17, 2023
2bdac0a
Add struct to serialize abi and bytecodes output compilation
IAvecilla May 17, 2023
85d051e
Add test for compiling with files
ilitteri May 17, 2023
5064b55
Merge branch 'zksolc_compiler_integration' of github.com:lambdaclass/…
ilitteri May 17, 2023
ecc1618
Get both abi and bin when compiling
ilitteri May 17, 2023
c0cd01c
Finish `ContractOuput`
ilitteri May 17, 2023
6b9a6a6
cargo fmt
ilitteri May 17, 2023
8b16cce
Change type of factory_deps field in to serialize
IAvecilla May 17, 2023
6693270
Fix typo in serde-json version dependency
IAvecilla May 18, 2023
9163902
Fix abi compilation output serialization
IAvecilla May 18, 2023
d210f8f
Add support for multiple combined-json arguments in CLI
IAvecilla May 18, 2023
acffa58
Remove empty file
ilitteri May 18, 2023
9e5db76
Update `compile`'s `mod.rs`
ilitteri May 18, 2023
4af7226
Handle errors
ilitteri May 18, 2023
b4d12cf
Add EIP712 initial implementation
ilitteri May 18, 2023
3fb7e8b
`cargo fmt`
ilitteri May 18, 2023
2f4e76c
Add `eip712` module to `lib.rs`
ilitteri May 18, 2023
f897aa8
Add future tests signatures
ilitteri May 18, 2023
bd181cc
Update deps
ilitteri May 18, 2023
b06a16d
Derive `Serialize` & `Deserialize` for `Eip712TransactionRequest`
ilitteri May 18, 2023
6eaaf6e
Add EIP712 metadata
ilitteri May 18, 2023
e11592a
Wrap ethers project in ZKProject
IAvecilla May 18, 2023
b9d0a12
Merge branch 'main' into zksolc_compiler_integration
IAvecilla May 19, 2023
b7dfe2d
Fix fmt
IAvecilla May 19, 2023
c5e0eef
Add solc and zksolc path as constants
IAvecilla May 19, 2023
b311876
`ZKSProvider` trait + `zks_estimateFee` & `zks_getTestnetPaymaster` m…
ilitteri May 19, 2023
ec7dea6
Refactor types
ilitteri May 20, 2023
51fccbd
Implement missing RPC methods
ilitteri May 20, 2023
b4e4ea0
Update Cargo.lock
ilitteri May 20, 2023
27dd741
Add TODOs and fixes
ilitteri May 20, 2023
6e097d8
Fix commented code, add tests & schemas
ilitteri May 22, 2023
1c8259c
Add more tests
ilitteri May 22, 2023
d72faf0
Improve trait method docs
ilitteri May 22, 2023
1067d46
Remove `TODO`
ilitteri May 22, 2023
08bb467
Add docs to README.md
ilitteri May 22, 2023
58592ea
Fix docs
ilitteri May 22, 2023
748a9e9
Implement `ZKSProvider` for `SignerMiddleware`
ilitteri May 22, 2023
8702472
Merge branch 'main' of github.com:lambdaclass/zksync-web3-rs into eip…
ilitteri May 22, 2023
5e2c183
cargo fmt
ilitteri May 22, 2023
715f92f
Implement first version of `struct_hash`
ilitteri May 22, 2023
bc31971
Add EIP712 structs
ilitteri May 22, 2023
41d0926
Add deps
ilitteri May 22, 2023
ba87b3f
Implement `Into<Eip712SignInput>` for `Eip712TransactionRequest`
ilitteri May 22, 2023
993a580
Add `sha2` crate as dep
ilitteri May 22, 2023
5306baa
Start contract deployment test
ilitteri May 22, 2023
d725c6e
Fix `struct_hash`
ilitteri May 22, 2023
f0d5917
Update tests
ilitteri May 22, 2023
6417537
Update constants types
ilitteri May 23, 2023
dfb9886
Add dummy test
ilitteri May 23, 2023
602ae44
Add verifier_contract address to the eip712 domain
ilitteri May 23, 2023
b7243e1
Remove TODO
ilitteri May 23, 2023
41f9621
Cleanup `eip712` module
ilitteri May 23, 2023
5c4d6ec
Merge branch 'zkprovider_impl' of github.com:lambdaclass/zksync-web3-…
ilitteri May 23, 2023
90e135d
Support EIP1559 transfers on L2
ilitteri May 23, 2023
1199ef2
Fix bytecode hash function
IAvecilla May 23, 2023
33aead2
Add test to check bytecode hash correctness
IAvecilla May 23, 2023
59cd27e
Merge branch 'zkprovider_impl' of github.com:lambdaclass/zksync-web3-…
ilitteri May 23, 2023
c854ed6
Merge branch 'main' of github.com:lambdaclass/zksync-web3-rs into zkp…
ilitteri May 23, 2023
213c29d
Merge branch 'zkprovider_impl' of github.com:lambdaclass/zksync-web3-…
ilitteri May 23, 2023
e665ba6
Add new bytecode hash function
IAvecilla May 23, 2023
7e3eb35
Mark struct hash function as todo
IAvecilla May 23, 2023
3e5aa96
Move comment
ilitteri May 23, 2023
fc074a4
Refactor contract hash concat step
ilitteri May 23, 2023
8b7e37c
Add sign input types hash map
ilitteri May 23, 2023
9833228
Update imports
ilitteri May 23, 2023
09c6bad
Fix chain id in domain
ilitteri May 23, 2023
2c017c9
Implement `struct_hash`
ilitteri May 23, 2023
5bfd596
Add dummy test for `Eip712` trait impl
ilitteri May 23, 2023
bd19965
Update `Eip712SignInput` struct serialization
ilitteri May 23, 2023
37293cf
Add `zks_utils` module
ilitteri May 23, 2023
5a028b0
Merge branch 'zkprovider_impl' of github.com:lambdaclass/zksync-web3-…
ilitteri May 24, 2023
960904a
Implement `rlp::Encoding` for `Eip712TransactionRequest`
ilitteri May 24, 2023
a580285
Update `test_eip712`
ilitteri May 24, 2023
f8709cc
Update `rlp` implementation
ilitteri May 24, 2023
10b6f3b
Update constant type
ilitteri May 24, 2023
022e4ec
Fix structures
ilitteri May 24, 2023
e631b96
Fixes
ilitteri May 29, 2023
79baa99
EIP712 bug fixes (#27)
ilitteri May 30, 2023
d50c516
Merge branch 'support_transfers' of github.com:lambdaclass/zksync-web…
ilitteri May 30, 2023
c713f5d
Complete factory deps Into implementation
ilitteri May 30, 2023
0cd37b8
Refactor `hash_bytecode`
ilitteri May 30, 2023
d85edff
`cargo fmt`
ilitteri May 30, 2023
bf02189
Add `const`s to `zks_utils` module
ilitteri May 30, 2023
742f47d
Add initial implementation of `ZKSSigner::deploy`
ilitteri May 30, 2023
b438c66
Implement `Eip712TransactionRequestBuilder`
ilitteri May 30, 2023
ea73138
Replace trait with struct
ilitteri May 31, 2023
199005e
Fix `data` generation
ilitteri May 31, 2023
dca8838
Remove prints
ilitteri May 31, 2023
00b510e
Improve integration test
ilitteri May 31, 2023
8c9efbd
`cargo fmt`
ilitteri May 31, 2023
f07d042
Remove unused imports
ilitteri May 31, 2023
7bb3d25
EIP712 RLP Encoding (#22)
ilitteri May 31, 2023
665b7b9
Add `ZKSSigner::address` method
ilitteri May 31, 2023
6744ffa
Refactor API
ilitteri May 31, 2023
c2e9ba9
Rename struct
ilitteri May 31, 2023
dab55fb
Merge branch 'eip712_transaction_support' of github.com:lambdaclass/z…
ilitteri May 31, 2023
a691bdc
Refactor modules
ilitteri May 31, 2023
03a3fd8
Export module types
ilitteri May 31, 2023
abf2da2
Refactor transaction request building
ilitteri May 31, 2023
7b95001
Refactor custom data building
ilitteri May 31, 2023
f00425a
Refactor modules
ilitteri May 31, 2023
ad18d2f
Remove `utils.rs` module
ilitteri May 31, 2023
fa3534c
Add `eth_balance` method
ilitteri May 31, 2023
5d6ff7c
Cleanup
ilitteri May 31, 2023
865eabd
Fix meta default
ilitteri May 31, 2023
d7865a6
Initial impl
ilitteri May 31, 2023
4a2e809
Support transfers using EIP712 transactions
ilitteri Jun 1, 2023
11710ef
Remove dummy tests
ilitteri Jun 1, 2023
6e0b0c3
`custom_data` & `data` shouldn't be `Option`s
ilitteri Jun 1, 2023
7f612e2
Remove useless method
ilitteri Jun 1, 2023
fcbd617
Implement `Default` for `Eip712TransactionRequest`
ilitteri Jun 1, 2023
6ba6bdd
Remove dummy tests
ilitteri Jun 1, 2023
5be1007
Remove `utils.rs` module
ilitteri Jun 1, 2023
07853a6
Change Into with From because it gives you Into for free
ilitteri Jun 1, 2023
eb57690
Remove dummy tests
ilitteri Jun 1, 2023
9eaf196
Change From with TryFrom
ilitteri Jun 1, 2023
78a4a4c
Remove unused imports
ilitteri Jun 1, 2023
687655e
Make clippy suggestions
ilitteri Jun 1, 2023
ffab0d3
Merge branch 'eip712_transaction_support' of github.com:lambdaclass/z…
ilitteri Jun 1, 2023
d080a4a
Solve conflicts
ilitteri Jun 1, 2023
8fdefe7
Fix clippy suggestions
ilitteri Jun 1, 2023
487824a
Merge branch 'main' of github.com:lambdaclass/zksync-web3-rs into sup…
ilitteri Jun 1, 2023
f9480ca
Merge branch 'support_deployments' of github.com:lambdaclass/zksync-w…
ilitteri Jun 1, 2023
1b6775e
Merge branch 'eip712_transfers' of github.com:lambdaclass/zksync-web3…
ilitteri Jun 1, 2023
d1e875d
Remove `Option`s from structs
ilitteri Jun 1, 2023
2ac44f2
Remove old files
ilitteri Jun 1, 2023
8857abb
Remove commented code
ilitteri Jun 1, 2023
cd09fb4
Add default implementation and methods to build (#35)
IAvecilla Jun 1, 2023
bbf431d
Refactor deployment-related methods & improve testing (#32)
ilitteri Jun 1, 2023
d4856e8
Rename `Eip712SignInput` -> `Eip712Transaction`
ilitteri Jun 1, 2023
4d7f6e8
Add initial docs
ilitteri Jun 1, 2023
3c4cad5
Update title
ilitteri Jun 1, 2023
659e9a5
Add intro to "Signing an EIP713 transaction"
ilitteri Jun 1, 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
106 changes: 106 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,111 @@
# zksync-web3-rs

## Everything you need to know about EIP712 on zkSync Era

The Ethereum Improvement Proposal [EIP-712: Typed structured data hashing and signing](https://eips.ethereum.org/EIPS/eip-712) introduces hashing and signing of typed-structured data as well as bytestrings.

In the following sections we'll explain how to build, sign, encode and send a well-formed EIP712 transaction request to the network.

The steps:

1. Create a base request and fill it with sufficient data for estimating the fee.
2. Estimate the fee and add it the request.
3. Derive the EIP712 signable transaction from the request and sign it and add the signature to the request.
5. RLP-encode the request and concatenate the transaction type at the beginning.
6. Send the transaction using the `sendRawTransaction` method.

### Building an EIP712 transaction request

These transactions have the same fields as standard Ethereum transactions, but they also have fields that contain additional L2-specific data that should be set in the `customData` field.

In the case of zkSync Era, this fields are the following:

- `gasPerPubdata`: A field denoting the maximum amount of gas the user is willing to pay for a single byte of pubdata.
- `customSignature`: A field with a custom signature for the cases in which the signer's account is not an EOA.
- `paymasterParams`: A field with parameters for configuring the custom paymaster for the transaction. Parameters include the address of the paymaster and the encoded input (you could find a tutorial on building a custom paymaster in the [zkSync Era docs](https://era.zksync.io/docs/dev/tutorials/custom-paymaster-tutorial.html)).
- `factory_deps`: A non-empty array of bytes. For deployment transactions, it should contain the bytecode of the contract being deployed. If the contract is a factory contract, i.e. it can deploy other contracts, the array should also contain the bytecodes of the contracts which it can deploy.

This is how a noop `customData` object looks like:

```json
"customData": {
"gasPerPubdata": "0xc350",
"factoryDeps": [],
"customSignature": "0x",
"paymasterParams": {
"paymaster": "0x0000000000000000000000000000000000000000",
"paymasterInput": "0x"
}
}
```

We call the representation of this structure `Eip712Meta` and its definition and implementation is located in the [`src/eip712/meta.rs`](/src/eip712/meta.rs) module.

The transaction request is built in three stages being the final the one being encoded and sent to the network.

In the first stage you fill the request with *input data* (i.e. this could be `from`, `to`, `nonce`, `gasPrice`, `value`, `chainId`, `type` in the case of a transfer transaction). In the second stage the request is filled with fee data obtained from the network given the first stage's result (i.e. `maxFeePerGas`, `maxPriorityFeePerGas`, `gasPerPubdata`, `gasLimit`). Finally, the last stage consists on adding the EIP712 signature to the `customSignature` field of the `customData` object.

This is how a noop EIP712 transaction request looks like:

```json
{
"to": "0x0000000000000000000000000000000000000000",
"from": "0x0000000000000000000000000000000000000000",
"nonce": "0x0",
"gasLimit": "0x0",
"gasPrice": "0x0",
"data": "0x",
"value": "0x0",
"chainId": "0x10e",
"type": "0x71",
"accessList": [],
"maxPriorityFeePerGas": "0x0",
"maxFeePerGas": "0x0",
"customData": {
"gasPerPubdata": "0xc350",
"factoryDeps": [],
"customSignature": "0x",
"paymasterParams": {
"paymaster": "0x0000000000000000000000000000000000000000",
"paymasterInput": "0x"
}
},
"ccipReadEnabled": false
}
```

### Building an EIP712 signable transaction

Instead of signing the RLP-encoded transaction, the user signs the a typed EIP712 structure which we called `Eip712Transaction`. This structure is built from the transaction request as it contains a subset of its fields. The `Eip712Transaction` structure is defined in the [`src/eip712/transaction.rs`](/src/eip712/transaction.rs) module and a noop one looks like the following:

```json
{
"txType": "0x71",
"from": "0x0000000000000000000000000000000000000000",
"to": "0x0000000000000000000000000000000000000000",
"gasLimit": "0x0",
"gasPerPubdataByteLimit": "0xc350",
"maxFeePerGas": "0x0",
"maxPriorityFeePerGas": "0x0",
"paymaster": "0x0000000000000000000000000000000000000000",
"nonce": "0x0",
"value": "0x0",
"data": "0x",
"factoryDeps": [],
"paymasterInput": "0x"
}
```

### Encoding an EIP712 transaction

### Signing an EIP712 transaction

The signing could be done by `ethers-rs` by the `LocalWallet` with the method `sign_typed_data`. What you are signing here is the keccak hash of the EIP712 transaction encoding. Internally, this is done by the `sighash` method.

### Sending an EIP712 transaction request

What is sent to the network is the concatenation of the transaction type with the RLP-encoding of the transaction request containing the signed message.

## zkSync Era’s JSON-RPC methods

### The `ZKSProvider` trait
Expand Down
188 changes: 0 additions & 188 deletions src/eip712/eip712_sign_input.rs

This file was deleted.

Loading