matter-labs/zksync

zk contract deploy failed

dengshuaige opened this issue · 1 comments

When I finished "zk init", use the "zk contract deploy", it returns can't find typechain, the returns:

error[E0277]: the size for values of type [u8] cannot be known at compilation time
--> core/lib/storage/src/chain/operations_ext/mod.rs:1444:15
|
1444 | .map(|account| (start_account, Address::from_slice(&account)))
| ^^^^^^^ doesn't have a size known at compile-time
|
= help: the trait Sized is not implemented for [u8]
= note: all function arguments must have a statically known size

error[E0282]: type annotations needed for Vec<T>
--> core/lib/storage/src/chain/state/mod.rs:623:17
|
623 | let mut account_diff = Vec::new();
| ^^^^^^^^^^^^^^^^
...
642 | .map(|acc| acc.block_number())
| ------------ type must be known at this point
|
help: consider giving account_diff an explicit type, where the type for type parameter T is specified
|
623 | let mut account_diff: Vec = Vec::new();
| ++++++++

error[E0609]: no field from_block on type &_
--> core/lib/storage/src/ethereum/mod.rs:520:46
|
520 | ... let (from_block, to_block) = (op.from_block as u32, op.to_block a...
| ^^^^^^^^^^

warning: unused import: num::bigint::ToBigInt
--> core/lib/storage/src/chain/account/mod.rs:24:5
|
24 | use num::bigint::ToBigInt;
| ^^^^^^^^^^^^^^^^^^^^^

warning: unused import: num::ToPrimitive
--> core/lib/storage/src/misc/mod.rs:9:5
|
9 | use num::ToPrimitive;
| ^^^^^^^^^^^^^^^^

Some errors have detailed explanations: E0277, E0282, E0609.
For more information about an error, try rustc --explain E0277.
warning: zksync_storage (lib) generated 21 warnings
error: could not compile zksync_storage (lib) due to 319 previous errors; 21 warnings emitted

Compilation Errors in Rust
Error 1: Size for [u8] not known at compile-time

rust
Copy code
error[E0277]: the size for values of type [u8] cannot be known at compilation time
--> core/lib/storage/src/chain/operations_ext/mod.rs:1444:15
| 1444 | .map(|account| (start_account, Address::from_slice(&account)))
Solution:
This error is related to Rust's safety mechanisms around data sizes. [u8] is a slice with an unknown size at compile time. Ensure that Address::from_slice is designed to take a slice (&[u8]) rather than a fixed array. This change should make the function compatible with dynamic slice sizes:

rust
Copy code
impl Address {
pub fn from_slice(slice: &[u8]) -> Self {
// Your code here
}
}
Error 2: Type annotations needed

rust
Copy code
error[E0282]: type annotations needed for Vec
--> core/lib/storage/src/chain/state/mod.rs:623:17
| 623 | let mut account_diff = Vec::new();
Solution:
You need to specify the type of elements stored in the vector because Rust's type inference doesn't have enough information to infer it. Assuming acc.block_number() returns an u64, declare the vector like this:

rust
Copy code
let mut account_diff: Vec = Vec::new();
Error 3: No field from_block on type

rust
Copy code
error[E0609]: no field from_block on type &_
--> core/lib/storage/src/ethereum/mod.rs:520:46
| 520 | ... let (from_block, to_block) = (op.from_block as u32, op.to_block as u32)...
Solution:
Check the structure you're accessing (op). It seems op does not have a from_block field. You need to ensure that op is correctly typed and indeed contains this field. If op is intended to be a struct or a type with this field, verify that you're using the correct type and importing all necessary modules.

Warnings: Unused Imports
These are less critical but cleaning them up will make your codebase cleaner and more efficient.

rust
Copy code
warning: unused import: num::bigint::ToBigInt
warning: unused import: num::ToPrimitive
Solution:
Remove unused imports:

rust
Copy code
// Remove these lines if the imports are not used
// use num::bigint::ToBigInt;
// use num::ToPrimitive;
Issue with Typechain
You mentioned that the deployment fails because it can't find "typechain." Typechain is a tool that generates TypeScript bindings for Ethereum smart contracts, which helps in interacting with contracts in a type-safe way.

Solution:

Ensure Typechain Installation:

Make sure Typechain is installed in your project. You can add it via npm or yarn if it's missing:
bash
Copy code
npm install --save-dev typechain @typechain/ethers-v5
or

bash
Copy code
yarn add --dev typechain @typechain/ethers-v5
Generate Typechain Artifacts:

After installation, you may need to generate or regenerate Typechain artifacts. This typically involves a command like:
bash
Copy code
npx typechain --target ethers-v5 'src/**/*.json'
Adjust the path to match where your contract ABI .json files are stored.

Check Typechain Configuration:

Ensure your project's configuration files (like tsconfig.json for TypeScript) are set up to include the Typechain output directories and that these are correctly referenced in your deployment scripts.
By following these steps, you should resolve the compilation issues and the missing Typechain dependency, allowing your contract deployment to proceed without errors.