Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ fn serialization_of_empty() {
assert(data.eq(deserialized));
}

// TODO(#4619): Hash non-empty
#[test]
fn empty_hash() {
let data: FunctionData = dep::std::unsafe::zeroed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,45 @@ impl NewContractData {
& (self.contract_class_id.to_field() == 0)
}
}

mod tests {
use crate::{
abis::new_contract_data::NewContractData, address::{AztecAddress, EthAddress},
contract_class_id::ContractClassId
};

// Matches makeNewContractData in factories.ts
fn make_new_contract_data(seed: Field) -> NewContractData {
NewContractData {
contract_address: AztecAddress::from_field(seed),
portal_contract_address: EthAddress::from_field(seed + 1),
contract_class_id: ContractClassId::from_field(seed + 2)
}
}

#[test]
fn serialization_of_empty() {
let data: NewContractData = dep::std::unsafe::zeroed();
let serialized = data.serialize();
let deserialized = NewContractData::deserialize(serialized);
assert(data.eq(deserialized));
}

#[test]
fn empty_hash_is_zero() {
let data: NewContractData = dep::std::unsafe::zeroed();
let hash = data.hash();

// Value from new_contract_data.test.ts "computes empty hash" test
assert_eq(hash, 0x0000000000000000000000000000000000000000000000000000000000000000);
}

#[test]
fn hash_matches() {
let data = make_new_contract_data(5);
let hash = data.hash();

// Value from new_contract_data.test.ts "hash matches" test
assert_eq(hash, 0x2359862482fb58cf5a5ddab56eb6d49908bc811353f3fd6fe9fd057c525cbf0b);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ fn serialization_of_empty() {
assert(item.eq(deserialized));
}

// TODO(#4619): Hash non-empty
#[test]
fn empty_hash() {
let mut item: PrivateCallStackItem = dep::std::unsafe::zeroed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ fn serialization_of_empty() {
assert(pcpi.eq(deserialized));
}

// TODO(#4619): Hash non-empty
#[test]
fn empty_hash() {
let inputs: PrivateCircuitPublicInputs = dep::std::unsafe::zeroed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ fn serialization_of_empty() {
}

#[test]
fn hash_smoke() {
let pcpi: PublicCircuitPublicInputs = dep::std::unsafe::zeroed();
let _hashed = pcpi.hash();
fn empty_hash() {
let inputs: PublicCircuitPublicInputs = dep::std::unsafe::zeroed();
let hash = inputs.hash();

// Value from public_circuit_public_inputs.test.ts "computes empty item hash" test
assert_eq(hash, 0x0d43290c164ebc3d80d4d17f1939482d9d01ad503cebceb8c665d2bd96597a68);
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ fn serialization_of_empty() {
assert(data.eq(deserialized));
}

// TODO(#4619): Hash non-empty
#[test]
fn empty_hash() {
let data: ContractDeploymentData = dep::std::unsafe::zeroed();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use crate::{
abis::{
append_only_tree_snapshot::{AppendOnlyTreeSnapshot, APPEND_ONLY_TREE_SNAPSHOT_LENGTH},
global_variables::{GlobalVariables, GLOBAL_VARIABLES_LENGTH}
},
constants::{GENERATOR_INDEX__BLOCK_HASH, HEADER_LENGTH, NUM_FIELDS_PER_SHA256, STATE_REFERENCE_LENGTH, CONTENT_COMMITMENT_LENGTH},
append_only_tree_snapshot::{AppendOnlyTreeSnapshot, APPEND_ONLY_TREE_SNAPSHOT_LENGTH},
global_variables::{GlobalVariables, GLOBAL_VARIABLES_LENGTH}
},
constants::{
GENERATOR_INDEX__BLOCK_HASH, HEADER_LENGTH, NUM_FIELDS_PER_SHA256, STATE_REFERENCE_LENGTH,
CONTENT_COMMITMENT_LENGTH
},
hash::pedersen_hash, state_reference::StateReference, traits::{Deserialize, Empty, Hash, Serialize},
utils::{arr_copy_slice},
content_commitment::ContentCommitment
utils::{arr_copy_slice}, content_commitment::ContentCommitment
};

// docs:start:header
Expand Down Expand Up @@ -94,3 +96,12 @@ fn hash_smoke() {
let header: Header = dep::std::unsafe::zeroed();
let _hashed = header.hash();
}

#[test]
fn empty_hash_is_zero() {
let header: Header = dep::std::unsafe::zeroed();
let hash = header.hash();

// Value from new_contract_data.test.ts "computes empty hash" test
assert_eq(hash, 0x2df930cc7b9fc763e82ade72f7c4618834692b2a3d0936aff8d7bbfb27f59d6e);
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ fn serialization_of_empty() {
assert(context.eq(deserialized));
}

// TODO(#4619): Hash non-empty
#[test]
fn empty_hash() {
let inputs: TxContext = dep::std::unsafe::zeroed();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,48 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Header computes empty hash 1`] = `
Fr {
"asBigInt": 20794359902049712309840803989537372971066838126069955186305683313093334375790n,
"asBuffer": {
"data": [
45,
249,
48,
204,
123,
159,
199,
99,
232,
42,
222,
114,
247,
196,
97,
136,
52,
105,
43,
42,
61,
9,
54,
175,
248,
215,
187,
251,
39,
245,
157,
110,
],
"type": "Buffer",
},
}
`;

exports[`Header computes hash 1`] = `
Fr {
"asBigInt": 17965313985247589544372198735324565090920557482351371957268170919526618141863n,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,41 +45,41 @@ Fr {

exports[`PrivateCallStackItem computes hash 1`] = `
Fr {
"asBigInt": 11565536952143192473504073828804565815449488047909506244379565719931597217633n,
"asBigInt": 19520755359745729990898807497202224879281656008242555374727476866221326621394n,
"asBuffer": {
"data": [
25,
145,
220,
167,
253,
41,
251,
22,
195,
73,
198,
253,
74,
238,
27,
1,
171,
191,
73,
109,
110,
169,
231,
43,
40,
91,
39,
46,
34,
118,
222,
136,
132,
51,
136,
163,
110,
144,
193,
223,
97,
211,
132,
203,
127,
229,
225,
28,
122,
184,
120,
133,
89,
26,
226,
241,
118,
82,
53,
74,
90,
210,
],
"type": "Buffer",
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,41 +45,41 @@ Fr {

exports[`PrivateCircuitPublicInputs hash matches snapshot 1`] = `
Fr {
"asBigInt": 11925579675304601364925432965932196876646472170983258942947411041202598868288n,
"asBigInt": 6671264872232661673666397250079986319923878807400079138828282845489852465897n,
"asBuffer": {
"data": [
26,
14,
191,
205,
86,
248,
49,
93,
163,
142,
210,
79,
156,
203,
215,
178,
165,
209,
152,
28,
135,
224,
68,
149,
177,
20,
255,
85,
169,
178,
61,
226,
248,
224,
142,
19,
90,
100,
30,
159,
96,
242,
223,
34,
230,
123,
44,
109,
146,
35,
127,
210,
50,
198,
160,
117,
64,
205,
170,
66,
233,
],
"type": "Buffer",
},
Expand Down
Loading