Open NikolayKostadinov21 opened 1 month ago
Noir compiler version: >=0.33.0
aztec version: 0.52.0
, currently the latest
aztec.js and the other js package: ^0.52.0
, currently the latest
main.nr
)package.json
and tsconfig.json
.package.json
:
{
"scripts": {
"test": "yarn vitest",
"compile": "${AZTEC_NARGO:-aztec-nargo} compile --silence-warnings",
"codegen": "aztec codegen target --outdir src/artifacts"
},
"type": "module",
"module": "esnext",
"dependencies": {
"@aztec/aztec.js": "^0.52.0",
"vite": "^5.4.2"
},
"devDependencies": {
"@aztec/accounts": "^0.52.0",
"@aztec/builder": "^0.52.0",
"@aztec/noir-contracts.js": "^0.52.0",
"@babel/preset-typescript": "^7.24.7",
"@types/node": "^22.5.1",
"typescript": "^5.5.4",
"vitest": "^2.0.5"
}
}
As you can see, I am using the Vitest testing framework, but feel free to use whichever you prefer.
tsconfig.json
{
"compilerOptions": {
"target": "es2020",
"lib": ["esnext", "dom", "es2017.object"],
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"skipLibCheck": true
},
"include": ["tests", "src", "src/**/*.json", "src/artifacts/*"]
}
yarn install
to install the dependencies.yarn compile
to compile the Noir smart contract program.
package.json
for reference.yarn codegen
to generate the ABI artifacts for communicating with the contract.aztec start --sandbox
yarn test
[!IMPORTANT] To reproduce the
error: Orphaned trait implementation
issue, paste this serialization code below theglobal
constants:impl Serialize<32> for [u8; 32] { fn serialize(self) -> [Field; 32] { let mut output = [0; 32]; for i in 0..THIRTY_TWO { output[i] = self[i] as Field; } output } }
@Thunkar
I'm gonna check whether it's sensible to implement Serialize<N>
for every primitive type in protocol_circuits
, since it has recently been removed for[Field; N]
while implementing public_dispatch
(CC @fcarreiro).
In the meantime @NikolayKostadinov21 I think you can reimplement Serialize
in your crate (just make sure the function it declares has the same name!) to get around the orphan rule. That way you can use arrays as arguments for your aztec functions.
@Thunkar shouldn't [u8; 32]
be covered by
[Field; N]
)Or is this a problem with the generics because THIRTY_TWO
is not 32
?
Oh, I forgot this got generalized, thanks @fcarreiro!
@NikolayKostadinov21 I think updating to the latest release (v0.56) should take care of this
Overview
I am trying to implement the
Serialize
trait for the structstruct BytesBatch { bytes: [u8; 32], }
. My attempts so far are unfruitful because of theNo method named 'serialize' found for type '[u8; 32]'
error. Since the orphan rule in Rust states that you can only implement a trait for a type if either the trait or the type is defined in your crate. This means that you cannot implement a foreign trait for a foreign type directly in your crate. Thus I am unable to serialize myBytesBatch
struct.main.nr
The problem
I cannot compile, nor test my smart contract program due to the aforementioned issues. The error is as follows:
And as already mentioned, obviously if I attempt to implement the
serialize
trait for[u8; 32]
, I get the error below: