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

Move get header assertions into constrained code #65

Merged
merged 4 commits into from
Jan 24, 2024
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
24 changes: 14 additions & 10 deletions circuit/src/get_header.nr
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,40 @@ struct BlockHeaderPartial {
#[oracle(get_header)]
unconstrained fn get_header_oracle(_block_no: Field) -> BlockHeaderPartial {}

unconstrained pub(crate) fn get_header(block_no: Field) -> BlockHeaderPartial {
let header = get_header_oracle(block_no);
unconstrained fn get_header_unconstrained(block_no: Field) -> BlockHeaderPartial {
get_header_oracle(block_no)
}

pub(crate) fn get_header(block_no: Field) -> BlockHeaderPartial {
let header = get_header_unconstrained(block_no);
let rlp_list:RLP_List<HEADER_FIELDS_COUNT> = decode1(header.encoded);
assert(
sub_array_equals(
header.stateRoot,
header.encoded,
rlp_list.offset[STATE_ROOT_INDEX]
)
), "stateRoot does not match"
);
assert(
sub_array_equals(
header.transactionsRoot,
header.encoded,
rlp_list.offset[TRANSACTIONS_ROOT_INDEX]
)
), "transactionsRoot does not match"
);
assert(
sub_array_equals(
header.receiptsRoot,
header.encoded,
rlp_list.offset[RECEIPTS_ROOT_INDEX]
)
), "receiptsRoot does not match"
);
assert(
sub_array_equals(
keccak256(header.encoded, header.encoded_len as u32),
header.hash,
0
)
), "hash does not match"
);
header
}
Expand Down Expand Up @@ -99,31 +103,31 @@ fn test_get_header_success() {
assert(get_header(0).stateRoot == stateRoot);
}

#[test(should_fail_with = "explicit trap hit in brillig")]
#[test(should_fail_with = "stateRoot does not match")]
fn test_get_header_invalid_state_root() {
let stateRoot = alter_array(stateRoot);
let blockPartial = BlockHeaderPartial { stateRoot, transactionsRoot, receiptsRoot, number, hash, encoded_len, encoded };
let _ = OracleMock::mock("get_header").returns(blockPartial);
assert(get_header(0).stateRoot == stateRoot);
}

#[test(should_fail_with = "explicit trap hit in brillig")]
#[test(should_fail_with = "transactionsRoot does not match")]
fn test_get_header_invalid_transactions_root() {
let transactionsRoot = alter_array(transactionsRoot);
let blockPartial = BlockHeaderPartial { stateRoot, transactionsRoot, receiptsRoot, number, hash, encoded_len, encoded };
let _ = OracleMock::mock("get_header").returns(blockPartial);
assert(get_header(0).stateRoot == stateRoot);
}

#[test(should_fail_with = "explicit trap hit in brillig")]
#[test(should_fail_with = "receiptsRoot does not match")]
fn test_get_header_invalid_receipt_root() {
let receiptsRoot = alter_array(receiptsRoot);
let blockPartial = BlockHeaderPartial { stateRoot, transactionsRoot, receiptsRoot, number, hash, encoded_len, encoded };
let _ = OracleMock::mock("get_header").returns(blockPartial);
assert(get_header(0).stateRoot == stateRoot);
}

