From 56c0a931cdfbafcc4093e014d299451c8d0f4b61 Mon Sep 17 00:00:00 2001 From: Arni Hod Date: Tue, 2 Jul 2024 18:34:38 +0300 Subject: [PATCH] chore: use builtins iter to define os_order_iter --- crates/gateway/src/utils.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/crates/gateway/src/utils.rs b/crates/gateway/src/utils.rs index 4c50e1dba..74060fb76 100644 --- a/crates/gateway/src/utils.rs +++ b/crates/gateway/src/utils.rs @@ -184,12 +184,9 @@ pub trait IntoEnumIteratorExt { fn iter() -> impl Iterator; } -// TODO(Arni): When the trait IntoEnumIteratorExt is removed, Make sure the order is maintained or -// address the different order. impl IntoEnumIteratorExt for Builtin { fn iter() -> impl Iterator { - // The OS expects this order for the builtins. - vec![ + let mut builtins_vector: Vec = vec![ Builtin::Pedersen, Builtin::RangeCheck, Builtin::Ecdsa, @@ -198,7 +195,22 @@ impl IntoEnumIteratorExt for Builtin { Builtin::Poseidon, Builtin::SegmentArena, Builtin::Keccak, - ] - .into_iter() + ]; + builtins_vector.sort_by_key(builtin_order); + builtins_vector.into_iter() + } +} + +// The OS expects this order for the builtins. +fn builtin_order(builtin: &Builtin) -> usize { + match builtin { + Builtin::Pedersen => 0, + Builtin::RangeCheck => 1, + Builtin::Ecdsa => 2, + Builtin::Bitwise => 3, + Builtin::EcOp => 4, + Builtin::Poseidon => 5, + Builtin::SegmentArena => 6, + Builtin::Keccak => 7, } }