#[test(should_fail_with = "explicit trap hit in brillig")]
#[test(should_fail_with = "hash does not match")]
fn test_get_header_invalid_hash() {
let hash = alter_array(hash);
let blockPartial = BlockHeaderPartial { stateRoot, transactionsRoot, receiptsRoot, number, hash, encoded_len, encoded };
Expand Down
2 changes: 1 addition & 1 deletion contracts/test/fixtures/example.proof
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0x011274fddc57437e2503f2a95956214ed76e6cf4d5fbc370c375efa3ffa5fafd0071e953f6f4d01056154ca1b7de33c78a7f3bfee9e811c010a589ae617552640fe8f06955295b9c700a458d39d88a3f82871ca52e95bf2a006426c0c8e143db02239805a0a78048af7c71a0cd66a1dac3808e4acc8524f0408fea2a2c84ab7a0a394e96a3d1a7b5bc3fc33b1cd4541161f772136548338060391ca06106d1471257f75f5970db5ad69b3d3c37afde0d160a588b5b335e9b3be4c7c9e658b58d1638330bd6a1898cce64201850017e605d5c22f1b97f9d7af210dee745bdeb8e29351a4f1e8eb8c46ee0a3cb8f80b901cba7c253ae468470c246c0d1c731fd9e13d757831f1679c1ff90ae8b600bb6fc1e3a4a668f78b9284901c7457ffc8aa60c6e0bcdcb24f2025c95f621342e96279ac81c987f439506b582331b81a803ee0b8c68e78be62274460befccf6d9d5752a141ac279663f2d223c01cd5cd5227c00c55c039e98f503917002910c1ad15eb8708489041a73230393fcd00e9a363813917e0fd28aec6412bc4c9382e7d71e0a08a4b07815488abfffce906e83cd0513ddbbaa59cc64ca8927bbbf010a0d957c253bad86645ab5b00c33b4eeb1e98210d52972a0ec13841e40d2c6e2fa1b15393fde81fdf59c7b9811ea087c6d4fc90b73332900bf32b075c6f2cbfb597f9aa9e2c063f6b57bcf6e7e2ee4ddba83401d5c2424e9ae3b5bda6bf8bede9d080604b927a958efcd3b53cf9b01b79bb843067d2c6d579e7856a1d2147b15b1d8bc842df9b55c1dd42bada2ae26da6294000418bbf98b6628f424eeaad95ed0592db2a15bba677fdaef92a07a73b12af0320d2864439eb1e285eebabcd84bc2a86072e5b2d8c7f25099e79b1758e750d83009fb3efb39c33356760645a44774f8e256b42654bc3bd53c5137bffa37ea48d515bd5b954d538d8a80e9aec0be7a5568aa7df66a79d7986bfc310212b84ad21c0147d1b268708bfbf655734dcffa8953472d38df6f5ec28876fc0f8bebbb32d90c6ca446358095e8b8933f64240b043d346f005574cffc51bda1e335c8359d89093684fba3df2fd00e0d8ffe92e1b54dd5826a378d22110fc2a63191da1c630f29a095ce4d62e9b3e7163d96c8baa82e5ab7de11dc9470fd09b82cdb5f741fd50140d8531495f112d5bbada8dbbf86bccffc1d6dd35fb0e8c682259107ba79d513ae6f4aa98554153e998aa334ac65aad147ce55e663eaa3d7a54ce7261cfa432f1f2e2248704aeee9311ab391e449e071cc85b57a7d351a717b435a507bcf0c04efb36bc558cc8206cccd64b0ed9a5433efbe798da319a9eb0bd56fed56522828ea5088e6c4f8dcf931513d59847347c463b7b0505ae10987b1ace9aef5b6291990cc316bae9f4169b8ff7ba7ee42cf337ca69ec3d6fc5601630829e9e652f401a4c5f66080923576add58d489d1b2725a9a2f96ec5eb433f55a9a6557ac9f118784837d603931dc5451bc8223030b51a60e4a324a85f7e81d497105b9476fe2436529f35f706f1f06782ec4f8ae37af87345ba68d7e1bd97b720ed946f0589060837655b03d8a5ab40b11836abac6e4d0b80752cd1b6816a9a46897ba82e1e300e8b46b4c4ce6a1c4247f46d73c134abe1669f2b1226878ba98dfea7a17eca1aa9502b0159ab650e2ce32f2dac54e94c98689a6305992d80f1794378382eea02bd49eff62b9e591b21b940ce5b2d413ec564f50df4881abee41abfe3cca5e71251b662ddd3f1f68549f58750118323efa848aa2b55cc5d54a481e7b18f302b0e3cc0f5c60a250224c08b6b7527470b55960ce06ab250dcc8cf1389105847a02bb4370e8a451663d1206fdd2733a173e20fccdd6d55f979c8e602152af9aa7624391022877d9473edbc6e9bfbb9268f8ee27dba34dffbce6f2017bf88645b4c03498becc101246aed5bab1a913a364e4b5345f2dd8bd6867eab534caaf593e21bc1d4249704b788b2a0c6e2b36a670365b42a9602343605007fea5d068a0ae003d5cde98bd6aa7cbf959cf454193f5b57e126f0ad2324f23e728bd9721e81dd1c4e162161da3d9a84dab8bc7649701072420b93d1cb8470c04722e9cdb2f8db1b359227cc2f3176e066d508f08b5df659264998329ce79940b8b1d03f611ce51f1e29535102a542e83db00a5c05c208562e93a2f8e143597d8756047ad7663c1402a26a37a818e87fc287e956aa278a3d0bace51e106a4f9f46be7d4b82f5eb1b3a7c7b4f2d39098667ec1cf0ab3ff8a15e45d5ef28a16b6901557120b070ee09024e28aa9e513d48f555e8ef6254cff9e9fe41a919a8d736f2241db295f91018f653e592c47aa2abe08f2e92986f2e0f83fcf60d7c06e4c0d04214bf1d5de10a481751ff6bf51a7519204600bf730c0f0f35a834061f9913d3d9173019af5714d767d028fe75f14f131f532124931d9c7abaeb6ca84a0c05380253d130a85a00084dd531bd1e31bb8492b229d5a8c6e23c9535740abe4b7efdf3c0f98fab621c4f4eb3183075ece69b4a287d56397c4462acbeafb607434ce5b3e666fc31d72ec2db75da3c88350b9a78783cc7b312b22682620a444cabbf352d0f9676e5572817470c68e72624800dce6fb9cfb42e8637fa4e9336f2ef7224f997f2c47b240f63320dfaf8cf32f9db1b44893c49b9bf1a7c00773a1f48534234c19acda16c20cce5b57048c0852172ca1c6a81c2a84718a918a9bcc76970d30b030d096ee001d24aea046711ad90ba333dca45e339a6e2ede86285fef94a81ebb08f453c53133bfe9179b702ffb851e215ab8b5c282ee11b009508a71a6812c1f2018109c702a99e435c285870cdee371bda8517abe99d919c0110aa2017f665a18d7d8e0c264816d68415fe0c082f6b47a1f559cd08967007213579902ffb75dc70a4bec62a12206fa8de13f325e7f64fd6fffd9e9567684835b8b3309b699b149bed7aaa1c53a9fbf9d24f6927823893d3ba4828f922bfd08a0768592aff206e8d7274fb
021d461b2a1b81b44a35994c1aa8cfb23347d3369d5bd1977c885590ac313d46240649641207f250de0b848a8071164ce9441dd6837960acca247ca7ed9c6599118c8d4c224e62f6aa1e16a96d761d968c1b0feb88a78a24c538673884d1019827ddff1f65114e00142036d3b51255df45689dbfec7473311b046f199e1df121106f14cc07487c77d9c44b10b7050f92eb6aafca8f8a5f5c856b1ad15969c0d90066c8dd2f940e86c1b14d5782fbbcd1eea68adc27c0e63b12232429a182e1f5004b0088d8490fbff069efd6b3410c6c83e48e4e1523eb4bd6d0cbfef7b9931214cbf1b2056c9f67dd23e119362bad0acd27e75997d5230556ba8d79975f9409152e9cf795ede442d5ffdc01ea2ae3c92fed2ada0911ffe6a0a1ccb65247a09a2866718c2cd40d7f1052b468d3ee765b4c6d8abd3e3c94112db6dbb3359002a22b576003cd93725f55c8bd23f05c41d01283f15d91518b415e7e1efdcc86bde1011c6493160b7c7d2c288e2559db78a12d23a6859df32992897534c4941432701ea70917a8018687a924f5d9780499c395a3d61624a6358488bfa7c3f55612711c8952fe8226c42ab00ec561d523c76e85809f41d0c8afcd6bfd974a063c57da143bd1f6f88f951135850395b00cc2724664ac89648721fd465bbd00eb7464940541e5511656f8c3ec08ffed11d9bc9a08ea88ca3000ff4ecd79fc26fe5927a01a3453e2ceaf05783d6e3019c0d546ffe82c082985ee6cbf7153d5b09308bf291e62bede8aed9824498c3e9afbb50212c3156a54bf5a88886043af46db24d978060a37737ab05fd5f776470f3ba0d18736c7939a539cadc958342f536f456e8112f088fc4111a249184a09ae17516dad0f8703067a86a24c319f65c3e1db63d6281a5b3b1b9b57540a72a79dbb1cfd1b4c10eeeff1520172f1cc92a9cf3b7aef17d5e2f272355e6457c6ebcff8162098965d7358a05c0d74afcabc604500edbf2a9f55e1464c8fc52db0b403330a966bfe027f705cd740b5db84f8d98f3245ce1eaf8c0a18b65bb56189d76148aa39f740ae65446c4f82e2d6ca8e42720f2dcd0f8c77ea68b21b9cbf5195b2a95b6585db9b0fb76bc6a1e76abd5ac6387e8b760ee3691254ef3b0a8cb848a63fe087041761ed0a5218f20375a6232d5f787f902396f7e4e4ffa600c46c49997e6cbf02f318798850c12a454af8aa616076fab4161a863860490bf6acb11e9725021a818eacab47c179302c45866dd1f6d6e066118210e108885bf163f8e781d979c906e74e61fb80f105b877a0cb2c78df38f013cef0175429ad9b884bdad871363c5e12e6f2205c3d2f4f31883509a635f60a0a780c98ec8abf20495315bf01b557d405a2185f491ff20f90509664992fa0962309f6a373249bda80409c09b0c36acb89dd77b82b9f47e856786e81690ca9291c0d520882d99d6458e1fd1ba839d7ceff46ecd20d50e572654ea1711553aa5417231cc3d92148be100803fdafbbfaf2dc0566bb1c63fd250e916da86f265b4e109161a08ee0f39d2e6037b9ea0e76785ada54822314c15f85cc131e5a1b69ee147aa1b212d4b63756ba5fb841aeeb9220d28e58ed68b94dec7ee8c10d6afa03088b3d27c604d7d1940b745264568c0e5bad7addb684301efcfc61debad080b31a212ec2c60ff0c5e7c8257c49c119b3e17ba3bc116351bf2f6229972fa9cf332c6634b6f4523938b9fd491e768a3d3f37134e2946aca8c3e64ca27cd61489d7017bb291a00bbdada5411de109dfc7f3d9f362f5baccf998fbd98f71e6787e330c1376a80f4706a0938405a572d7c25b1dddc026da2558fe23eb3b542da1ecb7165b30afdc952ed37c3b77bc45bc1a3ebd628cd4fabbcacb630704b0693664252fdda20270a98cd4688dd68eeea328897e664fa3fb944d34df88c222441624cd0b4bdbbb623fee3054ea190e1397776be41ec958770dd32da9cced66055764d007fd88270059b3c63cb828785249d278f00357c0456b61aa566da1c0cecc77f915d460fd84317fa9d8c2990b3e3b6cf0060a8951e3734f1d1f78757fee96ba93105e939ccc502f7d078aa1bbd966d990ee0d00982d67e81135ba07dd7714f33d0805d10e61ae9601a9d64af171a9783eee28763264fdf1099318c78bcef4f20d3034beda9941d2b061955ecb9823144943153efaeb9db39dac978bb28ec8b98d19d5888b351a5dff5534a4ba13585146857fb2f9a149e266d56bb276096d1949182573399e6070492f41830f5337bf61be0572f305cd233d905d1cfd1457352010bb5c2eb62c2c208378b5cdb416173d024161be0d6bde5971b04b3c96f56f3e16479e6a07bb9d46d9efb7e3248d461cb2de2e20693f3be8f462ea967e22c45610385b24f66b64c27e9e271e21164260bfc395575fc6a86ffc2f7e96fb322a5c114abcf5de7de75d42d260da29b34a8dc67ac393ebe4eda3f6bbdef36f7d72ab291480a340901a11fc23242db23dc43dedc141135f0b5f5b5eeb0cdd069f6e702d46d778cd4dc3d3491a56ac13b6a3d808c3417ad9cdcdda909d67836e646fea2bdd1323cbb7d2054212e1d14d0deaadd0bf327ba05806f163d1b8fe21fbd144149b415da03c89dc8e1a738d67f6e5a0866c70e5ebefeaba9b1bd242940e970215daaa2fd66df2c5e3673a2672bfdd3bca9e97e484932322c2b93a994e9a38fa1c410169eef9c41ebad4eaa64706833bd7ec40cc5aea141d10489341e8098237196d835132594570f510bb21af86557ae6b36a883a75da99b06b125f3a6a687a064a25f698f7e082adc6dc7f85eb2a512eaf057332b8e487de13651d408846ea2c9e9b2d0ca4768bed84abac952fe1cda6ccd182f7cf3a3875c0b26d9d6da64929253526231ed8f8db1033fded35aef500ee45fb5463e1c8c694a50c1ec95a83099a06e1ca96d23bed01c4a9ca53274562bd4e7e401d482555138fd797d8a3d921745ed8902e52e7708970661ea1873a184d0a8c5d8ae4d4ffb613755a0c065e
4 changes: 2 additions & 2 deletions packages/noir-ethereum-api/test/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { InputMap, WitnessMap, abiEncode } from '@noir-lang/noirc_abi';
const PROOF_PATH = '../../circuit/proofs/noir_ethereum_history_api.proof';
const INPUT_MAP_PATH = '../../circuit/Verifier.toml';

describe(
describe.concurrent(
'e2e',
() => {
let proof: Uint8Array;
Expand Down Expand Up @@ -49,6 +49,6 @@ describe(
});
},
{
timeout: 20000
timeout: 2 * 60 * 1000
}
);