diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index fa1571ff9..587dafe60 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -154,6 +154,15 @@ jobs: rsync -rcv src/ ../../CoqOfRust/ruint/ --include='*/' --include='*.v' --include='*.rs' --exclude='*' cd ../.. endGroup + startGroup "Translate alloy-core" + cd third-party/alloy-rs-core/crates/primitives + cp ../../rust-toolchain ./ + cargo coq-of-rust + touch src/lib.rs + cargo coq-of-rust + rsync -rcv src/ ../../../../CoqOfRust/alloy_primitives/ --include='*/' --include='*.v' --include='*.rs' --exclude='*' + cd ../../../.. + endGroup startGroup "Translate Move Sui" cd third-party/move-sui cp ../../rust-toolchain ./ diff --git a/.gitmodules b/.gitmodules index b65077fa4..55f54c939 100644 --- a/.gitmodules +++ b/.gitmodules @@ -13,3 +13,6 @@ [submodule "third-party/uint"] path = third-party/uint url = https://github.com/recmo/uint.git +[submodule "third-party/alloy-rs-core"] + path = third-party/alloy-rs-core + url = https://github.com/alloy-rs/core.git diff --git a/CoqOfRust/alloy_primitives/aliases.rs b/CoqOfRust/alloy_primitives/aliases.rs new file mode 100644 index 000000000..04b3b768f --- /dev/null +++ b/CoqOfRust/alloy_primitives/aliases.rs @@ -0,0 +1,128 @@ +//! Type aliases for common primitive types. + +use crate::{FixedBytes, Signed, Uint}; + +pub use ruint::aliases::{U0, U1, U1024, U2048, U320, U384, U4096, U448}; + +macro_rules! int_aliases { + ($($unsigned:ident, $signed:ident<$BITS:literal, $LIMBS:literal>),* $(,)?) => {$( + #[doc = concat!($BITS, "-bit [unsigned integer type][Uint], consisting of ", $LIMBS, ", 64-bit limbs.")] + pub type $unsigned = Uint<$BITS, $LIMBS>; + + #[doc = concat!($BITS, "-bit [signed integer type][Signed], consisting of ", $LIMBS, ", 64-bit limbs.")] + pub type $signed = Signed<$BITS, $LIMBS>; + + const _: () = assert!($LIMBS == ruint::nlimbs($BITS)); + )*}; +} + +/// The 0-bit signed integer type, capable of representing 0. +pub type I0 = Signed<0, 0>; + +/// The 1-bit signed integer type, capable of representing 0 and -1. +pub type I1 = Signed<1, 1>; + +int_aliases! { + U8, I8< 8, 1>, + U16, I16< 16, 1>, + U24, I24< 24, 1>, + U32, I32< 32, 1>, + U40, I40< 40, 1>, + U48, I48< 48, 1>, + U56, I56< 56, 1>, + U64, I64< 64, 1>, + + U72, I72< 72, 2>, + U80, I80< 80, 2>, + U88, I88< 88, 2>, + U96, I96< 96, 2>, + U104, I104<104, 2>, + U112, I112<112, 2>, + U120, I120<120, 2>, + U128, I128<128, 2>, + + U136, I136<136, 3>, + U144, I144<144, 3>, + U152, I152<152, 3>, + U160, I160<160, 3>, + U168, I168<168, 3>, + U176, I176<176, 3>, + U184, I184<184, 3>, + U192, I192<192, 3>, + + U200, I200<200, 4>, + U208, I208<208, 4>, + U216, I216<216, 4>, + U224, I224<224, 4>, + U232, I232<232, 4>, + U240, I240<240, 4>, + U248, I248<248, 4>, + U256, I256<256, 4>, + + U512, I512<512, 8>, +} + +macro_rules! fixed_bytes_aliases { + ($($(#[$attr:meta])* $name:ident<$N:literal>),* $(,)?) => {$( + #[doc = concat!($N, "-byte [fixed byte-array][FixedBytes] type.")] + $(#[$attr])* + pub type $name = FixedBytes<$N>; + )*}; +} + +fixed_bytes_aliases! { + B8<1>, + B16<2>, + B32<4>, + B64<8>, + B96<12>, + B128<16>, + /// See [`crate::B160`] as to why you likely want to use + /// [`Address`](crate::Address) instead. + #[doc(hidden)] + B160<20>, + B192<24>, + B224<28>, + B256<32>, + B512<64>, + B1024<128>, + B2048<256>, +} + +/// A block hash. +pub type BlockHash = B256; + +/// A block number. +pub type BlockNumber = u64; + +/// A block timestamp. +pub type BlockTimestamp = u64; + +/// A transaction hash is a keccak hash of an RLP encoded signed transaction. +#[doc(alias = "TransactionHash")] +pub type TxHash = B256; + +/// The sequence number of all existing transactions. +#[doc(alias = "TransactionNumber")] +pub type TxNumber = u64; + +/// The nonce of a transaction. +#[doc(alias = "TransactionNonce")] +pub type TxNonce = u64; + +/// The index of transaction in a block. +#[doc(alias = "TransactionIndex")] +pub type TxIndex = u64; + +/// Chain identifier type (introduced in EIP-155). +pub type ChainId = u64; + +/// An account storage key. +pub type StorageKey = B256; + +/// An account storage value. +pub type StorageValue = U256; + +/// Solidity contract functions are addressed using the first four bytes of the +/// Keccak-256 hash of their signature. +pub type Selector = FixedBytes<4>; diff --git a/CoqOfRust/alloy_primitives/aliases.v b/CoqOfRust/alloy_primitives/aliases.v new file mode 100644 index 000000000..b4a74a937 --- /dev/null +++ b/CoqOfRust/alloy_primitives/aliases.v @@ -0,0 +1,618 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module aliases. + Axiom I0 : + (Ty.path "alloy_primitives::aliases::I0") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 0; Value.Integer IntegerKind.Usize 0 ] + []). + + Axiom I1 : + (Ty.path "alloy_primitives::aliases::I1") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 1; Value.Integer IntegerKind.Usize 1 ] + []). + + Axiom U8 : + (Ty.path "alloy_primitives::aliases::U8") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 8; Value.Integer IntegerKind.Usize 1 ] + []). + + Axiom I8 : + (Ty.path "alloy_primitives::aliases::I8") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 8; Value.Integer IntegerKind.Usize 1 ] + []). + + Axiom U16 : + (Ty.path "alloy_primitives::aliases::U16") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.Usize 1 ] + []). + + Axiom I16 : + (Ty.path "alloy_primitives::aliases::I16") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.Usize 1 ] + []). + + Axiom U24 : + (Ty.path "alloy_primitives::aliases::U24") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 1 ] + []). + + Axiom I24 : + (Ty.path "alloy_primitives::aliases::I24") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 24; Value.Integer IntegerKind.Usize 1 ] + []). + + Axiom U32 : + (Ty.path "alloy_primitives::aliases::U32") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 32; Value.Integer IntegerKind.Usize 1 ] + []). + + Axiom I32 : + (Ty.path "alloy_primitives::aliases::I32") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 32; Value.Integer IntegerKind.Usize 1 ] + []). + + Axiom U40 : + (Ty.path "alloy_primitives::aliases::U40") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 40; Value.Integer IntegerKind.Usize 1 ] + []). + + Axiom I40 : + (Ty.path "alloy_primitives::aliases::I40") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 40; Value.Integer IntegerKind.Usize 1 ] + []). + + Axiom U48 : + (Ty.path "alloy_primitives::aliases::U48") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 48; Value.Integer IntegerKind.Usize 1 ] + []). + + Axiom I48 : + (Ty.path "alloy_primitives::aliases::I48") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 48; Value.Integer IntegerKind.Usize 1 ] + []). + + Axiom U56 : + (Ty.path "alloy_primitives::aliases::U56") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 56; Value.Integer IntegerKind.Usize 1 ] + []). + + Axiom I56 : + (Ty.path "alloy_primitives::aliases::I56") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 56; Value.Integer IntegerKind.Usize 1 ] + []). + + Axiom U64 : + (Ty.path "alloy_primitives::aliases::U64") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 64; Value.Integer IntegerKind.Usize 1 ] + []). + + Axiom I64 : + (Ty.path "alloy_primitives::aliases::I64") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 64; Value.Integer IntegerKind.Usize 1 ] + []). + + Axiom U72 : + (Ty.path "alloy_primitives::aliases::U72") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 72; Value.Integer IntegerKind.Usize 2 ] + []). + + Axiom I72 : + (Ty.path "alloy_primitives::aliases::I72") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 72; Value.Integer IntegerKind.Usize 2 ] + []). + + Axiom U80 : + (Ty.path "alloy_primitives::aliases::U80") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 80; Value.Integer IntegerKind.Usize 2 ] + []). + + Axiom I80 : + (Ty.path "alloy_primitives::aliases::I80") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 80; Value.Integer IntegerKind.Usize 2 ] + []). + + Axiom U88 : + (Ty.path "alloy_primitives::aliases::U88") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 88; Value.Integer IntegerKind.Usize 2 ] + []). + + Axiom I88 : + (Ty.path "alloy_primitives::aliases::I88") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 88; Value.Integer IntegerKind.Usize 2 ] + []). + + Axiom U96 : + (Ty.path "alloy_primitives::aliases::U96") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 96; Value.Integer IntegerKind.Usize 2 ] + []). + + Axiom I96 : + (Ty.path "alloy_primitives::aliases::I96") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 96; Value.Integer IntegerKind.Usize 2 ] + []). + + Axiom U104 : + (Ty.path "alloy_primitives::aliases::U104") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 104; Value.Integer IntegerKind.Usize 2 ] + []). + + Axiom I104 : + (Ty.path "alloy_primitives::aliases::I104") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 104; Value.Integer IntegerKind.Usize 2 ] + []). + + Axiom U112 : + (Ty.path "alloy_primitives::aliases::U112") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 112; Value.Integer IntegerKind.Usize 2 ] + []). + + Axiom I112 : + (Ty.path "alloy_primitives::aliases::I112") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 112; Value.Integer IntegerKind.Usize 2 ] + []). + + Axiom U120 : + (Ty.path "alloy_primitives::aliases::U120") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 120; Value.Integer IntegerKind.Usize 2 ] + []). + + Axiom I120 : + (Ty.path "alloy_primitives::aliases::I120") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 120; Value.Integer IntegerKind.Usize 2 ] + []). + + Axiom U128 : + (Ty.path "alloy_primitives::aliases::U128") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 128; Value.Integer IntegerKind.Usize 2 ] + []). + + Axiom I128 : + (Ty.path "alloy_primitives::aliases::I128") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 128; Value.Integer IntegerKind.Usize 2 ] + []). + + Axiom U136 : + (Ty.path "alloy_primitives::aliases::U136") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 136; Value.Integer IntegerKind.Usize 3 ] + []). + + Axiom I136 : + (Ty.path "alloy_primitives::aliases::I136") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 136; Value.Integer IntegerKind.Usize 3 ] + []). + + Axiom U144 : + (Ty.path "alloy_primitives::aliases::U144") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 144; Value.Integer IntegerKind.Usize 3 ] + []). + + Axiom I144 : + (Ty.path "alloy_primitives::aliases::I144") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 144; Value.Integer IntegerKind.Usize 3 ] + []). + + Axiom U152 : + (Ty.path "alloy_primitives::aliases::U152") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 152; Value.Integer IntegerKind.Usize 3 ] + []). + + Axiom I152 : + (Ty.path "alloy_primitives::aliases::I152") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 152; Value.Integer IntegerKind.Usize 3 ] + []). + + Axiom U160 : + (Ty.path "alloy_primitives::aliases::U160") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 160; Value.Integer IntegerKind.Usize 3 ] + []). + + Axiom I160 : + (Ty.path "alloy_primitives::aliases::I160") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 160; Value.Integer IntegerKind.Usize 3 ] + []). + + Axiom U168 : + (Ty.path "alloy_primitives::aliases::U168") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 168; Value.Integer IntegerKind.Usize 3 ] + []). + + Axiom I168 : + (Ty.path "alloy_primitives::aliases::I168") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 168; Value.Integer IntegerKind.Usize 3 ] + []). + + Axiom U176 : + (Ty.path "alloy_primitives::aliases::U176") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 176; Value.Integer IntegerKind.Usize 3 ] + []). + + Axiom I176 : + (Ty.path "alloy_primitives::aliases::I176") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 176; Value.Integer IntegerKind.Usize 3 ] + []). + + Axiom U184 : + (Ty.path "alloy_primitives::aliases::U184") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 184; Value.Integer IntegerKind.Usize 3 ] + []). + + Axiom I184 : + (Ty.path "alloy_primitives::aliases::I184") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 184; Value.Integer IntegerKind.Usize 3 ] + []). + + Axiom U192 : + (Ty.path "alloy_primitives::aliases::U192") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 192; Value.Integer IntegerKind.Usize 3 ] + []). + + Axiom I192 : + (Ty.path "alloy_primitives::aliases::I192") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 192; Value.Integer IntegerKind.Usize 3 ] + []). + + Axiom U200 : + (Ty.path "alloy_primitives::aliases::U200") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 200; Value.Integer IntegerKind.Usize 4 ] + []). + + Axiom I200 : + (Ty.path "alloy_primitives::aliases::I200") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 200; Value.Integer IntegerKind.Usize 4 ] + []). + + Axiom U208 : + (Ty.path "alloy_primitives::aliases::U208") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 208; Value.Integer IntegerKind.Usize 4 ] + []). + + Axiom I208 : + (Ty.path "alloy_primitives::aliases::I208") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 208; Value.Integer IntegerKind.Usize 4 ] + []). + + Axiom U216 : + (Ty.path "alloy_primitives::aliases::U216") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 216; Value.Integer IntegerKind.Usize 4 ] + []). + + Axiom I216 : + (Ty.path "alloy_primitives::aliases::I216") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 216; Value.Integer IntegerKind.Usize 4 ] + []). + + Axiom U224 : + (Ty.path "alloy_primitives::aliases::U224") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 224; Value.Integer IntegerKind.Usize 4 ] + []). + + Axiom I224 : + (Ty.path "alloy_primitives::aliases::I224") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 224; Value.Integer IntegerKind.Usize 4 ] + []). + + Axiom U232 : + (Ty.path "alloy_primitives::aliases::U232") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 232; Value.Integer IntegerKind.Usize 4 ] + []). + + Axiom I232 : + (Ty.path "alloy_primitives::aliases::I232") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 232; Value.Integer IntegerKind.Usize 4 ] + []). + + Axiom U240 : + (Ty.path "alloy_primitives::aliases::U240") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 240; Value.Integer IntegerKind.Usize 4 ] + []). + + Axiom I240 : + (Ty.path "alloy_primitives::aliases::I240") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 240; Value.Integer IntegerKind.Usize 4 ] + []). + + Axiom U248 : + (Ty.path "alloy_primitives::aliases::U248") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 248; Value.Integer IntegerKind.Usize 4 ] + []). + + Axiom I248 : + (Ty.path "alloy_primitives::aliases::I248") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 248; Value.Integer IntegerKind.Usize 4 ] + []). + + Axiom U256 : + (Ty.path "alloy_primitives::aliases::U256") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []). + + Axiom I256 : + (Ty.path "alloy_primitives::aliases::I256") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []). + + Axiom U512 : + (Ty.path "alloy_primitives::aliases::U512") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 512; Value.Integer IntegerKind.Usize 8 ] + []). + + Axiom I512 : + (Ty.path "alloy_primitives::aliases::I512") = + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 512; Value.Integer IntegerKind.Usize 8 ] + []). + + Axiom B8 : + (Ty.path "alloy_primitives::aliases::B8") = + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 1 ] + []). + + Axiom B16 : + (Ty.path "alloy_primitives::aliases::B16") = + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 2 ] + []). + + Axiom B32 : + (Ty.path "alloy_primitives::aliases::B32") = + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 4 ] + []). + + Axiom B64 : + (Ty.path "alloy_primitives::aliases::B64") = + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 8 ] + []). + + Axiom B96 : + (Ty.path "alloy_primitives::aliases::B96") = + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 12 ] + []). + + Axiom B128 : + (Ty.path "alloy_primitives::aliases::B128") = + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 16 ] + []). + + Axiom B160 : + (Ty.path "alloy_primitives::aliases::B160") = + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + []). + + Axiom B192 : + (Ty.path "alloy_primitives::aliases::B192") = + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + []). + + Axiom B224 : + (Ty.path "alloy_primitives::aliases::B224") = + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 28 ] + []). + + Axiom B256 : + (Ty.path "alloy_primitives::aliases::B256") = + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + []). + + Axiom B512 : + (Ty.path "alloy_primitives::aliases::B512") = + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 64 ] + []). + + Axiom B1024 : + (Ty.path "alloy_primitives::aliases::B1024") = + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 128 ] + []). + + Axiom B2048 : + (Ty.path "alloy_primitives::aliases::B2048") = + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + []). + + Axiom BlockHash : + (Ty.path "alloy_primitives::aliases::BlockHash") = + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + []). + + Axiom BlockNumber : (Ty.path "alloy_primitives::aliases::BlockNumber") = (Ty.path "u64"). + + Axiom BlockTimestamp : (Ty.path "alloy_primitives::aliases::BlockTimestamp") = (Ty.path "u64"). + + Axiom TxHash : + (Ty.path "alloy_primitives::aliases::TxHash") = + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + []). + + Axiom TxNumber : (Ty.path "alloy_primitives::aliases::TxNumber") = (Ty.path "u64"). + + Axiom TxNonce : (Ty.path "alloy_primitives::aliases::TxNonce") = (Ty.path "u64"). + + Axiom TxIndex : (Ty.path "alloy_primitives::aliases::TxIndex") = (Ty.path "u64"). + + Axiom ChainId : (Ty.path "alloy_primitives::aliases::ChainId") = (Ty.path "u64"). + + Axiom StorageKey : + (Ty.path "alloy_primitives::aliases::StorageKey") = + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + []). + + Axiom StorageValue : + (Ty.path "alloy_primitives::aliases::StorageValue") = + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []). + + Axiom Selector : + (Ty.path "alloy_primitives::aliases::Selector") = + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 4 ] + []). +End aliases. diff --git a/CoqOfRust/alloy_primitives/bits/address.rs b/CoqOfRust/alloy_primitives/bits/address.rs new file mode 100644 index 000000000..230da393e --- /dev/null +++ b/CoqOfRust/alloy_primitives/bits/address.rs @@ -0,0 +1,765 @@ +use crate::{aliases::U160, utils::keccak256, FixedBytes}; +use alloc::{ + borrow::Borrow, + string::{String, ToString}, +}; +use core::{fmt, mem::MaybeUninit, str}; + +/// Error type for address checksum validation. +#[derive(Clone, Copy, Debug)] +pub enum AddressError { + /// Error while decoding hex. + Hex(hex::FromHexError), + + /// Invalid ERC-55 checksum. + InvalidChecksum, +} + +impl From for AddressError { + #[inline] + fn from(value: hex::FromHexError) -> Self { + Self::Hex(value) + } +} + +#[cfg(feature = "std")] +impl std::error::Error for AddressError { + #[inline] + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + Self::Hex(err) => Some(err), + Self::InvalidChecksum => None, + } + } +} + +impl fmt::Display for AddressError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Hex(err) => err.fmt(f), + Self::InvalidChecksum => f.write_str("Bad address checksum"), + } + } +} + +wrap_fixed_bytes!( + // we implement Display with the checksum, so we don't derive it + extra_derives: [], + /// An Ethereum address, 20 bytes in length. + /// + /// This type is separate from [`B160`](crate::B160) / [`FixedBytes<20>`] + /// and is declared with the [`wrap_fixed_bytes!`] macro. This allows us + /// to implement address-specific functionality. + /// + /// The main difference with the generic [`FixedBytes`] implementation is that + /// [`Display`] formats the address using its [EIP-55] checksum + /// ([`to_checksum`]). + /// Use [`Debug`] to display the raw bytes without the checksum. + /// + /// [EIP-55]: https://eips.ethereum.org/EIPS/eip-55 + /// [`Debug`]: fmt::Debug + /// [`Display`]: fmt::Display + /// [`to_checksum`]: Address::to_checksum + /// + /// # Examples + /// + /// Parsing and formatting: + /// + /// ``` + /// use alloy_primitives::{address, Address}; + /// + /// let checksummed = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"; + /// let expected = address!("d8da6bf26964af9d7eed9e03e53415d37aa96045"); + /// let address = Address::parse_checksummed(checksummed, None).expect("valid checksum"); + /// assert_eq!(address, expected); + /// + /// // Format the address with the checksum + /// assert_eq!(address.to_string(), checksummed); + /// assert_eq!(address.to_checksum(None), checksummed); + /// + /// // Format the compressed checksummed address + /// assert_eq!(format!("{address:#}"), "0xd8dA…6045"); + /// + /// // Format the address without the checksum + /// assert_eq!(format!("{address:?}"), "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"); + /// ``` + pub struct Address<20>; +); + +impl From for Address { + #[inline] + fn from(value: U160) -> Self { + Self(FixedBytes(value.to_be_bytes())) + } +} + +impl From
for U160 { + #[inline] + fn from(value: Address) -> Self { + Self::from_be_bytes(value.0 .0) + } +} + +impl fmt::Display for Address { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let checksum = self.to_checksum_buffer(None); + let checksum = checksum.as_str(); + if f.alternate() { + // If the alternate flag is set, use middle-out compression + // "0x" + first 4 bytes + "…" + last 4 bytes + f.write_str(&checksum[..6])?; + f.write_str("…")?; + f.write_str(&checksum[38..]) + } else { + f.write_str(checksum) + } + } +} + +impl Address { + /// Creates an Ethereum address from an EVM word's upper 20 bytes + /// (`word[12..]`). + /// + /// # Examples + /// + /// ``` + /// # use alloy_primitives::{address, b256, Address}; + /// let word = b256!("000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa96045"); + /// assert_eq!(Address::from_word(word), address!("d8da6bf26964af9d7eed9e03e53415d37aa96045")); + /// ``` + #[inline] + #[must_use] + pub fn from_word(word: FixedBytes<32>) -> Self { + Self(FixedBytes(word[12..].try_into().unwrap())) + } + + /// Left-pads the address to 32 bytes (EVM word size). + /// + /// # Examples + /// + /// ``` + /// # use alloy_primitives::{address, b256, Address}; + /// assert_eq!( + /// address!("d8da6bf26964af9d7eed9e03e53415d37aa96045").into_word(), + /// b256!("000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa96045"), + /// ); + /// ``` + #[inline] + #[must_use] + pub fn into_word(&self) -> FixedBytes<32> { + let mut word = [0; 32]; + word[12..].copy_from_slice(self.as_slice()); + FixedBytes(word) + } + + /// Parse an Ethereum address, verifying its [EIP-55] checksum. + /// + /// You can optionally specify an [EIP-155 chain ID] to check the address + /// using [EIP-1191]. + /// + /// [EIP-55]: https://eips.ethereum.org/EIPS/eip-55 + /// [EIP-155 chain ID]: https://eips.ethereum.org/EIPS/eip-155 + /// [EIP-1191]: https://eips.ethereum.org/EIPS/eip-1191 + /// + /// # Errors + /// + /// This method returns an error if the provided string does not match the + /// expected checksum. + /// + /// # Examples + /// + /// ``` + /// # use alloy_primitives::{address, Address}; + /// let checksummed = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"; + /// let address = Address::parse_checksummed(checksummed, None).unwrap(); + /// let expected = address!("d8da6bf26964af9d7eed9e03e53415d37aa96045"); + /// assert_eq!(address, expected); + /// ``` + pub fn parse_checksummed>( + s: S, + chain_id: Option, + ) -> Result { + fn parse_checksummed(s: &str, chain_id: Option) -> Result { + // checksummed addresses always start with the "0x" prefix + if !s.starts_with("0x") { + return Err(AddressError::Hex(hex::FromHexError::InvalidStringLength)); + } + + let address: Address = s.parse()?; + if s == address.to_checksum_buffer(chain_id).as_str() { + Ok(address) + } else { + Err(AddressError::InvalidChecksum) + } + } + + parse_checksummed(s.as_ref(), chain_id) + } + + /// Encodes an Ethereum address to its [EIP-55] checksum into a heap-allocated string. + /// + /// You can optionally specify an [EIP-155 chain ID] to encode the address + /// using [EIP-1191]. + /// + /// [EIP-55]: https://eips.ethereum.org/EIPS/eip-55 + /// [EIP-155 chain ID]: https://eips.ethereum.org/EIPS/eip-155 + /// [EIP-1191]: https://eips.ethereum.org/EIPS/eip-1191 + /// + /// # Examples + /// + /// ``` + /// # use alloy_primitives::{address, Address}; + /// let address = address!("d8da6bf26964af9d7eed9e03e53415d37aa96045"); + /// + /// let checksummed: String = address.to_checksum(None); + /// assert_eq!(checksummed, "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"); + /// + /// let checksummed: String = address.to_checksum(Some(1)); + /// assert_eq!(checksummed, "0xD8Da6bf26964Af9d7EEd9e03e53415d37AA96045"); + /// ``` + #[inline] + #[must_use] + pub fn to_checksum(&self, chain_id: Option) -> String { + self.to_checksum_buffer(chain_id).as_str().into() + } + + /// Encodes an Ethereum address to its [EIP-55] checksum into the given buffer. + /// + /// For convenience, the buffer is returned as a `&mut str`, as the bytes + /// are guaranteed to be valid UTF-8. + /// + /// You can optionally specify an [EIP-155 chain ID] to encode the address + /// using [EIP-1191]. + /// + /// [EIP-55]: https://eips.ethereum.org/EIPS/eip-55 + /// [EIP-155 chain ID]: https://eips.ethereum.org/EIPS/eip-155 + /// [EIP-1191]: https://eips.ethereum.org/EIPS/eip-1191 + /// + /// # Panics + /// + /// Panics if `buf` is not exactly 42 bytes long. + /// + /// # Examples + /// + /// ``` + /// # use alloy_primitives::{address, Address}; + /// let address = address!("d8da6bf26964af9d7eed9e03e53415d37aa96045"); + /// let mut buf = [0; 42]; + /// + /// let checksummed: &mut str = address.to_checksum_raw(&mut buf, None); + /// assert_eq!(checksummed, "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"); + /// + /// let checksummed: &mut str = address.to_checksum_raw(&mut buf, Some(1)); + /// assert_eq!(checksummed, "0xD8Da6bf26964Af9d7EEd9e03e53415d37AA96045"); + /// ``` + #[inline] + #[must_use] + pub fn to_checksum_raw<'a>(&self, buf: &'a mut [u8], chain_id: Option) -> &'a mut str { + let buf: &mut [u8; 42] = buf.try_into().expect("buffer must be exactly 42 bytes long"); + self.to_checksum_inner(buf, chain_id); + // SAFETY: All bytes in the buffer are valid UTF-8. + unsafe { str::from_utf8_unchecked_mut(buf) } + } + + /// Encodes an Ethereum address to its [EIP-55] checksum into a stack-allocated buffer. + /// + /// You can optionally specify an [EIP-155 chain ID] to encode the address + /// using [EIP-1191]. + /// + /// [EIP-55]: https://eips.ethereum.org/EIPS/eip-55 + /// [EIP-155 chain ID]: https://eips.ethereum.org/EIPS/eip-155 + /// [EIP-1191]: https://eips.ethereum.org/EIPS/eip-1191 + /// + /// # Examples + /// + /// ``` + /// # use alloy_primitives::{address, Address, AddressChecksumBuffer}; + /// let address = address!("d8da6bf26964af9d7eed9e03e53415d37aa96045"); + /// + /// let mut buffer: AddressChecksumBuffer = address.to_checksum_buffer(None); + /// assert_eq!(buffer.as_str(), "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"); + /// + /// let checksummed: &str = buffer.format(&address, Some(1)); + /// assert_eq!(checksummed, "0xD8Da6bf26964Af9d7EEd9e03e53415d37AA96045"); + /// ``` + #[inline] + pub fn to_checksum_buffer(&self, chain_id: Option) -> AddressChecksumBuffer { + // SAFETY: The buffer is initialized by `format`. + let mut buf = unsafe { AddressChecksumBuffer::new() }; + buf.format(self, chain_id); + buf + } + + // https://eips.ethereum.org/EIPS/eip-55 + // > In English, convert the address to hex, but if the `i`th digit is a letter (ie. it’s one of + // > `abcdef`) print it in uppercase if the `4*i`th bit of the hash of the lowercase hexadecimal + // > address is 1 otherwise print it in lowercase. + // + // https://eips.ethereum.org/EIPS/eip-1191 + // > [...] If the chain id passed to the function belongs to a network that opted for using this + // > checksum variant, prefix the address with the chain id and the `0x` separator before + // > calculating the hash. [...] + #[allow(clippy::wrong_self_convention)] + fn to_checksum_inner(&self, buf: &mut [u8; 42], chain_id: Option) { + buf[0] = b'0'; + buf[1] = b'x'; + hex::encode_to_slice(self, &mut buf[2..]).unwrap(); + + let mut hasher = crate::Keccak256::new(); + match chain_id { + Some(chain_id) => { + hasher.update(itoa::Buffer::new().format(chain_id).as_bytes()); + // Clippy suggests an unnecessary copy. + #[allow(clippy::needless_borrows_for_generic_args)] + hasher.update(&*buf); + } + None => hasher.update(&buf[2..]), + } + let hash = hasher.finalize(); + + for (i, out) in buf[2..].iter_mut().enumerate() { + // This is made branchless for easier vectorization. + // Get the i-th nibble of the hash. + let hash_nibble = hash[i / 2] >> (4 * (1 - i % 2)) & 0xf; + // Make the character ASCII uppercase if it's a hex letter and the hash nibble is >= 8. + // We can use a simpler comparison for checking if the character is a hex letter because + // we know `out` is a hex-encoded character (`b'0'..=b'9' | b'a'..=b'f'`). + *out ^= 0b0010_0000 * ((*out >= b'a') & (hash_nibble >= 8)) as u8; + } + } + + /// Computes the `create` address for this address and nonce: + /// + /// `keccak256(rlp([sender, nonce]))[12:]` + /// + /// # Examples + /// + /// ``` + /// # use alloy_primitives::{address, Address}; + /// let sender = address!("b20a608c624Ca5003905aA834De7156C68b2E1d0"); + /// + /// let expected = address!("00000000219ab540356cBB839Cbe05303d7705Fa"); + /// assert_eq!(sender.create(0), expected); + /// + /// let expected = address!("e33c6e89e69d085897f98e92b06ebd541d1daa99"); + /// assert_eq!(sender.create(1), expected); + /// ``` + #[cfg(feature = "rlp")] + #[inline] + #[must_use] + pub fn create(&self, nonce: u64) -> Self { + use alloy_rlp::{Encodable, EMPTY_LIST_CODE, EMPTY_STRING_CODE}; + + // max u64 encoded length is `1 + u64::BYTES` + const MAX_LEN: usize = 1 + (1 + 20) + 9; + + let len = 22 + nonce.length(); + debug_assert!(len <= MAX_LEN); + + let mut out = [0u8; MAX_LEN]; + + // list header + // minus 1 to account for the list header itself + out[0] = EMPTY_LIST_CODE + len as u8 - 1; + + // address header + address + out[1] = EMPTY_STRING_CODE + 20; + out[2..22].copy_from_slice(self.as_slice()); + + // nonce + nonce.encode(&mut &mut out[22..]); + + let hash = keccak256(&out[..len]); + Self::from_word(hash) + } + + /// Computes the `CREATE2` address of a smart contract as specified in + /// [EIP-1014]: + /// + /// `keccak256(0xff ++ address ++ salt ++ keccak256(init_code))[12:]` + /// + /// The `init_code` is the code that, when executed, produces the runtime + /// bytecode that will be placed into the state, and which typically is used + /// by high level languages to implement a ‘constructor’. + /// + /// [EIP-1014]: https://eips.ethereum.org/EIPS/eip-1014 + /// + /// # Examples + /// + /// ``` + /// # use alloy_primitives::{address, b256, bytes, Address}; + /// let address = address!("8ba1f109551bD432803012645Ac136ddd64DBA72"); + /// let salt = b256!("7c5ea36004851c764c44143b1dcb59679b11c9a68e5f41497f6cf3d480715331"); + /// let init_code = bytes!("6394198df16000526103ff60206004601c335afa6040516060f3"); + /// let expected = address!("533ae9d683B10C02EbDb05471642F85230071FC3"); + /// assert_eq!(address.create2_from_code(salt, init_code), expected); + /// ``` + #[must_use] + pub fn create2_from_code(&self, salt: S, init_code: C) -> Self + where + // not `AsRef` because `[u8; N]` does not implement `AsRef<[u8; N]>` + S: Borrow<[u8; 32]>, + C: AsRef<[u8]>, + { + self._create2(salt.borrow(), &keccak256(init_code.as_ref()).0) + } + + /// Computes the `CREATE2` address of a smart contract as specified in + /// [EIP-1014], taking the pre-computed hash of the init code as input: + /// + /// `keccak256(0xff ++ address ++ salt ++ init_code_hash)[12:]` + /// + /// The `init_code` is the code that, when executed, produces the runtime + /// bytecode that will be placed into the state, and which typically is used + /// by high level languages to implement a ‘constructor’. + /// + /// [EIP-1014]: https://eips.ethereum.org/EIPS/eip-1014 + /// + /// # Examples + /// + /// ``` + /// # use alloy_primitives::{address, b256, Address}; + /// let address = address!("5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f"); + /// let salt = b256!("2b2f5776e38002e0c013d0d89828fdb06fee595ea2d5ed4b194e3883e823e350"); + /// let init_code_hash = b256!("96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f"); + /// let expected = address!("0d4a11d5EEaaC28EC3F61d100daF4d40471f1852"); + /// assert_eq!(address.create2(salt, init_code_hash), expected); + /// ``` + #[must_use] + pub fn create2(&self, salt: S, init_code_hash: H) -> Self + where + // not `AsRef` because `[u8; N]` does not implement `AsRef<[u8; N]>` + S: Borrow<[u8; 32]>, + H: Borrow<[u8; 32]>, + { + self._create2(salt.borrow(), init_code_hash.borrow()) + } + + // non-generic inner function + fn _create2(&self, salt: &[u8; 32], init_code_hash: &[u8; 32]) -> Self { + // note: creating a temporary buffer and copying everything over performs + // much better than calling `Keccak::update` multiple times + let mut bytes = [0; 85]; + bytes[0] = 0xff; + bytes[1..21].copy_from_slice(self.as_slice()); + bytes[21..53].copy_from_slice(salt); + bytes[53..85].copy_from_slice(init_code_hash); + let hash = keccak256(bytes); + Self::from_word(hash) + } + + /// Instantiate by hashing public key bytes. + /// + /// # Panics + /// + /// If the input is not exactly 64 bytes + pub fn from_raw_public_key(pubkey: &[u8]) -> Self { + assert_eq!(pubkey.len(), 64, "raw public key must be 64 bytes"); + let digest = keccak256(pubkey); + Self::from_slice(&digest[12..]) + } + + /// Converts an ECDSA verifying key to its corresponding Ethereum address. + #[inline] + #[cfg(feature = "k256")] + #[doc(alias = "from_verifying_key")] + pub fn from_public_key(pubkey: &k256::ecdsa::VerifyingKey) -> Self { + use k256::elliptic_curve::sec1::ToEncodedPoint; + let affine: &k256::AffinePoint = pubkey.as_ref(); + let encoded = affine.to_encoded_point(false); + Self::from_raw_public_key(&encoded.as_bytes()[1..]) + } + + /// Converts an ECDSA signing key to its corresponding Ethereum address. + #[inline] + #[cfg(feature = "k256")] + #[doc(alias = "from_signing_key")] + pub fn from_private_key(private_key: &k256::ecdsa::SigningKey) -> Self { + Self::from_public_key(private_key.verifying_key()) + } +} + +/// Stack-allocated buffer for efficiently computing address checksums. +/// +/// See [`Address::to_checksum_buffer`] for more information. +#[must_use] +#[allow(missing_copy_implementations)] +#[derive(Clone)] +pub struct AddressChecksumBuffer(MaybeUninit<[u8; 42]>); + +impl fmt::Debug for AddressChecksumBuffer { + #[inline] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.as_str().fmt(f) + } +} + +impl fmt::Display for AddressChecksumBuffer { + #[inline] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.as_str().fmt(f) + } +} + +impl AddressChecksumBuffer { + /// Creates a new buffer. + /// + /// # Safety + /// + /// The buffer must be initialized with [`format`](Self::format) before use. + /// Prefer [`Address::to_checksum_buffer`] instead. + #[inline] + pub const unsafe fn new() -> Self { + Self(MaybeUninit::uninit()) + } + + /// Calculates the checksum of an address into the buffer. + /// + /// See [`Address::to_checksum_buffer`] for more information. + #[inline] + pub fn format(&mut self, address: &Address, chain_id: Option) -> &mut str { + address.to_checksum_inner(unsafe { self.0.assume_init_mut() }, chain_id); + self.as_mut_str() + } + + /// Returns the checksum of a formatted address. + #[inline] + pub const fn as_str(&self) -> &str { + unsafe { str::from_utf8_unchecked(self.0.assume_init_ref()) } + } + + /// Returns the checksum of a formatted address. + #[inline] + pub fn as_mut_str(&mut self) -> &mut str { + unsafe { str::from_utf8_unchecked_mut(self.0.assume_init_mut()) } + } + + /// Returns the checksum of a formatted address. + #[inline] + #[allow(clippy::inherent_to_string_shadow_display)] + pub fn to_string(&self) -> String { + self.as_str().to_string() + } + + /// Returns the backing buffer. + #[inline] + pub const fn into_inner(self) -> [u8; 42] { + unsafe { self.0.assume_init() } + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::hex; + + #[test] + fn parse() { + let expected = hex!("0102030405060708090a0b0c0d0e0f1011121314"); + assert_eq!( + "0102030405060708090a0b0c0d0e0f1011121314".parse::
().unwrap().into_array(), + expected + ); + assert_eq!( + "0x0102030405060708090a0b0c0d0e0f1011121314".parse::
().unwrap(), + expected + ); + } + + // https://eips.ethereum.org/EIPS/eip-55 + #[test] + fn checksum() { + let addresses = [ + // All caps + "0x52908400098527886E0F7030069857D2E4169EE7", + "0x8617E340B3D01FA5F11F306F4090FD50E238070D", + // All Lower + "0xde709f2102306220921060314715629080e2fb77", + "0x27b1fdb04752bbc536007a920d24acb045561c26", + // Normal + "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed", + "0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359", + "0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB", + "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb", + ]; + for addr in addresses { + let parsed1: Address = addr.parse().unwrap(); + let parsed2 = Address::parse_checksummed(addr, None).unwrap(); + assert_eq!(parsed1, parsed2); + assert_eq!(parsed2.to_checksum(None), addr); + } + } + + // https://eips.ethereum.org/EIPS/eip-1191 + #[test] + fn checksum_chain_id() { + let eth_mainnet = [ + "0x27b1fdb04752bbc536007a920d24acb045561c26", + "0x3599689E6292b81B2d85451025146515070129Bb", + "0x42712D45473476b98452f434e72461577D686318", + "0x52908400098527886E0F7030069857D2E4169EE7", + "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed", + "0x6549f4939460DE12611948b3f82b88C3C8975323", + "0x66f9664f97F2b50F62D13eA064982f936dE76657", + "0x8617E340B3D01FA5F11F306F4090FD50E238070D", + "0x88021160C5C792225E4E5452585947470010289D", + "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb", + "0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB", + "0xde709f2102306220921060314715629080e2fb77", + "0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359", + ]; + let rsk_mainnet = [ + "0x27b1FdB04752BBc536007A920D24ACB045561c26", + "0x3599689E6292B81B2D85451025146515070129Bb", + "0x42712D45473476B98452f434E72461577d686318", + "0x52908400098527886E0F7030069857D2E4169ee7", + "0x5aaEB6053f3e94c9b9a09f33669435E7ef1bEAeD", + "0x6549F4939460DE12611948B3F82B88C3C8975323", + "0x66F9664f97f2B50F62d13EA064982F936de76657", + "0x8617E340b3D01Fa5f11f306f4090fd50E238070D", + "0x88021160c5C792225E4E5452585947470010289d", + "0xD1220A0Cf47c7B9BE7a2e6ba89F429762E7B9adB", + "0xDBF03B407c01E7CD3cBea99509D93F8Dddc8C6FB", + "0xDe709F2102306220921060314715629080e2FB77", + "0xFb6916095cA1Df60bb79ce92cE3EA74c37c5d359", + ]; + let rsk_testnet = [ + "0x27B1FdB04752BbC536007a920D24acB045561C26", + "0x3599689e6292b81b2D85451025146515070129Bb", + "0x42712D45473476B98452F434E72461577D686318", + "0x52908400098527886E0F7030069857D2e4169EE7", + "0x5aAeb6053F3e94c9b9A09F33669435E7EF1BEaEd", + "0x6549f4939460dE12611948b3f82b88C3c8975323", + "0x66f9664F97F2b50f62d13eA064982F936DE76657", + "0x8617e340b3D01fa5F11f306F4090Fd50e238070d", + "0x88021160c5C792225E4E5452585947470010289d", + "0xd1220a0CF47c7B9Be7A2E6Ba89f429762E7b9adB", + "0xdbF03B407C01E7cd3cbEa99509D93f8dDDc8C6fB", + "0xDE709F2102306220921060314715629080e2Fb77", + "0xFb6916095CA1dF60bb79CE92ce3Ea74C37c5D359", + ]; + for (addresses, chain_id) in [(eth_mainnet, 1), (rsk_mainnet, 30), (rsk_testnet, 31)] { + // EIP-1191 test cases treat mainnet as "not adopted" + let id = if chain_id == 1 { None } else { Some(chain_id) }; + for addr in addresses { + let parsed1: Address = addr.parse().unwrap(); + let parsed2 = Address::parse_checksummed(addr, id).unwrap(); + assert_eq!(parsed1, parsed2); + assert_eq!(parsed2.to_checksum(id), addr); + } + } + } + + // https://ethereum.stackexchange.com/questions/760/how-is-the-address-of-an-ethereum-contract-computed + #[test] + #[cfg(feature = "rlp")] + fn create() { + let from = "0x6ac7ea33f8831ea9dcc53393aaa88b25a785dbf0".parse::
().unwrap(); + for (nonce, expected) in [ + "0xcd234a471b72ba2f1ccf0a70fcaba648a5eecd8d", + "0x343c43a37d37dff08ae8c4a11544c718abb4fcf8", + "0xf778b86fa74e846c4f0a1fbd1335fe81c00a0c91", + "0xfffd933a0bc612844eaf0c6fe3e5b8e9b6c1d19c", + ] + .into_iter() + .enumerate() + { + let address = from.create(nonce as u64); + assert_eq!(address, expected.parse::
().unwrap()); + } + } + + #[test] + #[cfg(all(feature = "rlp", feature = "arbitrary"))] + #[cfg_attr(miri, ignore = "doesn't run in isolation and would take too long")] + fn create_correctness() { + fn create_slow(address: &Address, nonce: u64) -> Address { + use alloy_rlp::Encodable; + + let mut out = vec![]; + + alloy_rlp::Header { list: true, payload_length: address.length() + nonce.length() } + .encode(&mut out); + address.encode(&mut out); + nonce.encode(&mut out); + + Address::from_word(keccak256(out)) + } + + proptest::proptest!(|(address: Address, nonce: u64)| { + proptest::prop_assert_eq!(address.create(nonce), create_slow(&address, nonce)); + }); + } + + // https://eips.ethereum.org/EIPS/eip-1014 + #[test] + fn create2() { + let tests = [ + ( + "0000000000000000000000000000000000000000", + "0000000000000000000000000000000000000000000000000000000000000000", + "00", + "4D1A2e2bB4F88F0250f26Ffff098B0b30B26BF38", + ), + ( + "deadbeef00000000000000000000000000000000", + "0000000000000000000000000000000000000000000000000000000000000000", + "00", + "B928f69Bb1D91Cd65274e3c79d8986362984fDA3", + ), + ( + "deadbeef00000000000000000000000000000000", + "000000000000000000000000feed000000000000000000000000000000000000", + "00", + "D04116cDd17beBE565EB2422F2497E06cC1C9833", + ), + ( + "0000000000000000000000000000000000000000", + "0000000000000000000000000000000000000000000000000000000000000000", + "deadbeef", + "70f2b2914A2a4b783FaEFb75f459A580616Fcb5e", + ), + ( + "00000000000000000000000000000000deadbeef", + "00000000000000000000000000000000000000000000000000000000cafebabe", + "deadbeef", + "60f3f640a8508fC6a86d45DF051962668E1e8AC7", + ), + ( + "00000000000000000000000000000000deadbeef", + "00000000000000000000000000000000000000000000000000000000cafebabe", + "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef", + "1d8bfDC5D46DC4f61D6b6115972536eBE6A8854C", + ), + ( + "0000000000000000000000000000000000000000", + "0000000000000000000000000000000000000000000000000000000000000000", + "", + "E33C0C7F7df4809055C3ebA6c09CFe4BaF1BD9e0", + ), + ]; + for (from, salt, init_code, expected) in tests { + let from = from.parse::
().unwrap(); + + let salt = hex::decode(salt).unwrap(); + let salt: [u8; 32] = salt.try_into().unwrap(); + + let init_code = hex::decode(init_code).unwrap(); + let init_code_hash = keccak256(&init_code); + + let expected = expected.parse::
().unwrap(); + + assert_eq!(expected, from.create2(salt, init_code_hash)); + assert_eq!(expected, from.create2_from_code(salt, init_code)); + } + } + + #[test] + fn test_raw_public_key_to_address() { + let addr = "0Ac1dF02185025F65202660F8167210A80dD5086".parse::
().unwrap(); + + let pubkey_bytes = hex::decode("76698beebe8ee5c74d8cc50ab84ac301ee8f10af6f28d0ffd6adf4d6d3b9b762d46ca56d3dad2ce13213a6f42278dabbb53259f2d92681ea6a0b98197a719be3").unwrap(); + + assert_eq!(Address::from_raw_public_key(&pubkey_bytes), addr); + } +} diff --git a/CoqOfRust/alloy_primitives/bits/address.v b/CoqOfRust/alloy_primitives/bits/address.v new file mode 100644 index 000000000..71cc016f5 --- /dev/null +++ b/CoqOfRust/alloy_primitives/bits/address.v @@ -0,0 +1,3369 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module bits. + Module address. + (* + Enum AddressError + { + const_params := []; + ty_params := []; + variants := + [ + { + name := "Hex"; + item := StructTuple [ Ty.path "const_hex::error::FromHexError" ]; + }; + { + name := "InvalidChecksum"; + item := StructTuple []; + } + ]; + } + *) + + Axiom IsDiscriminant_AddressError_Hex : + M.IsDiscriminant "alloy_primitives::bits::address::AddressError::Hex" 0. + Axiom IsDiscriminant_AddressError_InvalidChecksum : + M.IsDiscriminant "alloy_primitives::bits::address::AddressError::InvalidChecksum" 1. + + Module Impl_core_clone_Clone_for_alloy_primitives_bits_address_AddressError. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::AddressError". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.deref (| M.read (| self |) |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_alloy_primitives_bits_address_AddressError. + + Module Impl_core_marker_Copy_for_alloy_primitives_bits_address_AddressError. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::AddressError". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_alloy_primitives_bits_address_AddressError. + + Module Impl_core_fmt_Debug_for_alloy_primitives_bits_address_AddressError. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::AddressError". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ]), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::bits::address::AddressError::Hex", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Hex" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::bits::address::AddressError::InvalidChecksum" + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "InvalidChecksum" |) |) + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_alloy_primitives_bits_address_AddressError. + + Module Impl_core_convert_From_const_hex_error_FromHexError_for_alloy_primitives_bits_address_AddressError. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::AddressError". + + (* + fn from(value: hex::FromHexError) -> Self { + Self::Hex(value) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::address::AddressError::Hex" + [ M.read (| value |) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "const_hex::error::FromHexError" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_const_hex_error_FromHexError_for_alloy_primitives_bits_address_AddressError. + + Module Impl_core_error_Error_for_alloy_primitives_bits_address_AddressError. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::AddressError". + + (* + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + Self::Hex(err) => Some(err), + Self::InvalidChecksum => None, + } + } + *) + Definition source (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.dyn [ ("core::error::Error::Trait", []) ] ] ]), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::bits::address::AddressError::Hex", + 0 + |) in + let err := M.alloc (| γ1_0 |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| err |) |) |) ] + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::bits::address::AddressError::InvalidChecksum" + |) in + M.alloc (| Value.StructTuple "core::option::Option::None" [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::error::Error" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("source", InstanceField.Method source) ]. + End Impl_core_error_Error_for_alloy_primitives_bits_address_AddressError. + + Module Impl_core_fmt_Display_for_alloy_primitives_bits_address_AddressError. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::AddressError". + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Hex(err) => err.fmt(f), + Self::InvalidChecksum => f.write_str("Bad address checksum"), + } + } + *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ]), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::bits::address::AddressError::Hex", + 0 + |) in + let err := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::Display", + Ty.path "const_hex::error::FromHexError", + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| err |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::bits::address::AddressError::InvalidChecksum" + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "Bad address checksum" |) |) + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Display" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Display_for_alloy_primitives_bits_address_AddressError. + + Module Impl_core_convert_From_ruint_Uint_Usize_160_Usize_3_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* + fn from(value: U160) -> Self { + Self(FixedBytes(value.to_be_bytes())) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::address::Address" + [ + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 160; Value.Integer IntegerKind.Usize 3 ] + [], + "to_be_bytes", + [ Value.Integer IntegerKind.Usize 20 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + ] + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 160; Value.Integer IntegerKind.Usize 3 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ruint_Uint_Usize_160_Usize_3_for_alloy_primitives_bits_address_Address. + + Module Impl_core_convert_From_alloy_primitives_bits_address_Address_for_ruint_Uint_Usize_160_Usize_3. + Definition Self : Ty.t := + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 160; Value.Integer IntegerKind.Usize 3 ] + []. + + (* + fn from(value: Address) -> Self { + Self::from_be_bytes(value.0 .0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 160; Value.Integer IntegerKind.Usize 3 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 160; Value.Integer IntegerKind.Usize 3 ] + [], + "from_be_bytes", + [ Value.Integer IntegerKind.Usize 20 ], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::address::Address", + 0 + |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::address::Address" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_address_Address_for_ruint_Uint_Usize_160_Usize_3. + + Module Impl_core_fmt_Display_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let checksum = self.to_checksum_buffer(None); + let checksum = checksum.as_str(); + if f.alternate() { + // If the alternate flag is set, use middle-out compression + // "0x" + first 4 bytes + "…" + last 4 bytes + f.write_str(&checksum[..6])?; + f.write_str("…")?; + f.write_str(&checksum[38..]) + } else { + f.write_str(checksum) + } + } + *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ checksum : + Ty.path "alloy_primitives::bits::address::AddressChecksumBuffer" := + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::bits::address::AddressChecksumBuffer", + M.get_associated_function (| + Ty.path "alloy_primitives::bits::address::Address", + "to_checksum_buffer", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + Value.StructTuple "core::option::Option::None" [] + ] + |) + |) in + let~ checksum : Ty.apply (Ty.path "&") [] [ Ty.path "str" ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_associated_function (| + Ty.path "alloy_primitives::bits::address::AddressChecksumBuffer", + "as_str", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, checksum |) ] + |) + |) in + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "alternate", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| f |) |) |) ] + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "core::fmt::Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| f |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.path "str", + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| checksum |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 6) + ] + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "core::fmt::Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "core::fmt::Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| f |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| String.String "038" "" |) |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "core::fmt::Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.path "str", + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| checksum |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 38) ] + ] + |) + |) + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| checksum |) |) |) + ] + |) + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Display" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Display_for_alloy_primitives_bits_address_Address. + + Module Impl_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* + pub fn from_word(word: FixedBytes<32>) -> Self { + Self(FixedBytes(word[12..].try_into().unwrap())) + } + *) + Definition from_word (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ word ] => + ltac:(M.monadic + (let word := M.alloc (| word |) in + Value.StructTuple + "alloy_primitives::bits::address::Address" + [ + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, word |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 12) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_word : + M.IsAssociatedFunction.Trait Self "from_word" from_word. + Admitted. + Global Typeclasses Opaque from_word. + + (* + pub fn into_word(&self) -> FixedBytes<32> { + let mut word = [0; 32]; + word[12..].copy_from_slice(self.as_slice()); + FixedBytes(word) + } + *) + Definition into_word (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ word : + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ] := + M.alloc (| + repeat (| Value.Integer IntegerKind.U8 0, Value.Integer IntegerKind.Usize 32 |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "copy_from_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, word |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 12) ] + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + "as_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloy_primitives::bits::address::Address", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + Value.StructTuple "alloy_primitives::bits::fixed::FixedBytes" [ M.read (| word |) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_into_word : + M.IsAssociatedFunction.Trait Self "into_word" into_word. + Admitted. + Global Typeclasses Opaque into_word. + + (* + pub fn parse_checksummed>( + s: S, + chain_id: Option, + ) -> Result { + fn parse_checksummed(s: &str, chain_id: Option) -> Result { + // checksummed addresses always start with the "0x" prefix + if !s.starts_with("0x") { + return Err(AddressError::Hex(hex::FromHexError::InvalidStringLength)); + } + + let address: Address = s.parse()?; + if s == address.to_checksum_buffer(chain_id).as_str() { + Ok(address) + } else { + Err(AddressError::InvalidChecksum) + } + } + + parse_checksummed(s.as_ref(), chain_id) + } + *) + Definition parse_checksummed (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ _ as S ], [ s; chain_id ] => + ltac:(M.monadic + (let s := M.alloc (| s |) in + let chain_id := M.alloc (| chain_id |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::bits::address::Address"; + Ty.path "alloy_primitives::bits::address::AddressError" + ], + M.get_associated_function (| Self, "parse_checksummed.parse_checksummed", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::convert::AsRef", + S, + [], + [ Ty.path "str" ], + "as_ref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, s |) ] + |) + |) + |); + M.read (| chain_id |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_parse_checksummed : + M.IsAssociatedFunction.Trait Self "parse_checksummed" parse_checksummed. + Admitted. + Global Typeclasses Opaque parse_checksummed. + + (* + pub fn to_checksum(&self, chain_id: Option) -> String { + self.to_checksum_buffer(chain_id).as_str().into() + } + *) + Definition to_checksum (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; chain_id ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let chain_id := M.alloc (| chain_id |) in + M.call_closure (| + Ty.path "alloc::string::String", + M.get_trait_method (| + "core::convert::Into", + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + [], + [ Ty.path "alloc::string::String" ], + "into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_associated_function (| + Ty.path "alloy_primitives::bits::address::AddressChecksumBuffer", + "as_str", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::bits::address::AddressChecksumBuffer", + M.get_associated_function (| + Ty.path "alloy_primitives::bits::address::Address", + "to_checksum_buffer", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| chain_id |) + ] + |) + |) + |) + ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_to_checksum : + M.IsAssociatedFunction.Trait Self "to_checksum" to_checksum. + Admitted. + Global Typeclasses Opaque to_checksum. + + (* + pub fn to_checksum_raw<'a>(&self, buf: &'a mut [u8], chain_id: Option) -> &'a mut str { + let buf: &mut [u8; 42] = buf.try_into().expect("buffer must be exactly 42 bytes long"); + self.to_checksum_inner(buf, chain_id); + // SAFETY: All bytes in the buffer are valid UTF-8. + unsafe { str::from_utf8_unchecked_mut(buf) } + } + *) + Definition to_checksum_raw (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; buf; chain_id ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let buf := M.alloc (| buf |) in + let chain_id := M.alloc (| chain_id |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + let~ buf : + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 42 ] + [ Ty.path "u8" ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 42 ] + [ Ty.path "u8" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 42 ] + [ Ty.path "u8" ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 42 ] + [ Ty.path "u8" ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 42 ] + [ Ty.path "u8" ] + ] + ], + "try_into", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| buf |) |) |) ] + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "buffer must be exactly 42 bytes long" |) |) + |) + ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "alloy_primitives::bits::address::Address", + "to_checksum_inner", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| buf |) |) |); + M.read (| chain_id |) + ] + |) + |) in + M.alloc (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.path "str" ], + M.get_function (| + "core::str::converts::from_utf8_unchecked_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| buf |) |) |) ] + |) + |) + |) + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_to_checksum_raw : + M.IsAssociatedFunction.Trait Self "to_checksum_raw" to_checksum_raw. + Admitted. + Global Typeclasses Opaque to_checksum_raw. + + (* + pub fn to_checksum_buffer(&self, chain_id: Option) -> AddressChecksumBuffer { + // SAFETY: The buffer is initialized by `format`. + let mut buf = unsafe { AddressChecksumBuffer::new() }; + buf.format(self, chain_id); + buf + } + *) + Definition to_checksum_buffer (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; chain_id ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let chain_id := M.alloc (| chain_id |) in + M.read (| + let~ buf : Ty.path "alloy_primitives::bits::address::AddressChecksumBuffer" := + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::bits::address::AddressChecksumBuffer", + M.get_associated_function (| + Ty.path "alloy_primitives::bits::address::AddressChecksumBuffer", + "new", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.apply (Ty.path "&mut") [] [ Ty.path "str" ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.path "str" ], + M.get_associated_function (| + Ty.path "alloy_primitives::bits::address::AddressChecksumBuffer", + "format", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, buf |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| chain_id |) + ] + |) + |) in + buf + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_to_checksum_buffer : + M.IsAssociatedFunction.Trait Self "to_checksum_buffer" to_checksum_buffer. + Admitted. + Global Typeclasses Opaque to_checksum_buffer. + + (* + fn to_checksum_inner(&self, buf: &mut [u8; 42], chain_id: Option) { + buf[0] = b'0'; + buf[1] = b'x'; + hex::encode_to_slice(self, &mut buf[2..]).unwrap(); + + let mut hasher = crate::Keccak256::new(); + match chain_id { + Some(chain_id) => { + hasher.update(itoa::Buffer::new().format(chain_id).as_bytes()); + // Clippy suggests an unnecessary copy. + #[allow(clippy::needless_borrows_for_generic_args)] + hasher.update(&*buf); + } + None => hasher.update(&buf[2..]), + } + let hash = hasher.finalize(); + + for (i, out) in buf[2..].iter_mut().enumerate() { + // This is made branchless for easier vectorization. + // Get the i-th nibble of the hash. + let hash_nibble = hash[i / 2] >> (4 * (1 - i % 2)) & 0xf; + // Make the character ASCII uppercase if it's a hex letter and the hash nibble is >= 8. + // We can use a simpler comparison for checking if the character is a hex letter because + // we know `out` is a hex-encoded character (`b'0'..=b'9' | b'a'..=b'f'`). + *out ^= 0b0010_0000 * (( *out >= b'a') & (hash_nibble >= 8)) as u8; + } + } + *) + Definition to_checksum_inner (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; buf; chain_id ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let buf := M.alloc (| buf |) in + let chain_id := M.alloc (| chain_id |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| buf |) |), + Value.Integer IntegerKind.Usize 0 + |), + M.read (| UnsupportedLiteral |) + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| buf |) |), + Value.Integer IntegerKind.Usize 1 + |), + M.read (| UnsupportedLiteral |) + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "const_hex::error::FromHexError" ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "const_hex::error::FromHexError" ], + M.get_function (| + "const_hex::encode_to_slice", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::address::Address" ] + ] + |), + [ + M.read (| self |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 42 ] + [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| buf |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 2) ] + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |) in + let~ hasher : Ty.path "alloy_primitives::utils::Keccak256" := + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::utils::Keccak256", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::Keccak256", + "new", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + chain_id, + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let chain_id := M.copy (| γ0_0 |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "alloy_primitives::utils::Keccak256", + "update", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, hasher |); + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_associated_function (| Ty.path "str", "as_bytes", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_associated_function (| + Ty.path "itoa::Buffer", + "format", + [], + [ Ty.path "u64" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.path "itoa::Buffer", + M.get_associated_function (| + Ty.path "itoa::Buffer", + "new", + [], + [] + |), + [] + |) + |) + |); + M.read (| chain_id |) + ] + |) + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "alloy_primitives::utils::Keccak256", + "update", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 42 ] + [ Ty.path "u8" ] + ] + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, hasher |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| buf |) |) |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (let _ := M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "alloy_primitives::utils::Keccak256", + "update", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ] + |), + [ + M.borrow (| Pointer.Kind.MutRef, hasher |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 42 ] + [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| buf |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 2) ] + ] + |) + |) + |) + ] + |) + |))) + ] + |) in + let~ hash : + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + M.get_associated_function (| + Ty.path "alloy_primitives::utils::Keccak256", + "finalize", + [], + [] + |), + [ M.read (| hasher |) ] + |) + |) in + M.use + (M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ Ty.path "u8" ] ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ Ty.path "u8" ], + [], + [], + "enumerate", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 42 ] + [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| buf |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 2) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.tuple [], + ltac:(M.monadic + (let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.path "usize"; + Ty.apply (Ty.path "&mut") [] [ Ty.path "u8" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::enumerate::Enumerate") + [] + [ + Ty.apply + (Ty.path "core::slice::iter::IterMut") + [] + [ Ty.path "u8" ] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let i := M.copy (| γ1_0 |) in + let out := M.copy (| γ1_1 |) in + let~ hash_nibble : Ty.path "u8" := + M.alloc (| + BinOp.bit_and + (BinOp.Wrap.shr (| + M.read (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "u8" ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path + "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, hash |); + BinOp.Wrap.div (| + M.read (| i |), + Value.Integer IntegerKind.Usize 2 + |) + ] + |) + |) + |), + BinOp.Wrap.mul (| + Value.Integer IntegerKind.Usize 4, + BinOp.Wrap.sub (| + Value.Integer IntegerKind.Usize 1, + BinOp.Wrap.rem (| + M.read (| i |), + Value.Integer IntegerKind.Usize 2 + |) + |) + |) + |)) + (Value.Integer IntegerKind.U8 15) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + let β := M.deref (| M.read (| out |) |) in + M.write (| + β, + BinOp.bit_xor + (M.read (| β |)) + (BinOp.Wrap.mul (| + Value.Integer IntegerKind.U8 32, + M.cast + (Ty.path "u8") + (BinOp.bit_and + (BinOp.ge (| + M.read (| M.deref (| M.read (| out |) |) |), + M.read (| UnsupportedLiteral |) + |)) + (BinOp.ge (| + M.read (| hash_nibble |), + Value.Integer IntegerKind.U8 8 + |))) + |)) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_to_checksum_inner : + M.IsAssociatedFunction.Trait Self "to_checksum_inner" to_checksum_inner. + Admitted. + Global Typeclasses Opaque to_checksum_inner. + + (* + pub fn create2_from_code(&self, salt: S, init_code: C) -> Self + where + // not `AsRef` because `[u8; N]` does not implement `AsRef<[u8; N]>` + S: Borrow<[u8; 32]>, + C: AsRef<[u8]>, + { + self._create2(salt.borrow(), &keccak256(init_code.as_ref()).0) + } + *) + Definition create2_from_code (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ _ as S; C ], [ self; salt; init_code ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let salt := M.alloc (| salt |) in + let init_code := M.alloc (| init_code |) in + M.call_closure (| + Ty.path "alloy_primitives::bits::address::Address", + M.get_associated_function (| + Ty.path "alloy_primitives::bits::address::Address", + "_create2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::borrow::Borrow", + S, + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ] + ], + "borrow", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, salt |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + M.get_function (| + "alloy_primitives::utils::keccak256", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::convert::AsRef", + C, + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "as_ref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, init_code |) ] + |) + ] + |) + |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_create2_from_code : + M.IsAssociatedFunction.Trait Self "create2_from_code" create2_from_code. + Admitted. + Global Typeclasses Opaque create2_from_code. + + (* + pub fn create2(&self, salt: S, init_code_hash: H) -> Self + where + // not `AsRef` because `[u8; N]` does not implement `AsRef<[u8; N]>` + S: Borrow<[u8; 32]>, + H: Borrow<[u8; 32]>, + { + self._create2(salt.borrow(), init_code_hash.borrow()) + } + *) + Definition create2 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ _ as S; H ], [ self; salt; init_code_hash ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let salt := M.alloc (| salt |) in + let init_code_hash := M.alloc (| init_code_hash |) in + M.call_closure (| + Ty.path "alloy_primitives::bits::address::Address", + M.get_associated_function (| + Ty.path "alloy_primitives::bits::address::Address", + "_create2", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::borrow::Borrow", + S, + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ] + ], + "borrow", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, salt |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::borrow::Borrow", + H, + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ] + ], + "borrow", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, init_code_hash |) ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_create2 : + M.IsAssociatedFunction.Trait Self "create2" create2. + Admitted. + Global Typeclasses Opaque create2. + + (* + fn _create2(&self, salt: &[u8; 32], init_code_hash: &[u8; 32]) -> Self { + // note: creating a temporary buffer and copying everything over performs + // much better than calling `Keccak::update` multiple times + let mut bytes = [0; 85]; + bytes[0] = 0xff; + bytes[1..21].copy_from_slice(self.as_slice()); + bytes[21..53].copy_from_slice(salt); + bytes[53..85].copy_from_slice(init_code_hash); + let hash = keccak256(bytes); + Self::from_word(hash) + } + *) + Definition _create2 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; salt; init_code_hash ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let salt := M.alloc (| salt |) in + let init_code_hash := M.alloc (| init_code_hash |) in + M.read (| + let~ bytes : + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 85 ] + [ Ty.path "u8" ] := + M.alloc (| + repeat (| Value.Integer IntegerKind.U8 0, Value.Integer IntegerKind.Usize 85 |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| bytes, Value.Integer IntegerKind.Usize 0 |), + Value.Integer IntegerKind.U8 255 + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "copy_from_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 85 ] + [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, bytes |); + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 1); + ("end_", Value.Integer IntegerKind.Usize 21) + ] + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + "as_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloy_primitives::bits::address::Address", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "copy_from_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 85 ] + [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, bytes |); + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 21); + ("end_", Value.Integer IntegerKind.Usize 53) + ] + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| salt |) |) |) + ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "copy_from_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 85 ] + [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, bytes |); + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 53); + ("end_", Value.Integer IntegerKind.Usize 85) + ] + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| init_code_hash |) |) |) + ] + |) + |) in + let~ hash : + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + M.get_function (| + "alloy_primitives::utils::keccak256", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 85 ] + [ Ty.path "u8" ] + ] + |), + [ M.read (| bytes |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::bits::address::Address", + M.get_associated_function (| + Ty.path "alloy_primitives::bits::address::Address", + "from_word", + [], + [] + |), + [ M.read (| hash |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction__create2 : + M.IsAssociatedFunction.Trait Self "_create2" _create2. + Admitted. + Global Typeclasses Opaque _create2. + + (* + pub fn from_raw_public_key(pubkey: &[u8]) -> Self { + assert_eq!(pubkey.len(), 64, "raw public key must be 64 bytes"); + let digest = keccak256(pubkey); + Self::from_slice(&digest[12..]) + } + *) + Definition from_raw_public_key (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ pubkey ] => + ltac:(M.monadic + (let pubkey := M.alloc (| pubkey |) in + M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| pubkey |) |) |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Integer IntegerKind.Usize 64 |) + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + BinOp.eq (| + M.read (| M.deref (| M.read (| left_val |) |) |), + M.read (| M.deref (| M.read (| right_val |) |) |) + |) + |) + |)) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : Ty.path "core::panicking::AssertKind" := + M.alloc (| + Value.StructTuple "core::panicking::AssertKind::Eq" [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "raw public key must be 64 bytes" + |) + ] + |) + |) + |) + |) + ] + |) + ] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + let~ digest : + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + M.get_function (| + "alloy_primitives::utils::keccak256", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ] + |), + [ M.read (| pubkey |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::bits::address::Address", + M.get_associated_function (| + Ty.path "alloy_primitives::bits::address::Address", + "from_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, digest |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 12) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_raw_public_key : + M.IsAssociatedFunction.Trait Self "from_raw_public_key" from_raw_public_key. + Admitted. + Global Typeclasses Opaque from_raw_public_key. + End Impl_alloy_primitives_bits_address_Address. + + (* StructTuple + { + name := "AddressChecksumBuffer"; + const_params := []; + ty_params := []; + fields := + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 42 ] [ Ty.path "u8" ] ] + ]; + } *) + + Module Impl_core_clone_Clone_for_alloy_primitives_bits_address_AddressChecksumBuffer. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::AddressChecksumBuffer". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple + "alloy_primitives::bits::address::AddressChecksumBuffer" + [ + M.call_closure (| + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 42 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 42 ] + [ Ty.path "u8" ] + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::AddressChecksumBuffer", + 0 + |) + |) + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_alloy_primitives_bits_address_AddressChecksumBuffer. + + Module Impl_core_fmt_Debug_for_alloy_primitives_bits_address_AddressChecksumBuffer. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::AddressChecksumBuffer". + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.as_str().fmt(f) + } + *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| "core::fmt::Debug", Ty.path "str", [], [], "fmt", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_associated_function (| + Ty.path "alloy_primitives::bits::address::AddressChecksumBuffer", + "as_str", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_alloy_primitives_bits_address_AddressChecksumBuffer. + + Module Impl_core_fmt_Display_for_alloy_primitives_bits_address_AddressChecksumBuffer. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::AddressChecksumBuffer". + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.as_str().fmt(f) + } + *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| "core::fmt::Display", Ty.path "str", [], [], "fmt", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_associated_function (| + Ty.path "alloy_primitives::bits::address::AddressChecksumBuffer", + "as_str", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Display" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Display_for_alloy_primitives_bits_address_AddressChecksumBuffer. + + Module Impl_alloy_primitives_bits_address_AddressChecksumBuffer. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::AddressChecksumBuffer". + + (* + pub const unsafe fn new() -> Self { + Self(MaybeUninit::uninit()) + } + *) + Definition new (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::bits::address::AddressChecksumBuffer" + [ + M.call_closure (| + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 42 ] + [ Ty.path "u8" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 42 ] + [ Ty.path "u8" ] + ], + "uninit", + [], + [] + |), + [] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : M.IsAssociatedFunction.Trait Self "new" new. + Admitted. + Global Typeclasses Opaque new. + + (* + pub fn format(&mut self, address: &Address, chain_id: Option) -> &mut str { + address.to_checksum_inner(unsafe { self.0.assume_init_mut() }, chain_id); + self.as_mut_str() + } + *) + Definition format (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; address; chain_id ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let address := M.alloc (| address |) in + let chain_id := M.alloc (| chain_id |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "alloy_primitives::bits::address::Address", + "to_checksum_inner", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| address |) |) |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 42 ] + [ Ty.path "u8" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 42 ] + [ Ty.path "u8" ] + ], + "assume_init_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::AddressChecksumBuffer", + 0 + |) + |) + ] + |) + |) + |) + |) + |); + M.read (| chain_id |) + ] + |) + |) in + M.alloc (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.path "str" ], + M.get_associated_function (| + Ty.path "alloy_primitives::bits::address::AddressChecksumBuffer", + "as_mut_str", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |) ] + |) + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_format : M.IsAssociatedFunction.Trait Self "format" format. + Admitted. + Global Typeclasses Opaque format. + + (* + pub const fn as_str(&self) -> &str { + unsafe { str::from_utf8_unchecked(self.0.assume_init_ref()) } + } + *) + Definition as_str (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_function (| "core::str::converts::from_utf8_unchecked", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 42 ] + [ Ty.path "u8" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 42 ] + [ Ty.path "u8" ] + ], + "assume_init_ref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::AddressChecksumBuffer", + 0 + |) + |) + ] + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_as_str : M.IsAssociatedFunction.Trait Self "as_str" as_str. + Admitted. + Global Typeclasses Opaque as_str. + + (* + pub fn as_mut_str(&mut self) -> &mut str { + unsafe { str::from_utf8_unchecked_mut(self.0.assume_init_mut()) } + } + *) + Definition as_mut_str (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.path "str" ], + M.get_function (| + "core::str::converts::from_utf8_unchecked_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 42 ] + [ Ty.path "u8" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 42 ] + [ Ty.path "u8" ] + ], + "assume_init_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::AddressChecksumBuffer", + 0 + |) + |) + ] + |) + |) + |) + ] + |) + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_as_mut_str : + M.IsAssociatedFunction.Trait Self "as_mut_str" as_mut_str. + Admitted. + Global Typeclasses Opaque as_mut_str. + + (* + pub fn to_string(&self) -> String { + self.as_str().to_string() + } + *) + Definition to_string (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "alloc::string::String", + M.get_trait_method (| + "alloc::string::ToString", + Ty.path "str", + [], + [], + "to_string", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_associated_function (| + Ty.path "alloy_primitives::bits::address::AddressChecksumBuffer", + "as_str", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_to_string : + M.IsAssociatedFunction.Trait Self "to_string" to_string. + Admitted. + Global Typeclasses Opaque to_string. + + (* + pub const fn into_inner(self) -> [u8; 42] { + unsafe { self.0.assume_init() } + } + *) + Definition into_inner (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 42 ] [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 42 ] + [ Ty.path "u8" ] + ], + "assume_init", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::address::AddressChecksumBuffer", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_into_inner : + M.IsAssociatedFunction.Trait Self "into_inner" into_inner. + Admitted. + Global Typeclasses Opaque into_inner. + End Impl_alloy_primitives_bits_address_AddressChecksumBuffer. + End address. +End bits. diff --git a/CoqOfRust/alloy_primitives/bits/bloom.rs b/CoqOfRust/alloy_primitives/bits/bloom.rs new file mode 100644 index 000000000..e64683eda --- /dev/null +++ b/CoqOfRust/alloy_primitives/bits/bloom.rs @@ -0,0 +1,264 @@ +//! Bloom type. +//! +//! Adapted from + +use crate::{keccak256, Address, Log, LogData, B256}; + +/// Number of bits to set per input in Ethereum bloom filter. +pub const BLOOM_BITS_PER_ITEM: usize = 3; +/// Size of the bloom filter in bytes. +pub const BLOOM_SIZE_BYTES: usize = 256; +/// Size of the bloom filter in bits +pub const BLOOM_SIZE_BITS: usize = BLOOM_SIZE_BYTES * 8; + +/// Mask, used in accrue +const MASK: usize = BLOOM_SIZE_BITS - 1; +/// Number of bytes per item, used in accrue +const ITEM_BYTES: usize = (BLOOM_SIZE_BITS.ilog2() as usize + 7) / 8; + +// BLOOM_SIZE_BYTES must be a power of 2 +#[allow(clippy::assertions_on_constants)] +const _: () = assert!(BLOOM_SIZE_BYTES.is_power_of_two()); + +/// Input to the [`Bloom::accrue`] method. +#[derive(Clone, Copy, Debug)] +pub enum BloomInput<'a> { + /// Raw input to be hashed. + Raw(&'a [u8]), + /// Already hashed input. + Hash(B256), +} + +impl BloomInput<'_> { + /// Consume the input, converting it to the hash. + #[inline] + pub fn into_hash(self) -> B256 { + match self { + BloomInput::Raw(raw) => keccak256(raw), + BloomInput::Hash(hash) => hash, + } + } +} + +impl From> for Bloom { + #[inline] + fn from(input: BloomInput<'_>) -> Self { + let mut bloom = Self::ZERO; + bloom.accrue(input); + bloom + } +} + +wrap_fixed_bytes!( + /// Ethereum 256 byte bloom filter. + pub struct Bloom<256>; +); + +impl<'a> FromIterator<&'a (Address, LogData)> for Bloom { + fn from_iter>(iter: T) -> Self { + let mut bloom = Self::ZERO; + bloom.extend(iter); + bloom + } +} + +impl<'a> Extend<&'a (Address, LogData)> for Bloom { + fn extend>(&mut self, iter: T) { + for (address, log_data) in iter { + self.accrue_raw_log(*address, log_data.topics()) + } + } +} + +impl<'a> FromIterator<&'a Log> for Bloom { + #[inline] + fn from_iter>(logs: T) -> Self { + let mut bloom = Self::ZERO; + bloom.extend(logs); + bloom + } +} + +impl<'a> Extend<&'a Log> for Bloom { + #[inline] + fn extend>(&mut self, logs: T) { + for log in logs { + self.accrue_log(log) + } + } +} + +impl<'a, 'b> FromIterator<&'a BloomInput<'b>> for Bloom { + #[inline] + fn from_iter>>(inputs: T) -> Self { + let mut bloom = Self::ZERO; + bloom.extend(inputs); + bloom + } +} + +impl<'a, 'b> Extend<&'a BloomInput<'b>> for Bloom { + #[inline] + fn extend>>(&mut self, inputs: T) { + for input in inputs { + self.accrue(*input); + } + } +} + +impl Bloom { + /// Returns a reference to the underlying data. + #[inline] + pub const fn data(&self) -> &[u8; BLOOM_SIZE_BYTES] { + &self.0 .0 + } + + /// Returns a mutable reference to the underlying data. + #[inline] + pub fn data_mut(&mut self) -> &mut [u8; BLOOM_SIZE_BYTES] { + &mut self.0 .0 + } + + /// Returns true if this bloom filter is a possible superset of the other + /// bloom filter, admitting false positives. + /// + /// Note: This method may return false positives. This is inherent to the + /// bloom filter data structure. + #[inline] + pub fn contains_input(&self, input: BloomInput<'_>) -> bool { + self.contains(&input.into()) + } + + /// Compile-time version of [`contains`](Self::contains). + /// + /// Note: This method may return false positives. This is inherent to the + /// bloom filter data structure. + pub const fn const_contains(self, other: Self) -> bool { + self.0.const_covers(other.0) + } + + /// Returns true if this bloom filter is a possible superset of the other + /// bloom filter, admitting false positives. + /// + /// Note: This method may return false positives. This is inherent to the + /// bloom filter data structure. + pub fn contains(&self, other: &Self) -> bool { + self.0.covers(&other.0) + } + + /// Accrues the input into the bloom filter. + pub fn accrue(&mut self, input: BloomInput<'_>) { + let hash = input.into_hash(); + + let mut ptr = 0; + + for _ in 0..3 { + let mut index = 0_usize; + for _ in 0..ITEM_BYTES { + index = (index << 8) | hash[ptr] as usize; + ptr += 1; + } + index &= MASK; + self.0[BLOOM_SIZE_BYTES - 1 - index / 8] |= 1 << (index % 8); + } + } + + /// Accrues the input into the bloom filter. + pub fn accrue_bloom(&mut self, bloom: &Self) { + *self |= *bloom; + } + + /// Specialised Bloom filter that sets three bits out of 2048, given an + /// arbitrary byte sequence. + /// + /// See Section 4.3.1 "Transaction Receipt" of the + /// [Ethereum Yellow Paper][ref] (page 6). + /// + /// [ref]: https://ethereum.github.io/yellowpaper/paper.pdf + pub fn m3_2048(&mut self, bytes: &[u8]) { + self.m3_2048_hashed(&keccak256(bytes)); + } + + /// [`m3_2048`](Self::m3_2048) but with a pre-hashed input. + pub fn m3_2048_hashed(&mut self, hash: &B256) { + for i in [0, 2, 4] { + let bit = (hash[i + 1] as usize + ((hash[i] as usize) << 8)) & 0x7FF; + self[BLOOM_SIZE_BYTES - 1 - bit / 8] |= 1 << (bit % 8); + } + } + + /// Ingests a raw log into the bloom filter. + pub fn accrue_raw_log(&mut self, address: Address, topics: &[B256]) { + self.m3_2048(address.as_slice()); + for topic in topics.iter() { + self.m3_2048(topic.as_slice()); + } + } + + /// Ingests a log into the bloom filter. + pub fn accrue_log(&mut self, log: &Log) { + self.accrue_raw_log(log.address, log.topics()) + } + + /// True if the bloom filter contains a log with given address and topics. + /// + /// Note: This method may return false positives. This is inherent to the + /// bloom filter data structure. + pub fn contains_raw_log(&self, address: Address, topics: &[B256]) -> bool { + let mut bloom = Self::default(); + bloom.accrue_raw_log(address, topics); + self.contains(&bloom) + } + + /// True if the bloom filter contains a log with given address and topics. + /// + /// Note: This method may return false positives. This is inherent to the + /// bloom filter data structure. + pub fn contains_log(&self, log: &Log) -> bool { + self.contains_raw_log(log.address, log.topics()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::hex; + + #[test] + fn works() { + let bloom = bloom!( + "00000000000000000000000000000000 + 00000000100000000000000000000000 + 00000000000000000000000000000000 + 00000000000000000000000000000000 + 00000000000000000000000000000000 + 00000000000000000000000000000000 + 00000002020000000000000000000000 + 00000000000000000000000800000000 + 10000000000000000000000000000000 + 00000000000000000000001000000000 + 00000000000000000000000000000000 + 00000000000000000000000000000000 + 00000000000000000000000000000000 + 00000000000000000000000000000000 + 00000000000000000000000000000000 + 00000000000000000000000000000000" + ); + let address = hex!("ef2d6d194084c2de36e0dabfce45d046b37d1106"); + let topic = hex!("02c69be41d0b7e40352fc85be1cd65eb03d40ef8427a0ca4596b1ead9a00e9fc"); + + let mut my_bloom = Bloom::default(); + assert!(!my_bloom.contains_input(BloomInput::Raw(&address))); + assert!(!my_bloom.contains_input(BloomInput::Raw(&topic))); + + my_bloom.accrue(BloomInput::Raw(&address)); + assert!(my_bloom.contains_input(BloomInput::Raw(&address))); + assert!(!my_bloom.contains_input(BloomInput::Raw(&topic))); + + my_bloom.accrue(BloomInput::Raw(&topic)); + assert!(my_bloom.contains_input(BloomInput::Raw(&address))); + assert!(my_bloom.contains_input(BloomInput::Raw(&topic))); + + assert_eq!(my_bloom, bloom); + } +} diff --git a/CoqOfRust/alloy_primitives/bits/bloom.v b/CoqOfRust/alloy_primitives/bits/bloom.v new file mode 100644 index 000000000..97db12f87 --- /dev/null +++ b/CoqOfRust/alloy_primitives/bits/bloom.v @@ -0,0 +1,2531 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module bits. + Module bloom. + Definition value_BLOOM_BITS_PER_ITEM : Value.t := + M.run_constant ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 3 |))). + + Axiom Constant_value_BLOOM_BITS_PER_ITEM : + (M.get_constant "alloy_primitives::bits::bloom::BLOOM_BITS_PER_ITEM") = + value_BLOOM_BITS_PER_ITEM. + Global Hint Rewrite Constant_value_BLOOM_BITS_PER_ITEM : constant_rewrites. + + Definition value_BLOOM_SIZE_BYTES : Value.t := + M.run_constant ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 256 |))). + + Axiom Constant_value_BLOOM_SIZE_BYTES : + (M.get_constant "alloy_primitives::bits::bloom::BLOOM_SIZE_BYTES") = value_BLOOM_SIZE_BYTES. + Global Hint Rewrite Constant_value_BLOOM_SIZE_BYTES : constant_rewrites. + + Definition value_BLOOM_SIZE_BITS : Value.t := + M.run_constant + ltac:(M.monadic + (M.alloc (| + BinOp.Wrap.mul (| + M.read (| M.get_constant "alloy_primitives::bits::bloom::BLOOM_SIZE_BYTES" |), + Value.Integer IntegerKind.Usize 8 + |) + |))). + + Axiom Constant_value_BLOOM_SIZE_BITS : + (M.get_constant "alloy_primitives::bits::bloom::BLOOM_SIZE_BITS") = value_BLOOM_SIZE_BITS. + Global Hint Rewrite Constant_value_BLOOM_SIZE_BITS : constant_rewrites. + + Definition value_MASK : Value.t := + M.run_constant + ltac:(M.monadic + (M.alloc (| + BinOp.Wrap.sub (| + M.read (| M.get_constant "alloy_primitives::bits::bloom::BLOOM_SIZE_BITS" |), + Value.Integer IntegerKind.Usize 1 + |) + |))). + + Axiom Constant_value_MASK : (M.get_constant "alloy_primitives::bits::bloom::MASK") = value_MASK. + Global Hint Rewrite Constant_value_MASK : constant_rewrites. + + Definition value_ITEM_BYTES : Value.t := + M.run_constant + ltac:(M.monadic + (M.alloc (| + BinOp.Wrap.div (| + BinOp.Wrap.add (| + M.cast + (Ty.path "usize") + (M.call_closure (| + Ty.path "u32", + M.get_associated_function (| Ty.path "usize", "ilog2", [], [] |), + [ M.read (| M.get_constant "alloy_primitives::bits::bloom::BLOOM_SIZE_BITS" |) ] + |)), + Value.Integer IntegerKind.Usize 7 + |), + Value.Integer IntegerKind.Usize 8 + |) + |))). + + Axiom Constant_value_ITEM_BYTES : + (M.get_constant "alloy_primitives::bits::bloom::ITEM_BYTES") = value_ITEM_BYTES. + Global Hint Rewrite Constant_value_ITEM_BYTES : constant_rewrites. + + (* + Enum BloomInput + { + const_params := []; + ty_params := []; + variants := + [ + { + name := "Raw"; + item := + StructTuple + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ]; + }; + { + name := "Hash"; + item := + StructTuple + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ]; + } + ]; + } + *) + + Axiom IsDiscriminant_BloomInput_Raw : + M.IsDiscriminant "alloy_primitives::bits::bloom::BloomInput::Raw" 0. + Axiom IsDiscriminant_BloomInput_Hash : + M.IsDiscriminant "alloy_primitives::bits::bloom::BloomInput::Hash" 1. + + Module Impl_core_clone_Clone_for_alloy_primitives_bits_bloom_BloomInput. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::BloomInput". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ + fun γ => + ltac:(M.monadic + (M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.deref (| M.read (| self |) |))) ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_alloy_primitives_bits_bloom_BloomInput. + + Module Impl_core_marker_Copy_for_alloy_primitives_bits_bloom_BloomInput. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::BloomInput". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_alloy_primitives_bits_bloom_BloomInput. + + Module Impl_core_fmt_Debug_for_alloy_primitives_bits_bloom_BloomInput. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::BloomInput". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ]), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::bits::bloom::BloomInput::Raw", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Raw" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::bits::bloom::BloomInput::Hash", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Hash" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_alloy_primitives_bits_bloom_BloomInput. + + Module Impl_alloy_primitives_bits_bloom_BloomInput. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::BloomInput". + + (* + pub fn into_hash(self) -> B256 { + match self { + BloomInput::Raw(raw) => keccak256(raw), + BloomInput::Hash(hash) => hash, + } + } + *) + Definition into_hash (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + []), + self, + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::bits::bloom::BloomInput::Raw", + 0 + |) in + let raw := M.copy (| γ0_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + M.get_function (| + "alloy_primitives::utils::keccak256", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ] + |), + [ M.read (| raw |) ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::bits::bloom::BloomInput::Hash", + 0 + |) in + let hash := M.copy (| γ0_0 |) in + hash)) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_into_hash : + M.IsAssociatedFunction.Trait Self "into_hash" into_hash. + Admitted. + Global Typeclasses Opaque into_hash. + End Impl_alloy_primitives_bits_bloom_BloomInput. + + Module Impl_core_convert_From_alloy_primitives_bits_bloom_BloomInput_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + fn from(input: BloomInput<'_>) -> Self { + let mut bloom = Self::ZERO; + bloom.accrue(input); + bloom + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ input ] => + ltac:(M.monadic + (let input := M.alloc (| input |) in + M.read (| + let~ bloom : Ty.path "alloy_primitives::bits::bloom::Bloom" := + M.copy (| M.get_constant "alloy_primitives::bits::bloom::ZERO" |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "alloy_primitives::bits::bloom::Bloom", + "accrue", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, bloom |); M.read (| input |) ] + |) + |) in + bloom + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::bloom::BloomInput" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_bloom_BloomInput_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_iter_traits_collect_FromIterator_ref__Tuple_alloy_primitives_bits_address_Address_alloy_primitives_log_LogData__for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + fn from_iter>(iter: T) -> Self { + let mut bloom = Self::ZERO; + bloom.extend(iter); + bloom + } + *) + Definition from_iter (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.read (| + let~ bloom : Ty.path "alloy_primitives::bits::bloom::Bloom" := + M.copy (| M.get_constant "alloy_primitives::bits::bloom::ZERO" |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::collect::Extend", + Ty.path "alloy_primitives::bits::bloom::Bloom", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "alloy_primitives::bits::address::Address"; + Ty.path "alloy_primitives::log::LogData" + ] + ] + ], + "extend", + [], + [ T ] + |), + [ M.borrow (| Pointer.Kind.MutRef, bloom |); M.read (| iter |) ] + |) + |) in + bloom + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::iter::traits::collect::FromIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "alloy_primitives::bits::address::Address"; + Ty.path "alloy_primitives::log::LogData" + ] + ] + ] + Self + (* Instance *) [ ("from_iter", InstanceField.Method from_iter) ]. + End Impl_core_iter_traits_collect_FromIterator_ref__Tuple_alloy_primitives_bits_address_Address_alloy_primitives_log_LogData__for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_iter_traits_collect_Extend_ref__Tuple_alloy_primitives_bits_address_Address_alloy_primitives_log_LogData__for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + fn extend>(&mut self, iter: T) { + for (address, log_data) in iter { + self.accrue_raw_log( *address, log_data.topics()) + } + } + *) + Definition extend (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ self; iter ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let iter := M.alloc (| iter |) in + M.read (| + M.use + (M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + T + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + T, + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| iter |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.tuple [], + ltac:(M.monadic + (let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "alloy_primitives::bits::address::Address"; + Ty.path "alloy_primitives::log::LogData" + ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + T + "IntoIter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ0_0 := M.read (| γ0_0 |) in + let γ2_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ2_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let address := M.alloc (| γ2_0 |) in + let log_data := M.alloc (| γ2_1 |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "alloy_primitives::bits::bloom::Bloom", + "accrue_raw_log", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| self |) |) + |); + M.read (| M.deref (| M.read (| address |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path + "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ] + ], + M.get_associated_function (| + Ty.path "alloy_primitives::log::LogData", + "topics", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| log_data |) |) + |) + ] + |) + |) + |) + ] + |) + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::iter::traits::collect::Extend" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.tuple + [ + Ty.path "alloy_primitives::bits::address::Address"; + Ty.path "alloy_primitives::log::LogData" + ] + ] + ] + Self + (* Instance *) [ ("extend", InstanceField.Method extend) ]. + End Impl_core_iter_traits_collect_Extend_ref__Tuple_alloy_primitives_bits_address_Address_alloy_primitives_log_LogData__for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_iter_traits_collect_FromIterator_ref__alloy_primitives_log_Log_alloy_primitives_log_LogData_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + fn from_iter>(logs: T) -> Self { + let mut bloom = Self::ZERO; + bloom.extend(logs); + bloom + } + *) + Definition from_iter (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ logs ] => + ltac:(M.monadic + (let logs := M.alloc (| logs |) in + M.read (| + let~ bloom : Ty.path "alloy_primitives::bits::bloom::Bloom" := + M.copy (| M.get_constant "alloy_primitives::bits::bloom::ZERO" |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::collect::Extend", + Ty.path "alloy_primitives::bits::bloom::Bloom", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::log::Log") + [] + [ Ty.path "alloy_primitives::log::LogData" ] + ] + ], + "extend", + [], + [ T ] + |), + [ M.borrow (| Pointer.Kind.MutRef, bloom |); M.read (| logs |) ] + |) + |) in + bloom + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::iter::traits::collect::FromIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::log::Log") + [] + [ Ty.path "alloy_primitives::log::LogData" ] + ] + ] + Self + (* Instance *) [ ("from_iter", InstanceField.Method from_iter) ]. + End Impl_core_iter_traits_collect_FromIterator_ref__alloy_primitives_log_Log_alloy_primitives_log_LogData_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_iter_traits_collect_Extend_ref__alloy_primitives_log_Log_alloy_primitives_log_LogData_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + fn extend>(&mut self, logs: T) { + for log in logs { + self.accrue_log(log) + } + } + *) + Definition extend (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ self; logs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let logs := M.alloc (| logs |) in + M.read (| + M.use + (M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + T + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + T, + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| logs |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.tuple [], + ltac:(M.monadic + (let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::log::Log") + [] + [ Ty.path "alloy_primitives::log::LogData" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + T + "IntoIter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let log := M.copy (| γ0_0 |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "alloy_primitives::bits::bloom::Bloom", + "accrue_log", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| self |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| log |) |) + |) + ] + |) + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::iter::traits::collect::Extend" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::log::Log") + [] + [ Ty.path "alloy_primitives::log::LogData" ] + ] + ] + Self + (* Instance *) [ ("extend", InstanceField.Method extend) ]. + End Impl_core_iter_traits_collect_Extend_ref__alloy_primitives_log_Log_alloy_primitives_log_LogData_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_iter_traits_collect_FromIterator_ref__alloy_primitives_bits_bloom_BloomInput_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + fn from_iter>>(inputs: T) -> Self { + let mut bloom = Self::ZERO; + bloom.extend(inputs); + bloom + } + *) + Definition from_iter (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ inputs ] => + ltac:(M.monadic + (let inputs := M.alloc (| inputs |) in + M.read (| + let~ bloom : Ty.path "alloy_primitives::bits::bloom::Bloom" := + M.copy (| M.get_constant "alloy_primitives::bits::bloom::ZERO" |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::collect::Extend", + Ty.path "alloy_primitives::bits::bloom::Bloom", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::bloom::BloomInput" ] + ], + "extend", + [], + [ T ] + |), + [ M.borrow (| Pointer.Kind.MutRef, bloom |); M.read (| inputs |) ] + |) + |) in + bloom + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::iter::traits::collect::FromIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::BloomInput" ] ] + Self + (* Instance *) [ ("from_iter", InstanceField.Method from_iter) ]. + End Impl_core_iter_traits_collect_FromIterator_ref__alloy_primitives_bits_bloom_BloomInput_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_iter_traits_collect_Extend_ref__alloy_primitives_bits_bloom_BloomInput_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + fn extend>>(&mut self, inputs: T) { + for input in inputs { + self.accrue( *input); + } + } + *) + Definition extend (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ self; inputs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let inputs := M.alloc (| inputs |) in + M.read (| + M.use + (M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + T + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + T, + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| inputs |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.tuple [], + ltac:(M.monadic + (let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::bloom::BloomInput" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + T + "IntoIter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let input := M.copy (| γ0_0 |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "alloy_primitives::bits::bloom::Bloom", + "accrue", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| self |) |) + |); + M.read (| M.deref (| M.read (| input |) |) |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::iter::traits::collect::Extend" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::BloomInput" ] ] + Self + (* Instance *) [ ("extend", InstanceField.Method extend) ]. + End Impl_core_iter_traits_collect_Extend_ref__alloy_primitives_bits_bloom_BloomInput_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + pub const fn data(&self) -> &[u8; BLOOM_SIZE_BYTES] { + &self.0 .0 + } + *) + Definition data (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_data : M.IsAssociatedFunction.Trait Self "data" data. + Admitted. + Global Typeclasses Opaque data. + + (* + pub fn data_mut(&mut self) -> &mut [u8; BLOOM_SIZE_BYTES] { + &mut self.0 .0 + } + *) + Definition data_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_data_mut : + M.IsAssociatedFunction.Trait Self "data_mut" data_mut. + Admitted. + Global Typeclasses Opaque data_mut. + + (* + pub fn contains_input(&self, input: BloomInput<'_>) -> bool { + self.contains(&input.into()) + } + *) + Definition contains_input (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "alloy_primitives::bits::bloom::Bloom", + "contains", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::bits::bloom::Bloom", + M.get_trait_method (| + "core::convert::Into", + Ty.path "alloy_primitives::bits::bloom::BloomInput", + [], + [ Ty.path "alloy_primitives::bits::bloom::Bloom" ], + "into", + [], + [] + |), + [ M.read (| input |) ] + |) + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_contains_input : + M.IsAssociatedFunction.Trait Self "contains_input" contains_input. + Admitted. + Global Typeclasses Opaque contains_input. + + (* + pub const fn const_contains(self, other: Self) -> bool { + self.0.const_covers(other.0) + } + *) + Definition const_contains (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + "const_covers", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + other, + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_const_contains : + M.IsAssociatedFunction.Trait Self "const_contains" const_contains. + Admitted. + Global Typeclasses Opaque const_contains. + + (* + pub fn contains(&self, other: &Self) -> bool { + self.0.covers(&other.0) + } + *) + Definition contains (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + "covers", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_contains : + M.IsAssociatedFunction.Trait Self "contains" contains. + Admitted. + Global Typeclasses Opaque contains. + + (* + pub fn accrue(&mut self, input: BloomInput<'_>) { + let hash = input.into_hash(); + + let mut ptr = 0; + + for _ in 0..3 { + let mut index = 0_usize; + for _ in 0..ITEM_BYTES { + index = (index << 8) | hash[ptr] as usize; + ptr += 1; + } + index &= MASK; + self.0[BLOOM_SIZE_BYTES - 1 - index / 8] |= 1 << (index % 8); + } + } + *) + Definition accrue (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; input ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let input := M.alloc (| input |) in + M.read (| + let~ hash : + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + M.get_associated_function (| + Ty.path "alloy_primitives::bits::bloom::BloomInput", + "into_hash", + [], + [] + |), + [ M.read (| input |) ] + |) + |) in + let~ ptr : Ty.path "usize" := M.alloc (| Value.Integer IntegerKind.Usize 0 |) in + M.use + (M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "i32" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.I32 0); + ("end_", Value.Integer IntegerKind.I32 3) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.tuple [], + ltac:(M.monadic + (let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "i32" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "i32" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let~ index : Ty.path "usize" := + M.alloc (| Value.Integer IntegerKind.Usize 0 |) in + let~ _ : Ty.tuple [] := + M.use + (M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", + M.read (| + M.get_constant + "alloy_primitives::bits::bloom::ITEM_BYTES" + |)) + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.tuple [], + ltac:(M.monadic + (let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path + "core::ops::range::Range") + [] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + iter + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "core::option::Option::None" + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.break (||) |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + index, + BinOp.bit_or + (BinOp.Wrap.shl (| + M.read (| index |), + Value.Integer + IntegerKind.I32 + 8 + |)) + (M.cast + (Ty.path "usize") + (M.read (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "u8" ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path + "alloy_primitives::bits::fixed::FixedBytes") + [ + Value.Integer + IntegerKind.Usize + 32 + ] + [], + [], + [ Ty.path "usize" + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + hash + |); + M.read (| ptr |) + ] + |) + |) + |))) + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + let β := ptr in + M.write (| + β, + BinOp.Wrap.add (| + M.read (| β |), + Value.Integer + IntegerKind.Usize + 1 + |) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + let~ _ : Ty.tuple [] := + M.alloc (| + let β := index in + M.write (| + β, + BinOp.bit_and + (M.read (| β |)) + (M.read (| + M.get_constant "alloy_primitives::bits::bloom::MASK" + |)) + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + let β := + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.path "u8" ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path + "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ Ty.path "usize" ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |); + BinOp.Wrap.sub (| + BinOp.Wrap.sub (| + M.read (| + M.get_constant + "alloy_primitives::bits::bloom::BLOOM_SIZE_BYTES" + |), + Value.Integer IntegerKind.Usize 1 + |), + BinOp.Wrap.div (| + M.read (| index |), + Value.Integer IntegerKind.Usize 8 + |) + |) + ] + |) + |) in + M.write (| + β, + BinOp.bit_or + (M.read (| β |)) + (BinOp.Wrap.shl (| + Value.Integer IntegerKind.U8 1, + BinOp.Wrap.rem (| + M.read (| index |), + Value.Integer IntegerKind.Usize 8 + |) + |)) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_accrue : M.IsAssociatedFunction.Trait Self "accrue" accrue. + Admitted. + Global Typeclasses Opaque accrue. + + (* + pub fn accrue_bloom(&mut self, bloom: &Self) { + *self |= *bloom; + } + *) + Definition accrue_bloom (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; bloom ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let bloom := M.alloc (| bloom |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::bit::BitOrAssign", + Ty.path "alloy_primitives::bits::bloom::Bloom", + [], + [ Ty.path "alloy_primitives::bits::bloom::Bloom" ], + "bitor_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |); + M.read (| M.deref (| M.read (| bloom |) |) |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_accrue_bloom : + M.IsAssociatedFunction.Trait Self "accrue_bloom" accrue_bloom. + Admitted. + Global Typeclasses Opaque accrue_bloom. + + (* + pub fn m3_2048(&mut self, bytes: &[u8]) { + self.m3_2048_hashed(&keccak256(bytes)); + } + *) + Definition m3_2048 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; bytes ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let bytes := M.alloc (| bytes |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "alloy_primitives::bits::bloom::Bloom", + "m3_2048_hashed", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + M.get_function (| + "alloy_primitives::utils::keccak256", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ] + |), + [ M.read (| bytes |) ] + |) + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_m3_2048 : + M.IsAssociatedFunction.Trait Self "m3_2048" m3_2048. + Admitted. + Global Typeclasses Opaque m3_2048. + + (* + pub fn m3_2048_hashed(&mut self, hash: &B256) { + for i in [0, 2, 4] { + let bit = (hash[i + 1] as usize + ((hash[i] as usize) << 8)) & 0x7FF; + self[BLOOM_SIZE_BYTES - 1 - bit / 8] |= 1 << (bit % 8); + } + } + *) + Definition m3_2048_hashed (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; hash ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let hash := M.alloc (| hash |) in + M.read (| + M.use + (M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 3 ] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 3 ] + [ Ty.path "usize" ], + [], + [], + "into_iter", + [], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.Usize 0; + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 4 + ] + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.tuple [], + ltac:(M.monadic + (let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 3 ] + [ Ty.path "usize" ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let i := M.copy (| γ0_0 |) in + let~ bit : Ty.path "usize" := + M.alloc (| + BinOp.bit_and + (BinOp.Wrap.add (| + M.cast + (Ty.path "usize") + (M.read (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "u8" ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path + "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| hash |) |) + |); + BinOp.Wrap.add (| + M.read (| i |), + Value.Integer IntegerKind.Usize 1 + |) + ] + |) + |) + |)), + BinOp.Wrap.shl (| + M.cast + (Ty.path "usize") + (M.read (| + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "u8" ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path + "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + [], + [ Ty.path "usize" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| hash |) |) + |); + M.read (| i |) + ] + |) + |) + |)), + Value.Integer IntegerKind.I32 8 + |) + |)) + (Value.Integer IntegerKind.Usize 2047) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + let β := + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.path "u8" ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.path "alloy_primitives::bits::bloom::Bloom", + [], + [ Ty.path "usize" ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| self |) |) + |); + BinOp.Wrap.sub (| + BinOp.Wrap.sub (| + M.read (| + M.get_constant + "alloy_primitives::bits::bloom::BLOOM_SIZE_BYTES" + |), + Value.Integer IntegerKind.Usize 1 + |), + BinOp.Wrap.div (| + M.read (| bit |), + Value.Integer IntegerKind.Usize 8 + |) + |) + ] + |) + |) in + M.write (| + β, + BinOp.bit_or + (M.read (| β |)) + (BinOp.Wrap.shl (| + Value.Integer IntegerKind.U8 1, + BinOp.Wrap.rem (| + M.read (| bit |), + Value.Integer IntegerKind.Usize 8 + |) + |)) + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_m3_2048_hashed : + M.IsAssociatedFunction.Trait Self "m3_2048_hashed" m3_2048_hashed. + Admitted. + Global Typeclasses Opaque m3_2048_hashed. + + (* + pub fn accrue_raw_log(&mut self, address: Address, topics: &[B256]) { + self.m3_2048(address.as_slice()); + for topic in topics.iter() { + self.m3_2048(topic.as_slice()); + } + } + *) + Definition accrue_raw_log (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; address; topics ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let address := M.alloc (| address |) in + let topics := M.alloc (| topics |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "alloy_primitives::bits::bloom::Bloom", + "m3_2048", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + "as_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloy_primitives::bits::address::Address", + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, address |) ] + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.use + (M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ], + "iter", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| topics |) |) |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.tuple [], + ltac:(M.monadic + (let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::slice::iter::Iter") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ], + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let topic := M.copy (| γ0_0 |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "alloy_primitives::bits::bloom::Bloom", + "m3_2048", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| self |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "u8" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + "as_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| topic |) |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_accrue_raw_log : + M.IsAssociatedFunction.Trait Self "accrue_raw_log" accrue_raw_log. + Admitted. + Global Typeclasses Opaque accrue_raw_log. + + (* + pub fn accrue_log(&mut self, log: &Log) { + self.accrue_raw_log(log.address, log.topics()) + } + *) + Definition accrue_log (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; log ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let log := M.alloc (| log |) in + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "alloy_primitives::bits::bloom::Bloom", + "accrue_raw_log", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| log |) |), + "alloy_primitives::log::Log", + "address" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ] + ], + M.get_associated_function (| + Ty.path "alloy_primitives::log::LogData", + "topics", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::log::LogData" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloy_primitives::log::Log") + [] + [ Ty.path "alloy_primitives::log::LogData" ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| log |) |) |) ] + |) + |) + |) + ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_accrue_log : + M.IsAssociatedFunction.Trait Self "accrue_log" accrue_log. + Admitted. + Global Typeclasses Opaque accrue_log. + + (* + pub fn contains_raw_log(&self, address: Address, topics: &[B256]) -> bool { + let mut bloom = Self::default(); + bloom.accrue_raw_log(address, topics); + self.contains(&bloom) + } + *) + Definition contains_raw_log (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; address; topics ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let address := M.alloc (| address |) in + let topics := M.alloc (| topics |) in + M.read (| + let~ bloom : Ty.path "alloy_primitives::bits::bloom::Bloom" := + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::bits::bloom::Bloom", + M.get_trait_method (| + "core::default::Default", + Ty.path "alloy_primitives::bits::bloom::Bloom", + [], + [], + "default", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "alloy_primitives::bits::bloom::Bloom", + "accrue_raw_log", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, bloom |); + M.read (| address |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| topics |) |) |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "alloy_primitives::bits::bloom::Bloom", + "contains", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, bloom |) |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_contains_raw_log : + M.IsAssociatedFunction.Trait Self "contains_raw_log" contains_raw_log. + Admitted. + Global Typeclasses Opaque contains_raw_log. + + (* + pub fn contains_log(&self, log: &Log) -> bool { + self.contains_raw_log(log.address, log.topics()) + } + *) + Definition contains_log (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; log ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let log := M.alloc (| log |) in + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "alloy_primitives::bits::bloom::Bloom", + "contains_raw_log", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| log |) |), + "alloy_primitives::log::Log", + "address" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ] + ], + M.get_associated_function (| + Ty.path "alloy_primitives::log::LogData", + "topics", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::log::LogData" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloy_primitives::log::Log") + [] + [ Ty.path "alloy_primitives::log::LogData" ], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| log |) |) |) ] + |) + |) + |) + ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_contains_log : + M.IsAssociatedFunction.Trait Self "contains_log" contains_log. + Admitted. + Global Typeclasses Opaque contains_log. + End Impl_alloy_primitives_bits_bloom_Bloom. + End bloom. +End bits. diff --git a/CoqOfRust/alloy_primitives/bits/fixed.rs b/CoqOfRust/alloy_primitives/bits/fixed.rs new file mode 100644 index 000000000..e37cc00ae --- /dev/null +++ b/CoqOfRust/alloy_primitives/bits/fixed.rs @@ -0,0 +1,698 @@ +use crate::aliases; +use core::{fmt, iter, ops, str}; +use derive_more::{Deref, DerefMut, From, Index, IndexMut, IntoIterator}; +use hex::FromHex; + +/// A byte array of fixed length (`[u8; N]`). +/// +/// This type allows us to more tightly control serialization, deserialization. +/// rlp encoding, decoding, and other type-level attributes for fixed-length +/// byte arrays. +/// +/// Users looking to prevent type-confusion between byte arrays of different +/// lengths should use the [`wrap_fixed_bytes!`](crate::wrap_fixed_bytes) macro +/// to create a new fixed-length byte array type. +#[derive( + Clone, + Copy, + PartialEq, + Eq, + PartialOrd, + Ord, + Hash, + Deref, + DerefMut, + From, + Index, + IndexMut, + IntoIterator, +)] +#[cfg_attr(feature = "arbitrary", derive(derive_arbitrary::Arbitrary, proptest_derive::Arbitrary))] +#[cfg_attr(feature = "allocative", derive(allocative::Allocative))] +#[repr(transparent)] +pub struct FixedBytes(#[into_iterator(owned, ref, ref_mut)] pub [u8; N]); + +crate::impl_fb_traits!(FixedBytes, N, const); + +impl Default for FixedBytes { + #[inline] + fn default() -> Self { + Self::ZERO + } +} + +impl Default for &FixedBytes { + #[inline] + fn default() -> Self { + &FixedBytes::ZERO + } +} + +impl From<&[u8; N]> for FixedBytes { + #[inline] + fn from(bytes: &[u8; N]) -> Self { + Self(*bytes) + } +} + +impl From<&mut [u8; N]> for FixedBytes { + #[inline] + fn from(bytes: &mut [u8; N]) -> Self { + Self(*bytes) + } +} + +/// Tries to create a `FixedBytes` by copying from a slice `&[u8]`. Succeeds +/// if `slice.len() == N`. +impl TryFrom<&[u8]> for FixedBytes { + type Error = core::array::TryFromSliceError; + + #[inline] + fn try_from(slice: &[u8]) -> Result { + <&Self>::try_from(slice).copied() + } +} + +/// Tries to create a `FixedBytes` by copying from a mutable slice `&mut +/// [u8]`. Succeeds if `slice.len() == N`. +impl TryFrom<&mut [u8]> for FixedBytes { + type Error = core::array::TryFromSliceError; + + #[inline] + fn try_from(slice: &mut [u8]) -> Result { + Self::try_from(&*slice) + } +} + +/// Tries to create a ref `FixedBytes` by copying from a slice `&[u8]`. +/// Succeeds if `slice.len() == N`. +impl<'a, const N: usize> TryFrom<&'a [u8]> for &'a FixedBytes { + type Error = core::array::TryFromSliceError; + + #[inline] + fn try_from(slice: &'a [u8]) -> Result<&'a FixedBytes, Self::Error> { + // SAFETY: `FixedBytes` is `repr(transparent)` for `[u8; N]` + <&[u8; N]>::try_from(slice).map(|array_ref| unsafe { core::mem::transmute(array_ref) }) + } +} + +/// Tries to create a ref `FixedBytes` by copying from a mutable slice `&mut +/// [u8]`. Succeeds if `slice.len() == N`. +impl<'a, const N: usize> TryFrom<&'a mut [u8]> for &'a mut FixedBytes { + type Error = core::array::TryFromSliceError; + + #[inline] + fn try_from(slice: &'a mut [u8]) -> Result<&'a mut FixedBytes, Self::Error> { + // SAFETY: `FixedBytes` is `repr(transparent)` for `[u8; N]` + <&mut [u8; N]>::try_from(slice).map(|array_ref| unsafe { core::mem::transmute(array_ref) }) + } +} + +// Ideally this would be: +// `impl From> for Uint` +// `impl From> for FixedBytes` +macro_rules! fixed_bytes_uint_conversions { + ($($int:ty => $fb:ty),* $(,)?) => {$( + impl From<$int> for $fb { + /// Converts a fixed-width unsigned integer into a fixed byte array + /// by interpreting the bytes as big-endian. + #[inline] + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + } + + impl From<$fb> for $int { + /// Converts a fixed byte array into a fixed-width unsigned integer + /// by interpreting the bytes as big-endian. + #[inline] + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + } + + const _: () = assert!(<$int>::BITS as usize == <$fb>::len_bytes() * 8); + )*}; +} + +fixed_bytes_uint_conversions! { + u8 => aliases::B8, + aliases::U8 => aliases::B8, + i8 => aliases::B8, + aliases::I8 => aliases::B8, + + u16 => aliases::B16, + aliases::U16 => aliases::B16, + i16 => aliases::B16, + aliases::I16 => aliases::B16, + + u32 => aliases::B32, + aliases::U32 => aliases::B32, + i32 => aliases::B32, + aliases::I32 => aliases::B32, + + u64 => aliases::B64, + aliases::U64 => aliases::B64, + i64 => aliases::B64, + aliases::I64 => aliases::B64, + + u128 => aliases::B128, + aliases::U128 => aliases::B128, + i128 => aliases::B128, + aliases::I128 => aliases::B128, + + aliases::U160 => aliases::B160, + aliases::I160 => aliases::B160, + + aliases::U256 => aliases::B256, + aliases::I256 => aliases::B256, + + aliases::U512 => aliases::B512, + aliases::I512 => aliases::B512, + +} + +impl From> for [u8; N] { + #[inline] + fn from(s: FixedBytes) -> Self { + s.0 + } +} + +impl AsRef<[u8; N]> for FixedBytes { + #[inline] + fn as_ref(&self) -> &[u8; N] { + &self.0 + } +} + +impl AsMut<[u8; N]> for FixedBytes { + #[inline] + fn as_mut(&mut self) -> &mut [u8; N] { + &mut self.0 + } +} + +impl AsRef<[u8]> for FixedBytes { + #[inline] + fn as_ref(&self) -> &[u8] { + &self.0 + } +} + +impl AsMut<[u8]> for FixedBytes { + #[inline] + fn as_mut(&mut self) -> &mut [u8] { + &mut self.0 + } +} + +impl fmt::Debug for FixedBytes { + #[inline] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.fmt_hex::(f, true) + } +} + +impl fmt::Display for FixedBytes { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + // If the alternate flag is NOT set, we write the full hex. + if N <= 4 || !f.alternate() { + return self.fmt_hex::(f, true); + } + + // If the alternate flag is set, we use middle-out compression. + const SEP_LEN: usize = '…'.len_utf8(); + let mut buf = [0; 2 + 4 + SEP_LEN + 4]; + buf[0] = b'0'; + buf[1] = b'x'; + hex::encode_to_slice(&self.0[0..2], &mut buf[2..6]).unwrap(); + '…'.encode_utf8(&mut buf[6..]); + hex::encode_to_slice(&self.0[N - 2..N], &mut buf[6 + SEP_LEN..]).unwrap(); + + // SAFETY: always valid UTF-8 + f.write_str(unsafe { str::from_utf8_unchecked(&buf) }) + } +} + +impl fmt::LowerHex for FixedBytes { + #[inline] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.fmt_hex::(f, f.alternate()) + } +} + +impl fmt::UpperHex for FixedBytes { + #[inline] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.fmt_hex::(f, f.alternate()) + } +} + +impl ops::BitAnd for FixedBytes { + type Output = Self; + + #[inline] + fn bitand(mut self, rhs: Self) -> Self::Output { + self &= rhs; + self + } +} + +impl ops::BitAndAssign for FixedBytes { + #[inline] + fn bitand_assign(&mut self, rhs: Self) { + // Note: `slice::Iter` has better codegen than `array::IntoIter` + iter::zip(self, &rhs).for_each(|(a, b)| *a &= *b); + } +} + +impl ops::BitOr for FixedBytes { + type Output = Self; + + #[inline] + fn bitor(mut self, rhs: Self) -> Self::Output { + self |= rhs; + self + } +} + +impl ops::BitOrAssign for FixedBytes { + #[inline] + fn bitor_assign(&mut self, rhs: Self) { + // Note: `slice::Iter` has better codegen than `array::IntoIter` + iter::zip(self, &rhs).for_each(|(a, b)| *a |= *b); + } +} + +impl ops::BitXor for FixedBytes { + type Output = Self; + + #[inline] + fn bitxor(mut self, rhs: Self) -> Self::Output { + self ^= rhs; + self + } +} + +impl ops::BitXorAssign for FixedBytes { + #[inline] + fn bitxor_assign(&mut self, rhs: Self) { + // Note: `slice::Iter` has better codegen than `array::IntoIter` + iter::zip(self, &rhs).for_each(|(a, b)| *a ^= *b); + } +} + +impl ops::Not for FixedBytes { + type Output = Self; + + #[inline] + fn not(mut self) -> Self::Output { + self.iter_mut().for_each(|byte| *byte = !*byte); + self + } +} + +impl str::FromStr for FixedBytes { + type Err = hex::FromHexError; + + #[inline] + fn from_str(s: &str) -> Result { + Self::from_hex(s) + } +} + +#[cfg(feature = "rand")] +impl rand::distributions::Distribution> + for rand::distributions::Standard +{ + #[inline] + fn sample(&self, rng: &mut R) -> FixedBytes { + FixedBytes::random_with(rng) + } +} + +impl FixedBytes { + /// Array of Zero bytes. + pub const ZERO: Self = Self([0u8; N]); + + /// Wraps the given byte array in [`FixedBytes`]. + #[inline] + pub const fn new(bytes: [u8; N]) -> Self { + Self(bytes) + } + + /// Creates a new [`FixedBytes`] with the last byte set to `x`. + #[inline] + pub const fn with_last_byte(x: u8) -> Self { + let mut bytes = [0u8; N]; + if N > 0 { + bytes[N - 1] = x; + } + Self(bytes) + } + + /// Creates a new [`FixedBytes`] where all bytes are set to `byte`. + #[inline] + pub const fn repeat_byte(byte: u8) -> Self { + Self([byte; N]) + } + + /// Returns the size of this byte array (`N`). + #[inline(always)] + pub const fn len_bytes() -> usize { + N + } + + /// Creates a new [`FixedBytes`] with cryptographically random content. + /// + /// # Panics + /// + /// Panics if the underlying call to + /// [`getrandom_uninit`](getrandom::getrandom_uninit) fails. + #[cfg(feature = "getrandom")] + #[inline] + #[track_caller] + pub fn random() -> Self { + Self::try_random().unwrap() + } + + /// Tries to create a new [`FixedBytes`] with cryptographically random + /// content. + /// + /// # Errors + /// + /// This function only propagates the error from the underlying call to + /// [`getrandom_uninit`](getrandom::getrandom_uninit). + #[cfg(feature = "getrandom")] + #[inline] + pub fn try_random() -> Result { + let mut bytes = Self::ZERO; + bytes.try_randomize()?; + Ok(bytes) + } + + /// Creates a new [`FixedBytes`] with the given random number generator. + #[cfg(feature = "rand")] + #[inline] + #[doc(alias = "random_using")] + pub fn random_with(rng: &mut R) -> Self { + let mut bytes = Self::ZERO; + bytes.randomize_with(rng); + bytes + } + + /// Fills this [`FixedBytes`] with cryptographically random content. + /// + /// # Panics + /// + /// Panics if the underlying call to + /// [`getrandom_uninit`](getrandom::getrandom_uninit) fails. + #[cfg(feature = "getrandom")] + #[inline] + #[track_caller] + pub fn randomize(&mut self) { + self.try_randomize().unwrap() + } + + /// Tries to fill this [`FixedBytes`] with cryptographically random content. + /// + /// # Errors + /// + /// This function only propagates the error from the underlying call to + /// [`getrandom_uninit`](getrandom::getrandom_uninit). + #[inline] + #[cfg(feature = "getrandom")] + pub fn try_randomize(&mut self) -> Result<(), getrandom::Error> { + getrandom::getrandom(&mut self.0) + } + + /// Fills this [`FixedBytes`] with the given random number generator. + #[cfg(feature = "rand")] + #[doc(alias = "randomize_using")] + pub fn randomize_with(&mut self, rng: &mut R) { + rng.fill_bytes(&mut self.0); + } + + /// Concatenate two `FixedBytes`. + /// + /// Due to constraints in the language, the user must specify the value of + /// the output size `Z`. + /// + /// # Panics + /// + /// Panics if `Z` is not equal to `N + M`. + pub const fn concat_const( + self, + other: FixedBytes, + ) -> FixedBytes { + assert!(N + M == Z, "Output size `Z` must equal the sum of the input sizes `N` and `M`"); + + let mut result = [0u8; Z]; + let mut i = 0; + while i < Z { + result[i] = if i >= N { other.0[i - N] } else { self.0[i] }; + i += 1; + } + FixedBytes(result) + } + + /// Create a new [`FixedBytes`] from the given slice `src`. + /// + /// For a fallible version, use the `TryFrom<&[u8]>` implementation. + /// + /// # Note + /// + /// The given bytes are interpreted in big endian order. + /// + /// # Panics + /// + /// If the length of `src` and the number of bytes in `Self` do not match. + #[inline] + #[track_caller] + pub fn from_slice(src: &[u8]) -> Self { + match Self::try_from(src) { + Ok(x) => x, + Err(_) => panic!("cannot convert a slice of length {} to FixedBytes<{N}>", src.len()), + } + } + + /// Create a new [`FixedBytes`] from the given slice `src`, left-padding it + /// with zeroes if necessary. + /// + /// # Note + /// + /// The given bytes are interpreted in big endian order. + /// + /// # Panics + /// + /// Panics if `src.len() > N`. + #[inline] + #[track_caller] + pub fn left_padding_from(value: &[u8]) -> Self { + let len = value.len(); + assert!(len <= N, "slice is too large. Expected <={N} bytes, got {len}"); + let mut bytes = Self::ZERO; + bytes[N - len..].copy_from_slice(value); + bytes + } + + /// Create a new [`FixedBytes`] from the given slice `src`, right-padding it + /// with zeroes if necessary. + /// + /// # Note + /// + /// The given bytes are interpreted in big endian order. + /// + /// # Panics + /// + /// Panics if `src.len() > N`. + #[inline] + #[track_caller] + pub fn right_padding_from(value: &[u8]) -> Self { + let len = value.len(); + assert!(len <= N, "slice is too large. Expected <={N} bytes, got {len}"); + let mut bytes = Self::ZERO; + bytes[..len].copy_from_slice(value); + bytes + } + + /// Returns a slice containing the entire array. Equivalent to `&s[..]`. + #[inline] + pub const fn as_slice(&self) -> &[u8] { + &self.0 + } + + /// Returns a mutable slice containing the entire array. Equivalent to + /// `&mut s[..]`. + #[inline] + pub fn as_mut_slice(&mut self) -> &mut [u8] { + &mut self.0 + } + + /// Returns `true` if all bits set in `self` are also set in `b`. + #[inline] + pub fn covers(&self, other: &Self) -> bool { + (*self & *other) == *other + } + + /// Returns `true` if all bits set in `self` are also set in `b`. + pub const fn const_covers(self, other: Self) -> bool { + // (self & other) == other + other.const_eq(&self.bit_and(other)) + } + + /// Compile-time equality. NOT constant-time equality. + pub const fn const_eq(&self, other: &Self) -> bool { + let mut i = 0; + while i < N { + if self.0[i] != other.0[i] { + return false; + } + i += 1; + } + true + } + + /// Returns `true` if no bits are set. + #[inline] + pub fn is_zero(&self) -> bool { + *self == Self::ZERO + } + + /// Returns `true` if no bits are set. + #[inline] + pub const fn const_is_zero(&self) -> bool { + self.const_eq(&Self::ZERO) + } + + /// Computes the bitwise AND of two `FixedBytes`. + pub const fn bit_and(self, rhs: Self) -> Self { + let mut ret = Self::ZERO; + let mut i = 0; + while i < N { + ret.0[i] = self.0[i] & rhs.0[i]; + i += 1; + } + ret + } + + /// Computes the bitwise OR of two `FixedBytes`. + pub const fn bit_or(self, rhs: Self) -> Self { + let mut ret = Self::ZERO; + let mut i = 0; + while i < N { + ret.0[i] = self.0[i] | rhs.0[i]; + i += 1; + } + ret + } + + /// Computes the bitwise XOR of two `FixedBytes`. + pub const fn bit_xor(self, rhs: Self) -> Self { + let mut ret = Self::ZERO; + let mut i = 0; + while i < N { + ret.0[i] = self.0[i] ^ rhs.0[i]; + i += 1; + } + ret + } + + fn fmt_hex(&self, f: &mut fmt::Formatter<'_>, prefix: bool) -> fmt::Result { + let mut buf = hex::Buffer::::new(); + let s = if UPPER { buf.format_upper(self) } else { buf.format(self) }; + // SAFETY: The buffer is guaranteed to be at least 2 bytes in length. + f.write_str(unsafe { s.get_unchecked((!prefix as usize) * 2..) }) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + macro_rules! test_fmt { + ($($fmt:literal, $hex:literal => $expected:literal;)+) => {$( + assert_eq!( + format!($fmt, fixed_bytes!($hex)), + $expected + ); + )+}; + } + + #[test] + fn concat_const() { + const A: FixedBytes<2> = fixed_bytes!("0123"); + const B: FixedBytes<2> = fixed_bytes!("4567"); + const EXPECTED: FixedBytes<4> = fixed_bytes!("01234567"); + const ACTUAL: FixedBytes<4> = A.concat_const(B); + + assert_eq!(ACTUAL, EXPECTED); + } + + #[test] + fn display() { + test_fmt! { + "{}", "0123456789abcdef" => "0x0123456789abcdef"; + "{:#}", "0123" => "0x0123"; + "{:#}", "01234567" => "0x01234567"; + "{:#}", "0123456789" => "0x0123…6789"; + } + } + + #[test] + fn debug() { + test_fmt! { + "{:?}", "0123456789abcdef" => "0x0123456789abcdef"; + "{:#?}", "0123456789abcdef" => "0x0123456789abcdef"; + } + } + + #[test] + fn lower_hex() { + test_fmt! { + "{:x}", "0123456789abcdef" => "0123456789abcdef"; + "{:#x}", "0123456789abcdef" => "0x0123456789abcdef"; + } + } + + #[test] + fn upper_hex() { + test_fmt! { + "{:X}", "0123456789abcdef" => "0123456789ABCDEF"; + "{:#X}", "0123456789abcdef" => "0x0123456789ABCDEF"; + } + } + + #[test] + fn left_padding_from() { + assert_eq!(FixedBytes::<4>::left_padding_from(&[0x01, 0x23]), fixed_bytes!("00000123")); + + assert_eq!( + FixedBytes::<4>::left_padding_from(&[0x01, 0x23, 0x45, 0x67]), + fixed_bytes!("01234567") + ); + } + + #[test] + #[should_panic(expected = "slice is too large. Expected <=4 bytes, got 5")] + fn left_padding_from_too_large() { + FixedBytes::<4>::left_padding_from(&[0x01, 0x23, 0x45, 0x67, 0x89]); + } + + #[test] + fn right_padding_from() { + assert_eq!(FixedBytes::<4>::right_padding_from(&[0x01, 0x23]), fixed_bytes!("01230000")); + + assert_eq!( + FixedBytes::<4>::right_padding_from(&[0x01, 0x23, 0x45, 0x67]), + fixed_bytes!("01234567") + ); + } + + #[test] + #[should_panic(expected = "slice is too large. Expected <=4 bytes, got 5")] + fn right_padding_from_too_large() { + FixedBytes::<4>::right_padding_from(&[0x01, 0x23, 0x45, 0x67, 0x89]); + } +} diff --git a/CoqOfRust/alloy_primitives/bits/fixed.v b/CoqOfRust/alloy_primitives/bits/fixed.v new file mode 100644 index 000000000..8ecf39983 --- /dev/null +++ b/CoqOfRust/alloy_primitives/bits/fixed.v @@ -0,0 +1,7718 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module bits. + Module fixed. + (* StructTuple + { + name := "FixedBytes"; + const_params := [ "N" ]; + ty_params := []; + fields := [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ]; + } *) + + Module Impl_core_clone_Clone_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* Clone *) + Definition clone (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.deref (| M.read (| self |) |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) [ ("clone", InstanceField.Method (clone N)) ]. + End Impl_core_clone_Clone_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_marker_Copy_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) []. + End Impl_core_marker_Copy_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_marker_StructuralPartialEq_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_cmp_PartialEq_alloy_primitives_bits_fixed_FixedBytes_N_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* PartialEq *) + Definition eq (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ] + (Self N) + (* Instance *) [ ("eq", InstanceField.Method (eq N)) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_bits_fixed_FixedBytes_N_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_cmp_Eq_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* Eq *) + Definition assert_receiver_is_total_eq + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method (assert_receiver_is_total_eq N)) ]. + End Impl_core_cmp_Eq_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_cmp_PartialOrd_alloy_primitives_bits_fixed_FixedBytes_N_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* PartialOrd *) + Definition partial_cmp + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ] + (Self N) + (* Instance *) [ ("partial_cmp", InstanceField.Method (partial_cmp N)) ]. + End Impl_core_cmp_PartialOrd_alloy_primitives_bits_fixed_FixedBytes_N_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_cmp_Ord_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* Ord *) + Definition cmp (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "core::cmp::Ordering", + M.get_trait_method (| + "core::cmp::Ord", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [], + "cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::cmp::Ord" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) [ ("cmp", InstanceField.Method (cmp N)) ]. + End Impl_core_cmp_Ord_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_hash_Hash_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* Hash *) + Definition hash (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [ __H ], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::hash::Hash" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) [ ("hash", InstanceField.Method (hash N)) ]. + End Impl_core_hash_Hash_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_ops_deref_Deref_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* Deref *) + Definition _Target (N : Value.t) : Ty.t := Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ]. + + (* Deref *) + Definition deref (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::ops::deref::Deref" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) + [ ("Target", InstanceField.Ty (_Target N)); ("deref", InstanceField.Method (deref N)) ]. + End Impl_core_ops_deref_Deref_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_ops_deref_DerefMut_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* DerefMut *) + Definition deref_mut + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::ops::deref::DerefMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) [ ("deref_mut", InstanceField.Method (deref_mut N)) ]. + End Impl_core_ops_deref_DerefMut_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_convert_From_array_N_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* From *) + Definition from (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple "alloy_primitives::bits::fixed::FixedBytes" [ M.read (| value |) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] + (Self N) + (* Instance *) [ ("from", InstanceField.Method (from N)) ]. + End Impl_core_convert_From_array_N_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_ops_index_Index_where_core_ops_index_Index_array_N_u8___IdxT___IdxT_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) (__IdxT : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* Index *) + Definition _Output (N : Value.t) (__IdxT : Ty.t) : Ty.t := + Ty.associated_in_trait + "core::ops::index::Index" + [] + [ __IdxT ] + (Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ]) + "Output". + + (* Index *) + Definition index + (N : Value.t) + (__IdxT : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N __IdxT in + match ε, τ, α with + | [], [], [ self; idx ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let idx := M.alloc (| idx |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "core::ops::index::Index" + [] + [ __IdxT ] + (Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ]) + "Output" + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ __IdxT ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |); + M.read (| idx |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (__IdxT : Ty.t), + M.IsTraitInstance + "core::ops::index::Index" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ __IdxT ] + (Self N __IdxT) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output N __IdxT)); + ("index", InstanceField.Method (index N __IdxT)) + ]. + End Impl_core_ops_index_Index_where_core_ops_index_Index_array_N_u8___IdxT___IdxT_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_ops_index_IndexMut_where_core_ops_index_IndexMut_array_N_u8___IdxT___IdxT_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) (__IdxT : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* IndexMut *) + Definition index_mut + (N : Value.t) + (__IdxT : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N __IdxT in + match ε, τ, α with + | [], [], [ self; idx ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let idx := M.alloc (| idx |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.associated_in_trait + "core::ops::index::Index" + [] + [ __IdxT ] + (Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ]) + "Output" + ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ __IdxT ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |); + M.read (| idx |) + ] + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t) (__IdxT : Ty.t), + M.IsTraitInstance + "core::ops::index::IndexMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ __IdxT ] + (Self N __IdxT) + (* Instance *) [ ("index_mut", InstanceField.Method (index_mut N __IdxT)) ]. + End Impl_core_ops_index_IndexMut_where_core_ops_index_IndexMut_array_N_u8___IdxT___IdxT_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_iter_traits_collect_IntoIterator_where_core_iter_traits_collect_IntoIterator_array_N_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* IntoIterator *) + Definition _Item (N : Value.t) : Ty.t := + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ]) + "Item". + + (* IntoIterator *) + Definition _IntoIter (N : Value.t) : Ty.t := + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ]) + "IntoIter". + + (* IntoIterator *) + Definition into_iter + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ]) + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::iter::traits::collect::IntoIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) + [ + ("Item", InstanceField.Ty (_Item N)); + ("IntoIter", InstanceField.Ty (_IntoIter N)); + ("into_iter", InstanceField.Method (into_iter N)) + ]. + End Impl_core_iter_traits_collect_IntoIterator_where_core_iter_traits_collect_IntoIterator_array_N_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_iter_traits_collect_IntoIterator_where_core_iter_traits_collect_IntoIterator_ref__array_N_u8_for_ref__alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]. + + (* IntoIterator *) + Definition _Item (N : Value.t) : Ty.t := + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ]) + "Item". + + (* IntoIterator *) + Definition _IntoIter (N : Value.t) : Ty.t := + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ]) + "IntoIter". + + (* IntoIterator *) + Definition into_iter + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ]) + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::iter::traits::collect::IntoIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) + [ + ("Item", InstanceField.Ty (_Item N)); + ("IntoIter", InstanceField.Ty (_IntoIter N)); + ("into_iter", InstanceField.Method (into_iter N)) + ]. + End Impl_core_iter_traits_collect_IntoIterator_where_core_iter_traits_collect_IntoIterator_ref__array_N_u8_for_ref__alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_iter_traits_collect_IntoIterator_where_core_iter_traits_collect_IntoIterator_ref_mut_array_N_u8_for_ref_mut_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]. + + (* IntoIterator *) + Definition _Item (N : Value.t) : Ty.t := + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ]) + "Item". + + (* IntoIterator *) + Definition _IntoIter (N : Value.t) : Ty.t := + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ]) + "IntoIter". + + (* IntoIterator *) + Definition into_iter + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ]) + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::iter::traits::collect::IntoIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) + [ + ("Item", InstanceField.Ty (_Item N)); + ("IntoIter", InstanceField.Ty (_IntoIter N)); + ("into_iter", InstanceField.Method (into_iter N)) + ]. + End Impl_core_iter_traits_collect_IntoIterator_where_core_iter_traits_collect_IntoIterator_ref_mut_array_N_u8_for_ref_mut_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_default_Default_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn default() -> Self { + Self::ZERO + } + *) + Definition default (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic (M.read (| M.get_constant "alloy_primitives::bits::fixed::ZERO" |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) [ ("default", InstanceField.Method (default N)) ]. + End Impl_core_default_Default_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_default_Default_for_ref__alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]. + + (* + fn default() -> Self { + &FixedBytes::ZERO + } + *) + Definition default (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::bits::fixed::ZERO" + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) [ ("default", InstanceField.Method (default N)) ]. + End Impl_core_default_Default_for_ref__alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_convert_From_ref__array_N_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn from(bytes: &[u8; N]) -> Self { + Self( *bytes) + } + *) + Definition from (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ bytes ] => + ltac:(M.monadic + (let bytes := M.alloc (| bytes |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ M.read (| M.deref (| M.read (| bytes |) |) |) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] ] + (Self N) + (* Instance *) [ ("from", InstanceField.Method (from N)) ]. + End Impl_core_convert_From_ref__array_N_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_convert_From_ref_mut_array_N_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn from(bytes: &mut [u8; N]) -> Self { + Self( *bytes) + } + *) + Definition from (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ bytes ] => + ltac:(M.monadic + (let bytes := M.alloc (| bytes |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ M.read (| M.deref (| M.read (| bytes |) |) |) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] ] + (Self N) + (* Instance *) [ ("from", InstanceField.Method (from N)) ]. + End Impl_core_convert_From_ref_mut_array_N_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_convert_TryFrom_ref__slice_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* type Error = core::array::TryFromSliceError; *) + Definition _Error (N : Value.t) : Ty.t := Ty.path "core::array::TryFromSliceError". + + (* + fn try_from(slice: &[u8]) -> Result { + <&Self>::try_from(slice).copied() + } + *) + Definition try_from (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ slice ] => + ltac:(M.monadic + (let slice := M.alloc (| slice |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []; + Ty.path "core::array::TryFromSliceError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]; + Ty.path "core::array::TryFromSliceError" + ], + "copied", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ], + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ], + "try_from", + [], + [] + |), + [ M.read (| slice |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + (Self N) + (* Instance *) + [ ("Error", InstanceField.Ty (_Error N)); ("try_from", InstanceField.Method (try_from N)) + ]. + End Impl_core_convert_TryFrom_ref__slice_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_convert_TryFrom_ref_mut_slice_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* type Error = core::array::TryFromSliceError; *) + Definition _Error (N : Value.t) : Ty.t := Ty.path "core::array::TryFromSliceError". + + (* + fn try_from(slice: &mut [u8]) -> Result { + Self::try_from(&*slice) + } + *) + Definition try_from (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ slice ] => + ltac:(M.monadic + (let slice := M.alloc (| slice |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [], + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ], + "try_from", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| slice |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + (Self N) + (* Instance *) + [ ("Error", InstanceField.Ty (_Error N)); ("try_from", InstanceField.Method (try_from N)) + ]. + End Impl_core_convert_TryFrom_ref_mut_slice_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_convert_TryFrom_ref__slice_u8_for_ref__alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]. + + (* type Error = core::array::TryFromSliceError; *) + Definition _Error (N : Value.t) : Ty.t := Ty.path "core::array::TryFromSliceError". + + (* + fn try_from(slice: &'a [u8]) -> Result<&'a FixedBytes, Self::Error> { + // SAFETY: `FixedBytes` is `repr(transparent)` for `[u8; N]` + <&[u8; N]>::try_from(slice).map(|array_ref| unsafe { core::mem::transmute(array_ref) }) + } + *) + Definition try_from (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ slice ] => + ltac:(M.monadic + (let slice := M.alloc (| slice |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ]; + Ty.path "core::array::TryFromSliceError" + ], + "map", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] + ] + ] + (Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ], + "try_from", + [], + [] + |), + [ M.read (| slice |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] + ] + ] + (Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ N ] + [] + ])), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let array_ref := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ N ] + [] + ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ N ] + [] + ] + ] + |), + [ M.read (| array_ref |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + (Self N) + (* Instance *) + [ ("Error", InstanceField.Ty (_Error N)); ("try_from", InstanceField.Method (try_from N)) + ]. + End Impl_core_convert_TryFrom_ref__slice_u8_for_ref__alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_convert_TryFrom_ref_mut_slice_u8_for_ref_mut_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]. + + (* type Error = core::array::TryFromSliceError; *) + Definition _Error (N : Value.t) : Ty.t := Ty.path "core::array::TryFromSliceError". + + (* + fn try_from(slice: &'a mut [u8]) -> Result<&'a mut FixedBytes, Self::Error> { + // SAFETY: `FixedBytes` is `repr(transparent)` for `[u8; N]` + <&mut [u8; N]>::try_from(slice).map(|array_ref| unsafe { core::mem::transmute(array_ref) }) + } + *) + Definition try_from (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ slice ] => + ltac:(M.monadic + (let slice := M.alloc (| slice |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ]; + Ty.path "core::array::TryFromSliceError" + ], + "map", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] + ] + ] + (Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ], + "try_from", + [], + [] + |), + [ M.read (| slice |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] + ] + ] + (Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ N ] + [] + ])), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let array_ref := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ N ] + [] + ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ N ] + [] + ] + ] + |), + [ M.read (| array_ref |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + (Self N) + (* Instance *) + [ ("Error", InstanceField.Ty (_Error N)); ("try_from", InstanceField.Method (try_from N)) + ]. + End Impl_core_convert_TryFrom_ref_mut_slice_u8_for_ref_mut_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_convert_From_u8_for_alloy_primitives_bits_fixed_FixedBytes_Usize_1. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 1 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 1 ] [ Ty.path "u8" ], + M.get_associated_function (| Ty.path "u8", "to_be_bytes", [], [] |), + [ M.read (| value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u8" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_u8_for_alloy_primitives_bits_fixed_FixedBytes_Usize_1. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_1_for_u8. + Definition Self : Ty.t := Ty.path "u8". + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.path "u8", + M.get_associated_function (| Ty.path "u8", "from_be_bytes", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 1 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_1_for_u8. + + Module Impl_core_convert_From_ruint_Uint_Usize_8_Usize_1_for_alloy_primitives_bits_fixed_FixedBytes_Usize_1. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 1 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 1 ] [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 8; Value.Integer IntegerKind.Usize 1 ] + [], + "to_be_bytes", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 8; Value.Integer IntegerKind.Usize 1 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ruint_Uint_Usize_8_Usize_1_for_alloy_primitives_bits_fixed_FixedBytes_Usize_1. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_1_for_ruint_Uint_Usize_8_Usize_1. + Definition Self : Ty.t := + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 8; Value.Integer IntegerKind.Usize 1 ] + []. + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 8; Value.Integer IntegerKind.Usize 1 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 8; Value.Integer IntegerKind.Usize 1 ] + [], + "from_be_bytes", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 1 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_1_for_ruint_Uint_Usize_8_Usize_1. + + Module Impl_core_convert_From_i8_for_alloy_primitives_bits_fixed_FixedBytes_Usize_1. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 1 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 1 ] [ Ty.path "u8" ], + M.get_associated_function (| Ty.path "i8", "to_be_bytes", [], [] |), + [ M.read (| value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i8" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_i8_for_alloy_primitives_bits_fixed_FixedBytes_Usize_1. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_1_for_i8. + Definition Self : Ty.t := Ty.path "i8". + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.path "i8", + M.get_associated_function (| Ty.path "i8", "from_be_bytes", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 1 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_1_for_i8. + + Module Impl_core_convert_From_alloy_primitives_signed_int_Signed_Usize_8_Usize_1_for_alloy_primitives_bits_fixed_FixedBytes_Usize_1. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 1 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 1 ] [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 8; Value.Integer IntegerKind.Usize 1 ] + [], + "to_be_bytes", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 8; Value.Integer IntegerKind.Usize 1 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_signed_int_Signed_Usize_8_Usize_1_for_alloy_primitives_bits_fixed_FixedBytes_Usize_1. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_1_for_alloy_primitives_signed_int_Signed_Usize_8_Usize_1. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 8; Value.Integer IntegerKind.Usize 1 ] + []. + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 8; Value.Integer IntegerKind.Usize 1 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 8; Value.Integer IntegerKind.Usize 1 ] + [], + "from_be_bytes", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 1 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_1_for_alloy_primitives_signed_int_Signed_Usize_8_Usize_1. + + Module Impl_core_convert_From_u16_for_alloy_primitives_bits_fixed_FixedBytes_Usize_2. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 2 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ Ty.path "u8" ], + M.get_associated_function (| Ty.path "u16", "to_be_bytes", [], [] |), + [ M.read (| value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u16" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_u16_for_alloy_primitives_bits_fixed_FixedBytes_Usize_2. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_2_for_u16. + Definition Self : Ty.t := Ty.path "u16". + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.path "u16", + M.get_associated_function (| Ty.path "u16", "from_be_bytes", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 2 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_2_for_u16. + + Module Impl_core_convert_From_ruint_Uint_Usize_16_Usize_1_for_alloy_primitives_bits_fixed_FixedBytes_Usize_2. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 2 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.Usize 1 ] + [], + "to_be_bytes", + [ Value.Integer IntegerKind.Usize 2 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.Usize 1 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ruint_Uint_Usize_16_Usize_1_for_alloy_primitives_bits_fixed_FixedBytes_Usize_2. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_2_for_ruint_Uint_Usize_16_Usize_1. + Definition Self : Ty.t := + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.Usize 1 ] + []. + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.Usize 1 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.Usize 1 ] + [], + "from_be_bytes", + [ Value.Integer IntegerKind.Usize 2 ], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 2 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_2_for_ruint_Uint_Usize_16_Usize_1. + + Module Impl_core_convert_From_i16_for_alloy_primitives_bits_fixed_FixedBytes_Usize_2. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 2 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ Ty.path "u8" ], + M.get_associated_function (| Ty.path "i16", "to_be_bytes", [], [] |), + [ M.read (| value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i16" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_i16_for_alloy_primitives_bits_fixed_FixedBytes_Usize_2. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_2_for_i16. + Definition Self : Ty.t := Ty.path "i16". + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.path "i16", + M.get_associated_function (| Ty.path "i16", "from_be_bytes", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 2 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_2_for_i16. + + Module Impl_core_convert_From_alloy_primitives_signed_int_Signed_Usize_16_Usize_1_for_alloy_primitives_bits_fixed_FixedBytes_Usize_2. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 2 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 2 ] [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.Usize 1 ] + [], + "to_be_bytes", + [ Value.Integer IntegerKind.Usize 2 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.Usize 1 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_signed_int_Signed_Usize_16_Usize_1_for_alloy_primitives_bits_fixed_FixedBytes_Usize_2. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_2_for_alloy_primitives_signed_int_Signed_Usize_16_Usize_1. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.Usize 1 ] + []. + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.Usize 1 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 16; Value.Integer IntegerKind.Usize 1 ] + [], + "from_be_bytes", + [ Value.Integer IntegerKind.Usize 2 ], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 2 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_2_for_alloy_primitives_signed_int_Signed_Usize_16_Usize_1. + + Module Impl_core_convert_From_u32_for_alloy_primitives_bits_fixed_FixedBytes_Usize_4. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 4 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 4 ] [ Ty.path "u8" ], + M.get_associated_function (| Ty.path "u32", "to_be_bytes", [], [] |), + [ M.read (| value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u32" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_u32_for_alloy_primitives_bits_fixed_FixedBytes_Usize_4. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_4_for_u32. + Definition Self : Ty.t := Ty.path "u32". + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| Ty.path "u32", "from_be_bytes", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 4 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_4_for_u32. + + Module Impl_core_convert_From_ruint_Uint_Usize_32_Usize_1_for_alloy_primitives_bits_fixed_FixedBytes_Usize_4. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 4 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 4 ] [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 32; Value.Integer IntegerKind.Usize 1 ] + [], + "to_be_bytes", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 32; Value.Integer IntegerKind.Usize 1 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ruint_Uint_Usize_32_Usize_1_for_alloy_primitives_bits_fixed_FixedBytes_Usize_4. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_4_for_ruint_Uint_Usize_32_Usize_1. + Definition Self : Ty.t := + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 32; Value.Integer IntegerKind.Usize 1 ] + []. + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 32; Value.Integer IntegerKind.Usize 1 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 32; Value.Integer IntegerKind.Usize 1 ] + [], + "from_be_bytes", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 4 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_4_for_ruint_Uint_Usize_32_Usize_1. + + Module Impl_core_convert_From_i32_for_alloy_primitives_bits_fixed_FixedBytes_Usize_4. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 4 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 4 ] [ Ty.path "u8" ], + M.get_associated_function (| Ty.path "i32", "to_be_bytes", [], [] |), + [ M.read (| value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i32" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_i32_for_alloy_primitives_bits_fixed_FixedBytes_Usize_4. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_4_for_i32. + Definition Self : Ty.t := Ty.path "i32". + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.path "i32", + M.get_associated_function (| Ty.path "i32", "from_be_bytes", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 4 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_4_for_i32. + + Module Impl_core_convert_From_alloy_primitives_signed_int_Signed_Usize_32_Usize_1_for_alloy_primitives_bits_fixed_FixedBytes_Usize_4. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 4 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 4 ] [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 32; Value.Integer IntegerKind.Usize 1 ] + [], + "to_be_bytes", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 32; Value.Integer IntegerKind.Usize 1 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_signed_int_Signed_Usize_32_Usize_1_for_alloy_primitives_bits_fixed_FixedBytes_Usize_4. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_4_for_alloy_primitives_signed_int_Signed_Usize_32_Usize_1. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 32; Value.Integer IntegerKind.Usize 1 ] + []. + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 32; Value.Integer IntegerKind.Usize 1 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 32; Value.Integer IntegerKind.Usize 1 ] + [], + "from_be_bytes", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 4 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_4_for_alloy_primitives_signed_int_Signed_Usize_32_Usize_1. + + Module Impl_core_convert_From_u64_for_alloy_primitives_bits_fixed_FixedBytes_Usize_8. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 8 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 8 ] [ Ty.path "u8" ], + M.get_associated_function (| Ty.path "u64", "to_be_bytes", [], [] |), + [ M.read (| value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u64" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_u64_for_alloy_primitives_bits_fixed_FixedBytes_Usize_8. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_8_for_u64. + Definition Self : Ty.t := Ty.path "u64". + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.path "u64", + M.get_associated_function (| Ty.path "u64", "from_be_bytes", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 8 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_8_for_u64. + + Module Impl_core_convert_From_ruint_Uint_Usize_64_Usize_1_for_alloy_primitives_bits_fixed_FixedBytes_Usize_8. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 8 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 8 ] [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 64; Value.Integer IntegerKind.Usize 1 ] + [], + "to_be_bytes", + [ Value.Integer IntegerKind.Usize 8 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 64; Value.Integer IntegerKind.Usize 1 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ruint_Uint_Usize_64_Usize_1_for_alloy_primitives_bits_fixed_FixedBytes_Usize_8. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_8_for_ruint_Uint_Usize_64_Usize_1. + Definition Self : Ty.t := + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 64; Value.Integer IntegerKind.Usize 1 ] + []. + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 64; Value.Integer IntegerKind.Usize 1 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 64; Value.Integer IntegerKind.Usize 1 ] + [], + "from_be_bytes", + [ Value.Integer IntegerKind.Usize 8 ], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 8 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_8_for_ruint_Uint_Usize_64_Usize_1. + + Module Impl_core_convert_From_i64_for_alloy_primitives_bits_fixed_FixedBytes_Usize_8. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 8 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 8 ] [ Ty.path "u8" ], + M.get_associated_function (| Ty.path "i64", "to_be_bytes", [], [] |), + [ M.read (| value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i64" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_i64_for_alloy_primitives_bits_fixed_FixedBytes_Usize_8. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_8_for_i64. + Definition Self : Ty.t := Ty.path "i64". + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.path "i64", + M.get_associated_function (| Ty.path "i64", "from_be_bytes", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 8 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_8_for_i64. + + Module Impl_core_convert_From_alloy_primitives_signed_int_Signed_Usize_64_Usize_1_for_alloy_primitives_bits_fixed_FixedBytes_Usize_8. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 8 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 8 ] [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 64; Value.Integer IntegerKind.Usize 1 ] + [], + "to_be_bytes", + [ Value.Integer IntegerKind.Usize 8 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 64; Value.Integer IntegerKind.Usize 1 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_signed_int_Signed_Usize_64_Usize_1_for_alloy_primitives_bits_fixed_FixedBytes_Usize_8. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_8_for_alloy_primitives_signed_int_Signed_Usize_64_Usize_1. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 64; Value.Integer IntegerKind.Usize 1 ] + []. + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 64; Value.Integer IntegerKind.Usize 1 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 64; Value.Integer IntegerKind.Usize 1 ] + [], + "from_be_bytes", + [ Value.Integer IntegerKind.Usize 8 ], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 8 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_8_for_alloy_primitives_signed_int_Signed_Usize_64_Usize_1. + + Module Impl_core_convert_From_u128_for_alloy_primitives_bits_fixed_FixedBytes_Usize_16. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 16 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "u8" ], + M.get_associated_function (| Ty.path "u128", "to_be_bytes", [], [] |), + [ M.read (| value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u128" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_u128_for_alloy_primitives_bits_fixed_FixedBytes_Usize_16. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_16_for_u128. + Definition Self : Ty.t := Ty.path "u128". + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.path "u128", + M.get_associated_function (| Ty.path "u128", "from_be_bytes", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 16 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_16_for_u128. + + Module Impl_core_convert_From_ruint_Uint_Usize_128_Usize_2_for_alloy_primitives_bits_fixed_FixedBytes_Usize_16. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 16 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 128; Value.Integer IntegerKind.Usize 2 ] + [], + "to_be_bytes", + [ Value.Integer IntegerKind.Usize 16 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 128; Value.Integer IntegerKind.Usize 2 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ruint_Uint_Usize_128_Usize_2_for_alloy_primitives_bits_fixed_FixedBytes_Usize_16. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_16_for_ruint_Uint_Usize_128_Usize_2. + Definition Self : Ty.t := + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 128; Value.Integer IntegerKind.Usize 2 ] + []. + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 128; Value.Integer IntegerKind.Usize 2 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 128; Value.Integer IntegerKind.Usize 2 ] + [], + "from_be_bytes", + [ Value.Integer IntegerKind.Usize 16 ], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 16 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_16_for_ruint_Uint_Usize_128_Usize_2. + + Module Impl_core_convert_From_i128_for_alloy_primitives_bits_fixed_FixedBytes_Usize_16. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 16 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "u8" ], + M.get_associated_function (| Ty.path "i128", "to_be_bytes", [], [] |), + [ M.read (| value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i128" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_i128_for_alloy_primitives_bits_fixed_FixedBytes_Usize_16. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_16_for_i128. + Definition Self : Ty.t := Ty.path "i128". + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.path "i128", + M.get_associated_function (| Ty.path "i128", "from_be_bytes", [], [] |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 16 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_16_for_i128. + + Module Impl_core_convert_From_alloy_primitives_signed_int_Signed_Usize_128_Usize_2_for_alloy_primitives_bits_fixed_FixedBytes_Usize_16. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 16 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 16 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 128; Value.Integer IntegerKind.Usize 2 ] + [], + "to_be_bytes", + [ Value.Integer IntegerKind.Usize 16 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 128; Value.Integer IntegerKind.Usize 2 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_signed_int_Signed_Usize_128_Usize_2_for_alloy_primitives_bits_fixed_FixedBytes_Usize_16. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_16_for_alloy_primitives_signed_int_Signed_Usize_128_Usize_2. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 128; Value.Integer IntegerKind.Usize 2 ] + []. + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 128; Value.Integer IntegerKind.Usize 2 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 128; Value.Integer IntegerKind.Usize 2 ] + [], + "from_be_bytes", + [ Value.Integer IntegerKind.Usize 16 ], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 16 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_16_for_alloy_primitives_signed_int_Signed_Usize_128_Usize_2. + + Module Impl_core_convert_From_ruint_Uint_Usize_160_Usize_3_for_alloy_primitives_bits_fixed_FixedBytes_Usize_20. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 160; Value.Integer IntegerKind.Usize 3 ] + [], + "to_be_bytes", + [ Value.Integer IntegerKind.Usize 20 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 160; Value.Integer IntegerKind.Usize 3 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ruint_Uint_Usize_160_Usize_3_for_alloy_primitives_bits_fixed_FixedBytes_Usize_20. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_20_for_ruint_Uint_Usize_160_Usize_3. + Definition Self : Ty.t := + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 160; Value.Integer IntegerKind.Usize 3 ] + []. + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 160; Value.Integer IntegerKind.Usize 3 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 160; Value.Integer IntegerKind.Usize 3 ] + [], + "from_be_bytes", + [ Value.Integer IntegerKind.Usize 20 ], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_20_for_ruint_Uint_Usize_160_Usize_3. + + Module Impl_core_convert_From_alloy_primitives_signed_int_Signed_Usize_160_Usize_3_for_alloy_primitives_bits_fixed_FixedBytes_Usize_20. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 160; Value.Integer IntegerKind.Usize 3 ] + [], + "to_be_bytes", + [ Value.Integer IntegerKind.Usize 20 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 160; Value.Integer IntegerKind.Usize 3 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_signed_int_Signed_Usize_160_Usize_3_for_alloy_primitives_bits_fixed_FixedBytes_Usize_20. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_20_for_alloy_primitives_signed_int_Signed_Usize_160_Usize_3. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 160; Value.Integer IntegerKind.Usize 3 ] + []. + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 160; Value.Integer IntegerKind.Usize 3 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 160; Value.Integer IntegerKind.Usize 3 ] + [], + "from_be_bytes", + [ Value.Integer IntegerKind.Usize 20 ], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_20_for_alloy_primitives_signed_int_Signed_Usize_160_Usize_3. + + Module Impl_core_convert_From_ruint_Uint_Usize_256_Usize_4_for_alloy_primitives_bits_fixed_FixedBytes_Usize_32. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + "to_be_bytes", + [ Value.Integer IntegerKind.Usize 32 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ruint_Uint_Usize_256_Usize_4_for_alloy_primitives_bits_fixed_FixedBytes_Usize_32. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_32_for_ruint_Uint_Usize_256_Usize_4. + Definition Self : Ty.t := + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []. + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + "from_be_bytes", + [ Value.Integer IntegerKind.Usize 32 ], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_32_for_ruint_Uint_Usize_256_Usize_4. + + Module Impl_core_convert_From_alloy_primitives_signed_int_Signed_Usize_256_Usize_4_for_alloy_primitives_bits_fixed_FixedBytes_Usize_32. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + "to_be_bytes", + [ Value.Integer IntegerKind.Usize 32 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_signed_int_Signed_Usize_256_Usize_4_for_alloy_primitives_bits_fixed_FixedBytes_Usize_32. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_32_for_alloy_primitives_signed_int_Signed_Usize_256_Usize_4. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []. + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + "from_be_bytes", + [ Value.Integer IntegerKind.Usize 32 ], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_32_for_alloy_primitives_signed_int_Signed_Usize_256_Usize_4. + + Module Impl_core_convert_From_ruint_Uint_Usize_512_Usize_8_for_alloy_primitives_bits_fixed_FixedBytes_Usize_64. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 64 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 512; Value.Integer IntegerKind.Usize 8 ] + [], + "to_be_bytes", + [ Value.Integer IntegerKind.Usize 64 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 512; Value.Integer IntegerKind.Usize 8 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ruint_Uint_Usize_512_Usize_8_for_alloy_primitives_bits_fixed_FixedBytes_Usize_64. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_64_for_ruint_Uint_Usize_512_Usize_8. + Definition Self : Ty.t := + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 512; Value.Integer IntegerKind.Usize 8 ] + []. + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 512; Value.Integer IntegerKind.Usize 8 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 512; Value.Integer IntegerKind.Usize 8 ] + [], + "from_be_bytes", + [ Value.Integer IntegerKind.Usize 64 ], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 64 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_64_for_ruint_Uint_Usize_512_Usize_8. + + Module Impl_core_convert_From_alloy_primitives_signed_int_Signed_Usize_512_Usize_8_for_alloy_primitives_bits_fixed_FixedBytes_Usize_64. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 64 ] + []. + + (* + fn from(value: $int) -> Self { + Self(value.to_be_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 64 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 512; Value.Integer IntegerKind.Usize 8 ] + [], + "to_be_bytes", + [ Value.Integer IntegerKind.Usize 64 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 512; Value.Integer IntegerKind.Usize 8 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_signed_int_Signed_Usize_512_Usize_8_for_alloy_primitives_bits_fixed_FixedBytes_Usize_64. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_64_for_alloy_primitives_signed_int_Signed_Usize_512_Usize_8. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 512; Value.Integer IntegerKind.Usize 8 ] + []. + + (* + fn from(value: $fb) -> Self { + Self::from_be_bytes(value.0) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 512; Value.Integer IntegerKind.Usize 8 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 512; Value.Integer IntegerKind.Usize 8 ] + [], + "from_be_bytes", + [ Value.Integer IntegerKind.Usize 64 ], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 64 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_64_for_alloy_primitives_signed_int_Signed_Usize_512_Usize_8. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_N_for_array_N_u8. + Definition Self (N : Value.t) : Ty.t := Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ]. + + (* + fn from(s: FixedBytes) -> Self { + s.0 + } + *) + Definition from (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ s ] => + ltac:(M.monadic + (let s := M.alloc (| s |) in + M.read (| + M.SubPointer.get_struct_tuple_field (| + s, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ] + (Self N) + (* Instance *) [ ("from", InstanceField.Method (from N)) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_N_for_array_N_u8. + + Module Impl_core_convert_AsRef_array_N_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn as_ref(&self) -> &[u8; N] { + &self.0 + } + *) + Definition as_ref (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::convert::AsRef" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] + (Self N) + (* Instance *) [ ("as_ref", InstanceField.Method (as_ref N)) ]. + End Impl_core_convert_AsRef_array_N_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_convert_AsMut_array_N_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn as_mut(&mut self) -> &mut [u8; N] { + &mut self.0 + } + *) + Definition as_mut (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::convert::AsMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] + (Self N) + (* Instance *) [ ("as_mut", InstanceField.Method (as_mut N)) ]. + End Impl_core_convert_AsMut_array_N_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_convert_AsRef_slice_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn as_ref(&self) -> &[u8] { + &self.0 + } + *) + Definition as_ref (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::convert::AsRef" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + (Self N) + (* Instance *) [ ("as_ref", InstanceField.Method (as_ref N)) ]. + End Impl_core_convert_AsRef_slice_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_convert_AsMut_slice_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn as_mut(&mut self) -> &mut [u8] { + &mut self.0 + } + *) + Definition as_mut (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::convert::AsMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + (Self N) + (* Instance *) [ ("as_mut", InstanceField.Method (as_mut N)) ]. + End Impl_core_convert_AsMut_slice_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_fmt_Debug_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.fmt_hex::(f, true) + } + *) + Definition fmt (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [], + "fmt_hex", + [ Value.Bool false ], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + Value.Bool true + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) [ ("fmt", InstanceField.Method (fmt N)) ]. + End Impl_core_fmt_Debug_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_fmt_Display_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + // If the alternate flag is NOT set, we write the full hex. + if N <= 4 || !f.alternate() { + return self.fmt_hex::(f, true); + } + + // If the alternate flag is set, we use middle-out compression. + const SEP_LEN: usize = '…'.len_utf8(); + let mut buf = [0; 2 + 4 + SEP_LEN + 4]; + buf[0] = b'0'; + buf[1] = b'x'; + hex::encode_to_slice(&self.0[0..2], &mut buf[2..6]).unwrap(); + '…'.encode_utf8(&mut buf[6..]); + hex::encode_to_slice(&self.0[N - 2..N], &mut buf[6 + SEP_LEN..]).unwrap(); + + // SAFETY: always valid UTF-8 + f.write_str(unsafe { str::from_utf8_unchecked(&buf) }) + } + *) + Definition fmt (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + BinOp.le (| + M.read (| + M.get_constant "alloy_primitives::bits::fixed::N" + |), + Value.Integer IntegerKind.Usize 4 + |), + ltac:(M.monadic + (UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "alternate", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| f |) |) + |) + ] + |) + |))) + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ N ] + [], + "fmt_hex", + [ Value.Bool false ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| f |) |) + |); + Value.Bool true + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ buf : + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 13 ] + [ Ty.path "u8" ] := + M.alloc (| + repeat (| + Value.Integer IntegerKind.U8 0, + Value.Integer IntegerKind.Usize 13 + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| buf, Value.Integer IntegerKind.Usize 0 |), + M.read (| UnsupportedLiteral |) + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| buf, Value.Integer IntegerKind.Usize 1 |), + M.read (| UnsupportedLiteral |) + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "const_hex::error::FromHexError" ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "const_hex::error::FromHexError" ], + M.get_function (| + "const_hex::encode_to_slice", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |); + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 0); + ("end_", Value.Integer IntegerKind.Usize 2) + ] + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 13 ] + [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, buf |); + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 2); + ("end_", Value.Integer IntegerKind.Usize 6) + ] + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |) in + let~ _ : Ty.apply (Ty.path "&mut") [] [ Ty.path "str" ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.path "str" ], + M.get_associated_function (| Ty.path "char", "encode_utf8", [], [] |), + [ + Value.UnicodeChar 8230; + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 13 ] + [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, buf |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 6) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "const_hex::error::FromHexError" ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "const_hex::error::FromHexError" ], + M.get_function (| + "const_hex::encode_to_slice", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |); + Value.StructRecord + "core::ops::range::Range" + [ + ("start", + BinOp.Wrap.sub (| + M.read (| + M.get_constant "alloy_primitives::bits::fixed::N" + |), + Value.Integer IntegerKind.Usize 2 + |)); + ("end_", + M.read (| + M.get_constant "alloy_primitives::bits::fixed::N" + |)) + ] + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 13 ] + [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, buf |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + BinOp.Wrap.add (| + Value.Integer IntegerKind.Usize 6, + M.read (| + M.get_constant + "alloy_primitives::bits::fixed::fmt::SEP_LEN" + |) + |)) + ] + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_function (| + "core::str::converts::from_utf8_unchecked", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, buf |) |) + |) + ] + |) + |) + |) + ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::fmt::Display" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) [ ("fmt", InstanceField.Method (fmt N)) ]. + End Impl_core_fmt_Display_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_fmt_LowerHex_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.fmt_hex::(f, f.alternate()) + } + *) + Definition fmt (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [], + "fmt_hex", + [ Value.Bool false ], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "alternate", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| f |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::fmt::LowerHex" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) [ ("fmt", InstanceField.Method (fmt N)) ]. + End Impl_core_fmt_LowerHex_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_fmt_UpperHex_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.fmt_hex::(f, f.alternate()) + } + *) + Definition fmt (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [], + "fmt_hex", + [ Value.Bool true ], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "alternate", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| f |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::fmt::UpperHex" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) [ ("fmt", InstanceField.Method (fmt N)) ]. + End Impl_core_fmt_UpperHex_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_ops_bit_BitAnd_alloy_primitives_bits_fixed_FixedBytes_N_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* type Output = Self; *) + Definition _Output (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn bitand(mut self, rhs: Self) -> Self::Output { + self &= rhs; + self + } + *) + Definition bitand (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::bit::BitAndAssign", + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [], + [], + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ], + "bitand_assign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, self |); M.read (| rhs |) ] + |) + |) in + self + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::ops::bit::BitAnd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ] + (Self N) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output N)); ("bitand", InstanceField.Method (bitand N)) ]. + End Impl_core_ops_bit_BitAnd_alloy_primitives_bits_fixed_FixedBytes_N_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_ops_bit_BitAndAssign_alloy_primitives_bits_fixed_FixedBytes_N_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn bitand_assign(&mut self, rhs: Self) { + // Note: `slice::Iter` has better codegen than `array::IntoIter` + iter::zip(self, &rhs).for_each(|(a, b)| *a &= *b); + } + *) + Definition bitand_assign + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ Ty.path "u8" ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u8" ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ Ty.path "u8" ]; + Ty.apply (Ty.path "&") [] [ Ty.path "u8" ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ Ty.path "u8" ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u8" ] + ], + M.get_function (| + "core::iter::adapters::zip::zip", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ N ] + [] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ N ] + [] + ] + ] + |), + [ M.read (| self |); M.borrow (| Pointer.Kind.Ref, rhs |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ Ty.path "u8" ]; + Ty.apply (Ty.path "&") [] [ Ty.path "u8" ] + ] + ] + ] + (Ty.tuple [])), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let a := M.copy (| γ0_0 |) in + let b := M.copy (| γ0_1 |) in + let β := M.deref (| M.read (| a |) |) in + M.write (| + β, + BinOp.bit_and + (M.read (| β |)) + (M.read (| M.deref (| M.read (| b |) |) |)) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::ops::bit::BitAndAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ] + (Self N) + (* Instance *) [ ("bitand_assign", InstanceField.Method (bitand_assign N)) ]. + End Impl_core_ops_bit_BitAndAssign_alloy_primitives_bits_fixed_FixedBytes_N_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_ops_bit_BitOr_alloy_primitives_bits_fixed_FixedBytes_N_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* type Output = Self; *) + Definition _Output (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn bitor(mut self, rhs: Self) -> Self::Output { + self |= rhs; + self + } + *) + Definition bitor (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::bit::BitOrAssign", + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [], + [], + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ], + "bitor_assign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, self |); M.read (| rhs |) ] + |) + |) in + self + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::ops::bit::BitOr" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ] + (Self N) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output N)); ("bitor", InstanceField.Method (bitor N)) ]. + End Impl_core_ops_bit_BitOr_alloy_primitives_bits_fixed_FixedBytes_N_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_ops_bit_BitOrAssign_alloy_primitives_bits_fixed_FixedBytes_N_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn bitor_assign(&mut self, rhs: Self) { + // Note: `slice::Iter` has better codegen than `array::IntoIter` + iter::zip(self, &rhs).for_each(|(a, b)| *a |= *b); + } + *) + Definition bitor_assign + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ Ty.path "u8" ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u8" ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ Ty.path "u8" ]; + Ty.apply (Ty.path "&") [] [ Ty.path "u8" ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ Ty.path "u8" ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u8" ] + ], + M.get_function (| + "core::iter::adapters::zip::zip", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ N ] + [] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ N ] + [] + ] + ] + |), + [ M.read (| self |); M.borrow (| Pointer.Kind.Ref, rhs |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ Ty.path "u8" ]; + Ty.apply (Ty.path "&") [] [ Ty.path "u8" ] + ] + ] + ] + (Ty.tuple [])), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let a := M.copy (| γ0_0 |) in + let b := M.copy (| γ0_1 |) in + let β := M.deref (| M.read (| a |) |) in + M.write (| + β, + BinOp.bit_or + (M.read (| β |)) + (M.read (| M.deref (| M.read (| b |) |) |)) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::ops::bit::BitOrAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ] + (Self N) + (* Instance *) [ ("bitor_assign", InstanceField.Method (bitor_assign N)) ]. + End Impl_core_ops_bit_BitOrAssign_alloy_primitives_bits_fixed_FixedBytes_N_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_ops_bit_BitXor_alloy_primitives_bits_fixed_FixedBytes_N_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* type Output = Self; *) + Definition _Output (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn bitxor(mut self, rhs: Self) -> Self::Output { + self ^= rhs; + self + } + *) + Definition bitxor (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::bit::BitXorAssign", + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [], + [], + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ], + "bitxor_assign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, self |); M.read (| rhs |) ] + |) + |) in + self + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::ops::bit::BitXor" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ] + (Self N) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output N)); ("bitxor", InstanceField.Method (bitxor N)) ]. + End Impl_core_ops_bit_BitXor_alloy_primitives_bits_fixed_FixedBytes_N_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_ops_bit_BitXorAssign_alloy_primitives_bits_fixed_FixedBytes_N_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn bitxor_assign(&mut self, rhs: Self) { + // Note: `slice::Iter` has better codegen than `array::IntoIter` + iter::zip(self, &rhs).for_each(|(a, b)| *a ^= *b); + } + *) + Definition bitxor_assign + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ Ty.path "u8" ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u8" ] + ], + [], + [], + "for_each", + [], + [ + Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ Ty.path "u8" ]; + Ty.apply (Ty.path "&") [] [ Ty.path "u8" ] + ] + ] + ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::zip::Zip") + [] + [ + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ Ty.path "u8" ]; + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u8" ] + ], + M.get_function (| + "core::iter::adapters::zip::zip", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ N ] + [] + ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ N ] + [] + ] + ] + |), + [ M.read (| self |); M.borrow (| Pointer.Kind.Ref, rhs |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ + Ty.tuple + [ + Ty.tuple + [ + Ty.apply (Ty.path "&mut") [] [ Ty.path "u8" ]; + Ty.apply (Ty.path "&") [] [ Ty.path "u8" ] + ] + ] + ] + (Ty.tuple [])), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let a := M.copy (| γ0_0 |) in + let b := M.copy (| γ0_1 |) in + let β := M.deref (| M.read (| a |) |) in + M.write (| + β, + BinOp.bit_xor + (M.read (| β |)) + (M.read (| M.deref (| M.read (| b |) |) |)) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::ops::bit::BitXorAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ] + (Self N) + (* Instance *) [ ("bitxor_assign", InstanceField.Method (bitxor_assign N)) ]. + End Impl_core_ops_bit_BitXorAssign_alloy_primitives_bits_fixed_FixedBytes_N_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_ops_bit_Not_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* type Output = Self; *) + Definition _Output (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn not(mut self) -> Self::Output { + self.iter_mut().for_each(|byte| *byte = !*byte); + self + } + *) + Definition not (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ Ty.path "u8" ], + [], + [], + "for_each", + [], + [ + Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ Ty.path "u8" ] ] ] + (Ty.tuple []) + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "iter_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ N ] + [], + [], + [], + "deref_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, self |) ] + |) + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ Ty.path "u8" ] ] ] + (Ty.tuple [])), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let byte := M.copy (| γ |) in + M.write (| + M.deref (| M.read (| byte |) |), + UnOp.not (| + M.read (| M.deref (| M.read (| byte |) |) |) + |) + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) in + self + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::ops::bit::Not" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) + [ ("Output", InstanceField.Ty (_Output N)); ("not", InstanceField.Method (not N)) ]. + End Impl_core_ops_bit_Not_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_str_traits_FromStr_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* type Err = hex::FromHexError; *) + Definition _Err (N : Value.t) : Ty.t := Ty.path "const_hex::error::FromHexError". + + (* + fn from_str(s: &str) -> Result { + Self::from_hex(s) + } + *) + Definition from_str (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ s ] => + ltac:(M.monadic + (let s := M.alloc (| s |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []; + Ty.path "const_hex::error::FromHexError" + ], + M.get_trait_method (| + "const_hex::traits::FromHex", + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [], + [], + [], + "from_hex", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + |), + [ M.read (| s |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::str::traits::FromStr" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) + [ ("Err", InstanceField.Ty (_Err N)); ("from_str", InstanceField.Method (from_str N)) ]. + End Impl_core_str_traits_FromStr_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* pub const ZERO: Self = Self([0u8; N]); *) + (* Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] *) + Definition value_ZERO (N : Value.t) : Value.t := + let Self : Ty.t := Self N in + M.run + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ repeat (| Value.Integer IntegerKind.U8 0, N |) ] + |))). + + Global Instance AssociatedConstant_value_ZERO : + forall (N : Value.t), + M.IsAssociatedConstant.Trait (Self N) "value_ZERO" (value_ZERO N). + Admitted. + Global Typeclasses Opaque value_ZERO. + + (* + pub const fn new(bytes: [u8; N]) -> Self { + Self(bytes) + } + *) + Definition new (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ bytes ] => + ltac:(M.monadic + (let bytes := M.alloc (| bytes |) in + Value.StructTuple "alloy_primitives::bits::fixed::FixedBytes" [ M.read (| bytes |) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (N : Value.t), + M.IsAssociatedFunction.Trait (Self N) "new" (new N). + Admitted. + Global Typeclasses Opaque new. + + (* + pub const fn with_last_byte(x: u8) -> Self { + let mut bytes = [0u8; N]; + if N > 0 { + bytes[N - 1] = x; + } + Self(bytes) + } + *) + Definition with_last_byte + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ x ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + M.read (| + let~ bytes : Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] := + M.alloc (| repeat (| Value.Integer IntegerKind.U8 0, N |) |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.gt (| + M.read (| M.get_constant "alloy_primitives::bits::fixed::N" |), + Value.Integer IntegerKind.Usize 0 + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + bytes, + BinOp.Wrap.sub (| + M.read (| M.get_constant "alloy_primitives::bits::fixed::N" |), + Value.Integer IntegerKind.Usize 1 + |) + |), + M.read (| x |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + Value.StructTuple "alloy_primitives::bits::fixed::FixedBytes" [ M.read (| bytes |) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_with_last_byte : + forall (N : Value.t), + M.IsAssociatedFunction.Trait (Self N) "with_last_byte" (with_last_byte N). + Admitted. + Global Typeclasses Opaque with_last_byte. + + (* + pub const fn repeat_byte(byte: u8) -> Self { + Self([byte; N]) + } + *) + Definition repeat_byte + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ byte ] => + ltac:(M.monadic + (let byte := M.alloc (| byte |) in + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ repeat (| M.read (| byte |), N |) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_repeat_byte : + forall (N : Value.t), + M.IsAssociatedFunction.Trait (Self N) "repeat_byte" (repeat_byte N). + Admitted. + Global Typeclasses Opaque repeat_byte. + + (* + pub const fn len_bytes() -> usize { + N + } + *) + Definition len_bytes + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic (M.read (| M.get_constant "alloy_primitives::bits::fixed::N" |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_len_bytes : + forall (N : Value.t), + M.IsAssociatedFunction.Trait (Self N) "len_bytes" (len_bytes N). + Admitted. + Global Typeclasses Opaque len_bytes. + + (* + pub const fn concat_const( + self, + other: FixedBytes, + ) -> FixedBytes { + assert!(N + M == Z, "Output size `Z` must equal the sum of the input sizes `N` and `M`"); + + let mut result = [0u8; Z]; + let mut i = 0; + while i < Z { + result[i] = if i >= N { other.0[i - N] } else { self.0[i] }; + i += 1; + } + FixedBytes(result) + } + *) + Definition concat_const + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [ M_; Z ], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + BinOp.eq (| + BinOp.Wrap.add (| + M.read (| M.get_constant "alloy_primitives::bits::fixed::N" |), + M.read (| + M.get_constant + "alloy_primitives::bits::fixed::concat_const::M" + |) + |), + M.read (| + M.get_constant "alloy_primitives::bits::fixed::concat_const::Z" + |) + |) + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| + "Output size `Z` must equal the sum of the input sizes `N` and `M`" + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ result : Ty.apply (Ty.path "array") [ Z ] [ Ty.path "u8" ] := + M.alloc (| repeat (| Value.Integer IntegerKind.U8 0, Z |) |) in + let~ i : Ty.path "usize" := M.alloc (| Value.Integer IntegerKind.Usize 0 |) in + let~ _ : Ty.tuple [] := + M.loop (| + Ty.tuple [], + ltac:(M.monadic + (M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.lt (| + M.read (| i |), + M.read (| + M.get_constant + "alloy_primitives::bits::fixed::concat_const::Z" + |) + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| result, M.read (| i |) |), + M.read (| + M.match_operator (| + Some (Ty.path "u8"), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.ge (| + M.read (| i |), + M.read (| + M.get_constant + "alloy_primitives::bits::fixed::N" + |) + |) + |)) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + other, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |), + BinOp.Wrap.sub (| + M.read (| i |), + M.read (| + M.get_constant "alloy_primitives::bits::fixed::N" + |) + |) + |))); + fun γ => + ltac:(M.monadic + (M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |), + M.read (| i |) + |))) + ] + |) + |) + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + let β := i in + M.write (| + β, + BinOp.Wrap.add (| + M.read (| β |), + Value.Integer IntegerKind.Usize 1 + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |) in + M.alloc (| Value.Tuple [] |) + |) + |) + |))) + ] + |))) + |) in + M.alloc (| + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ M.read (| result |) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_concat_const : + forall (N : Value.t), + M.IsAssociatedFunction.Trait (Self N) "concat_const" (concat_const N). + Admitted. + Global Typeclasses Opaque concat_const. + + (* + pub fn from_slice(src: &[u8]) -> Self { + match Self::try_from(src) { + Ok(x) => x, + Err(_) => panic!("cannot convert a slice of length {} to FixedBytes<{N}>", src.len()), + } + } + *) + Definition from_slice + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ src ] => + ltac:(M.monadic + (let src := M.alloc (| src |) in + M.read (| + M.match_operator (| + Some (Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [], + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ], + "try_from", + [], + [] + |), + [ M.read (| src |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::result::Result::Ok", + 0 + |) in + let x := M.copy (| γ0_0 |) in + x)); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::result::Result::Err", + 0 + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 3; + Value.Integer IntegerKind.Usize 2 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "cannot convert a slice of length " |); + mk_str (| " to FixedBytes<" |); + mk_str (| ">" |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "u8" ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| src |) |) + |) + ] + |) + |) + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.get_constant + "alloy_primitives::bits::fixed::N" + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_slice : + forall (N : Value.t), + M.IsAssociatedFunction.Trait (Self N) "from_slice" (from_slice N). + Admitted. + Global Typeclasses Opaque from_slice. + + (* + pub fn left_padding_from(value: &[u8]) -> Self { + let len = value.len(); + assert!(len <= N, "slice is too large. Expected <={N} bytes, got {len}"); + let mut bytes = Self::ZERO; + bytes[N - len..].copy_from_slice(value); + bytes + } + *) + Definition left_padding_from + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.read (| + let~ len : Ty.path "usize" := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| value |) |) |) ] + |) + |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + BinOp.le (| + M.read (| len |), + M.read (| M.get_constant "alloy_primitives::bits::fixed::N" |) + |) + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 2 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "slice is too large. Expected <=" |); + mk_str (| " bytes, got " |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.get_constant + "alloy_primitives::bits::fixed::N" + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, len |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ bytes : + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] := + M.copy (| M.get_constant "alloy_primitives::bits::fixed::ZERO" |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "copy_from_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ N ] + [], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, bytes |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + BinOp.Wrap.sub (| + M.read (| + M.get_constant "alloy_primitives::bits::fixed::N" + |), + M.read (| len |) + |)) + ] + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| value |) |) |) + ] + |) + |) in + bytes + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_left_padding_from : + forall (N : Value.t), + M.IsAssociatedFunction.Trait (Self N) "left_padding_from" (left_padding_from N). + Admitted. + Global Typeclasses Opaque left_padding_from. + + (* + pub fn right_padding_from(value: &[u8]) -> Self { + let len = value.len(); + assert!(len <= N, "slice is too large. Expected <={N} bytes, got {len}"); + let mut bytes = Self::ZERO; + bytes[..len].copy_from_slice(value); + bytes + } + *) + Definition right_padding_from + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.read (| + let~ len : Ty.path "usize" := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| value |) |) |) ] + |) + |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + BinOp.le (| + M.read (| len |), + M.read (| M.get_constant "alloy_primitives::bits::fixed::N" |) + |) + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 2 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "slice is too large. Expected <=" |); + mk_str (| " bytes, got " |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.get_constant + "alloy_primitives::bits::fixed::N" + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, len |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ bytes : + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] := + M.copy (| M.get_constant "alloy_primitives::bits::fixed::ZERO" |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "copy_from_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ N ] + [], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, bytes |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", M.read (| len |)) ] + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| value |) |) |) + ] + |) + |) in + bytes + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_right_padding_from : + forall (N : Value.t), + M.IsAssociatedFunction.Trait (Self N) "right_padding_from" (right_padding_from N). + Admitted. + Global Typeclasses Opaque right_padding_from. + + (* + pub const fn as_slice(&self) -> &[u8] { + &self.0 + } + *) + Definition as_slice (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_as_slice : + forall (N : Value.t), + M.IsAssociatedFunction.Trait (Self N) "as_slice" (as_slice N). + Admitted. + Global Typeclasses Opaque as_slice. + + (* + pub fn as_mut_slice(&mut self) -> &mut [u8] { + &mut self.0 + } + *) + Definition as_mut_slice + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_as_mut_slice : + forall (N : Value.t), + M.IsAssociatedFunction.Trait (Self N) "as_mut_slice" (as_mut_slice N). + Admitted. + Global Typeclasses Opaque as_mut_slice. + + (* + pub fn covers(&self, other: &Self) -> bool { + ( *self & *other) == *other + } + *) + Definition covers (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [], + [], + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [], + M.get_trait_method (| + "core::ops::bit::BitAnd", + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [], + [], + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ], + "bitand", + [], + [] + |), + [ + M.read (| M.deref (| M.read (| self |) |) |); + M.read (| M.deref (| M.read (| other |) |) |) + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_covers : + forall (N : Value.t), + M.IsAssociatedFunction.Trait (Self N) "covers" (covers N). + Admitted. + Global Typeclasses Opaque covers. + + (* + pub const fn const_covers(self, other: Self) -> bool { + // (self & other) == other + other.const_eq(&self.bit_and(other)) + } + *) + Definition const_covers + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [], + "const_eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, other |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [], + "bit_and", + [], + [] + |), + [ M.read (| self |); M.read (| other |) ] + |) + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_const_covers : + forall (N : Value.t), + M.IsAssociatedFunction.Trait (Self N) "const_covers" (const_covers N). + Admitted. + Global Typeclasses Opaque const_covers. + + (* + pub const fn const_eq(&self, other: &Self) -> bool { + let mut i = 0; + while i < N { + if self.0[i] != other.0[i] { + return false; + } + i += 1; + } + true + } + *) + Definition const_eq (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ i : Ty.path "usize" := M.alloc (| Value.Integer IntegerKind.Usize 0 |) in + let~ _ : Ty.tuple [] := + M.loop (| + Ty.tuple [], + ltac:(M.monadic + (M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.lt (| + M.read (| i |), + M.read (| + M.get_constant "alloy_primitives::bits::fixed::N" + |) + |) + |)) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.ne (| + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |), + M.read (| i |) + |) + |), + M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |), + M.read (| i |) + |) + |) + |) + |)) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.return_ (| Value.Bool false |) |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + let β := i in + M.write (| + β, + BinOp.Wrap.add (| + M.read (| β |), + Value.Integer IntegerKind.Usize 1 + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |) in + M.alloc (| Value.Tuple [] |) + |) + |) + |))) + ] + |))) + |) in + M.alloc (| Value.Bool true |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_const_eq : + forall (N : Value.t), + M.IsAssociatedFunction.Trait (Self N) "const_eq" (const_eq N). + Admitted. + Global Typeclasses Opaque const_eq. + + (* + pub fn is_zero(&self) -> bool { + *self == Self::ZERO + } + *) + Definition is_zero (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [], + [], + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::bits::fixed::ZERO" + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_is_zero : + forall (N : Value.t), + M.IsAssociatedFunction.Trait (Self N) "is_zero" (is_zero N). + Admitted. + Global Typeclasses Opaque is_zero. + + (* + pub const fn const_is_zero(&self) -> bool { + self.const_eq(&Self::ZERO) + } + *) + Definition const_is_zero + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [], + "const_eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::bits::fixed::ZERO" + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_const_is_zero : + forall (N : Value.t), + M.IsAssociatedFunction.Trait (Self N) "const_is_zero" (const_is_zero N). + Admitted. + Global Typeclasses Opaque const_is_zero. + + (* + pub const fn bit_and(self, rhs: Self) -> Self { + let mut ret = Self::ZERO; + let mut i = 0; + while i < N { + ret.0[i] = self.0[i] & rhs.0[i]; + i += 1; + } + ret + } + *) + Definition bit_and (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ ret : Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] := + M.copy (| M.get_constant "alloy_primitives::bits::fixed::ZERO" |) in + let~ i : Ty.path "usize" := M.alloc (| Value.Integer IntegerKind.Usize 0 |) in + let~ _ : Ty.tuple [] := + M.loop (| + Ty.tuple [], + ltac:(M.monadic + (M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.lt (| + M.read (| i |), + M.read (| M.get_constant "alloy_primitives::bits::fixed::N" |) + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + ret, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |), + M.read (| i |) + |), + BinOp.bit_and + (M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |), + M.read (| i |) + |) + |)) + (M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |), + M.read (| i |) + |) + |)) + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + let β := i in + M.write (| + β, + BinOp.Wrap.add (| + M.read (| β |), + Value.Integer IntegerKind.Usize 1 + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |) in + M.alloc (| Value.Tuple [] |) + |) + |) + |))) + ] + |))) + |) in + ret + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_bit_and : + forall (N : Value.t), + M.IsAssociatedFunction.Trait (Self N) "bit_and" (bit_and N). + Admitted. + Global Typeclasses Opaque bit_and. + + (* + pub const fn bit_or(self, rhs: Self) -> Self { + let mut ret = Self::ZERO; + let mut i = 0; + while i < N { + ret.0[i] = self.0[i] | rhs.0[i]; + i += 1; + } + ret + } + *) + Definition bit_or (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ ret : Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] := + M.copy (| M.get_constant "alloy_primitives::bits::fixed::ZERO" |) in + let~ i : Ty.path "usize" := M.alloc (| Value.Integer IntegerKind.Usize 0 |) in + let~ _ : Ty.tuple [] := + M.loop (| + Ty.tuple [], + ltac:(M.monadic + (M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.lt (| + M.read (| i |), + M.read (| M.get_constant "alloy_primitives::bits::fixed::N" |) + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + ret, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |), + M.read (| i |) + |), + BinOp.bit_or + (M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |), + M.read (| i |) + |) + |)) + (M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |), + M.read (| i |) + |) + |)) + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + let β := i in + M.write (| + β, + BinOp.Wrap.add (| + M.read (| β |), + Value.Integer IntegerKind.Usize 1 + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |) in + M.alloc (| Value.Tuple [] |) + |) + |) + |))) + ] + |))) + |) in + ret + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_bit_or : + forall (N : Value.t), + M.IsAssociatedFunction.Trait (Self N) "bit_or" (bit_or N). + Admitted. + Global Typeclasses Opaque bit_or. + + (* + pub const fn bit_xor(self, rhs: Self) -> Self { + let mut ret = Self::ZERO; + let mut i = 0; + while i < N { + ret.0[i] = self.0[i] ^ rhs.0[i]; + i += 1; + } + ret + } + *) + Definition bit_xor (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ ret : Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] := + M.copy (| M.get_constant "alloy_primitives::bits::fixed::ZERO" |) in + let~ i : Ty.path "usize" := M.alloc (| Value.Integer IntegerKind.Usize 0 |) in + let~ _ : Ty.tuple [] := + M.loop (| + Ty.tuple [], + ltac:(M.monadic + (M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.lt (| + M.read (| i |), + M.read (| M.get_constant "alloy_primitives::bits::fixed::N" |) + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + ret, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |), + M.read (| i |) + |), + BinOp.bit_xor + (M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |), + M.read (| i |) + |) + |)) + (M.read (| + M.SubPointer.get_array_field (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |), + M.read (| i |) + |) + |)) + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + let β := i in + M.write (| + β, + BinOp.Wrap.add (| + M.read (| β |), + Value.Integer IntegerKind.Usize 1 + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |) in + M.alloc (| Value.Tuple [] |) + |) + |) + |))) + ] + |))) + |) in + ret + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_bit_xor : + forall (N : Value.t), + M.IsAssociatedFunction.Trait (Self N) "bit_xor" (bit_xor N). + Admitted. + Global Typeclasses Opaque bit_xor. + + (* + fn fmt_hex(&self, f: &mut fmt::Formatter<'_>, prefix: bool) -> fmt::Result { + let mut buf = hex::Buffer::::new(); + let s = if UPPER { buf.format_upper(self) } else { buf.format(self) }; + // SAFETY: The buffer is guaranteed to be at least 2 bytes in length. + f.write_str(unsafe { s.get_unchecked((!prefix as usize) * 2..) }) + } + *) + Definition fmt_hex (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [ UPPER ], [], [ self; f; prefix ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + let prefix := M.alloc (| prefix |) in + M.read (| + let~ buf : Ty.apply (Ty.path "const_hex::buffer::Buffer") [ N; Value.Bool true ] [] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "const_hex::buffer::Buffer") [ N; Value.Bool true ] [], + M.get_associated_function (| + Ty.apply (Ty.path "const_hex::buffer::Buffer") [ N; Value.Bool true ] [], + "new", + [], + [] + |), + [] + |) + |) in + let~ s : Ty.apply (Ty.path "&mut") [] [ Ty.path "str" ] := + M.copy (| + M.match_operator (| + Some (Ty.apply (Ty.path "&mut") [] [ Ty.path "str" ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.get_constant "alloy_primitives::bits::fixed::fmt_hex::UPPER") in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.path "str" ], + M.get_associated_function (| + Ty.apply + (Ty.path "const_hex::buffer::Buffer") + [ N; Value.Bool true ] + [], + "format_upper", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, buf |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ N ] + [], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&mut") [] [ Ty.path "str" ], + M.get_associated_function (| + Ty.apply + (Ty.path "const_hex::buffer::Buffer") + [ N; Value.Bool true ] + [], + "format", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, buf |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ N ] + [], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) + |) + ] + |) + |) + |) + |))) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_associated_function (| + Ty.path "str", + "get_unchecked", + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| s |) |) |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ + ("start", + BinOp.Wrap.mul (| + M.cast (Ty.path "usize") (UnOp.not (| M.read (| prefix |) |)), + Value.Integer IntegerKind.Usize 2 + |)) + ] + ] + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_fmt_hex : + forall (N : Value.t), + M.IsAssociatedFunction.Trait (Self N) "fmt_hex" (fmt_hex N). + Admitted. + Global Typeclasses Opaque fmt_hex. + End Impl_alloy_primitives_bits_fixed_FixedBytes_N. + End fixed. +End bits. diff --git a/CoqOfRust/alloy_primitives/bits/function.rs b/CoqOfRust/alloy_primitives/bits/function.rs new file mode 100644 index 000000000..20ab1dbea --- /dev/null +++ b/CoqOfRust/alloy_primitives/bits/function.rs @@ -0,0 +1,97 @@ +use crate::{Address, FixedBytes, Selector}; +use core::borrow::Borrow; + +wrap_fixed_bytes! { + /// An Ethereum ABI function pointer, 24 bytes in length. + /// + /// An address (20 bytes), followed by a function selector (4 bytes). + /// Encoded identical to `bytes24`. + pub struct Function<24>; +} + +impl From<(A, S)> for Function +where + A: Borrow<[u8; 20]>, + S: Borrow<[u8; 4]>, +{ + #[inline] + fn from((address, selector): (A, S)) -> Self { + Self::from_address_and_selector(address, selector) + } +} + +impl Function { + /// Creates an Ethereum function from an EVM word's lower 24 bytes + /// (`word[..24]`). + /// + /// Note that this is different from `Address::from_word`, which uses the + /// upper 20 bytes. + #[inline] + #[must_use] + pub fn from_word(word: FixedBytes<32>) -> Self { + Self(FixedBytes(word[..24].try_into().unwrap())) + } + + /// Right-pads the function to 32 bytes (EVM word size). + /// + /// Note that this is different from `Address::into_word`, which left-pads + /// the address. + #[inline] + #[must_use] + pub fn into_word(&self) -> FixedBytes<32> { + let mut word = [0; 32]; + word[..24].copy_from_slice(self.as_slice()); + FixedBytes(word) + } + + /// Creates an Ethereum function from an address and selector. + #[inline] + pub fn from_address_and_selector(address: A, selector: S) -> Self + where + A: Borrow<[u8; 20]>, + S: Borrow<[u8; 4]>, + { + let mut bytes = [0; 24]; + bytes[..20].copy_from_slice(address.borrow()); + bytes[20..].copy_from_slice(selector.borrow()); + Self(FixedBytes(bytes)) + } + + /// Returns references to the address and selector of the function. + #[inline] + pub fn as_address_and_selector(&self) -> (&Address, &Selector) { + // SAFETY: Function (24) = Address (20) + Selector (4) + unsafe { (&*self.as_ptr().cast(), &*self.as_ptr().add(20).cast()) } + } + + /// Returns the address and selector of the function. + #[inline] + pub fn to_address_and_selector(&self) -> (Address, Selector) { + let (a, s) = self.as_address_and_selector(); + (*a, *s) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::hex; + + #[test] + fn function_parts() { + let f = Function::new(hex!( + " + ffffffffffffffffffffffffffffffffffffffff + 12345678 + " + )); + + let (a1, s1) = f.as_address_and_selector(); + assert_eq!(a1, hex!("ffffffffffffffffffffffffffffffffffffffff")); + assert_eq!(s1, &hex!("12345678")); + + let (a2, s2) = f.to_address_and_selector(); + assert_eq!(a2, *a1); + assert_eq!(s2, *s1); + } +} diff --git a/CoqOfRust/alloy_primitives/bits/function.v b/CoqOfRust/alloy_primitives/bits/function.v new file mode 100644 index 000000000..855804810 --- /dev/null +++ b/CoqOfRust/alloy_primitives/bits/function.v @@ -0,0 +1,828 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module bits. + Module function. + Module Impl_core_convert_From_where_core_borrow_Borrow_A_array_Usize_20_u8_where_core_borrow_Borrow_S_array_Usize_4_u8_Tuple_A_S__for_alloy_primitives_bits_function_Function. + Definition Self (A S : Ty.t) : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* + fn from((address, selector): (A, S)) -> Self { + Self::from_address_and_selector(address, selector) + } + *) + Definition from (A S : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self A S in + match ε, τ, α with + | [], [], [ β0 ] => + ltac:(M.monadic + (let β0 := M.alloc (| β0 |) in + M.match_operator (| + None, + β0, + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let address := M.copy (| γ0_0 |) in + let selector := M.copy (| γ0_1 |) in + M.call_closure (| + Ty.path "alloy_primitives::bits::function::Function", + M.get_associated_function (| + Ty.path "alloy_primitives::bits::function::Function", + "from_address_and_selector", + [], + [ A; S ] + |), + [ M.read (| address |); M.read (| selector |) ] + |))) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (A S : Ty.t), + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.tuple [ A; S ] ] + (Self A S) + (* Instance *) [ ("from", InstanceField.Method (from A S)) ]. + End Impl_core_convert_From_where_core_borrow_Borrow_A_array_Usize_20_u8_where_core_borrow_Borrow_S_array_Usize_4_u8_Tuple_A_S__for_alloy_primitives_bits_function_Function. + + Module Impl_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* + pub fn from_word(word: FixedBytes<32>) -> Self { + Self(FixedBytes(word[..24].try_into().unwrap())) + } + *) + Definition from_word (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ word ] => + ltac:(M.monadic + (let word := M.alloc (| word |) in + Value.StructTuple + "alloy_primitives::bits::function::Function" + [ + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ], + "try_into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, word |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 24) ] + ] + |) + |) + |) + ] + |) + ] + |) + ] + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_word : + M.IsAssociatedFunction.Trait Self "from_word" from_word. + Admitted. + Global Typeclasses Opaque from_word. + + (* + pub fn into_word(&self) -> FixedBytes<32> { + let mut word = [0; 32]; + word[..24].copy_from_slice(self.as_slice()); + FixedBytes(word) + } + *) + Definition into_word (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ word : + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ] := + M.alloc (| + repeat (| Value.Integer IntegerKind.U8 0, Value.Integer IntegerKind.Usize 32 |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "copy_from_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, word |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 24) ] + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + "as_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloy_primitives::bits::function::Function", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + Value.StructTuple "alloy_primitives::bits::fixed::FixedBytes" [ M.read (| word |) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_into_word : + M.IsAssociatedFunction.Trait Self "into_word" into_word. + Admitted. + Global Typeclasses Opaque into_word. + + (* + pub fn from_address_and_selector(address: A, selector: S) -> Self + where + A: Borrow<[u8; 20]>, + S: Borrow<[u8; 4]>, + { + let mut bytes = [0; 24]; + bytes[..20].copy_from_slice(address.borrow()); + bytes[20..].copy_from_slice(selector.borrow()); + Self(FixedBytes(bytes)) + } + *) + Definition from_address_and_selector + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ A; _ as S ], [ address; selector ] => + ltac:(M.monadic + (let address := M.alloc (| address |) in + let selector := M.alloc (| selector |) in + M.read (| + let~ bytes : + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] := + M.alloc (| + repeat (| Value.Integer IntegerKind.U8 0, Value.Integer IntegerKind.Usize 24 |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "copy_from_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, bytes |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 20) ] + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::borrow::Borrow", + A, + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ], + "borrow", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, address |) ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "copy_from_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, bytes |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 20) ] + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::borrow::Borrow", + S, + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.path "u8" ] + ], + "borrow", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, selector |) ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + Value.StructTuple + "alloy_primitives::bits::function::Function" + [ + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ M.read (| bytes |) ] + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_address_and_selector : + M.IsAssociatedFunction.Trait Self "from_address_and_selector" from_address_and_selector. + Admitted. + Global Typeclasses Opaque from_address_and_selector. + + (* + pub fn as_address_and_selector(&self) -> (&Address, &Selector) { + // SAFETY: Function (24) = Address (20) + Selector (4) + unsafe { (&*self.as_ptr().cast(), &*self.as_ptr().add(20).cast()) } + } + *) + Definition as_address_and_selector + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "*const") + [] + [ Ty.path "alloy_primitives::bits::address::Address" ], + M.get_associated_function (| + Ty.apply (Ty.path "*const") [] [ Ty.path "u8" ], + "cast", + [], + [ Ty.path "alloy_primitives::bits::address::Address" ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "*const") [] [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "as_ptr", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path + "alloy_primitives::bits::function::Function", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) + |) + ] + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "*const") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 4 ] + [] + ], + M.get_associated_function (| + Ty.apply (Ty.path "*const") [] [ Ty.path "u8" ], + "cast", + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 4 ] + [] + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "*const") [] [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply (Ty.path "*const") [] [ Ty.path "u8" ], + "add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "*const") [] [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "as_ptr", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path + "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path + "alloy_primitives::bits::function::Function", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) + |) + ] + |) + |) + |) + ] + |); + Value.Integer IntegerKind.Usize 20 + ] + |) + ] + |) + |) + |) + |) + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_as_address_and_selector : + M.IsAssociatedFunction.Trait Self "as_address_and_selector" as_address_and_selector. + Admitted. + Global Typeclasses Opaque as_address_and_selector. + + (* + pub fn to_address_and_selector(&self) -> (Address, Selector) { + let (a, s) = self.as_address_and_selector(); + ( *a, *s) + } + *) + Definition to_address_and_selector + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::address::Address" ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 4 ] + [] + ] + ], + M.get_associated_function (| + Ty.path "alloy_primitives::bits::function::Function", + "as_address_and_selector", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let a := M.copy (| γ0_0 |) in + let s := M.copy (| γ0_1 |) in + M.alloc (| + Value.Tuple + [ + M.read (| M.deref (| M.read (| a |) |) |); + M.read (| M.deref (| M.read (| s |) |) |) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_to_address_and_selector : + M.IsAssociatedFunction.Trait Self "to_address_and_selector" to_address_and_selector. + Admitted. + Global Typeclasses Opaque to_address_and_selector. + End Impl_alloy_primitives_bits_function_Function. + End function. +End bits. diff --git a/CoqOfRust/alloy_primitives/bits/macros.rs b/CoqOfRust/alloy_primitives/bits/macros.rs new file mode 100644 index 000000000..c07d8dccd --- /dev/null +++ b/CoqOfRust/alloy_primitives/bits/macros.rs @@ -0,0 +1,819 @@ +/// Wrap a fixed-size byte array in a newtype, delegating all methods to the +/// underlying [`crate::FixedBytes`]. +/// +/// This functionally creates a new named `FixedBytes` that cannot be +/// type-confused for another named `FixedBytes`. +/// +/// # Examples +/// +/// ``` +/// use alloy_primitives::wrap_fixed_bytes; +/// +/// // These hashes are the same length, and have the same functionality, but +/// // are distinct types +/// wrap_fixed_bytes!(pub struct KeccakOutput<32>;); +/// wrap_fixed_bytes!(pub struct MerkleTreeItem<32>;); +/// ``` +#[macro_export] +macro_rules! wrap_fixed_bytes { + ( + $(#[$attrs:meta])* + $vis:vis struct $name:ident<$n:literal>; + ) => { + $crate::wrap_fixed_bytes!( + extra_derives: [$crate::private::derive_more::Display], + $(#[$attrs])* + $vis struct $name<$n>; + ); + }; + + ( + extra_derives: [$($extra_derives:path),* $(,)?], + $(#[$attrs:meta])* + $vis:vis struct $name:ident<$n:literal>; + ) => { + $(#[$attrs])* + #[derive( + Clone, + Copy, + Default, + PartialEq, + Eq, + PartialOrd, + Ord, + Hash, + $crate::private::derive_more::AsMut, + $crate::private::derive_more::AsRef, + $crate::private::derive_more::BitAnd, + $crate::private::derive_more::BitAndAssign, + $crate::private::derive_more::BitOr, + $crate::private::derive_more::BitOrAssign, + $crate::private::derive_more::BitXor, + $crate::private::derive_more::BitXorAssign, + $crate::private::derive_more::Not, + $crate::private::derive_more::Deref, + $crate::private::derive_more::DerefMut, + $crate::private::derive_more::From, + $crate::private::derive_more::FromStr, + $crate::private::derive_more::Index, + $crate::private::derive_more::IndexMut, + $crate::private::derive_more::Into, + $crate::private::derive_more::IntoIterator, + $crate::private::derive_more::LowerHex, + $crate::private::derive_more::UpperHex, + $( + $extra_derives, + )* + )] + #[repr(transparent)] + $vis struct $name(#[into_iterator(owned, ref, ref_mut)] pub $crate::FixedBytes<$n>); + + impl $crate::private::From<[u8; $n]> for $name { + #[inline] + fn from(value: [u8; $n]) -> Self { + Self($crate::FixedBytes(value)) + } + } + + impl $crate::private::From<$name> for [u8; $n] { + #[inline] + fn from(value: $name) -> Self { + value.0 .0 + } + } + + impl<'a> $crate::private::From<&'a [u8; $n]> for $name { + #[inline] + fn from(value: &'a [u8; $n]) -> Self { + Self($crate::FixedBytes(*value)) + } + } + + impl<'a> $crate::private::From<&'a mut [u8; $n]> for $name { + #[inline] + fn from(value: &'a mut [u8; $n]) -> Self { + Self($crate::FixedBytes(*value)) + } + } + + impl $crate::private::TryFrom<&[u8]> for $name { + type Error = $crate::private::core::array::TryFromSliceError; + + #[inline] + fn try_from(slice: &[u8]) -> Result { + <&Self as $crate::private::TryFrom<&[u8]>>::try_from(slice).copied() + } + } + + impl $crate::private::TryFrom<&mut [u8]> for $name { + type Error = $crate::private::core::array::TryFromSliceError; + + #[inline] + fn try_from(slice: &mut [u8]) -> Result { + >::try_from(&*slice) + } + } + + impl<'a> $crate::private::TryFrom<&'a [u8]> for &'a $name { + type Error = $crate::private::core::array::TryFromSliceError; + + #[inline] + #[allow(unsafe_code)] + fn try_from(slice: &'a [u8]) -> Result<&'a $name, Self::Error> { + // SAFETY: `$name` is `repr(transparent)` for `FixedBytes<$n>` + // and consequently `[u8; $n]` + <&[u8; $n] as $crate::private::TryFrom<&[u8]>>::try_from(slice) + .map(|array_ref| unsafe { $crate::private::core::mem::transmute(array_ref) }) + } + } + + impl<'a> $crate::private::TryFrom<&'a mut [u8]> for &'a mut $name { + type Error = $crate::private::core::array::TryFromSliceError; + + #[inline] + #[allow(unsafe_code)] + fn try_from(slice: &'a mut [u8]) -> Result<&'a mut $name, Self::Error> { + // SAFETY: `$name` is `repr(transparent)` for `FixedBytes<$n>` + // and consequently `[u8; $n]` + <&mut [u8; $n] as $crate::private::TryFrom<&mut [u8]>>::try_from(slice) + .map(|array_ref| unsafe { $crate::private::core::mem::transmute(array_ref) }) + } + } + + impl $crate::private::AsRef<[u8; $n]> for $name { + #[inline] + fn as_ref(&self) -> &[u8; $n] { + &self.0 .0 + } + } + + impl $crate::private::AsMut<[u8; $n]> for $name { + #[inline] + fn as_mut(&mut self) -> &mut [u8; $n] { + &mut self.0 .0 + } + } + + impl $crate::private::AsRef<[u8]> for $name { + #[inline] + fn as_ref(&self) -> &[u8] { + &self.0 .0 + } + } + + impl $crate::private::AsMut<[u8]> for $name { + #[inline] + fn as_mut(&mut self) -> &mut [u8] { + &mut self.0 .0 + } + } + + impl $crate::private::core::fmt::Debug for $name { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + $crate::private::core::fmt::Debug::fmt(&self.0, f) + } + } + + $crate::impl_fb_traits!($name, $n); + $crate::impl_rlp!($name, $n); + $crate::impl_serde!($name); + $crate::impl_allocative!($name); + $crate::impl_arbitrary!($name, $n); + $crate::impl_rand!($name); + + impl $name { + /// Array of Zero bytes. + pub const ZERO: Self = Self($crate::FixedBytes::ZERO); + + /// Wraps the given byte array in this type. + #[inline] + pub const fn new(bytes: [u8; $n]) -> Self { + Self($crate::FixedBytes(bytes)) + } + + /// Creates a new byte array with the last byte set to `x`. + #[inline] + pub const fn with_last_byte(x: u8) -> Self { + Self($crate::FixedBytes::with_last_byte(x)) + } + + /// Creates a new byte array where all bytes are set to `byte`. + #[inline] + pub const fn repeat_byte(byte: u8) -> Self { + Self($crate::FixedBytes::repeat_byte(byte)) + } + + /// Returns the size of this array in bytes. + #[inline] + pub const fn len_bytes() -> usize { + $n + } + + $crate::impl_getrandom!(); + $crate::impl_rand!(); + + /// Create a new byte array from the given slice `src`. + /// + /// For a fallible version, use the `TryFrom<&[u8]>` implementation. + /// + /// # Note + /// + /// The given bytes are interpreted in big endian order. + /// + /// # Panics + /// + /// If the length of `src` and the number of bytes in `Self` do not match. + #[inline] + #[track_caller] + pub fn from_slice(src: &[u8]) -> Self { + match Self::try_from(src) { + Ok(x) => x, + Err(_) => panic!("cannot convert a slice of length {} to {}", src.len(), stringify!($name)), + } + } + + /// Create a new byte array from the given slice `src`, left-padding it + /// with zeroes if necessary. + /// + /// # Note + /// + /// The given bytes are interpreted in big endian order. + /// + /// # Panics + /// + /// Panics if `src.len() > N`. + #[inline] + #[track_caller] + pub fn left_padding_from(value: &[u8]) -> Self { + Self($crate::FixedBytes::left_padding_from(value)) + } + + /// Create a new byte array from the given slice `src`, right-padding it + /// with zeroes if necessary. + /// + /// # Note + /// + /// The given bytes are interpreted in big endian order. + /// + /// # Panics + /// + /// Panics if `src.len() > N`. + #[inline] + #[track_caller] + pub fn right_padding_from(value: &[u8]) -> Self { + Self($crate::FixedBytes::right_padding_from(value)) + } + + /// Returns the inner bytes array. + #[inline] + pub const fn into_array(self) -> [u8; $n] { + self.0 .0 + } + + /// Returns `true` if all bits set in `b` are also set in `self`. + #[inline] + pub fn covers(&self, b: &Self) -> bool { + &(*b & *self) == b + } + + /// Compile-time equality. NOT constant-time equality. + pub const fn const_eq(&self, other: &Self) -> bool { + self.0.const_eq(&other.0) + } + + /// Computes the bitwise AND of two `FixedBytes`. + pub const fn bit_and(self, rhs: Self) -> Self { + Self(self.0.bit_and(rhs.0)) + } + + /// Computes the bitwise OR of two `FixedBytes`. + pub const fn bit_or(self, rhs: Self) -> Self { + Self(self.0.bit_or(rhs.0)) + } + + /// Computes the bitwise XOR of two `FixedBytes`. + pub const fn bit_xor(self, rhs: Self) -> Self { + Self(self.0.bit_xor(rhs.0)) + } + } + }; +} + +// Extra traits that cannot be derived automatically +#[doc(hidden)] +#[macro_export] +macro_rules! impl_fb_traits { + (impl<$($const:ident)?> Borrow<$t:ty> for $b:ty) => { + impl<$($const N: usize)?> $crate::private::Borrow<$t> for $b { + #[inline] + fn borrow(&self) -> &$t { + $crate::private::Borrow::borrow(&self.0) + } + } + }; + + (impl<$($const:ident)?> BorrowMut<$t:ty> for $b:ty) => { + impl<$($const N: usize)?> $crate::private::BorrowMut<$t> for $b { + #[inline] + fn borrow_mut(&mut self) -> &mut $t { + $crate::private::BorrowMut::borrow_mut(&mut self.0) + } + } + }; + + (unsafe impl<$lt:lifetime, $($const:ident)?> From<$a:ty> for $b:ty) => { + impl<$lt, $($const N: usize)?> $crate::private::From<$a> for $b { + #[inline] + #[allow(unsafe_code)] + fn from(value: $a) -> $b { + // SAFETY: guaranteed by caller + unsafe { $crate::private::core::mem::transmute::<$a, $b>(value) } + } + } + }; + + (impl<$($const:ident)?> cmp::$tr:ident<$a:ty> for $b:ty where fn $fn:ident -> $ret:ty $(, [$e:expr])?) => { + impl<$($const N: usize)?> $crate::private::$tr<$a> for $b { + #[inline] + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + } + + impl<$($const N: usize)?> $crate::private::$tr<$b> for $a { + #[inline] + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + } + + impl<$($const N: usize)?> $crate::private::$tr<&$a> for $b { + #[inline] + fn $fn(&self, other: &&$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, *other) + } + } + + impl<$($const N: usize)?> $crate::private::$tr<$b> for &$a { + #[inline] + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn(*self, &other.0 $([$e])?) + } + } + + impl<$($const N: usize)?> $crate::private::$tr<$a> for &$b { + #[inline] + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + } + + impl<$($const N: usize)?> $crate::private::$tr<&$b> for $a { + #[inline] + fn $fn(&self, other: &&$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + } + }; + + ($t:ty, $n:tt $(, $const:ident)?) => { + // Borrow is not automatically implemented for references + $crate::impl_fb_traits!(impl<$($const)?> Borrow<[u8]> for $t); + $crate::impl_fb_traits!(impl<$($const)?> Borrow<[u8]> for &$t); + $crate::impl_fb_traits!(impl<$($const)?> Borrow<[u8]> for &mut $t); + $crate::impl_fb_traits!(impl<$($const)?> Borrow<[u8; $n]> for $t); + $crate::impl_fb_traits!(impl<$($const)?> Borrow<[u8; $n]> for &$t); + $crate::impl_fb_traits!(impl<$($const)?> Borrow<[u8; $n]> for &mut $t); + + $crate::impl_fb_traits!(impl<$($const)?> BorrowMut<[u8]> for $t); + $crate::impl_fb_traits!(impl<$($const)?> BorrowMut<[u8]> for &mut $t); + $crate::impl_fb_traits!(impl<$($const)?> BorrowMut<[u8; $n]> for $t); + $crate::impl_fb_traits!(impl<$($const)?> BorrowMut<[u8; $n]> for &mut $t); + + // Implement conversion traits for references with `mem::transmute` + // SAFETY: `repr(transparent)` + $crate::impl_fb_traits!(unsafe impl<'a, $($const)?> From<&'a [u8; $n]> for &'a $t); + $crate::impl_fb_traits!(unsafe impl<'a, $($const)?> From<&'a mut [u8; $n]> for &'a $t); + $crate::impl_fb_traits!(unsafe impl<'a, $($const)?> From<&'a mut [u8; $n]> for &'a mut $t); + + $crate::impl_fb_traits!(unsafe impl<'a, $($const)?> From<&'a $t> for &'a [u8; $n]); + $crate::impl_fb_traits!(unsafe impl<'a, $($const)?> From<&'a mut $t> for &'a [u8; $n]); + $crate::impl_fb_traits!(unsafe impl<'a, $($const)?> From<&'a mut $t> for &'a mut [u8; $n]); + + // Implement PartialEq, PartialOrd, with slice and array + $crate::impl_fb_traits!(impl<$($const)?> cmp::PartialEq<[u8]> for $t where fn eq -> bool); + $crate::impl_fb_traits!(impl<$($const)?> cmp::PartialEq<[u8; $n]> for $t where fn eq -> bool); + $crate::impl_fb_traits!( + impl<$($const)?> cmp::PartialOrd<[u8]> for $t + where + fn partial_cmp -> $crate::private::Option<$crate::private::Ordering>, + [..] // slices $t + ); + + impl<$($const N: usize)?> $crate::hex::FromHex for $t { + type Error = $crate::hex::FromHexError; + + #[inline] + fn from_hex>(hex: T) -> Result { + $crate::hex::decode_to_array(hex).map(Self::new) + } + } + }; +} + +#[doc(hidden)] +#[macro_export] +#[cfg(feature = "getrandom")] +macro_rules! impl_getrandom { + () => { + /// Instantiates a new fixed byte array with cryptographically random + /// content. + /// + /// # Panics + /// + /// Panics if the underlying call to `getrandom_uninit` + /// fails. + #[inline] + #[track_caller] + #[cfg_attr(docsrs, doc(cfg(feature = "getrandom")))] + pub fn random() -> Self { + Self($crate::FixedBytes::random()) + } + + /// Tries to create a new fixed byte array with cryptographically random + /// content. + /// + /// # Errors + /// + /// This function only propagates the error from the underlying call to + /// `getrandom_uninit`. + #[inline] + #[cfg_attr(docsrs, doc(cfg(feature = "getrandom")))] + pub fn try_random() -> $crate::private::Result { + $crate::FixedBytes::try_random().map(Self) + } + + /// Fills this fixed byte array with cryptographically random content. + /// + /// # Panics + /// + /// Panics if the underlying call to `getrandom_uninit` fails. + #[inline] + #[track_caller] + #[cfg_attr(docsrs, doc(cfg(feature = "getrandom")))] + pub fn randomize(&mut self) { + self.try_randomize().unwrap() + } + + /// Tries to fill this fixed byte array with cryptographically random content. + /// + /// # Errors + /// + /// This function only propagates the error from the underlying call to + /// `getrandom_uninit`. + #[inline] + #[cfg_attr(docsrs, doc(cfg(feature = "getrandom")))] + pub fn try_randomize( + &mut self, + ) -> $crate::private::Result<(), $crate::private::getrandom::Error> { + self.0.try_randomize() + } + }; +} + +#[doc(hidden)] +#[macro_export] +#[cfg(not(feature = "getrandom"))] +macro_rules! impl_getrandom { + () => {}; +} + +#[doc(hidden)] +#[macro_export] +#[cfg(feature = "rand")] +macro_rules! impl_rand { + () => { + /// Creates a new fixed byte array with the given random number generator. + #[inline] + #[doc(alias = "random_using")] + #[cfg_attr(docsrs, doc(cfg(feature = "rand")))] + pub fn random_with(rng: &mut R) -> Self { + Self($crate::FixedBytes::random_with(rng)) + } + + /// Fills this fixed byte array with the given random number generator. + #[inline] + #[doc(alias = "randomize_using")] + #[cfg_attr(docsrs, doc(cfg(feature = "rand")))] + pub fn randomize_with(&mut self, rng: &mut R) { + self.0.randomize_with(rng); + } + }; + + ($t:ty) => { + #[cfg_attr(docsrs, doc(cfg(feature = "rand")))] + impl $crate::private::rand::distributions::Distribution<$t> + for $crate::private::rand::distributions::Standard + { + #[inline] + fn sample(&self, rng: &mut R) -> $t { + <$t>::random_with(rng) + } + } + }; +} + +#[doc(hidden)] +#[macro_export] +#[cfg(not(feature = "rand"))] +macro_rules! impl_rand { + ($($t:tt)*) => {}; +} + +#[doc(hidden)] +#[macro_export] +#[cfg(feature = "rlp")] +macro_rules! impl_rlp { + ($t:ty, $n:literal) => { + #[cfg_attr(docsrs, doc(cfg(feature = "rlp")))] + impl $crate::private::alloy_rlp::Decodable for $t { + #[inline] + fn decode(buf: &mut &[u8]) -> $crate::private::alloy_rlp::Result { + $crate::private::alloy_rlp::Decodable::decode(buf).map(Self) + } + } + + #[cfg_attr(docsrs, doc(cfg(feature = "rlp")))] + impl $crate::private::alloy_rlp::Encodable for $t { + #[inline] + fn length(&self) -> usize { + $crate::private::alloy_rlp::Encodable::length(&self.0) + } + + #[inline] + fn encode(&self, out: &mut dyn bytes::BufMut) { + $crate::private::alloy_rlp::Encodable::encode(&self.0, out) + } + } + + $crate::private::alloy_rlp::impl_max_encoded_len!($t, { + $n + $crate::private::alloy_rlp::length_of_length($n) + }); + }; +} + +#[doc(hidden)] +#[macro_export] +#[cfg(not(feature = "rlp"))] +macro_rules! impl_rlp { + ($t:ty, $n:literal) => {}; +} + +#[doc(hidden)] +#[macro_export] +#[cfg(feature = "allocative")] +macro_rules! impl_allocative { + ($t:ty) => { + #[cfg_attr(docsrs, doc(cfg(feature = "allocative")))] + impl $crate::private::allocative::Allocative for $t { + #[inline] + fn visit<'a, 'b: 'a>(&self, visitor: &'a mut $crate::private::allocative::Visitor<'b>) { + $crate::private::allocative::Allocative::visit(&self.0, visitor) + } + } + }; +} + +#[doc(hidden)] +#[macro_export] +#[cfg(not(feature = "allocative"))] +macro_rules! impl_allocative { + ($t:ty) => {}; +} + +#[doc(hidden)] +#[macro_export] +#[cfg(feature = "serde")] +macro_rules! impl_serde { + ($t:ty) => { + #[cfg_attr(docsrs, doc(cfg(feature = "serde")))] + impl $crate::private::serde::Serialize for $t { + #[inline] + fn serialize(&self, serializer: S) -> Result { + $crate::private::serde::Serialize::serialize(&self.0, serializer) + } + } + + #[cfg_attr(docsrs, doc(cfg(feature = "serde")))] + impl<'de> $crate::private::serde::Deserialize<'de> for $t { + #[inline] + fn deserialize>( + deserializer: D, + ) -> Result { + $crate::private::serde::Deserialize::deserialize(deserializer).map(Self) + } + } + }; +} + +#[doc(hidden)] +#[macro_export] +#[cfg(not(feature = "serde"))] +macro_rules! impl_serde { + ($t:ty) => {}; +} + +#[doc(hidden)] +#[macro_export] +#[cfg(feature = "arbitrary")] +macro_rules! impl_arbitrary { + ($t:ty, $n:literal) => { + #[cfg_attr(docsrs, doc(cfg(feature = "arbitrary")))] + impl<'a> $crate::private::arbitrary::Arbitrary<'a> for $t { + #[inline] + fn arbitrary(u: &mut $crate::private::arbitrary::Unstructured<'a>) -> $crate::private::arbitrary::Result { + <$crate::FixedBytes<$n> as $crate::private::arbitrary::Arbitrary>::arbitrary(u).map(Self) + } + + #[inline] + fn arbitrary_take_rest(u: $crate::private::arbitrary::Unstructured<'a>) -> $crate::private::arbitrary::Result { + <$crate::FixedBytes<$n> as $crate::private::arbitrary::Arbitrary>::arbitrary_take_rest(u).map(Self) + } + + #[inline] + fn size_hint(depth: usize) -> (usize, Option) { + <$crate::FixedBytes<$n> as $crate::private::arbitrary::Arbitrary>::size_hint(depth) + } + } + + #[cfg_attr(docsrs, doc(cfg(feature = "arbitrary")))] + impl $crate::private::proptest::arbitrary::Arbitrary for $t { + type Parameters = <$crate::FixedBytes<$n> as $crate::private::proptest::arbitrary::Arbitrary>::Parameters; + type Strategy = $crate::private::proptest::strategy::Map< + <$crate::FixedBytes<$n> as $crate::private::proptest::arbitrary::Arbitrary>::Strategy, + fn($crate::FixedBytes<$n>) -> Self, + >; + + #[inline] + fn arbitrary() -> Self::Strategy { + use $crate::private::proptest::strategy::Strategy; + <$crate::FixedBytes<$n> as $crate::private::proptest::arbitrary::Arbitrary>::arbitrary() + .prop_map(Self) + } + + #[inline] + fn arbitrary_with(args: Self::Parameters) -> Self::Strategy { + use $crate::private::proptest::strategy::Strategy; + <$crate::FixedBytes<$n> as $crate::private::proptest::arbitrary::Arbitrary>::arbitrary_with(args) + .prop_map(Self) + } + } + }; +} + +#[doc(hidden)] +#[macro_export] +#[cfg(not(feature = "arbitrary"))] +macro_rules! impl_arbitrary { + ($t:ty, $n:literal) => {}; +} + +macro_rules! fixed_bytes_macros { + ($d:tt $($(#[$attr:meta])* macro $name:ident($ty:ident $($rest:tt)*);)*) => {$( + /// Converts a sequence of string literals containing hex-encoded data + #[doc = concat!( + "into a new [`", stringify!($ty), "`][crate::", stringify!($ty), "] at compile time.\n", + )] + /// + /// If the input is empty, a zero-initialized array is returned. + /// + /// Note that the strings cannot be prefixed with `0x`. + /// + /// See [`hex!`](crate::hex!) for more information. + /// + /// # Examples + /// + /// ``` + #[doc = concat!("use alloy_primitives::{", stringify!($name), ", ", stringify!($ty), "};")] + /// + #[doc = concat!("const ZERO: ", stringify!($ty $($rest)*), " = ", stringify!($name), "!();")] + #[doc = concat!("assert_eq!(ZERO, ", stringify!($ty), "::ZERO);")] + /// + /// # stringify!( + #[doc = concat!("let byte_array: ", stringify!($ty), " = ", stringify!($name), "!(\"0123abcd…\");")] + /// # ); + /// ``` + $(#[$attr])* + #[macro_export] + macro_rules! $name { + () => { + $crate::$ty::ZERO + }; + + ($d ($d s:literal)+) => { + $crate::$ty::new($crate::hex!($d ($d s)+)) + }; + } + )*}; +} + +fixed_bytes_macros! { $ + macro address(Address); + + macro b64(B64); + + macro b128(B128); + + macro b256(B256); + + macro b512(B512); + + macro bloom(Bloom); + + macro fixed_bytes(FixedBytes<0>); // <0> is just for the doctest +} + +/// Converts a sequence of string literals containing hex-encoded data into a +/// new [`Bytes`][crate::Bytes] at compile time. +/// +/// If the input is empty, an empty instance is returned. +/// +/// Note that the strings cannot be prefixed with `0x`. +/// +/// See [`hex!`](crate::hex!) for more information. +/// +/// # Examples +/// +/// ``` +/// use alloy_primitives::{bytes, Bytes}; +/// +/// static MY_BYTES: Bytes = bytes!("0123abcd"); +/// assert_eq!(MY_BYTES, Bytes::from(&[0x01, 0x23, 0xab, 0xcd])); +/// ``` +#[macro_export] +macro_rules! bytes { + () => { + $crate::Bytes::new() + }; + + ($($s:literal)+) => {{ + // force const eval + const STATIC_BYTES: &'static [u8] = &$crate::hex!($($s)+); + $crate::Bytes::from_static(STATIC_BYTES) + }}; + + [$($inner:literal),+ $(,)?] => {{ + // force const eval + const STATIC_BYTES: &'static [u8] = &[$($inner),+]; + $crate::Bytes::from_static(STATIC_BYTES) + }}; + + [$inner:literal; $size:literal] => {{ + // force const eval + const STATIC_BYTES: &'static [u8; $size] = &[$inner; $size]; + $crate::Bytes::from_static(STATIC_BYTES) + }}; +} + +#[cfg(test)] +mod tests { + use crate::{hex, Address, Bytes, FixedBytes}; + + #[test] + fn bytes_macros() { + static B1: Bytes = bytes!("010203040506070809"); + static B2: Bytes = bytes![1, 2, 3, 4, 5, 6, 7, 8, 9]; + static B3: Bytes = bytes![1, 2, 3, 4, 5, 6, 7, 8, 9,]; + + assert_eq!(B1, B2); + assert_eq!(B1, B3); + + static B4: Bytes = bytes!("0000"); + static B5: Bytes = bytes![0; 2]; + static B6: Bytes = bytes![0, 0]; + assert_eq!(B4, B5); + assert_eq!(B4, B6); + } + + #[test] + fn fixed_byte_macros() { + const A0: Address = address!(); + assert_eq!(A0, Address::ZERO); + + const A1: Address = address!("0102030405060708090a0b0c0d0e0f1011121314"); + const A2: Address = Address(fixed_bytes!("0102030405060708090a0b0c0d0e0f1011121314")); + const A3: Address = Address(FixedBytes(hex!("0102030405060708090a0b0c0d0e0f1011121314"))); + assert_eq!(A1, A2); + assert_eq!(A1, A3); + assert_eq!(A1, hex!("0102030405060708090a0b0c0d0e0f1011121314")); + + static B: Bytes = bytes!("112233"); + assert_eq!(B[..], [0x11, 0x22, 0x33]); + + static EMPTY_BYTES1: Bytes = bytes!(); + static EMPTY_BYTES2: Bytes = bytes!(""); + assert_eq!(EMPTY_BYTES1, EMPTY_BYTES2); + assert_eq!(EMPTY_BYTES1, Bytes::new()); + assert!(EMPTY_BYTES1.is_empty()); + } +} diff --git a/CoqOfRust/alloy_primitives/bits/macros.v b/CoqOfRust/alloy_primitives/bits/macros.v new file mode 100644 index 000000000..f9c17d7ed --- /dev/null +++ b/CoqOfRust/alloy_primitives/bits/macros.v @@ -0,0 +1,20033 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module bits. + Module address. + (* StructTuple + { + name := "Address"; + const_params := []; + ty_params := []; + fields := + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ]; + } *) + + Module Impl_core_clone_Clone_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.deref (| M.read (| self |) |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_alloy_primitives_bits_address_Address. + + Module Impl_core_marker_Copy_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_alloy_primitives_bits_address_Address. + + Module Impl_core_default_Default_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* Default *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::bits::address::Address" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [], + "default", + [], + [] + |), + [] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_alloy_primitives_bits_address_Address. + + Module Impl_core_marker_StructuralPartialEq_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + Axiom Implements : + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_alloy_primitives_bits_address_Address. + + Module Impl_core_cmp_PartialEq_alloy_primitives_bits_address_Address_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* PartialEq *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::address::Address" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_bits_address_Address_for_alloy_primitives_bits_address_Address. + + Module Impl_core_cmp_Eq_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* Eq *) + Definition assert_receiver_is_total_eq + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method assert_receiver_is_total_eq) ]. + End Impl_core_cmp_Eq_for_alloy_primitives_bits_address_Address. + + Module Impl_core_cmp_PartialOrd_alloy_primitives_bits_address_Address_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* PartialOrd *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::address::Address" ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_alloy_primitives_bits_address_Address_for_alloy_primitives_bits_address_Address. + + Module Impl_core_cmp_Ord_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* Ord *) + Definition cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "core::cmp::Ordering", + M.get_trait_method (| + "core::cmp::Ord", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [], + "cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Ord" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("cmp", InstanceField.Method cmp) ]. + End Impl_core_cmp_Ord_for_alloy_primitives_bits_address_Address. + + Module Impl_core_hash_Hash_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* Hash *) + Definition hash (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ __H ], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::hash::Hash" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("hash", InstanceField.Method hash) ]. + End Impl_core_hash_Hash_for_alloy_primitives_bits_address_Address. + + Module Impl_core_convert_AsMut_alloy_primitives_bits_fixed_FixedBytes_Usize_20_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* $crate::private::derive_more::AsMut *) + Definition as_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::AsMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ] + Self + (* Instance *) [ ("as_mut", InstanceField.Method as_mut) ]. + End Impl_core_convert_AsMut_alloy_primitives_bits_fixed_FixedBytes_Usize_20_for_alloy_primitives_bits_address_Address. + + Module Impl_core_convert_AsRef_alloy_primitives_bits_fixed_FixedBytes_Usize_20_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* $crate::private::derive_more::AsRef *) + Definition as_ref (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::AsRef" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ] + Self + (* Instance *) [ ("as_ref", InstanceField.Method as_ref) ]. + End Impl_core_convert_AsRef_alloy_primitives_bits_fixed_FixedBytes_Usize_20_for_alloy_primitives_bits_address_Address. + + Module Impl_core_ops_bit_BitAnd_alloy_primitives_bits_address_Address_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* $crate::private::derive_more::BitAnd *) + Definition _Output : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* $crate::private::derive_more::BitAnd *) + Definition bitand (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + Value.StructTuple + "alloy_primitives::bits::address::Address" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + M.get_trait_method (| + "core::ops::bit::BitAnd", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ], + "bitand", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::address::Address", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::address::Address", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::bit::BitAnd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::address::Address" ] + Self + (* Instance *) + [ ("Output", InstanceField.Ty _Output); ("bitand", InstanceField.Method bitand) ]. + End Impl_core_ops_bit_BitAnd_alloy_primitives_bits_address_Address_for_alloy_primitives_bits_address_Address. + + Module Impl_core_ops_bit_BitAndAssign_alloy_primitives_bits_address_Address_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* $crate::private::derive_more::BitAndAssign *) + Definition bitand_assign (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::bit::BitAndAssign", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ], + "bitand_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::address::Address", + 0 + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::bit::BitAndAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::address::Address" ] + Self + (* Instance *) [ ("bitand_assign", InstanceField.Method bitand_assign) ]. + End Impl_core_ops_bit_BitAndAssign_alloy_primitives_bits_address_Address_for_alloy_primitives_bits_address_Address. + + Module Impl_core_ops_bit_BitOr_alloy_primitives_bits_address_Address_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* $crate::private::derive_more::BitOr *) + Definition _Output : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* $crate::private::derive_more::BitOr *) + Definition bitor (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + Value.StructTuple + "alloy_primitives::bits::address::Address" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + M.get_trait_method (| + "core::ops::bit::BitOr", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ], + "bitor", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::address::Address", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::address::Address", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::bit::BitOr" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::address::Address" ] + Self + (* Instance *) + [ ("Output", InstanceField.Ty _Output); ("bitor", InstanceField.Method bitor) ]. + End Impl_core_ops_bit_BitOr_alloy_primitives_bits_address_Address_for_alloy_primitives_bits_address_Address. + + Module Impl_core_ops_bit_BitOrAssign_alloy_primitives_bits_address_Address_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* $crate::private::derive_more::BitOrAssign *) + Definition bitor_assign (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::bit::BitOrAssign", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ], + "bitor_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::address::Address", + 0 + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::bit::BitOrAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::address::Address" ] + Self + (* Instance *) [ ("bitor_assign", InstanceField.Method bitor_assign) ]. + End Impl_core_ops_bit_BitOrAssign_alloy_primitives_bits_address_Address_for_alloy_primitives_bits_address_Address. + + Module Impl_core_ops_bit_BitXor_alloy_primitives_bits_address_Address_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* $crate::private::derive_more::BitXor *) + Definition _Output : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* $crate::private::derive_more::BitXor *) + Definition bitxor (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + Value.StructTuple + "alloy_primitives::bits::address::Address" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + M.get_trait_method (| + "core::ops::bit::BitXor", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ], + "bitxor", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::address::Address", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::address::Address", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::bit::BitXor" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::address::Address" ] + Self + (* Instance *) + [ ("Output", InstanceField.Ty _Output); ("bitxor", InstanceField.Method bitxor) ]. + End Impl_core_ops_bit_BitXor_alloy_primitives_bits_address_Address_for_alloy_primitives_bits_address_Address. + + Module Impl_core_ops_bit_BitXorAssign_alloy_primitives_bits_address_Address_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* $crate::private::derive_more::BitXorAssign *) + Definition bitxor_assign (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::bit::BitXorAssign", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ], + "bitxor_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::address::Address", + 0 + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::bit::BitXorAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::address::Address" ] + Self + (* Instance *) [ ("bitxor_assign", InstanceField.Method bitxor_assign) ]. + End Impl_core_ops_bit_BitXorAssign_alloy_primitives_bits_address_Address_for_alloy_primitives_bits_address_Address. + + Module Impl_core_ops_bit_Not_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* $crate::private::derive_more::Not *) + Definition _Output : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* $crate::private::derive_more::Not *) + Definition not (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple + "alloy_primitives::bits::address::Address" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + M.get_trait_method (| + "core::ops::bit::Not", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [], + "not", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::address::Address", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::bit::Not" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("Output", InstanceField.Ty _Output); ("not", InstanceField.Method not) ]. + End Impl_core_ops_bit_Not_for_alloy_primitives_bits_address_Address. + + Module Impl_core_ops_deref_Deref_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* $crate::private::derive_more::Deref *) + Definition _Target : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + []. + + (* $crate::private::derive_more::Deref *) + Definition deref (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::deref::Deref" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("Target", InstanceField.Ty _Target); ("deref", InstanceField.Method deref) ]. + End Impl_core_ops_deref_Deref_for_alloy_primitives_bits_address_Address. + + Module Impl_core_ops_deref_DerefMut_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* $crate::private::derive_more::DerefMut *) + Definition deref_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::deref::DerefMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("deref_mut", InstanceField.Method deref_mut) ]. + End Impl_core_ops_deref_DerefMut_for_alloy_primitives_bits_address_Address. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_20_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* $crate::private::derive_more::From *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple "alloy_primitives::bits::address::Address" [ M.read (| value |) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_20_for_alloy_primitives_bits_address_Address. + + Module Impl_core_str_traits_FromStr_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* $crate::private::derive_more::FromStr *) + Definition _Err : Ty.t := + Ty.associated_in_trait + "core::str::traits::FromStr" + [] + [] + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + []) + "Err". + + (* $crate::private::derive_more::FromStr *) + Definition from_str (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ src ] => + ltac:(M.monadic + (let src := M.alloc (| src |) in + M.catch_return (| + ltac:(M.monadic + (Value.StructTuple + "core::result::Result::Ok" + [ + Value.StructTuple + "alloy_primitives::bits::address::Address" + [ + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "const_hex::error::FromHexError" + ]; + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + []; + Ty.path "const_hex::error::FromHexError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + []; + Ty.path "const_hex::error::FromHexError" + ], + M.get_trait_method (| + "core::str::traits::FromStr", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [], + "from_str", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| src |) |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::bits::address::Address"; + Ty.path "const_hex::error::FromHexError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "alloy_primitives::bits::address::Address"; + Ty.path "const_hex::error::FromHexError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "const_hex::error::FromHexError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) + ] + ])) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::str::traits::FromStr" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("Err", InstanceField.Ty _Err); ("from_str", InstanceField.Method from_str) ]. + End Impl_core_str_traits_FromStr_for_alloy_primitives_bits_address_Address. + + Module Impl_core_ops_index_Index_where_core_ops_index_Index_alloy_primitives_bits_fixed_FixedBytes_Usize_20___IdxT___IdxT_for_alloy_primitives_bits_address_Address. + Definition Self (__IdxT : Ty.t) : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* $crate::private::derive_more::Index *) + Definition _Output (__IdxT : Ty.t) : Ty.t := + Ty.associated_in_trait + "core::ops::index::Index" + [] + [ __IdxT ] + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + []) + "Output". + + (* $crate::private::derive_more::Index *) + Definition index (__IdxT : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self __IdxT in + match ε, τ, α with + | [], [], [ self; idx ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let idx := M.alloc (| idx |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "core::ops::index::Index" + [] + [ __IdxT ] + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + []) + "Output" + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ __IdxT ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |); + M.read (| idx |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (__IdxT : Ty.t), + M.IsTraitInstance + "core::ops::index::Index" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ __IdxT ] + (Self __IdxT) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output __IdxT)); + ("index", InstanceField.Method (index __IdxT)) + ]. + End Impl_core_ops_index_Index_where_core_ops_index_Index_alloy_primitives_bits_fixed_FixedBytes_Usize_20___IdxT___IdxT_for_alloy_primitives_bits_address_Address. + + Module Impl_core_ops_index_IndexMut_where_core_ops_index_IndexMut_alloy_primitives_bits_fixed_FixedBytes_Usize_20___IdxT___IdxT_for_alloy_primitives_bits_address_Address. + Definition Self (__IdxT : Ty.t) : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* $crate::private::derive_more::IndexMut *) + Definition index_mut + (__IdxT : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self __IdxT in + match ε, τ, α with + | [], [], [ self; idx ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let idx := M.alloc (| idx |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.associated_in_trait + "core::ops::index::Index" + [] + [ __IdxT ] + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + []) + "Output" + ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ __IdxT ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |); + M.read (| idx |) + ] + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (__IdxT : Ty.t), + M.IsTraitInstance + "core::ops::index::IndexMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ __IdxT ] + (Self __IdxT) + (* Instance *) [ ("index_mut", InstanceField.Method (index_mut __IdxT)) ]. + End Impl_core_ops_index_IndexMut_where_core_ops_index_IndexMut_alloy_primitives_bits_fixed_FixedBytes_Usize_20___IdxT___IdxT_for_alloy_primitives_bits_address_Address. + + Module Impl_core_convert_From_alloy_primitives_bits_address_Address_for_alloy_primitives_bits_fixed_FixedBytes_Usize_20. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + []. + + (* $crate::private::derive_more::Into *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + M.get_trait_method (| + "core::convert::From", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ], + "from", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::address::Address", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::address::Address" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_address_Address_for_alloy_primitives_bits_fixed_FixedBytes_Usize_20. + + Module Impl_core_iter_traits_collect_IntoIterator_where_core_iter_traits_collect_IntoIterator_alloy_primitives_bits_fixed_FixedBytes_Usize_20_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* $crate::private::derive_more::IntoIterator *) + Definition _Item : Ty.t := + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + []) + "Item". + + (* $crate::private::derive_more::IntoIterator *) + Definition _IntoIter : Ty.t := + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + []) + "IntoIter". + + (* $crate::private::derive_more::IntoIterator *) + Definition into_iter (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::address::Address", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::iter::traits::collect::IntoIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("Item", InstanceField.Ty _Item); + ("IntoIter", InstanceField.Ty _IntoIter); + ("into_iter", InstanceField.Method into_iter) + ]. + End Impl_core_iter_traits_collect_IntoIterator_where_core_iter_traits_collect_IntoIterator_alloy_primitives_bits_fixed_FixedBytes_Usize_20_for_alloy_primitives_bits_address_Address. + + Module Impl_core_iter_traits_collect_IntoIterator_where_core_iter_traits_collect_IntoIterator_ref__alloy_primitives_bits_fixed_FixedBytes_Usize_20_for_ref__alloy_primitives_bits_address_Address. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::address::Address" ]. + + (* $crate::private::derive_more::IntoIterator *) + Definition _Item : Ty.t := + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ]) + "Item". + + (* $crate::private::derive_more::IntoIterator *) + Definition _IntoIter : Ty.t := + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ]) + "IntoIter". + + (* $crate::private::derive_more::IntoIterator *) + Definition into_iter (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ]) + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::iter::traits::collect::IntoIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("Item", InstanceField.Ty _Item); + ("IntoIter", InstanceField.Ty _IntoIter); + ("into_iter", InstanceField.Method into_iter) + ]. + End Impl_core_iter_traits_collect_IntoIterator_where_core_iter_traits_collect_IntoIterator_ref__alloy_primitives_bits_fixed_FixedBytes_Usize_20_for_ref__alloy_primitives_bits_address_Address. + + Module Impl_core_iter_traits_collect_IntoIterator_where_core_iter_traits_collect_IntoIterator_ref_mut_alloy_primitives_bits_fixed_FixedBytes_Usize_20_for_ref_mut_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := + Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::address::Address" ]. + + (* $crate::private::derive_more::IntoIterator *) + Definition _Item : Ty.t := + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ]) + "Item". + + (* $crate::private::derive_more::IntoIterator *) + Definition _IntoIter : Ty.t := + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ]) + "IntoIter". + + (* $crate::private::derive_more::IntoIterator *) + Definition into_iter (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ]) + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::iter::traits::collect::IntoIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("Item", InstanceField.Ty _Item); + ("IntoIter", InstanceField.Ty _IntoIter); + ("into_iter", InstanceField.Method into_iter) + ]. + End Impl_core_iter_traits_collect_IntoIterator_where_core_iter_traits_collect_IntoIterator_ref_mut_alloy_primitives_bits_fixed_FixedBytes_Usize_20_for_ref_mut_alloy_primitives_bits_address_Address. + + Module Impl_core_fmt_LowerHex_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* $crate::private::derive_more::LowerHex *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; __derive_more_f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __derive_more_f := M.alloc (| __derive_more_f |) in + M.read (| + let~ _0 : + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::LowerHex", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| _0 |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| __derive_more_f |) |) |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::LowerHex" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_LowerHex_for_alloy_primitives_bits_address_Address. + + Module Impl_core_fmt_UpperHex_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* $crate::private::derive_more::UpperHex *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; __derive_more_f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __derive_more_f := M.alloc (| __derive_more_f |) in + M.read (| + let~ _0 : + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::UpperHex", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| _0 |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| __derive_more_f |) |) |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::UpperHex" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_UpperHex_for_alloy_primitives_bits_address_Address. + + Module Impl_core_convert_From_array_Usize_20_u8_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* + fn from(value: [u8; $n]) -> Self { + Self($crate::FixedBytes(value)) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::address::Address" + [ Value.StructTuple "alloy_primitives::bits::fixed::FixedBytes" [ M.read (| value |) ] + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_array_Usize_20_u8_for_alloy_primitives_bits_address_Address. + + Module Impl_core_convert_From_alloy_primitives_bits_address_Address_for_array_Usize_20_u8. + Definition Self : Ty.t := + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ]. + + (* + fn from(value: $name) -> Self { + value.0 .0 + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.read (| + M.SubPointer.get_struct_tuple_field (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::address::Address", + 0 + |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::address::Address" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_address_Address_for_array_Usize_20_u8. + + Module Impl_core_convert_From_ref__array_Usize_20_u8_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* + fn from(value: &'a [u8; $n]) -> Self { + Self($crate::FixedBytes( *value)) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::address::Address" + [ + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ M.read (| M.deref (| M.read (| value |) |) |) ] + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ] ] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref__array_Usize_20_u8_for_alloy_primitives_bits_address_Address. + + Module Impl_core_convert_From_ref_mut_array_Usize_20_u8_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* + fn from(value: &'a mut [u8; $n]) -> Self { + Self($crate::FixedBytes( *value)) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::address::Address" + [ + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ M.read (| M.deref (| M.read (| value |) |) |) ] + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ] ] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref_mut_array_Usize_20_u8_for_alloy_primitives_bits_address_Address. + + Module Impl_core_convert_TryFrom_ref__slice_u8_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* type Error = $crate::private::core::array::TryFromSliceError; *) + Definition _Error : Ty.t := Ty.path "core::array::TryFromSliceError". + + (* + fn try_from(slice: &[u8]) -> Result { + <&Self as $crate::private::TryFrom<&[u8]>>::try_from(slice).copied() + } + *) + Definition try_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ slice ] => + ltac:(M.monadic + (let slice := M.alloc (| slice |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::bits::address::Address"; + Ty.path "core::array::TryFromSliceError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::address::Address" ]; + Ty.path "core::array::TryFromSliceError" + ], + "copied", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::address::Address" ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::address::Address" ], + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ], + "try_from", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| slice |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("try_from", InstanceField.Method try_from) ]. + End Impl_core_convert_TryFrom_ref__slice_u8_for_alloy_primitives_bits_address_Address. + + Module Impl_core_convert_TryFrom_ref_mut_slice_u8_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* type Error = $crate::private::core::array::TryFromSliceError; *) + Definition _Error : Ty.t := Ty.path "core::array::TryFromSliceError". + + (* + fn try_from(slice: &mut [u8]) -> Result { + >::try_from(&*slice) + } + *) + Definition try_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ slice ] => + ltac:(M.monadic + (let slice := M.alloc (| slice |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::bits::address::Address"; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "alloy_primitives::bits::address::Address", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ], + "try_from", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| slice |) |) |) |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("try_from", InstanceField.Method try_from) ]. + End Impl_core_convert_TryFrom_ref_mut_slice_u8_for_alloy_primitives_bits_address_Address. + + Module Impl_core_convert_TryFrom_ref__slice_u8_for_ref__alloy_primitives_bits_address_Address. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::address::Address" ]. + + (* type Error = $crate::private::core::array::TryFromSliceError; *) + Definition _Error : Ty.t := Ty.path "core::array::TryFromSliceError". + + (* + fn try_from(slice: &'a [u8]) -> Result<&'a $name, Self::Error> { + // SAFETY: `$name` is `repr(transparent)` for `FixedBytes<$n>` + // and consequently `[u8; $n]` + <&[u8; $n] as $crate::private::TryFrom<&[u8]>>::try_from(slice) + .map(|array_ref| unsafe { $crate::private::core::mem::transmute(array_ref) }) + } + *) + Definition try_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ slice ] => + ltac:(M.monadic + (let slice := M.alloc (| slice |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::address::Address" ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "map", + [], + [ + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::address::Address" ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ] + ] + ] + (Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::address::Address" ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ], + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ], + "try_from", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| slice |) |) |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ] + ] + ] + (Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::address::Address" ])), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let array_ref := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::address::Address" ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::address::Address" ] + ] + |), + [ M.read (| array_ref |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("try_from", InstanceField.Method try_from) ]. + End Impl_core_convert_TryFrom_ref__slice_u8_for_ref__alloy_primitives_bits_address_Address. + + Module Impl_core_convert_TryFrom_ref_mut_slice_u8_for_ref_mut_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := + Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::address::Address" ]. + + (* type Error = $crate::private::core::array::TryFromSliceError; *) + Definition _Error : Ty.t := Ty.path "core::array::TryFromSliceError". + + (* + fn try_from(slice: &'a mut [u8]) -> Result<&'a mut $name, Self::Error> { + // SAFETY: `$name` is `repr(transparent)` for `FixedBytes<$n>` + // and consequently `[u8; $n]` + <&mut [u8; $n] as $crate::private::TryFrom<&mut [u8]>>::try_from(slice) + .map(|array_ref| unsafe { $crate::private::core::mem::transmute(array_ref) }) + } + *) + Definition try_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ slice ] => + ltac:(M.monadic + (let slice := M.alloc (| slice |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::address::Address" ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "map", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::address::Address" ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ] + ] + ] + (Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::address::Address" ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ], + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ], + "try_from", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| slice |) |) |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ] + ] + ] + (Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::address::Address" ])), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let array_ref := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::address::Address" ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::address::Address" ] + ] + |), + [ M.read (| array_ref |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("try_from", InstanceField.Method try_from) ]. + End Impl_core_convert_TryFrom_ref_mut_slice_u8_for_ref_mut_alloy_primitives_bits_address_Address. + + Module Impl_core_convert_AsRef_array_Usize_20_u8_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* + fn as_ref(&self) -> &[u8; $n] { + &self.0 .0 + } + *) + Definition as_ref (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::AsRef" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("as_ref", InstanceField.Method as_ref) ]. + End Impl_core_convert_AsRef_array_Usize_20_u8_for_alloy_primitives_bits_address_Address. + + Module Impl_core_convert_AsMut_array_Usize_20_u8_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* + fn as_mut(&mut self) -> &mut [u8; $n] { + &mut self.0 .0 + } + *) + Definition as_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::AsMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("as_mut", InstanceField.Method as_mut) ]. + End Impl_core_convert_AsMut_array_Usize_20_u8_for_alloy_primitives_bits_address_Address. + + Module Impl_core_convert_AsRef_slice_u8_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* + fn as_ref(&self) -> &[u8] { + &self.0 .0 + } + *) + Definition as_ref (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::AsRef" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("as_ref", InstanceField.Method as_ref) ]. + End Impl_core_convert_AsRef_slice_u8_for_alloy_primitives_bits_address_Address. + + Module Impl_core_convert_AsMut_slice_u8_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* + fn as_mut(&mut self) -> &mut [u8] { + &mut self.0 .0 + } + *) + Definition as_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::AsMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("as_mut", InstanceField.Method as_mut) ]. + End Impl_core_convert_AsMut_slice_u8_for_alloy_primitives_bits_address_Address. + + Module Impl_core_fmt_Debug_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + $crate::private::core::fmt::Debug::fmt(&self.0, f) + } + *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::Debug", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_alloy_primitives_bits_address_Address. + + Module Impl_core_borrow_Borrow_slice_u8_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* + fn borrow(&self) -> &$t { + $crate::private::Borrow::borrow(&self.0) + } + *) + Definition borrow (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow", InstanceField.Method borrow) ]. + End Impl_core_borrow_Borrow_slice_u8_for_alloy_primitives_bits_address_Address. + + Module Impl_core_borrow_Borrow_slice_u8_for_ref__alloy_primitives_bits_address_Address. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::address::Address" ]. + + (* + fn borrow(&self) -> &$t { + $crate::private::Borrow::borrow(&self.0) + } + *) + Definition borrow (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow", InstanceField.Method borrow) ]. + End Impl_core_borrow_Borrow_slice_u8_for_ref__alloy_primitives_bits_address_Address. + + Module Impl_core_borrow_Borrow_slice_u8_for_ref_mut_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := + Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::address::Address" ]. + + (* + fn borrow(&self) -> &$t { + $crate::private::Borrow::borrow(&self.0) + } + *) + Definition borrow (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow", InstanceField.Method borrow) ]. + End Impl_core_borrow_Borrow_slice_u8_for_ref_mut_alloy_primitives_bits_address_Address. + + Module Impl_core_borrow_Borrow_array_Usize_20_u8_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* + fn borrow(&self) -> &$t { + $crate::private::Borrow::borrow(&self.0) + } + *) + Definition borrow (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow", InstanceField.Method borrow) ]. + End Impl_core_borrow_Borrow_array_Usize_20_u8_for_alloy_primitives_bits_address_Address. + + Module Impl_core_borrow_Borrow_array_Usize_20_u8_for_ref__alloy_primitives_bits_address_Address. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::address::Address" ]. + + (* + fn borrow(&self) -> &$t { + $crate::private::Borrow::borrow(&self.0) + } + *) + Definition borrow (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow", InstanceField.Method borrow) ]. + End Impl_core_borrow_Borrow_array_Usize_20_u8_for_ref__alloy_primitives_bits_address_Address. + + Module Impl_core_borrow_Borrow_array_Usize_20_u8_for_ref_mut_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := + Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::address::Address" ]. + + (* + fn borrow(&self) -> &$t { + $crate::private::Borrow::borrow(&self.0) + } + *) + Definition borrow (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow", InstanceField.Method borrow) ]. + End Impl_core_borrow_Borrow_array_Usize_20_u8_for_ref_mut_alloy_primitives_bits_address_Address. + + Module Impl_core_borrow_BorrowMut_slice_u8_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* + fn borrow_mut(&mut self) -> &mut $t { + $crate::private::BorrowMut::borrow_mut(&mut self.0) + } + *) + Definition borrow_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::borrow::BorrowMut", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "borrow_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |) + ] + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::BorrowMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow_mut", InstanceField.Method borrow_mut) ]. + End Impl_core_borrow_BorrowMut_slice_u8_for_alloy_primitives_bits_address_Address. + + Module Impl_core_borrow_BorrowMut_slice_u8_for_ref_mut_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := + Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::address::Address" ]. + + (* + fn borrow_mut(&mut self) -> &mut $t { + $crate::private::BorrowMut::borrow_mut(&mut self.0) + } + *) + Definition borrow_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::borrow::BorrowMut", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "borrow_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |) + ] + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::BorrowMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow_mut", InstanceField.Method borrow_mut) ]. + End Impl_core_borrow_BorrowMut_slice_u8_for_ref_mut_alloy_primitives_bits_address_Address. + + Module Impl_core_borrow_BorrowMut_array_Usize_20_u8_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* + fn borrow_mut(&mut self) -> &mut $t { + $crate::private::BorrowMut::borrow_mut(&mut self.0) + } + *) + Definition borrow_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::borrow::BorrowMut", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ], + "borrow_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |) + ] + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::BorrowMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow_mut", InstanceField.Method borrow_mut) ]. + End Impl_core_borrow_BorrowMut_array_Usize_20_u8_for_alloy_primitives_bits_address_Address. + + Module Impl_core_borrow_BorrowMut_array_Usize_20_u8_for_ref_mut_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := + Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::address::Address" ]. + + (* + fn borrow_mut(&mut self) -> &mut $t { + $crate::private::BorrowMut::borrow_mut(&mut self.0) + } + *) + Definition borrow_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::borrow::BorrowMut", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ], + "borrow_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |) + ] + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::BorrowMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow_mut", InstanceField.Method borrow_mut) ]. + End Impl_core_borrow_BorrowMut_array_Usize_20_u8_for_ref_mut_alloy_primitives_bits_address_Address. + + Module Impl_core_convert_From_ref__array_Usize_20_u8_for_ref__alloy_primitives_bits_address_Address. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::address::Address" ]. + + (* + fn from(value: $a) -> $b { + // SAFETY: guaranteed by caller + unsafe { $crate::private::core::mem::transmute::<$a, $b>(value) } + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::address::Address" ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ]; + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::address::Address" ] + ] + |), + [ M.read (| value |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ] ] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref__array_Usize_20_u8_for_ref__alloy_primitives_bits_address_Address. + + Module Impl_core_convert_From_ref_mut_array_Usize_20_u8_for_ref__alloy_primitives_bits_address_Address. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::address::Address" ]. + + (* + fn from(value: $a) -> $b { + // SAFETY: guaranteed by caller + unsafe { $crate::private::core::mem::transmute::<$a, $b>(value) } + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::address::Address" ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ]; + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::address::Address" ] + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| value |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ] ] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref_mut_array_Usize_20_u8_for_ref__alloy_primitives_bits_address_Address. + + Module Impl_core_convert_From_ref_mut_array_Usize_20_u8_for_ref_mut_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := + Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::address::Address" ]. + + (* + fn from(value: $a) -> $b { + // SAFETY: guaranteed by caller + unsafe { $crate::private::core::mem::transmute::<$a, $b>(value) } + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::address::Address" ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::address::Address" ] + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| value |) |) |) ] + |) + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ] ] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref_mut_array_Usize_20_u8_for_ref_mut_alloy_primitives_bits_address_Address. + + Module Impl_core_convert_From_ref__alloy_primitives_bits_address_Address_for_ref__array_Usize_20_u8. + Definition Self : Ty.t := + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ] ]. + + (* + fn from(value: $a) -> $b { + // SAFETY: guaranteed by caller + unsafe { $crate::private::core::mem::transmute::<$a, $b>(value) } + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ] + ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::address::Address" ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ] + ] + |), + [ M.read (| value |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::address::Address" ] ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref__alloy_primitives_bits_address_Address_for_ref__array_Usize_20_u8. + + Module Impl_core_convert_From_ref_mut_alloy_primitives_bits_address_Address_for_ref__array_Usize_20_u8. + Definition Self : Ty.t := + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ] ]. + + (* + fn from(value: $a) -> $b { + // SAFETY: guaranteed by caller + unsafe { $crate::private::core::mem::transmute::<$a, $b>(value) } + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ] + ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::address::Address" ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ] + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| value |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::address::Address" ] ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref_mut_alloy_primitives_bits_address_Address_for_ref__array_Usize_20_u8. + + Module Impl_core_convert_From_ref_mut_alloy_primitives_bits_address_Address_for_ref_mut_array_Usize_20_u8. + Definition Self : Ty.t := + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ] ]. + + (* + fn from(value: $a) -> $b { + // SAFETY: guaranteed by caller + unsafe { $crate::private::core::mem::transmute::<$a, $b>(value) } + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::address::Address" ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ] + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| value |) |) |) ] + |) + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::address::Address" ] ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref_mut_alloy_primitives_bits_address_Address_for_ref_mut_array_Usize_20_u8. + + Module Impl_core_cmp_PartialEq_slice_u8_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_slice_u8_for_alloy_primitives_bits_address_Address. + + Module Impl_core_cmp_PartialEq_alloy_primitives_bits_address_Address_for_slice_u8. + Definition Self : Ty.t := Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ]. + + (* + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::address::Address" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_bits_address_Address_for_slice_u8. + + Module Impl_core_cmp_PartialEq_ref__slice_u8_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* + fn $fn(&self, other: &&$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, *other) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.deref (| M.read (| other |) |) |) |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_ref__slice_u8_for_alloy_primitives_bits_address_Address. + + Module Impl_core_cmp_PartialEq_alloy_primitives_bits_address_Address_for_ref__slice_u8. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ]. + + (* + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn( *self, &other.0 $([$e])?) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::address::Address" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_bits_address_Address_for_ref__slice_u8. + + Module Impl_core_cmp_PartialEq_slice_u8_for_ref__alloy_primitives_bits_address_Address. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::address::Address" ]. + + (* + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_slice_u8_for_ref__alloy_primitives_bits_address_Address. + + Module Impl_core_cmp_PartialEq_ref__alloy_primitives_bits_address_Address_for_slice_u8. + Definition Self : Ty.t := Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ]. + + (* + fn $fn(&self, other: &&$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| other |) |) |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::address::Address" ] ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_ref__alloy_primitives_bits_address_Address_for_slice_u8. + + Module Impl_core_cmp_PartialEq_array_Usize_20_u8_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_array_Usize_20_u8_for_alloy_primitives_bits_address_Address. + + Module Impl_core_cmp_PartialEq_alloy_primitives_bits_address_Address_for_array_Usize_20_u8. + Definition Self : Ty.t := + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ]. + + (* + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::address::Address" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_bits_address_Address_for_array_Usize_20_u8. + + Module Impl_core_cmp_PartialEq_ref__array_Usize_20_u8_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* + fn $fn(&self, other: &&$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, *other) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.deref (| M.read (| other |) |) |) |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ] ] + ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_ref__array_Usize_20_u8_for_alloy_primitives_bits_address_Address. + + Module Impl_core_cmp_PartialEq_alloy_primitives_bits_address_Address_for_ref__array_Usize_20_u8. + Definition Self : Ty.t := + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ] ]. + + (* + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn( *self, &other.0 $([$e])?) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::address::Address" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_bits_address_Address_for_ref__array_Usize_20_u8. + + Module Impl_core_cmp_PartialEq_array_Usize_20_u8_for_ref__alloy_primitives_bits_address_Address. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::address::Address" ]. + + (* + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_array_Usize_20_u8_for_ref__alloy_primitives_bits_address_Address. + + Module Impl_core_cmp_PartialEq_ref__alloy_primitives_bits_address_Address_for_array_Usize_20_u8. + Definition Self : Ty.t := + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ]. + + (* + fn $fn(&self, other: &&$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 20 ] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| other |) |) |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::address::Address" ] ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_ref__alloy_primitives_bits_address_Address_for_array_Usize_20_u8. + + Module Impl_core_cmp_PartialOrd_slice_u8_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_slice_u8_for_alloy_primitives_bits_address_Address. + + Module Impl_core_cmp_PartialOrd_alloy_primitives_bits_address_Address_for_slice_u8. + Definition Self : Ty.t := Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ]. + + (* + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::address::Address" ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_alloy_primitives_bits_address_Address_for_slice_u8. + + Module Impl_core_cmp_PartialOrd_ref__slice_u8_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* + fn $fn(&self, other: &&$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, *other) + } + *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.deref (| M.read (| other |) |) |) |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_ref__slice_u8_for_alloy_primitives_bits_address_Address. + + Module Impl_core_cmp_PartialOrd_alloy_primitives_bits_address_Address_for_ref__slice_u8. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ]. + + (* + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn( *self, &other.0 $([$e])?) + } + *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::address::Address" ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_alloy_primitives_bits_address_Address_for_ref__slice_u8. + + Module Impl_core_cmp_PartialOrd_slice_u8_for_ref__alloy_primitives_bits_address_Address. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::address::Address" ]. + + (* + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_slice_u8_for_ref__alloy_primitives_bits_address_Address. + + Module Impl_core_cmp_PartialOrd_ref__alloy_primitives_bits_address_Address_for_slice_u8. + Definition Self : Ty.t := Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ]. + + (* + fn $fn(&self, other: &&$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| other |) |) |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::address::Address" ] ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_ref__alloy_primitives_bits_address_Address_for_slice_u8. + + Module Impl_const_hex_traits_FromHex_for_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* type Error = $crate::hex::FromHexError; *) + Definition _Error : Ty.t := Ty.path "const_hex::error::FromHexError". + + (* + fn from_hex>(hex: T) -> Result { + $crate::hex::decode_to_array(hex).map(Self::new) + } + *) + Definition from_hex (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ hex ] => + ltac:(M.monadic + (let hex := M.alloc (| hex |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::bits::address::Address"; + Ty.path "const_hex::error::FromHexError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ]; + Ty.path "const_hex::error::FromHexError" + ], + "map", + [], + [ + Ty.path "alloy_primitives::bits::address::Address"; + Ty.function + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ] + ] + (Ty.path "alloy_primitives::bits::address::Address") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 20 ] + [ Ty.path "u8" ]; + Ty.path "const_hex::error::FromHexError" + ], + M.get_function (| + "const_hex::decode_to_array", + [ Value.Integer IntegerKind.Usize 20 ], + [ T ] + |), + [ M.read (| hex |) ] + |); + M.get_associated_function (| + Ty.path "alloy_primitives::bits::address::Address", + "new", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "const_hex::traits::FromHex" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("from_hex", InstanceField.Method from_hex) ]. + End Impl_const_hex_traits_FromHex_for_alloy_primitives_bits_address_Address. + + Module Impl_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::address::Address". + + (* pub const ZERO: Self = Self($crate::FixedBytes::ZERO); *) + (* Ty.path "alloy_primitives::bits::address::Address" *) + Definition value_ZERO : Value.t := + M.run + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "alloy_primitives::bits::address::Address" + [ M.read (| M.get_constant "alloy_primitives::bits::fixed::ZERO" |) ] + |))). + + Global Instance AssociatedConstant_value_ZERO : + M.IsAssociatedConstant.Trait Self "value_ZERO" value_ZERO. + Admitted. + Global Typeclasses Opaque value_ZERO. + + (* + pub const fn new(bytes: [u8; $n]) -> Self { + Self($crate::FixedBytes(bytes)) + } + *) + Definition new (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ bytes ] => + ltac:(M.monadic + (let bytes := M.alloc (| bytes |) in + Value.StructTuple + "alloy_primitives::bits::address::Address" + [ Value.StructTuple "alloy_primitives::bits::fixed::FixedBytes" [ M.read (| bytes |) ] + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : M.IsAssociatedFunction.Trait Self "new" new. + Admitted. + Global Typeclasses Opaque new. + + (* + pub const fn with_last_byte(x: u8) -> Self { + Self($crate::FixedBytes::with_last_byte(x)) + } + *) + Definition with_last_byte (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ x ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + Value.StructTuple + "alloy_primitives::bits::address::Address" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + "with_last_byte", + [], + [] + |), + [ M.read (| x |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_with_last_byte : + M.IsAssociatedFunction.Trait Self "with_last_byte" with_last_byte. + Admitted. + Global Typeclasses Opaque with_last_byte. + + (* + pub const fn repeat_byte(byte: u8) -> Self { + Self($crate::FixedBytes::repeat_byte(byte)) + } + *) + Definition repeat_byte (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ byte ] => + ltac:(M.monadic + (let byte := M.alloc (| byte |) in + Value.StructTuple + "alloy_primitives::bits::address::Address" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + "repeat_byte", + [], + [] + |), + [ M.read (| byte |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_repeat_byte : + M.IsAssociatedFunction.Trait Self "repeat_byte" repeat_byte. + Admitted. + Global Typeclasses Opaque repeat_byte. + + (* + pub const fn len_bytes() -> usize { + $n + } + *) + Definition len_bytes (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => ltac:(M.monadic (Value.Integer IntegerKind.Usize 20)) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_len_bytes : + M.IsAssociatedFunction.Trait Self "len_bytes" len_bytes. + Admitted. + Global Typeclasses Opaque len_bytes. + + (* + pub fn from_slice(src: &[u8]) -> Self { + match Self::try_from(src) { + Ok(x) => x, + Err(_) => panic!("cannot convert a slice of length {} to {}", src.len(), stringify!($name)), + } + } + *) + Definition from_slice (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ src ] => + ltac:(M.monadic + (let src := M.alloc (| src |) in + M.read (| + M.match_operator (| + Some (Ty.path "alloy_primitives::bits::address::Address"), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::bits::address::Address"; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "alloy_primitives::bits::address::Address", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ], + "try_from", + [], + [] + |), + [ M.read (| src |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::result::Result::Ok", + 0 + |) in + let x := M.copy (| γ0_0 |) in + x)); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::result::Result::Err", + 0 + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "cannot convert a slice of length " |); + mk_str (| " to Address" |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "u8" ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| src |) |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_slice : + M.IsAssociatedFunction.Trait Self "from_slice" from_slice. + Admitted. + Global Typeclasses Opaque from_slice. + + (* + pub fn left_padding_from(value: &[u8]) -> Self { + Self($crate::FixedBytes::left_padding_from(value)) + } + *) + Definition left_padding_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::address::Address" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + "left_padding_from", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| value |) |) |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_left_padding_from : + M.IsAssociatedFunction.Trait Self "left_padding_from" left_padding_from. + Admitted. + Global Typeclasses Opaque left_padding_from. + + (* + pub fn right_padding_from(value: &[u8]) -> Self { + Self($crate::FixedBytes::right_padding_from(value)) + } + *) + Definition right_padding_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::address::Address" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + "right_padding_from", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| value |) |) |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_right_padding_from : + M.IsAssociatedFunction.Trait Self "right_padding_from" right_padding_from. + Admitted. + Global Typeclasses Opaque right_padding_from. + + (* + pub const fn into_array(self) -> [u8; $n] { + self.0 .0 + } + *) + Definition into_array (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_tuple_field (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::address::Address", + 0 + |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_into_array : + M.IsAssociatedFunction.Trait Self "into_array" into_array. + Admitted. + Global Typeclasses Opaque into_array. + + (* + pub fn covers(&self, b: &Self) -> bool { + &( *b & *self) == b + } + *) + Definition covers (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; b ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let b := M.alloc (| b |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::address::Address" ], + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::address::Address" ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::bits::address::Address", + M.get_trait_method (| + "core::ops::bit::BitAnd", + Ty.path "alloy_primitives::bits::address::Address", + [], + [ Ty.path "alloy_primitives::bits::address::Address" ], + "bitand", + [], + [] + |), + [ + M.read (| M.deref (| M.read (| b |) |) |); + M.read (| M.deref (| M.read (| self |) |) |) + ] + |) + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, b |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_covers : M.IsAssociatedFunction.Trait Self "covers" covers. + Admitted. + Global Typeclasses Opaque covers. + + (* + pub const fn const_eq(&self, other: &Self) -> bool { + self.0.const_eq(&other.0) + } + *) + Definition const_eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + "const_eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::address::Address", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_const_eq : + M.IsAssociatedFunction.Trait Self "const_eq" const_eq. + Admitted. + Global Typeclasses Opaque const_eq. + + (* + pub const fn bit_and(self, rhs: Self) -> Self { + Self(self.0.bit_and(rhs.0)) + } + *) + Definition bit_and (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + Value.StructTuple + "alloy_primitives::bits::address::Address" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + "bit_and", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::address::Address", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::address::Address", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_bit_and : + M.IsAssociatedFunction.Trait Self "bit_and" bit_and. + Admitted. + Global Typeclasses Opaque bit_and. + + (* + pub const fn bit_or(self, rhs: Self) -> Self { + Self(self.0.bit_or(rhs.0)) + } + *) + Definition bit_or (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + Value.StructTuple + "alloy_primitives::bits::address::Address" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + "bit_or", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::address::Address", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::address::Address", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_bit_or : M.IsAssociatedFunction.Trait Self "bit_or" bit_or. + Admitted. + Global Typeclasses Opaque bit_or. + + (* + pub const fn bit_xor(self, rhs: Self) -> Self { + Self(self.0.bit_xor(rhs.0)) + } + *) + Definition bit_xor (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + Value.StructTuple + "alloy_primitives::bits::address::Address" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + [], + "bit_xor", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::address::Address", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::address::Address", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_bit_xor : + M.IsAssociatedFunction.Trait Self "bit_xor" bit_xor. + Admitted. + Global Typeclasses Opaque bit_xor. + End Impl_alloy_primitives_bits_address_Address. + End address. + + Module bloom. + (* StructTuple + { + name := "Bloom"; + const_params := []; + ty_params := []; + fields := + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ]; + } *) + + Module Impl_core_clone_Clone_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.deref (| M.read (| self |) |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_marker_Copy_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_default_Default_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* Default *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::bits::bloom::Bloom" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [], + "default", + [], + [] + |), + [] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_marker_StructuralPartialEq_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + Axiom Implements : + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_cmp_PartialEq_alloy_primitives_bits_bloom_Bloom_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* PartialEq *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_bits_bloom_Bloom_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_cmp_Eq_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* Eq *) + Definition assert_receiver_is_total_eq + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method assert_receiver_is_total_eq) ]. + End Impl_core_cmp_Eq_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_cmp_PartialOrd_alloy_primitives_bits_bloom_Bloom_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* PartialOrd *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_alloy_primitives_bits_bloom_Bloom_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_cmp_Ord_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* Ord *) + Definition cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "core::cmp::Ordering", + M.get_trait_method (| + "core::cmp::Ord", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [], + "cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Ord" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("cmp", InstanceField.Method cmp) ]. + End Impl_core_cmp_Ord_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_hash_Hash_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* Hash *) + Definition hash (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ __H ], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::hash::Hash" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("hash", InstanceField.Method hash) ]. + End Impl_core_hash_Hash_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_convert_AsMut_alloy_primitives_bits_fixed_FixedBytes_Usize_256_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* $crate::private::derive_more::AsMut *) + Definition as_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::AsMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ] + Self + (* Instance *) [ ("as_mut", InstanceField.Method as_mut) ]. + End Impl_core_convert_AsMut_alloy_primitives_bits_fixed_FixedBytes_Usize_256_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_convert_AsRef_alloy_primitives_bits_fixed_FixedBytes_Usize_256_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* $crate::private::derive_more::AsRef *) + Definition as_ref (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::AsRef" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ] + Self + (* Instance *) [ ("as_ref", InstanceField.Method as_ref) ]. + End Impl_core_convert_AsRef_alloy_primitives_bits_fixed_FixedBytes_Usize_256_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_ops_bit_BitAnd_alloy_primitives_bits_bloom_Bloom_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* $crate::private::derive_more::BitAnd *) + Definition _Output : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* $crate::private::derive_more::BitAnd *) + Definition bitand (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + Value.StructTuple + "alloy_primitives::bits::bloom::Bloom" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + M.get_trait_method (| + "core::ops::bit::BitAnd", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ], + "bitand", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::bit::BitAnd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] + Self + (* Instance *) + [ ("Output", InstanceField.Ty _Output); ("bitand", InstanceField.Method bitand) ]. + End Impl_core_ops_bit_BitAnd_alloy_primitives_bits_bloom_Bloom_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_ops_bit_BitAndAssign_alloy_primitives_bits_bloom_Bloom_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* $crate::private::derive_more::BitAndAssign *) + Definition bitand_assign (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::bit::BitAndAssign", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ], + "bitand_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::bit::BitAndAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] + Self + (* Instance *) [ ("bitand_assign", InstanceField.Method bitand_assign) ]. + End Impl_core_ops_bit_BitAndAssign_alloy_primitives_bits_bloom_Bloom_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_ops_bit_BitOr_alloy_primitives_bits_bloom_Bloom_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* $crate::private::derive_more::BitOr *) + Definition _Output : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* $crate::private::derive_more::BitOr *) + Definition bitor (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + Value.StructTuple + "alloy_primitives::bits::bloom::Bloom" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + M.get_trait_method (| + "core::ops::bit::BitOr", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ], + "bitor", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::bit::BitOr" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] + Self + (* Instance *) + [ ("Output", InstanceField.Ty _Output); ("bitor", InstanceField.Method bitor) ]. + End Impl_core_ops_bit_BitOr_alloy_primitives_bits_bloom_Bloom_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_ops_bit_BitOrAssign_alloy_primitives_bits_bloom_Bloom_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* $crate::private::derive_more::BitOrAssign *) + Definition bitor_assign (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::bit::BitOrAssign", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ], + "bitor_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::bit::BitOrAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] + Self + (* Instance *) [ ("bitor_assign", InstanceField.Method bitor_assign) ]. + End Impl_core_ops_bit_BitOrAssign_alloy_primitives_bits_bloom_Bloom_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_ops_bit_BitXor_alloy_primitives_bits_bloom_Bloom_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* $crate::private::derive_more::BitXor *) + Definition _Output : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* $crate::private::derive_more::BitXor *) + Definition bitxor (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + Value.StructTuple + "alloy_primitives::bits::bloom::Bloom" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + M.get_trait_method (| + "core::ops::bit::BitXor", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ], + "bitxor", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::bit::BitXor" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] + Self + (* Instance *) + [ ("Output", InstanceField.Ty _Output); ("bitxor", InstanceField.Method bitxor) ]. + End Impl_core_ops_bit_BitXor_alloy_primitives_bits_bloom_Bloom_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_ops_bit_BitXorAssign_alloy_primitives_bits_bloom_Bloom_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* $crate::private::derive_more::BitXorAssign *) + Definition bitxor_assign (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::bit::BitXorAssign", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ], + "bitxor_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::bit::BitXorAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] + Self + (* Instance *) [ ("bitxor_assign", InstanceField.Method bitxor_assign) ]. + End Impl_core_ops_bit_BitXorAssign_alloy_primitives_bits_bloom_Bloom_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_ops_bit_Not_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* $crate::private::derive_more::Not *) + Definition _Output : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* $crate::private::derive_more::Not *) + Definition not (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple + "alloy_primitives::bits::bloom::Bloom" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + M.get_trait_method (| + "core::ops::bit::Not", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [], + "not", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::bit::Not" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("Output", InstanceField.Ty _Output); ("not", InstanceField.Method not) ]. + End Impl_core_ops_bit_Not_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_ops_deref_Deref_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* $crate::private::derive_more::Deref *) + Definition _Target : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + []. + + (* $crate::private::derive_more::Deref *) + Definition deref (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::deref::Deref" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("Target", InstanceField.Ty _Target); ("deref", InstanceField.Method deref) ]. + End Impl_core_ops_deref_Deref_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_ops_deref_DerefMut_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* $crate::private::derive_more::DerefMut *) + Definition deref_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::deref::DerefMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("deref_mut", InstanceField.Method deref_mut) ]. + End Impl_core_ops_deref_DerefMut_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_256_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* $crate::private::derive_more::From *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple "alloy_primitives::bits::bloom::Bloom" [ M.read (| value |) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_256_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_str_traits_FromStr_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* $crate::private::derive_more::FromStr *) + Definition _Err : Ty.t := + Ty.associated_in_trait + "core::str::traits::FromStr" + [] + [] + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + []) + "Err". + + (* $crate::private::derive_more::FromStr *) + Definition from_str (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ src ] => + ltac:(M.monadic + (let src := M.alloc (| src |) in + M.catch_return (| + ltac:(M.monadic + (Value.StructTuple + "core::result::Result::Ok" + [ + Value.StructTuple + "alloy_primitives::bits::bloom::Bloom" + [ + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "const_hex::error::FromHexError" + ]; + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + []; + Ty.path "const_hex::error::FromHexError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + []; + Ty.path "const_hex::error::FromHexError" + ], + M.get_trait_method (| + "core::str::traits::FromStr", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [], + "from_str", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| src |) |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::bits::bloom::Bloom"; + Ty.path "const_hex::error::FromHexError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::bits::bloom::Bloom"; + Ty.path "const_hex::error::FromHexError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "const_hex::error::FromHexError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) + ] + ])) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::str::traits::FromStr" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("Err", InstanceField.Ty _Err); ("from_str", InstanceField.Method from_str) ]. + End Impl_core_str_traits_FromStr_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_ops_index_Index_where_core_ops_index_Index_alloy_primitives_bits_fixed_FixedBytes_Usize_256___IdxT___IdxT_for_alloy_primitives_bits_bloom_Bloom. + Definition Self (__IdxT : Ty.t) : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* $crate::private::derive_more::Index *) + Definition _Output (__IdxT : Ty.t) : Ty.t := + Ty.associated_in_trait + "core::ops::index::Index" + [] + [ __IdxT ] + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + []) + "Output". + + (* $crate::private::derive_more::Index *) + Definition index (__IdxT : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self __IdxT in + match ε, τ, α with + | [], [], [ self; idx ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let idx := M.alloc (| idx |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "core::ops::index::Index" + [] + [ __IdxT ] + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + []) + "Output" + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ __IdxT ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |); + M.read (| idx |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (__IdxT : Ty.t), + M.IsTraitInstance + "core::ops::index::Index" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ __IdxT ] + (Self __IdxT) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output __IdxT)); + ("index", InstanceField.Method (index __IdxT)) + ]. + End Impl_core_ops_index_Index_where_core_ops_index_Index_alloy_primitives_bits_fixed_FixedBytes_Usize_256___IdxT___IdxT_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_ops_index_IndexMut_where_core_ops_index_IndexMut_alloy_primitives_bits_fixed_FixedBytes_Usize_256___IdxT___IdxT_for_alloy_primitives_bits_bloom_Bloom. + Definition Self (__IdxT : Ty.t) : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* $crate::private::derive_more::IndexMut *) + Definition index_mut + (__IdxT : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self __IdxT in + match ε, τ, α with + | [], [], [ self; idx ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let idx := M.alloc (| idx |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.associated_in_trait + "core::ops::index::Index" + [] + [ __IdxT ] + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + []) + "Output" + ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ __IdxT ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |); + M.read (| idx |) + ] + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (__IdxT : Ty.t), + M.IsTraitInstance + "core::ops::index::IndexMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ __IdxT ] + (Self __IdxT) + (* Instance *) [ ("index_mut", InstanceField.Method (index_mut __IdxT)) ]. + End Impl_core_ops_index_IndexMut_where_core_ops_index_IndexMut_alloy_primitives_bits_fixed_FixedBytes_Usize_256___IdxT___IdxT_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_convert_From_alloy_primitives_bits_bloom_Bloom_for_alloy_primitives_bits_fixed_FixedBytes_Usize_256. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + []. + + (* $crate::private::derive_more::Into *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + M.get_trait_method (| + "core::convert::From", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ], + "from", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_bloom_Bloom_for_alloy_primitives_bits_fixed_FixedBytes_Usize_256. + + Module Impl_core_iter_traits_collect_IntoIterator_where_core_iter_traits_collect_IntoIterator_alloy_primitives_bits_fixed_FixedBytes_Usize_256_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* $crate::private::derive_more::IntoIterator *) + Definition _Item : Ty.t := + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + []) + "Item". + + (* $crate::private::derive_more::IntoIterator *) + Definition _IntoIter : Ty.t := + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + []) + "IntoIter". + + (* $crate::private::derive_more::IntoIterator *) + Definition into_iter (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::iter::traits::collect::IntoIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("Item", InstanceField.Ty _Item); + ("IntoIter", InstanceField.Ty _IntoIter); + ("into_iter", InstanceField.Method into_iter) + ]. + End Impl_core_iter_traits_collect_IntoIterator_where_core_iter_traits_collect_IntoIterator_alloy_primitives_bits_fixed_FixedBytes_Usize_256_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_iter_traits_collect_IntoIterator_where_core_iter_traits_collect_IntoIterator_ref__alloy_primitives_bits_fixed_FixedBytes_Usize_256_for_ref__alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]. + + (* $crate::private::derive_more::IntoIterator *) + Definition _Item : Ty.t := + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ]) + "Item". + + (* $crate::private::derive_more::IntoIterator *) + Definition _IntoIter : Ty.t := + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ]) + "IntoIter". + + (* $crate::private::derive_more::IntoIterator *) + Definition into_iter (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ]) + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::iter::traits::collect::IntoIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("Item", InstanceField.Ty _Item); + ("IntoIter", InstanceField.Ty _IntoIter); + ("into_iter", InstanceField.Method into_iter) + ]. + End Impl_core_iter_traits_collect_IntoIterator_where_core_iter_traits_collect_IntoIterator_ref__alloy_primitives_bits_fixed_FixedBytes_Usize_256_for_ref__alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_iter_traits_collect_IntoIterator_where_core_iter_traits_collect_IntoIterator_ref_mut_alloy_primitives_bits_fixed_FixedBytes_Usize_256_for_ref_mut_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := + Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]. + + (* $crate::private::derive_more::IntoIterator *) + Definition _Item : Ty.t := + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ]) + "Item". + + (* $crate::private::derive_more::IntoIterator *) + Definition _IntoIter : Ty.t := + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ]) + "IntoIter". + + (* $crate::private::derive_more::IntoIterator *) + Definition into_iter (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ]) + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::iter::traits::collect::IntoIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("Item", InstanceField.Ty _Item); + ("IntoIter", InstanceField.Ty _IntoIter); + ("into_iter", InstanceField.Method into_iter) + ]. + End Impl_core_iter_traits_collect_IntoIterator_where_core_iter_traits_collect_IntoIterator_ref_mut_alloy_primitives_bits_fixed_FixedBytes_Usize_256_for_ref_mut_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_fmt_LowerHex_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* $crate::private::derive_more::LowerHex *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; __derive_more_f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __derive_more_f := M.alloc (| __derive_more_f |) in + M.read (| + let~ _0 : + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::LowerHex", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| _0 |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| __derive_more_f |) |) |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::LowerHex" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_LowerHex_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_fmt_UpperHex_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* $crate::private::derive_more::UpperHex *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; __derive_more_f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __derive_more_f := M.alloc (| __derive_more_f |) in + M.read (| + let~ _0 : + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::UpperHex", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| _0 |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| __derive_more_f |) |) |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::UpperHex" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_UpperHex_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_fmt_Display_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* $crate::private::derive_more::Display *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; __derive_more_f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __derive_more_f := M.alloc (| __derive_more_f |) in + M.read (| + let~ _0 : + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::Display", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| _0 |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| __derive_more_f |) |) |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Display" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Display_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_convert_From_array_Usize_256_u8_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + fn from(value: [u8; $n]) -> Self { + Self($crate::FixedBytes(value)) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::bloom::Bloom" + [ Value.StructTuple "alloy_primitives::bits::fixed::FixedBytes" [ M.read (| value |) ] + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_array_Usize_256_u8_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_convert_From_alloy_primitives_bits_bloom_Bloom_for_array_Usize_256_u8. + Definition Self : Ty.t := + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ]. + + (* + fn from(value: $name) -> Self { + value.0 .0 + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.read (| + M.SubPointer.get_struct_tuple_field (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::bloom::Bloom", + 0 + |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_bloom_Bloom_for_array_Usize_256_u8. + + Module Impl_core_convert_From_ref__array_Usize_256_u8_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + fn from(value: &'a [u8; $n]) -> Self { + Self($crate::FixedBytes( *value)) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::bloom::Bloom" + [ + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ M.read (| M.deref (| M.read (| value |) |) |) ] + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ] + ] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref__array_Usize_256_u8_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_convert_From_ref_mut_array_Usize_256_u8_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + fn from(value: &'a mut [u8; $n]) -> Self { + Self($crate::FixedBytes( *value)) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::bloom::Bloom" + [ + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ M.read (| M.deref (| M.read (| value |) |) |) ] + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ] + ] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref_mut_array_Usize_256_u8_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_convert_TryFrom_ref__slice_u8_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* type Error = $crate::private::core::array::TryFromSliceError; *) + Definition _Error : Ty.t := Ty.path "core::array::TryFromSliceError". + + (* + fn try_from(slice: &[u8]) -> Result { + <&Self as $crate::private::TryFrom<&[u8]>>::try_from(slice).copied() + } + *) + Definition try_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ slice ] => + ltac:(M.monadic + (let slice := M.alloc (| slice |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::bits::bloom::Bloom"; + Ty.path "core::array::TryFromSliceError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]; + Ty.path "core::array::TryFromSliceError" + ], + "copied", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ], + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ], + "try_from", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| slice |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("try_from", InstanceField.Method try_from) ]. + End Impl_core_convert_TryFrom_ref__slice_u8_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_convert_TryFrom_ref_mut_slice_u8_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* type Error = $crate::private::core::array::TryFromSliceError; *) + Definition _Error : Ty.t := Ty.path "core::array::TryFromSliceError". + + (* + fn try_from(slice: &mut [u8]) -> Result { + >::try_from(&*slice) + } + *) + Definition try_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ slice ] => + ltac:(M.monadic + (let slice := M.alloc (| slice |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::bits::bloom::Bloom"; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "alloy_primitives::bits::bloom::Bloom", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ], + "try_from", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| slice |) |) |) |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("try_from", InstanceField.Method try_from) ]. + End Impl_core_convert_TryFrom_ref_mut_slice_u8_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_convert_TryFrom_ref__slice_u8_for_ref__alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]. + + (* type Error = $crate::private::core::array::TryFromSliceError; *) + Definition _Error : Ty.t := Ty.path "core::array::TryFromSliceError". + + (* + fn try_from(slice: &'a [u8]) -> Result<&'a $name, Self::Error> { + // SAFETY: `$name` is `repr(transparent)` for `FixedBytes<$n>` + // and consequently `[u8; $n]` + <&[u8; $n] as $crate::private::TryFrom<&[u8]>>::try_from(slice) + .map(|array_ref| unsafe { $crate::private::core::mem::transmute(array_ref) }) + } + *) + Definition try_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ slice ] => + ltac:(M.monadic + (let slice := M.alloc (| slice |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "map", + [], + [ + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ] + ] + ] + (Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ], + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ], + "try_from", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| slice |) |) |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ] + ] + ] + (Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::bloom::Bloom" ])), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let array_ref := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::bloom::Bloom" ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] + ] + |), + [ M.read (| array_ref |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("try_from", InstanceField.Method try_from) ]. + End Impl_core_convert_TryFrom_ref__slice_u8_for_ref__alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_convert_TryFrom_ref_mut_slice_u8_for_ref_mut_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := + Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]. + + (* type Error = $crate::private::core::array::TryFromSliceError; *) + Definition _Error : Ty.t := Ty.path "core::array::TryFromSliceError". + + (* + fn try_from(slice: &'a mut [u8]) -> Result<&'a mut $name, Self::Error> { + // SAFETY: `$name` is `repr(transparent)` for `FixedBytes<$n>` + // and consequently `[u8; $n]` + <&mut [u8; $n] as $crate::private::TryFrom<&mut [u8]>>::try_from(slice) + .map(|array_ref| unsafe { $crate::private::core::mem::transmute(array_ref) }) + } + *) + Definition try_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ slice ] => + ltac:(M.monadic + (let slice := M.alloc (| slice |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "map", + [], + [ + Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ] + ] + ] + (Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ], + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ], + "try_from", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| slice |) |) |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ] + ] + ] + (Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::bloom::Bloom" ])), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let array_ref := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::bloom::Bloom" ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] + ] + |), + [ M.read (| array_ref |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("try_from", InstanceField.Method try_from) ]. + End Impl_core_convert_TryFrom_ref_mut_slice_u8_for_ref_mut_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_convert_AsRef_array_Usize_256_u8_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + fn as_ref(&self) -> &[u8; $n] { + &self.0 .0 + } + *) + Definition as_ref (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::AsRef" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("as_ref", InstanceField.Method as_ref) ]. + End Impl_core_convert_AsRef_array_Usize_256_u8_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_convert_AsMut_array_Usize_256_u8_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + fn as_mut(&mut self) -> &mut [u8; $n] { + &mut self.0 .0 + } + *) + Definition as_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::AsMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("as_mut", InstanceField.Method as_mut) ]. + End Impl_core_convert_AsMut_array_Usize_256_u8_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_convert_AsRef_slice_u8_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + fn as_ref(&self) -> &[u8] { + &self.0 .0 + } + *) + Definition as_ref (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::AsRef" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("as_ref", InstanceField.Method as_ref) ]. + End Impl_core_convert_AsRef_slice_u8_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_convert_AsMut_slice_u8_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + fn as_mut(&mut self) -> &mut [u8] { + &mut self.0 .0 + } + *) + Definition as_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::AsMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("as_mut", InstanceField.Method as_mut) ]. + End Impl_core_convert_AsMut_slice_u8_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_fmt_Debug_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + $crate::private::core::fmt::Debug::fmt(&self.0, f) + } + *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::Debug", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_borrow_Borrow_slice_u8_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + fn borrow(&self) -> &$t { + $crate::private::Borrow::borrow(&self.0) + } + *) + Definition borrow (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow", InstanceField.Method borrow) ]. + End Impl_core_borrow_Borrow_slice_u8_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_borrow_Borrow_slice_u8_for_ref__alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]. + + (* + fn borrow(&self) -> &$t { + $crate::private::Borrow::borrow(&self.0) + } + *) + Definition borrow (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow", InstanceField.Method borrow) ]. + End Impl_core_borrow_Borrow_slice_u8_for_ref__alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_borrow_Borrow_slice_u8_for_ref_mut_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := + Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]. + + (* + fn borrow(&self) -> &$t { + $crate::private::Borrow::borrow(&self.0) + } + *) + Definition borrow (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow", InstanceField.Method borrow) ]. + End Impl_core_borrow_Borrow_slice_u8_for_ref_mut_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_borrow_Borrow_array_Usize_256_u8_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + fn borrow(&self) -> &$t { + $crate::private::Borrow::borrow(&self.0) + } + *) + Definition borrow (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow", InstanceField.Method borrow) ]. + End Impl_core_borrow_Borrow_array_Usize_256_u8_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_borrow_Borrow_array_Usize_256_u8_for_ref__alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]. + + (* + fn borrow(&self) -> &$t { + $crate::private::Borrow::borrow(&self.0) + } + *) + Definition borrow (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow", InstanceField.Method borrow) ]. + End Impl_core_borrow_Borrow_array_Usize_256_u8_for_ref__alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_borrow_Borrow_array_Usize_256_u8_for_ref_mut_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := + Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]. + + (* + fn borrow(&self) -> &$t { + $crate::private::Borrow::borrow(&self.0) + } + *) + Definition borrow (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow", InstanceField.Method borrow) ]. + End Impl_core_borrow_Borrow_array_Usize_256_u8_for_ref_mut_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_borrow_BorrowMut_slice_u8_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + fn borrow_mut(&mut self) -> &mut $t { + $crate::private::BorrowMut::borrow_mut(&mut self.0) + } + *) + Definition borrow_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::borrow::BorrowMut", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "borrow_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |) + ] + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::BorrowMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow_mut", InstanceField.Method borrow_mut) ]. + End Impl_core_borrow_BorrowMut_slice_u8_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_borrow_BorrowMut_slice_u8_for_ref_mut_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := + Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]. + + (* + fn borrow_mut(&mut self) -> &mut $t { + $crate::private::BorrowMut::borrow_mut(&mut self.0) + } + *) + Definition borrow_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::borrow::BorrowMut", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "borrow_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |) + ] + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::BorrowMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow_mut", InstanceField.Method borrow_mut) ]. + End Impl_core_borrow_BorrowMut_slice_u8_for_ref_mut_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_borrow_BorrowMut_array_Usize_256_u8_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + fn borrow_mut(&mut self) -> &mut $t { + $crate::private::BorrowMut::borrow_mut(&mut self.0) + } + *) + Definition borrow_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::borrow::BorrowMut", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ], + "borrow_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |) + ] + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::BorrowMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow_mut", InstanceField.Method borrow_mut) ]. + End Impl_core_borrow_BorrowMut_array_Usize_256_u8_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_borrow_BorrowMut_array_Usize_256_u8_for_ref_mut_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := + Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]. + + (* + fn borrow_mut(&mut self) -> &mut $t { + $crate::private::BorrowMut::borrow_mut(&mut self.0) + } + *) + Definition borrow_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::borrow::BorrowMut", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ], + "borrow_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |) + ] + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::BorrowMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow_mut", InstanceField.Method borrow_mut) ]. + End Impl_core_borrow_BorrowMut_array_Usize_256_u8_for_ref_mut_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_convert_From_ref__array_Usize_256_u8_for_ref__alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]. + + (* + fn from(value: $a) -> $b { + // SAFETY: guaranteed by caller + unsafe { $crate::private::core::mem::transmute::<$a, $b>(value) } + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ]; + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] + ] + |), + [ M.read (| value |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ] + ] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref__array_Usize_256_u8_for_ref__alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_convert_From_ref_mut_array_Usize_256_u8_for_ref__alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]. + + (* + fn from(value: $a) -> $b { + // SAFETY: guaranteed by caller + unsafe { $crate::private::core::mem::transmute::<$a, $b>(value) } + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ]; + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| value |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ] + ] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref_mut_array_Usize_256_u8_for_ref__alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_convert_From_ref_mut_array_Usize_256_u8_for_ref_mut_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := + Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]. + + (* + fn from(value: $a) -> $b { + // SAFETY: guaranteed by caller + unsafe { $crate::private::core::mem::transmute::<$a, $b>(value) } + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::bloom::Bloom" ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| value |) |) |) ] + |) + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ] + ] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref_mut_array_Usize_256_u8_for_ref_mut_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_convert_From_ref__alloy_primitives_bits_bloom_Bloom_for_ref__array_Usize_256_u8. + Definition Self : Ty.t := + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ] ]. + + (* + fn from(value: $a) -> $b { + // SAFETY: guaranteed by caller + unsafe { $crate::private::core::mem::transmute::<$a, $b>(value) } + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ] + ] + |), + [ M.read (| value |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref__alloy_primitives_bits_bloom_Bloom_for_ref__array_Usize_256_u8. + + Module Impl_core_convert_From_ref_mut_alloy_primitives_bits_bloom_Bloom_for_ref__array_Usize_256_u8. + Definition Self : Ty.t := + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ] ]. + + (* + fn from(value: $a) -> $b { + // SAFETY: guaranteed by caller + unsafe { $crate::private::core::mem::transmute::<$a, $b>(value) } + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ] + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| value |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref_mut_alloy_primitives_bits_bloom_Bloom_for_ref__array_Usize_256_u8. + + Module Impl_core_convert_From_ref_mut_alloy_primitives_bits_bloom_Bloom_for_ref_mut_array_Usize_256_u8. + Definition Self : Ty.t := + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ] ]. + + (* + fn from(value: $a) -> $b { + // SAFETY: guaranteed by caller + unsafe { $crate::private::core::mem::transmute::<$a, $b>(value) } + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ] + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| value |) |) |) ] + |) + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref_mut_alloy_primitives_bits_bloom_Bloom_for_ref_mut_array_Usize_256_u8. + + Module Impl_core_cmp_PartialEq_slice_u8_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_slice_u8_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_cmp_PartialEq_alloy_primitives_bits_bloom_Bloom_for_slice_u8. + Definition Self : Ty.t := Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ]. + + (* + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_bits_bloom_Bloom_for_slice_u8. + + Module Impl_core_cmp_PartialEq_ref__slice_u8_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + fn $fn(&self, other: &&$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, *other) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.deref (| M.read (| other |) |) |) |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_ref__slice_u8_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_cmp_PartialEq_alloy_primitives_bits_bloom_Bloom_for_ref__slice_u8. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ]. + + (* + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn( *self, &other.0 $([$e])?) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_bits_bloom_Bloom_for_ref__slice_u8. + + Module Impl_core_cmp_PartialEq_slice_u8_for_ref__alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]. + + (* + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_slice_u8_for_ref__alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_cmp_PartialEq_ref__alloy_primitives_bits_bloom_Bloom_for_slice_u8. + Definition Self : Ty.t := Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ]. + + (* + fn $fn(&self, other: &&$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| other |) |) |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_ref__alloy_primitives_bits_bloom_Bloom_for_slice_u8. + + Module Impl_core_cmp_PartialEq_array_Usize_256_u8_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_array_Usize_256_u8_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_cmp_PartialEq_alloy_primitives_bits_bloom_Bloom_for_array_Usize_256_u8. + Definition Self : Ty.t := + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ]. + + (* + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_bits_bloom_Bloom_for_array_Usize_256_u8. + + Module Impl_core_cmp_PartialEq_ref__array_Usize_256_u8_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + fn $fn(&self, other: &&$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, *other) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.deref (| M.read (| other |) |) |) |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ] + ] + ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_ref__array_Usize_256_u8_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_cmp_PartialEq_alloy_primitives_bits_bloom_Bloom_for_ref__array_Usize_256_u8. + Definition Self : Ty.t := + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ] ]. + + (* + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn( *self, &other.0 $([$e])?) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_bits_bloom_Bloom_for_ref__array_Usize_256_u8. + + Module Impl_core_cmp_PartialEq_array_Usize_256_u8_for_ref__alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]. + + (* + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_array_Usize_256_u8_for_ref__alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_cmp_PartialEq_ref__alloy_primitives_bits_bloom_Bloom_for_array_Usize_256_u8. + Definition Self : Ty.t := + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ]. + + (* + fn $fn(&self, other: &&$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 256 ] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| other |) |) |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_ref__alloy_primitives_bits_bloom_Bloom_for_array_Usize_256_u8. + + Module Impl_core_cmp_PartialOrd_slice_u8_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_slice_u8_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_cmp_PartialOrd_alloy_primitives_bits_bloom_Bloom_for_slice_u8. + Definition Self : Ty.t := Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ]. + + (* + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_alloy_primitives_bits_bloom_Bloom_for_slice_u8. + + Module Impl_core_cmp_PartialOrd_ref__slice_u8_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* + fn $fn(&self, other: &&$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, *other) + } + *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.deref (| M.read (| other |) |) |) |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_ref__slice_u8_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_cmp_PartialOrd_alloy_primitives_bits_bloom_Bloom_for_ref__slice_u8. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ]. + + (* + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn( *self, &other.0 $([$e])?) + } + *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_alloy_primitives_bits_bloom_Bloom_for_ref__slice_u8. + + Module Impl_core_cmp_PartialOrd_slice_u8_for_ref__alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ]. + + (* + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_slice_u8_for_ref__alloy_primitives_bits_bloom_Bloom. + + Module Impl_core_cmp_PartialOrd_ref__alloy_primitives_bits_bloom_Bloom_for_slice_u8. + Definition Self : Ty.t := Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ]. + + (* + fn $fn(&self, other: &&$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| other |) |) |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_ref__alloy_primitives_bits_bloom_Bloom_for_slice_u8. + + Module Impl_const_hex_traits_FromHex_for_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* type Error = $crate::hex::FromHexError; *) + Definition _Error : Ty.t := Ty.path "const_hex::error::FromHexError". + + (* + fn from_hex>(hex: T) -> Result { + $crate::hex::decode_to_array(hex).map(Self::new) + } + *) + Definition from_hex (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ hex ] => + ltac:(M.monadic + (let hex := M.alloc (| hex |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::bits::bloom::Bloom"; + Ty.path "const_hex::error::FromHexError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ]; + Ty.path "const_hex::error::FromHexError" + ], + "map", + [], + [ + Ty.path "alloy_primitives::bits::bloom::Bloom"; + Ty.function + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ] + ] + (Ty.path "alloy_primitives::bits::bloom::Bloom") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 256 ] + [ Ty.path "u8" ]; + Ty.path "const_hex::error::FromHexError" + ], + M.get_function (| + "const_hex::decode_to_array", + [ Value.Integer IntegerKind.Usize 256 ], + [ T ] + |), + [ M.read (| hex |) ] + |); + M.get_associated_function (| + Ty.path "alloy_primitives::bits::bloom::Bloom", + "new", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "const_hex::traits::FromHex" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("from_hex", InstanceField.Method from_hex) ]. + End Impl_const_hex_traits_FromHex_for_alloy_primitives_bits_bloom_Bloom. + + Module Impl_alloy_primitives_bits_bloom_Bloom. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::bloom::Bloom". + + (* pub const ZERO: Self = Self($crate::FixedBytes::ZERO); *) + (* Ty.path "alloy_primitives::bits::bloom::Bloom" *) + Definition value_ZERO : Value.t := + M.run + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "alloy_primitives::bits::bloom::Bloom" + [ M.read (| M.get_constant "alloy_primitives::bits::fixed::ZERO" |) ] + |))). + + Global Instance AssociatedConstant_value_ZERO : + M.IsAssociatedConstant.Trait Self "value_ZERO" value_ZERO. + Admitted. + Global Typeclasses Opaque value_ZERO. + + (* + pub const fn new(bytes: [u8; $n]) -> Self { + Self($crate::FixedBytes(bytes)) + } + *) + Definition new (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ bytes ] => + ltac:(M.monadic + (let bytes := M.alloc (| bytes |) in + Value.StructTuple + "alloy_primitives::bits::bloom::Bloom" + [ Value.StructTuple "alloy_primitives::bits::fixed::FixedBytes" [ M.read (| bytes |) ] + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : M.IsAssociatedFunction.Trait Self "new" new. + Admitted. + Global Typeclasses Opaque new. + + (* + pub const fn with_last_byte(x: u8) -> Self { + Self($crate::FixedBytes::with_last_byte(x)) + } + *) + Definition with_last_byte (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ x ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + Value.StructTuple + "alloy_primitives::bits::bloom::Bloom" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + "with_last_byte", + [], + [] + |), + [ M.read (| x |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_with_last_byte : + M.IsAssociatedFunction.Trait Self "with_last_byte" with_last_byte. + Admitted. + Global Typeclasses Opaque with_last_byte. + + (* + pub const fn repeat_byte(byte: u8) -> Self { + Self($crate::FixedBytes::repeat_byte(byte)) + } + *) + Definition repeat_byte (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ byte ] => + ltac:(M.monadic + (let byte := M.alloc (| byte |) in + Value.StructTuple + "alloy_primitives::bits::bloom::Bloom" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + "repeat_byte", + [], + [] + |), + [ M.read (| byte |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_repeat_byte : + M.IsAssociatedFunction.Trait Self "repeat_byte" repeat_byte. + Admitted. + Global Typeclasses Opaque repeat_byte. + + (* + pub const fn len_bytes() -> usize { + $n + } + *) + Definition len_bytes (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => ltac:(M.monadic (Value.Integer IntegerKind.Usize 256)) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_len_bytes : + M.IsAssociatedFunction.Trait Self "len_bytes" len_bytes. + Admitted. + Global Typeclasses Opaque len_bytes. + + (* + pub fn from_slice(src: &[u8]) -> Self { + match Self::try_from(src) { + Ok(x) => x, + Err(_) => panic!("cannot convert a slice of length {} to {}", src.len(), stringify!($name)), + } + } + *) + Definition from_slice (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ src ] => + ltac:(M.monadic + (let src := M.alloc (| src |) in + M.read (| + M.match_operator (| + Some (Ty.path "alloy_primitives::bits::bloom::Bloom"), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::bits::bloom::Bloom"; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "alloy_primitives::bits::bloom::Bloom", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ], + "try_from", + [], + [] + |), + [ M.read (| src |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::result::Result::Ok", + 0 + |) in + let x := M.copy (| γ0_0 |) in + x)); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::result::Result::Err", + 0 + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "cannot convert a slice of length " |); + mk_str (| " to Bloom" |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "u8" ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| src |) |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_slice : + M.IsAssociatedFunction.Trait Self "from_slice" from_slice. + Admitted. + Global Typeclasses Opaque from_slice. + + (* + pub fn left_padding_from(value: &[u8]) -> Self { + Self($crate::FixedBytes::left_padding_from(value)) + } + *) + Definition left_padding_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::bloom::Bloom" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + "left_padding_from", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| value |) |) |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_left_padding_from : + M.IsAssociatedFunction.Trait Self "left_padding_from" left_padding_from. + Admitted. + Global Typeclasses Opaque left_padding_from. + + (* + pub fn right_padding_from(value: &[u8]) -> Self { + Self($crate::FixedBytes::right_padding_from(value)) + } + *) + Definition right_padding_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::bloom::Bloom" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + "right_padding_from", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| value |) |) |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_right_padding_from : + M.IsAssociatedFunction.Trait Self "right_padding_from" right_padding_from. + Admitted. + Global Typeclasses Opaque right_padding_from. + + (* + pub const fn into_array(self) -> [u8; $n] { + self.0 .0 + } + *) + Definition into_array (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_tuple_field (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::bloom::Bloom", + 0 + |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_into_array : + M.IsAssociatedFunction.Trait Self "into_array" into_array. + Admitted. + Global Typeclasses Opaque into_array. + + (* + pub fn covers(&self, b: &Self) -> bool { + &( *b & *self) == b + } + *) + Definition covers (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; b ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let b := M.alloc (| b |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ], + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::bloom::Bloom" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::bits::bloom::Bloom", + M.get_trait_method (| + "core::ops::bit::BitAnd", + Ty.path "alloy_primitives::bits::bloom::Bloom", + [], + [ Ty.path "alloy_primitives::bits::bloom::Bloom" ], + "bitand", + [], + [] + |), + [ + M.read (| M.deref (| M.read (| b |) |) |); + M.read (| M.deref (| M.read (| self |) |) |) + ] + |) + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, b |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_covers : M.IsAssociatedFunction.Trait Self "covers" covers. + Admitted. + Global Typeclasses Opaque covers. + + (* + pub const fn const_eq(&self, other: &Self) -> bool { + self.0.const_eq(&other.0) + } + *) + Definition const_eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + "const_eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_const_eq : + M.IsAssociatedFunction.Trait Self "const_eq" const_eq. + Admitted. + Global Typeclasses Opaque const_eq. + + (* + pub const fn bit_and(self, rhs: Self) -> Self { + Self(self.0.bit_and(rhs.0)) + } + *) + Definition bit_and (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + Value.StructTuple + "alloy_primitives::bits::bloom::Bloom" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + "bit_and", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_bit_and : + M.IsAssociatedFunction.Trait Self "bit_and" bit_and. + Admitted. + Global Typeclasses Opaque bit_and. + + (* + pub const fn bit_or(self, rhs: Self) -> Self { + Self(self.0.bit_or(rhs.0)) + } + *) + Definition bit_or (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + Value.StructTuple + "alloy_primitives::bits::bloom::Bloom" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + "bit_or", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_bit_or : M.IsAssociatedFunction.Trait Self "bit_or" bit_or. + Admitted. + Global Typeclasses Opaque bit_or. + + (* + pub const fn bit_xor(self, rhs: Self) -> Self { + Self(self.0.bit_xor(rhs.0)) + } + *) + Definition bit_xor (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + Value.StructTuple + "alloy_primitives::bits::bloom::Bloom" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 256 ] + [], + "bit_xor", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::bloom::Bloom", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_bit_xor : + M.IsAssociatedFunction.Trait Self "bit_xor" bit_xor. + Admitted. + Global Typeclasses Opaque bit_xor. + End Impl_alloy_primitives_bits_bloom_Bloom. + End bloom. + + Module fixed. + Module Impl_core_borrow_Borrow_slice_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn borrow(&self) -> &$t { + $crate::private::Borrow::borrow(&self.0) + } + *) + Definition borrow (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + (Self N) + (* Instance *) [ ("borrow", InstanceField.Method (borrow N)) ]. + End Impl_core_borrow_Borrow_slice_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_borrow_Borrow_slice_u8_for_ref__alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]. + + (* + fn borrow(&self) -> &$t { + $crate::private::Borrow::borrow(&self.0) + } + *) + Definition borrow (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + (Self N) + (* Instance *) [ ("borrow", InstanceField.Method (borrow N)) ]. + End Impl_core_borrow_Borrow_slice_u8_for_ref__alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_borrow_Borrow_slice_u8_for_ref_mut_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]. + + (* + fn borrow(&self) -> &$t { + $crate::private::Borrow::borrow(&self.0) + } + *) + Definition borrow (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + (Self N) + (* Instance *) [ ("borrow", InstanceField.Method (borrow N)) ]. + End Impl_core_borrow_Borrow_slice_u8_for_ref_mut_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_borrow_Borrow_array_N_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn borrow(&self) -> &$t { + $crate::private::Borrow::borrow(&self.0) + } + *) + Definition borrow (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] + (Self N) + (* Instance *) [ ("borrow", InstanceField.Method (borrow N)) ]. + End Impl_core_borrow_Borrow_array_N_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_borrow_Borrow_array_N_u8_for_ref__alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]. + + (* + fn borrow(&self) -> &$t { + $crate::private::Borrow::borrow(&self.0) + } + *) + Definition borrow (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] + (Self N) + (* Instance *) [ ("borrow", InstanceField.Method (borrow N)) ]. + End Impl_core_borrow_Borrow_array_N_u8_for_ref__alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_borrow_Borrow_array_N_u8_for_ref_mut_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]. + + (* + fn borrow(&self) -> &$t { + $crate::private::Borrow::borrow(&self.0) + } + *) + Definition borrow (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] + (Self N) + (* Instance *) [ ("borrow", InstanceField.Method (borrow N)) ]. + End Impl_core_borrow_Borrow_array_N_u8_for_ref_mut_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_borrow_BorrowMut_slice_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn borrow_mut(&mut self) -> &mut $t { + $crate::private::BorrowMut::borrow_mut(&mut self.0) + } + *) + Definition borrow_mut + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::borrow::BorrowMut", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "borrow_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + ] + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::borrow::BorrowMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + (Self N) + (* Instance *) [ ("borrow_mut", InstanceField.Method (borrow_mut N)) ]. + End Impl_core_borrow_BorrowMut_slice_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_borrow_BorrowMut_slice_u8_for_ref_mut_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]. + + (* + fn borrow_mut(&mut self) -> &mut $t { + $crate::private::BorrowMut::borrow_mut(&mut self.0) + } + *) + Definition borrow_mut + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::borrow::BorrowMut", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "borrow_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + ] + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::borrow::BorrowMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + (Self N) + (* Instance *) [ ("borrow_mut", InstanceField.Method (borrow_mut N)) ]. + End Impl_core_borrow_BorrowMut_slice_u8_for_ref_mut_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_borrow_BorrowMut_array_N_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn borrow_mut(&mut self) -> &mut $t { + $crate::private::BorrowMut::borrow_mut(&mut self.0) + } + *) + Definition borrow_mut + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::borrow::BorrowMut", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + "borrow_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + ] + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::borrow::BorrowMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] + (Self N) + (* Instance *) [ ("borrow_mut", InstanceField.Method (borrow_mut N)) ]. + End Impl_core_borrow_BorrowMut_array_N_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_borrow_BorrowMut_array_N_u8_for_ref_mut_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]. + + (* + fn borrow_mut(&mut self) -> &mut $t { + $crate::private::BorrowMut::borrow_mut(&mut self.0) + } + *) + Definition borrow_mut + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::borrow::BorrowMut", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + "borrow_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + ] + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::borrow::BorrowMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] + (Self N) + (* Instance *) [ ("borrow_mut", InstanceField.Method (borrow_mut N)) ]. + End Impl_core_borrow_BorrowMut_array_N_u8_for_ref_mut_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_convert_From_ref__array_N_u8_for_ref__alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]. + + (* + fn from(value: $a) -> $b { + // SAFETY: guaranteed by caller + unsafe { $crate::private::core::mem::transmute::<$a, $b>(value) } + } + *) + Definition from (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ] + ] + |), + [ M.read (| value |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] ] + (Self N) + (* Instance *) [ ("from", InstanceField.Method (from N)) ]. + End Impl_core_convert_From_ref__array_N_u8_for_ref__alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_convert_From_ref_mut_array_N_u8_for_ref__alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]. + + (* + fn from(value: $a) -> $b { + // SAFETY: guaranteed by caller + unsafe { $crate::private::core::mem::transmute::<$a, $b>(value) } + } + *) + Definition from (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ] + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| value |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] ] + (Self N) + (* Instance *) [ ("from", InstanceField.Method (from N)) ]. + End Impl_core_convert_From_ref_mut_array_N_u8_for_ref__alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_convert_From_ref_mut_array_N_u8_for_ref_mut_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]. + + (* + fn from(value: $a) -> $b { + // SAFETY: guaranteed by caller + unsafe { $crate::private::core::mem::transmute::<$a, $b>(value) } + } + *) + Definition from (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ N ] + [] + ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ N ] + [] + ] + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| value |) |) |) ] + |) + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] ] + (Self N) + (* Instance *) [ ("from", InstanceField.Method (from N)) ]. + End Impl_core_convert_From_ref_mut_array_N_u8_for_ref_mut_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_convert_From_ref__alloy_primitives_bits_fixed_FixedBytes_N_for_ref__array_N_u8. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ]. + + (* + fn from(value: $a) -> $b { + // SAFETY: guaranteed by caller + unsafe { $crate::private::core::mem::transmute::<$a, $b>(value) } + } + *) + Definition from (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]; + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] + ] + |), + [ M.read (| value |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ] + ] + (Self N) + (* Instance *) [ ("from", InstanceField.Method (from N)) ]. + End Impl_core_convert_From_ref__alloy_primitives_bits_fixed_FixedBytes_N_for_ref__array_N_u8. + + Module Impl_core_convert_From_ref_mut_alloy_primitives_bits_fixed_FixedBytes_N_for_ref__array_N_u8. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ]. + + (* + fn from(value: $a) -> $b { + // SAFETY: guaranteed by caller + unsafe { $crate::private::core::mem::transmute::<$a, $b>(value) } + } + *) + Definition from (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]; + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| value |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ] + ] + (Self N) + (* Instance *) [ ("from", InstanceField.Method (from N)) ]. + End Impl_core_convert_From_ref_mut_alloy_primitives_bits_fixed_FixedBytes_N_for_ref__array_N_u8. + + Module Impl_core_convert_From_ref_mut_alloy_primitives_bits_fixed_FixedBytes_N_for_ref_mut_array_N_u8. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ]. + + (* + fn from(value: $a) -> $b { + // SAFETY: guaranteed by caller + unsafe { $crate::private::core::mem::transmute::<$a, $b>(value) } + } + *) + Definition from (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ N ] + [] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| value |) |) |) ] + |) + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ] + ] + (Self N) + (* Instance *) [ ("from", InstanceField.Method (from N)) ]. + End Impl_core_convert_From_ref_mut_alloy_primitives_bits_fixed_FixedBytes_N_for_ref_mut_array_N_u8. + + Module Impl_core_cmp_PartialEq_slice_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + *) + Definition eq (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + (Self N) + (* Instance *) [ ("eq", InstanceField.Method (eq N)) ]. + End Impl_core_cmp_PartialEq_slice_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_cmp_PartialEq_alloy_primitives_bits_fixed_FixedBytes_N_for_slice_u8. + Definition Self (N : Value.t) : Ty.t := Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ]. + + (* + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + *) + Definition eq (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ] + (Self N) + (* Instance *) [ ("eq", InstanceField.Method (eq N)) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_bits_fixed_FixedBytes_N_for_slice_u8. + + Module Impl_core_cmp_PartialEq_ref__slice_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn $fn(&self, other: &&$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, *other) + } + *) + Definition eq (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.deref (| M.read (| other |) |) |) |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + (Self N) + (* Instance *) [ ("eq", InstanceField.Method (eq N)) ]. + End Impl_core_cmp_PartialEq_ref__slice_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_cmp_PartialEq_alloy_primitives_bits_fixed_FixedBytes_N_for_ref__slice_u8. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ]. + + (* + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn( *self, &other.0 $([$e])?) + } + *) + Definition eq (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ] + (Self N) + (* Instance *) [ ("eq", InstanceField.Method (eq N)) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_bits_fixed_FixedBytes_N_for_ref__slice_u8. + + Module Impl_core_cmp_PartialEq_slice_u8_for_ref__alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]. + + (* + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + *) + Definition eq (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + (Self N) + (* Instance *) [ ("eq", InstanceField.Method (eq N)) ]. + End Impl_core_cmp_PartialEq_slice_u8_for_ref__alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_cmp_PartialEq_ref__alloy_primitives_bits_fixed_FixedBytes_N_for_slice_u8. + Definition Self (N : Value.t) : Ty.t := Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ]. + + (* + fn $fn(&self, other: &&$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + *) + Definition eq (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| other |) |) |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ] + ] + (Self N) + (* Instance *) [ ("eq", InstanceField.Method (eq N)) ]. + End Impl_core_cmp_PartialEq_ref__alloy_primitives_bits_fixed_FixedBytes_N_for_slice_u8. + + Module Impl_core_cmp_PartialEq_array_N_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + *) + Definition eq (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] + (Self N) + (* Instance *) [ ("eq", InstanceField.Method (eq N)) ]. + End Impl_core_cmp_PartialEq_array_N_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_cmp_PartialEq_alloy_primitives_bits_fixed_FixedBytes_N_for_array_N_u8. + Definition Self (N : Value.t) : Ty.t := Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ]. + + (* + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + *) + Definition eq (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ] + (Self N) + (* Instance *) [ ("eq", InstanceField.Method (eq N)) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_bits_fixed_FixedBytes_N_for_array_N_u8. + + Module Impl_core_cmp_PartialEq_ref__array_N_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn $fn(&self, other: &&$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, *other) + } + *) + Definition eq (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.deref (| M.read (| other |) |) |) |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] ] + (Self N) + (* Instance *) [ ("eq", InstanceField.Method (eq N)) ]. + End Impl_core_cmp_PartialEq_ref__array_N_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_cmp_PartialEq_alloy_primitives_bits_fixed_FixedBytes_N_for_ref__array_N_u8. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ]. + + (* + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn( *self, &other.0 $([$e])?) + } + *) + Definition eq (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ] + (Self N) + (* Instance *) [ ("eq", InstanceField.Method (eq N)) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_bits_fixed_FixedBytes_N_for_ref__array_N_u8. + + Module Impl_core_cmp_PartialEq_array_N_u8_for_ref__alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]. + + (* + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + *) + Definition eq (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] + (Self N) + (* Instance *) [ ("eq", InstanceField.Method (eq N)) ]. + End Impl_core_cmp_PartialEq_array_N_u8_for_ref__alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_cmp_PartialEq_ref__alloy_primitives_bits_fixed_FixedBytes_N_for_array_N_u8. + Definition Self (N : Value.t) : Ty.t := Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ]. + + (* + fn $fn(&self, other: &&$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + *) + Definition eq (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| other |) |) |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ] + ] + (Self N) + (* Instance *) [ ("eq", InstanceField.Method (eq N)) ]. + End Impl_core_cmp_PartialEq_ref__alloy_primitives_bits_fixed_FixedBytes_N_for_array_N_u8. + + Module Impl_core_cmp_PartialOrd_slice_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + *) + Definition partial_cmp + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + (Self N) + (* Instance *) [ ("partial_cmp", InstanceField.Method (partial_cmp N)) ]. + End Impl_core_cmp_PartialOrd_slice_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_cmp_PartialOrd_alloy_primitives_bits_fixed_FixedBytes_N_for_slice_u8. + Definition Self (N : Value.t) : Ty.t := Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ]. + + (* + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + *) + Definition partial_cmp + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ] + (Self N) + (* Instance *) [ ("partial_cmp", InstanceField.Method (partial_cmp N)) ]. + End Impl_core_cmp_PartialOrd_alloy_primitives_bits_fixed_FixedBytes_N_for_slice_u8. + + Module Impl_core_cmp_PartialOrd_ref__slice_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* + fn $fn(&self, other: &&$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, *other) + } + *) + Definition partial_cmp + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.deref (| M.read (| other |) |) |) |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + (Self N) + (* Instance *) [ ("partial_cmp", InstanceField.Method (partial_cmp N)) ]. + End Impl_core_cmp_PartialOrd_ref__slice_u8_for_alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_cmp_PartialOrd_alloy_primitives_bits_fixed_FixedBytes_N_for_ref__slice_u8. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ]. + + (* + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn( *self, &other.0 $([$e])?) + } + *) + Definition partial_cmp + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ] + (Self N) + (* Instance *) [ ("partial_cmp", InstanceField.Method (partial_cmp N)) ]. + End Impl_core_cmp_PartialOrd_alloy_primitives_bits_fixed_FixedBytes_N_for_ref__slice_u8. + + Module Impl_core_cmp_PartialOrd_slice_u8_for_ref__alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ]. + + (* + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + *) + Definition partial_cmp + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + (Self N) + (* Instance *) [ ("partial_cmp", InstanceField.Method (partial_cmp N)) ]. + End Impl_core_cmp_PartialOrd_slice_u8_for_ref__alloy_primitives_bits_fixed_FixedBytes_N. + + Module Impl_core_cmp_PartialOrd_ref__alloy_primitives_bits_fixed_FixedBytes_N_for_slice_u8. + Definition Self (N : Value.t) : Ty.t := Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ]. + + (* + fn $fn(&self, other: &&$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + *) + Definition partial_cmp + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| other |) |) |) |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ] + ] + (Self N) + (* Instance *) [ ("partial_cmp", InstanceField.Method (partial_cmp N)) ]. + End Impl_core_cmp_PartialOrd_ref__alloy_primitives_bits_fixed_FixedBytes_N_for_slice_u8. + + Module Impl_const_hex_traits_FromHex_for_alloy_primitives_bits_fixed_FixedBytes_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []. + + (* type Error = $crate::hex::FromHexError; *) + Definition _Error (N : Value.t) : Ty.t := Ty.path "const_hex::error::FromHexError". + + (* + fn from_hex>(hex: T) -> Result { + $crate::hex::decode_to_array(hex).map(Self::new) + } + *) + Definition from_hex (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [ T ], [ hex ] => + ltac:(M.monadic + (let hex := M.alloc (| hex |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []; + Ty.path "const_hex::error::FromHexError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ]; + Ty.path "const_hex::error::FromHexError" + ], + "map", + [], + [ + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []; + Ty.function + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] + (Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ]; + Ty.path "const_hex::error::FromHexError" + ], + M.get_function (| "const_hex::decode_to_array", [ N ], [ T ] |), + [ M.read (| hex |) ] + |); + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [], + "new", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "const_hex::traits::FromHex" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) + [ ("Error", InstanceField.Ty (_Error N)); ("from_hex", InstanceField.Method (from_hex N)) + ]. + End Impl_const_hex_traits_FromHex_for_alloy_primitives_bits_fixed_FixedBytes_N. + End fixed. + + Module function. + (* StructTuple + { + name := "Function"; + const_params := []; + ty_params := []; + fields := + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ]; + } *) + + Module Impl_core_clone_Clone_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.deref (| M.read (| self |) |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_alloy_primitives_bits_function_Function. + + Module Impl_core_marker_Copy_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_alloy_primitives_bits_function_Function. + + Module Impl_core_default_Default_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* Default *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::bits::function::Function" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [], + "default", + [], + [] + |), + [] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_alloy_primitives_bits_function_Function. + + Module Impl_core_marker_StructuralPartialEq_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + Axiom Implements : + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_alloy_primitives_bits_function_Function. + + Module Impl_core_cmp_PartialEq_alloy_primitives_bits_function_Function_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* PartialEq *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::function::Function" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_bits_function_Function_for_alloy_primitives_bits_function_Function. + + Module Impl_core_cmp_Eq_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* Eq *) + Definition assert_receiver_is_total_eq + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method assert_receiver_is_total_eq) ]. + End Impl_core_cmp_Eq_for_alloy_primitives_bits_function_Function. + + Module Impl_core_cmp_PartialOrd_alloy_primitives_bits_function_Function_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* PartialOrd *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::function::Function" ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_alloy_primitives_bits_function_Function_for_alloy_primitives_bits_function_Function. + + Module Impl_core_cmp_Ord_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* Ord *) + Definition cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "core::cmp::Ordering", + M.get_trait_method (| + "core::cmp::Ord", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [], + "cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Ord" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("cmp", InstanceField.Method cmp) ]. + End Impl_core_cmp_Ord_for_alloy_primitives_bits_function_Function. + + Module Impl_core_hash_Hash_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* Hash *) + Definition hash (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ __H ], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::hash::Hash" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("hash", InstanceField.Method hash) ]. + End Impl_core_hash_Hash_for_alloy_primitives_bits_function_Function. + + Module Impl_core_convert_AsMut_alloy_primitives_bits_fixed_FixedBytes_Usize_24_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* $crate::private::derive_more::AsMut *) + Definition as_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::AsMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ] + Self + (* Instance *) [ ("as_mut", InstanceField.Method as_mut) ]. + End Impl_core_convert_AsMut_alloy_primitives_bits_fixed_FixedBytes_Usize_24_for_alloy_primitives_bits_function_Function. + + Module Impl_core_convert_AsRef_alloy_primitives_bits_fixed_FixedBytes_Usize_24_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* $crate::private::derive_more::AsRef *) + Definition as_ref (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::AsRef" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ] + Self + (* Instance *) [ ("as_ref", InstanceField.Method as_ref) ]. + End Impl_core_convert_AsRef_alloy_primitives_bits_fixed_FixedBytes_Usize_24_for_alloy_primitives_bits_function_Function. + + Module Impl_core_ops_bit_BitAnd_alloy_primitives_bits_function_Function_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* $crate::private::derive_more::BitAnd *) + Definition _Output : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* $crate::private::derive_more::BitAnd *) + Definition bitand (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + Value.StructTuple + "alloy_primitives::bits::function::Function" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + M.get_trait_method (| + "core::ops::bit::BitAnd", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ], + "bitand", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::function::Function", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::function::Function", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::bit::BitAnd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::function::Function" ] + Self + (* Instance *) + [ ("Output", InstanceField.Ty _Output); ("bitand", InstanceField.Method bitand) ]. + End Impl_core_ops_bit_BitAnd_alloy_primitives_bits_function_Function_for_alloy_primitives_bits_function_Function. + + Module Impl_core_ops_bit_BitAndAssign_alloy_primitives_bits_function_Function_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* $crate::private::derive_more::BitAndAssign *) + Definition bitand_assign (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::bit::BitAndAssign", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ], + "bitand_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::function::Function", + 0 + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::bit::BitAndAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::function::Function" ] + Self + (* Instance *) [ ("bitand_assign", InstanceField.Method bitand_assign) ]. + End Impl_core_ops_bit_BitAndAssign_alloy_primitives_bits_function_Function_for_alloy_primitives_bits_function_Function. + + Module Impl_core_ops_bit_BitOr_alloy_primitives_bits_function_Function_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* $crate::private::derive_more::BitOr *) + Definition _Output : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* $crate::private::derive_more::BitOr *) + Definition bitor (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + Value.StructTuple + "alloy_primitives::bits::function::Function" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + M.get_trait_method (| + "core::ops::bit::BitOr", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ], + "bitor", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::function::Function", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::function::Function", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::bit::BitOr" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::function::Function" ] + Self + (* Instance *) + [ ("Output", InstanceField.Ty _Output); ("bitor", InstanceField.Method bitor) ]. + End Impl_core_ops_bit_BitOr_alloy_primitives_bits_function_Function_for_alloy_primitives_bits_function_Function. + + Module Impl_core_ops_bit_BitOrAssign_alloy_primitives_bits_function_Function_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* $crate::private::derive_more::BitOrAssign *) + Definition bitor_assign (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::bit::BitOrAssign", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ], + "bitor_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::function::Function", + 0 + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::bit::BitOrAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::function::Function" ] + Self + (* Instance *) [ ("bitor_assign", InstanceField.Method bitor_assign) ]. + End Impl_core_ops_bit_BitOrAssign_alloy_primitives_bits_function_Function_for_alloy_primitives_bits_function_Function. + + Module Impl_core_ops_bit_BitXor_alloy_primitives_bits_function_Function_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* $crate::private::derive_more::BitXor *) + Definition _Output : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* $crate::private::derive_more::BitXor *) + Definition bitxor (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + Value.StructTuple + "alloy_primitives::bits::function::Function" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + M.get_trait_method (| + "core::ops::bit::BitXor", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ], + "bitxor", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::function::Function", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::function::Function", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::bit::BitXor" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::function::Function" ] + Self + (* Instance *) + [ ("Output", InstanceField.Ty _Output); ("bitxor", InstanceField.Method bitxor) ]. + End Impl_core_ops_bit_BitXor_alloy_primitives_bits_function_Function_for_alloy_primitives_bits_function_Function. + + Module Impl_core_ops_bit_BitXorAssign_alloy_primitives_bits_function_Function_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* $crate::private::derive_more::BitXorAssign *) + Definition bitxor_assign (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::bit::BitXorAssign", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ], + "bitxor_assign", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::function::Function", + 0 + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::bit::BitXorAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::function::Function" ] + Self + (* Instance *) [ ("bitxor_assign", InstanceField.Method bitxor_assign) ]. + End Impl_core_ops_bit_BitXorAssign_alloy_primitives_bits_function_Function_for_alloy_primitives_bits_function_Function. + + Module Impl_core_ops_bit_Not_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* $crate::private::derive_more::Not *) + Definition _Output : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* $crate::private::derive_more::Not *) + Definition not (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple + "alloy_primitives::bits::function::Function" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + M.get_trait_method (| + "core::ops::bit::Not", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [], + "not", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::function::Function", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::bit::Not" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("Output", InstanceField.Ty _Output); ("not", InstanceField.Method not) ]. + End Impl_core_ops_bit_Not_for_alloy_primitives_bits_function_Function. + + Module Impl_core_ops_deref_Deref_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* $crate::private::derive_more::Deref *) + Definition _Target : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + []. + + (* $crate::private::derive_more::Deref *) + Definition deref (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::deref::Deref" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("Target", InstanceField.Ty _Target); ("deref", InstanceField.Method deref) ]. + End Impl_core_ops_deref_Deref_for_alloy_primitives_bits_function_Function. + + Module Impl_core_ops_deref_DerefMut_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* $crate::private::derive_more::DerefMut *) + Definition deref_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::deref::DerefMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("deref_mut", InstanceField.Method deref_mut) ]. + End Impl_core_ops_deref_DerefMut_for_alloy_primitives_bits_function_Function. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_24_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* $crate::private::derive_more::From *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple "alloy_primitives::bits::function::Function" [ M.read (| value |) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_Usize_24_for_alloy_primitives_bits_function_Function. + + Module Impl_core_str_traits_FromStr_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* $crate::private::derive_more::FromStr *) + Definition _Err : Ty.t := + Ty.associated_in_trait + "core::str::traits::FromStr" + [] + [] + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + []) + "Err". + + (* $crate::private::derive_more::FromStr *) + Definition from_str (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ src ] => + ltac:(M.monadic + (let src := M.alloc (| src |) in + M.catch_return (| + ltac:(M.monadic + (Value.StructTuple + "core::result::Result::Ok" + [ + Value.StructTuple + "alloy_primitives::bits::function::Function" + [ + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "const_hex::error::FromHexError" + ]; + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + []; + Ty.path "const_hex::error::FromHexError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + []; + Ty.path "const_hex::error::FromHexError" + ], + M.get_trait_method (| + "core::str::traits::FromStr", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [], + "from_str", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| src |) |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "alloy_primitives::bits::function::Function"; + Ty.path "const_hex::error::FromHexError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "alloy_primitives::bits::function::Function"; + Ty.path "const_hex::error::FromHexError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "const_hex::error::FromHexError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) + ] + ])) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::str::traits::FromStr" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("Err", InstanceField.Ty _Err); ("from_str", InstanceField.Method from_str) ]. + End Impl_core_str_traits_FromStr_for_alloy_primitives_bits_function_Function. + + Module Impl_core_ops_index_Index_where_core_ops_index_Index_alloy_primitives_bits_fixed_FixedBytes_Usize_24___IdxT___IdxT_for_alloy_primitives_bits_function_Function. + Definition Self (__IdxT : Ty.t) : Ty.t := + Ty.path "alloy_primitives::bits::function::Function". + + (* $crate::private::derive_more::Index *) + Definition _Output (__IdxT : Ty.t) : Ty.t := + Ty.associated_in_trait + "core::ops::index::Index" + [] + [ __IdxT ] + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + []) + "Output". + + (* $crate::private::derive_more::Index *) + Definition index (__IdxT : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self __IdxT in + match ε, τ, α with + | [], [], [ self; idx ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let idx := M.alloc (| idx |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.associated_in_trait + "core::ops::index::Index" + [] + [ __IdxT ] + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + []) + "Output" + ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ __IdxT ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |); + M.read (| idx |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (__IdxT : Ty.t), + M.IsTraitInstance + "core::ops::index::Index" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ __IdxT ] + (Self __IdxT) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output __IdxT)); + ("index", InstanceField.Method (index __IdxT)) + ]. + End Impl_core_ops_index_Index_where_core_ops_index_Index_alloy_primitives_bits_fixed_FixedBytes_Usize_24___IdxT___IdxT_for_alloy_primitives_bits_function_Function. + + Module Impl_core_ops_index_IndexMut_where_core_ops_index_IndexMut_alloy_primitives_bits_fixed_FixedBytes_Usize_24___IdxT___IdxT_for_alloy_primitives_bits_function_Function. + Definition Self (__IdxT : Ty.t) : Ty.t := + Ty.path "alloy_primitives::bits::function::Function". + + (* $crate::private::derive_more::IndexMut *) + Definition index_mut + (__IdxT : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self __IdxT in + match ε, τ, α with + | [], [], [ self; idx ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let idx := M.alloc (| idx |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.associated_in_trait + "core::ops::index::Index" + [] + [ __IdxT ] + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + []) + "Output" + ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ __IdxT ], + "index_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |); + M.read (| idx |) + ] + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (__IdxT : Ty.t), + M.IsTraitInstance + "core::ops::index::IndexMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ __IdxT ] + (Self __IdxT) + (* Instance *) [ ("index_mut", InstanceField.Method (index_mut __IdxT)) ]. + End Impl_core_ops_index_IndexMut_where_core_ops_index_IndexMut_alloy_primitives_bits_fixed_FixedBytes_Usize_24___IdxT___IdxT_for_alloy_primitives_bits_function_Function. + + Module Impl_core_convert_From_alloy_primitives_bits_function_Function_for_alloy_primitives_bits_fixed_FixedBytes_Usize_24. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + []. + + (* $crate::private::derive_more::Into *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + M.get_trait_method (| + "core::convert::From", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ], + "from", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::function::Function", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::function::Function" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_function_Function_for_alloy_primitives_bits_fixed_FixedBytes_Usize_24. + + Module Impl_core_iter_traits_collect_IntoIterator_where_core_iter_traits_collect_IntoIterator_alloy_primitives_bits_fixed_FixedBytes_Usize_24_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* $crate::private::derive_more::IntoIterator *) + Definition _Item : Ty.t := + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + []) + "Item". + + (* $crate::private::derive_more::IntoIterator *) + Definition _IntoIter : Ty.t := + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + []) + "IntoIter". + + (* $crate::private::derive_more::IntoIterator *) + Definition into_iter (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply + (Ty.path "core::array::iter::IntoIter") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::function::Function", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::iter::traits::collect::IntoIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("Item", InstanceField.Ty _Item); + ("IntoIter", InstanceField.Ty _IntoIter); + ("into_iter", InstanceField.Method into_iter) + ]. + End Impl_core_iter_traits_collect_IntoIterator_where_core_iter_traits_collect_IntoIterator_alloy_primitives_bits_fixed_FixedBytes_Usize_24_for_alloy_primitives_bits_function_Function. + + Module Impl_core_iter_traits_collect_IntoIterator_where_core_iter_traits_collect_IntoIterator_ref__alloy_primitives_bits_fixed_FixedBytes_Usize_24_for_ref__alloy_primitives_bits_function_Function. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::function::Function" ]. + + (* $crate::private::derive_more::IntoIterator *) + Definition _Item : Ty.t := + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ]) + "Item". + + (* $crate::private::derive_more::IntoIterator *) + Definition _IntoIter : Ty.t := + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ]) + "IntoIter". + + (* $crate::private::derive_more::IntoIterator *) + Definition into_iter (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ]) + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::iter::traits::collect::IntoIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("Item", InstanceField.Ty _Item); + ("IntoIter", InstanceField.Ty _IntoIter); + ("into_iter", InstanceField.Method into_iter) + ]. + End Impl_core_iter_traits_collect_IntoIterator_where_core_iter_traits_collect_IntoIterator_ref__alloy_primitives_bits_fixed_FixedBytes_Usize_24_for_ref__alloy_primitives_bits_function_Function. + + Module Impl_core_iter_traits_collect_IntoIterator_where_core_iter_traits_collect_IntoIterator_ref_mut_alloy_primitives_bits_fixed_FixedBytes_Usize_24_for_ref_mut_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := + Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::function::Function" ]. + + (* $crate::private::derive_more::IntoIterator *) + Definition _Item : Ty.t := + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ]) + "Item". + + (* $crate::private::derive_more::IntoIterator *) + Definition _IntoIter : Ty.t := + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ]) + "IntoIter". + + (* $crate::private::derive_more::IntoIterator *) + Definition into_iter (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + (Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ]) + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ], + [], + [], + "into_iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::iter::traits::collect::IntoIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("Item", InstanceField.Ty _Item); + ("IntoIter", InstanceField.Ty _IntoIter); + ("into_iter", InstanceField.Method into_iter) + ]. + End Impl_core_iter_traits_collect_IntoIterator_where_core_iter_traits_collect_IntoIterator_ref_mut_alloy_primitives_bits_fixed_FixedBytes_Usize_24_for_ref_mut_alloy_primitives_bits_function_Function. + + Module Impl_core_fmt_LowerHex_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* $crate::private::derive_more::LowerHex *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; __derive_more_f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __derive_more_f := M.alloc (| __derive_more_f |) in + M.read (| + let~ _0 : + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::LowerHex", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| _0 |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| __derive_more_f |) |) |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::LowerHex" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_LowerHex_for_alloy_primitives_bits_function_Function. + + Module Impl_core_fmt_UpperHex_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* $crate::private::derive_more::UpperHex *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; __derive_more_f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __derive_more_f := M.alloc (| __derive_more_f |) in + M.read (| + let~ _0 : + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::UpperHex", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| _0 |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| __derive_more_f |) |) |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::UpperHex" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_UpperHex_for_alloy_primitives_bits_function_Function. + + Module Impl_core_fmt_Display_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* $crate::private::derive_more::Display *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; __derive_more_f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let __derive_more_f := M.alloc (| __derive_more_f |) in + M.read (| + let~ _0 : + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::Display", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| _0 |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| __derive_more_f |) |) |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Display" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Display_for_alloy_primitives_bits_function_Function. + + Module Impl_core_convert_From_array_Usize_24_u8_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* + fn from(value: [u8; $n]) -> Self { + Self($crate::FixedBytes(value)) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::function::Function" + [ Value.StructTuple "alloy_primitives::bits::fixed::FixedBytes" [ M.read (| value |) ] + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_array_Usize_24_u8_for_alloy_primitives_bits_function_Function. + + Module Impl_core_convert_From_alloy_primitives_bits_function_Function_for_array_Usize_24_u8. + Definition Self : Ty.t := + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ]. + + (* + fn from(value: $name) -> Self { + value.0 .0 + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.read (| + M.SubPointer.get_struct_tuple_field (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bits::function::Function", + 0 + |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::function::Function" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_function_Function_for_array_Usize_24_u8. + + Module Impl_core_convert_From_ref__array_Usize_24_u8_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* + fn from(value: &'a [u8; $n]) -> Self { + Self($crate::FixedBytes( *value)) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::function::Function" + [ + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ M.read (| M.deref (| M.read (| value |) |) |) ] + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ] ] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref__array_Usize_24_u8_for_alloy_primitives_bits_function_Function. + + Module Impl_core_convert_From_ref_mut_array_Usize_24_u8_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* + fn from(value: &'a mut [u8; $n]) -> Self { + Self($crate::FixedBytes( *value)) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::function::Function" + [ + Value.StructTuple + "alloy_primitives::bits::fixed::FixedBytes" + [ M.read (| M.deref (| M.read (| value |) |) |) ] + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ] ] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref_mut_array_Usize_24_u8_for_alloy_primitives_bits_function_Function. + + Module Impl_core_convert_TryFrom_ref__slice_u8_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* type Error = $crate::private::core::array::TryFromSliceError; *) + Definition _Error : Ty.t := Ty.path "core::array::TryFromSliceError". + + (* + fn try_from(slice: &[u8]) -> Result { + <&Self as $crate::private::TryFrom<&[u8]>>::try_from(slice).copied() + } + *) + Definition try_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ slice ] => + ltac:(M.monadic + (let slice := M.alloc (| slice |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::bits::function::Function"; + Ty.path "core::array::TryFromSliceError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::function::Function" ]; + Ty.path "core::array::TryFromSliceError" + ], + "copied", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::function::Function" ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::function::Function" ], + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ], + "try_from", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| slice |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("try_from", InstanceField.Method try_from) ]. + End Impl_core_convert_TryFrom_ref__slice_u8_for_alloy_primitives_bits_function_Function. + + Module Impl_core_convert_TryFrom_ref_mut_slice_u8_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* type Error = $crate::private::core::array::TryFromSliceError; *) + Definition _Error : Ty.t := Ty.path "core::array::TryFromSliceError". + + (* + fn try_from(slice: &mut [u8]) -> Result { + >::try_from(&*slice) + } + *) + Definition try_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ slice ] => + ltac:(M.monadic + (let slice := M.alloc (| slice |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::bits::function::Function"; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "alloy_primitives::bits::function::Function", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ], + "try_from", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| slice |) |) |) |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("try_from", InstanceField.Method try_from) ]. + End Impl_core_convert_TryFrom_ref_mut_slice_u8_for_alloy_primitives_bits_function_Function. + + Module Impl_core_convert_TryFrom_ref__slice_u8_for_ref__alloy_primitives_bits_function_Function. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::function::Function" ]. + + (* type Error = $crate::private::core::array::TryFromSliceError; *) + Definition _Error : Ty.t := Ty.path "core::array::TryFromSliceError". + + (* + fn try_from(slice: &'a [u8]) -> Result<&'a $name, Self::Error> { + // SAFETY: `$name` is `repr(transparent)` for `FixedBytes<$n>` + // and consequently `[u8; $n]` + <&[u8; $n] as $crate::private::TryFrom<&[u8]>>::try_from(slice) + .map(|array_ref| unsafe { $crate::private::core::mem::transmute(array_ref) }) + } + *) + Definition try_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ slice ] => + ltac:(M.monadic + (let slice := M.alloc (| slice |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::function::Function" ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "map", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::function::Function" ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ] + ] + ] + (Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::function::Function" ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ], + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ], + "try_from", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| slice |) |) |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ] + ] + ] + (Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::function::Function" ])), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let array_ref := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::function::Function" ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::function::Function" ] + ] + |), + [ M.read (| array_ref |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("try_from", InstanceField.Method try_from) ]. + End Impl_core_convert_TryFrom_ref__slice_u8_for_ref__alloy_primitives_bits_function_Function. + + Module Impl_core_convert_TryFrom_ref_mut_slice_u8_for_ref_mut_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := + Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::function::Function" ]. + + (* type Error = $crate::private::core::array::TryFromSliceError; *) + Definition _Error : Ty.t := Ty.path "core::array::TryFromSliceError". + + (* + fn try_from(slice: &'a mut [u8]) -> Result<&'a mut $name, Self::Error> { + // SAFETY: `$name` is `repr(transparent)` for `FixedBytes<$n>` + // and consequently `[u8; $n]` + <&mut [u8; $n] as $crate::private::TryFrom<&mut [u8]>>::try_from(slice) + .map(|array_ref| unsafe { $crate::private::core::mem::transmute(array_ref) }) + } + *) + Definition try_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ slice ] => + ltac:(M.monadic + (let slice := M.alloc (| slice |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::function::Function" ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "map", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::function::Function" ]; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ] + ] + ] + (Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::function::Function" ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ], + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ], + "try_from", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| slice |) |) |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ] + ] + ] + (Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::function::Function" ])), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let array_ref := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::function::Function" ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::function::Function" ] + ] + |), + [ M.read (| array_ref |) ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("try_from", InstanceField.Method try_from) ]. + End Impl_core_convert_TryFrom_ref_mut_slice_u8_for_ref_mut_alloy_primitives_bits_function_Function. + + Module Impl_core_convert_AsRef_array_Usize_24_u8_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* + fn as_ref(&self) -> &[u8; $n] { + &self.0 .0 + } + *) + Definition as_ref (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::AsRef" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("as_ref", InstanceField.Method as_ref) ]. + End Impl_core_convert_AsRef_array_Usize_24_u8_for_alloy_primitives_bits_function_Function. + + Module Impl_core_convert_AsMut_array_Usize_24_u8_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* + fn as_mut(&mut self) -> &mut [u8; $n] { + &mut self.0 .0 + } + *) + Definition as_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::AsMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("as_mut", InstanceField.Method as_mut) ]. + End Impl_core_convert_AsMut_array_Usize_24_u8_for_alloy_primitives_bits_function_Function. + + Module Impl_core_convert_AsRef_slice_u8_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* + fn as_ref(&self) -> &[u8] { + &self.0 .0 + } + *) + Definition as_ref (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::AsRef" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("as_ref", InstanceField.Method as_ref) ]. + End Impl_core_convert_AsRef_slice_u8_for_alloy_primitives_bits_function_Function. + + Module Impl_core_convert_AsMut_slice_u8_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* + fn as_mut(&mut self) -> &mut [u8] { + &mut self.0 .0 + } + *) + Definition as_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::AsMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("as_mut", InstanceField.Method as_mut) ]. + End Impl_core_convert_AsMut_slice_u8_for_alloy_primitives_bits_function_Function. + + Module Impl_core_fmt_Debug_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + $crate::private::core::fmt::Debug::fmt(&self.0, f) + } + *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::Debug", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_alloy_primitives_bits_function_Function. + + Module Impl_core_borrow_Borrow_slice_u8_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* + fn borrow(&self) -> &$t { + $crate::private::Borrow::borrow(&self.0) + } + *) + Definition borrow (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow", InstanceField.Method borrow) ]. + End Impl_core_borrow_Borrow_slice_u8_for_alloy_primitives_bits_function_Function. + + Module Impl_core_borrow_Borrow_slice_u8_for_ref__alloy_primitives_bits_function_Function. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::function::Function" ]. + + (* + fn borrow(&self) -> &$t { + $crate::private::Borrow::borrow(&self.0) + } + *) + Definition borrow (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow", InstanceField.Method borrow) ]. + End Impl_core_borrow_Borrow_slice_u8_for_ref__alloy_primitives_bits_function_Function. + + Module Impl_core_borrow_Borrow_slice_u8_for_ref_mut_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := + Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::function::Function" ]. + + (* + fn borrow(&self) -> &$t { + $crate::private::Borrow::borrow(&self.0) + } + *) + Definition borrow (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow", InstanceField.Method borrow) ]. + End Impl_core_borrow_Borrow_slice_u8_for_ref_mut_alloy_primitives_bits_function_Function. + + Module Impl_core_borrow_Borrow_array_Usize_24_u8_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* + fn borrow(&self) -> &$t { + $crate::private::Borrow::borrow(&self.0) + } + *) + Definition borrow (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow", InstanceField.Method borrow) ]. + End Impl_core_borrow_Borrow_array_Usize_24_u8_for_alloy_primitives_bits_function_Function. + + Module Impl_core_borrow_Borrow_array_Usize_24_u8_for_ref__alloy_primitives_bits_function_Function. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::function::Function" ]. + + (* + fn borrow(&self) -> &$t { + $crate::private::Borrow::borrow(&self.0) + } + *) + Definition borrow (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow", InstanceField.Method borrow) ]. + End Impl_core_borrow_Borrow_array_Usize_24_u8_for_ref__alloy_primitives_bits_function_Function. + + Module Impl_core_borrow_Borrow_array_Usize_24_u8_for_ref_mut_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := + Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::function::Function" ]. + + (* + fn borrow(&self) -> &$t { + $crate::private::Borrow::borrow(&self.0) + } + *) + Definition borrow (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::borrow::Borrow", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ], + "borrow", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow", InstanceField.Method borrow) ]. + End Impl_core_borrow_Borrow_array_Usize_24_u8_for_ref_mut_alloy_primitives_bits_function_Function. + + Module Impl_core_borrow_BorrowMut_slice_u8_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* + fn borrow_mut(&mut self) -> &mut $t { + $crate::private::BorrowMut::borrow_mut(&mut self.0) + } + *) + Definition borrow_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::borrow::BorrowMut", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "borrow_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |) + ] + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::BorrowMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow_mut", InstanceField.Method borrow_mut) ]. + End Impl_core_borrow_BorrowMut_slice_u8_for_alloy_primitives_bits_function_Function. + + Module Impl_core_borrow_BorrowMut_slice_u8_for_ref_mut_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := + Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::function::Function" ]. + + (* + fn borrow_mut(&mut self) -> &mut $t { + $crate::private::BorrowMut::borrow_mut(&mut self.0) + } + *) + Definition borrow_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::borrow::BorrowMut", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "borrow_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |) + ] + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::BorrowMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow_mut", InstanceField.Method borrow_mut) ]. + End Impl_core_borrow_BorrowMut_slice_u8_for_ref_mut_alloy_primitives_bits_function_Function. + + Module Impl_core_borrow_BorrowMut_array_Usize_24_u8_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* + fn borrow_mut(&mut self) -> &mut $t { + $crate::private::BorrowMut::borrow_mut(&mut self.0) + } + *) + Definition borrow_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::borrow::BorrowMut", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ], + "borrow_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |) + ] + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::BorrowMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow_mut", InstanceField.Method borrow_mut) ]. + End Impl_core_borrow_BorrowMut_array_Usize_24_u8_for_alloy_primitives_bits_function_Function. + + Module Impl_core_borrow_BorrowMut_array_Usize_24_u8_for_ref_mut_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := + Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::function::Function" ]. + + (* + fn borrow_mut(&mut self) -> &mut $t { + $crate::private::BorrowMut::borrow_mut(&mut self.0) + } + *) + Definition borrow_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::borrow::BorrowMut", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ], + "borrow_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |) + ] + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::BorrowMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow_mut", InstanceField.Method borrow_mut) ]. + End Impl_core_borrow_BorrowMut_array_Usize_24_u8_for_ref_mut_alloy_primitives_bits_function_Function. + + Module Impl_core_convert_From_ref__array_Usize_24_u8_for_ref__alloy_primitives_bits_function_Function. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::function::Function" ]. + + (* + fn from(value: $a) -> $b { + // SAFETY: guaranteed by caller + unsafe { $crate::private::core::mem::transmute::<$a, $b>(value) } + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::function::Function" ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ]; + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::function::Function" ] + ] + |), + [ M.read (| value |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ] ] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref__array_Usize_24_u8_for_ref__alloy_primitives_bits_function_Function. + + Module Impl_core_convert_From_ref_mut_array_Usize_24_u8_for_ref__alloy_primitives_bits_function_Function. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::function::Function" ]. + + (* + fn from(value: $a) -> $b { + // SAFETY: guaranteed by caller + unsafe { $crate::private::core::mem::transmute::<$a, $b>(value) } + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::function::Function" ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ]; + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::function::Function" ] + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| value |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ] ] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref_mut_array_Usize_24_u8_for_ref__alloy_primitives_bits_function_Function. + + Module Impl_core_convert_From_ref_mut_array_Usize_24_u8_for_ref_mut_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := + Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::function::Function" ]. + + (* + fn from(value: $a) -> $b { + // SAFETY: guaranteed by caller + unsafe { $crate::private::core::mem::transmute::<$a, $b>(value) } + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::function::Function" ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ]; + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::function::Function" ] + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| value |) |) |) ] + |) + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ] ] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref_mut_array_Usize_24_u8_for_ref_mut_alloy_primitives_bits_function_Function. + + Module Impl_core_convert_From_ref__alloy_primitives_bits_function_Function_for_ref__array_Usize_24_u8. + Definition Self : Ty.t := + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ] ]. + + (* + fn from(value: $a) -> $b { + // SAFETY: guaranteed by caller + unsafe { $crate::private::core::mem::transmute::<$a, $b>(value) } + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ] + ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::function::Function" ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ] + ] + |), + [ M.read (| value |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::function::Function" ] ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref__alloy_primitives_bits_function_Function_for_ref__array_Usize_24_u8. + + Module Impl_core_convert_From_ref_mut_alloy_primitives_bits_function_Function_for_ref__array_Usize_24_u8. + Definition Self : Ty.t := + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ] ]. + + (* + fn from(value: $a) -> $b { + // SAFETY: guaranteed by caller + unsafe { $crate::private::core::mem::transmute::<$a, $b>(value) } + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ] + ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::function::Function" ]; + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ] + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| value |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::function::Function" ] ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref_mut_alloy_primitives_bits_function_Function_for_ref__array_Usize_24_u8. + + Module Impl_core_convert_From_ref_mut_alloy_primitives_bits_function_Function_for_ref_mut_array_Usize_24_u8. + Definition Self : Ty.t := + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ] ]. + + (* + fn from(value: $a) -> $b { + // SAFETY: guaranteed by caller + unsafe { $crate::private::core::mem::transmute::<$a, $b>(value) } + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ], + M.get_function (| + "core::intrinsics::transmute", + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ Ty.path "alloy_primitives::bits::function::Function" ]; + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ] + ] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| value |) |) |) ] + |) + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&mut") [] [ Ty.path "alloy_primitives::bits::function::Function" ] ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref_mut_alloy_primitives_bits_function_Function_for_ref_mut_array_Usize_24_u8. + + Module Impl_core_cmp_PartialEq_slice_u8_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_slice_u8_for_alloy_primitives_bits_function_Function. + + Module Impl_core_cmp_PartialEq_alloy_primitives_bits_function_Function_for_slice_u8. + Definition Self : Ty.t := Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ]. + + (* + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::function::Function" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_bits_function_Function_for_slice_u8. + + Module Impl_core_cmp_PartialEq_ref__slice_u8_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* + fn $fn(&self, other: &&$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, *other) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.deref (| M.read (| other |) |) |) |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_ref__slice_u8_for_alloy_primitives_bits_function_Function. + + Module Impl_core_cmp_PartialEq_alloy_primitives_bits_function_Function_for_ref__slice_u8. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ]. + + (* + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn( *self, &other.0 $([$e])?) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::function::Function" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_bits_function_Function_for_ref__slice_u8. + + Module Impl_core_cmp_PartialEq_slice_u8_for_ref__alloy_primitives_bits_function_Function. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::function::Function" ]. + + (* + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_slice_u8_for_ref__alloy_primitives_bits_function_Function. + + Module Impl_core_cmp_PartialEq_ref__alloy_primitives_bits_function_Function_for_slice_u8. + Definition Self : Ty.t := Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ]. + + (* + fn $fn(&self, other: &&$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| other |) |) |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::function::Function" ] ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_ref__alloy_primitives_bits_function_Function_for_slice_u8. + + Module Impl_core_cmp_PartialEq_array_Usize_24_u8_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_array_Usize_24_u8_for_alloy_primitives_bits_function_Function. + + Module Impl_core_cmp_PartialEq_alloy_primitives_bits_function_Function_for_array_Usize_24_u8. + Definition Self : Ty.t := + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ]. + + (* + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::function::Function" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_bits_function_Function_for_array_Usize_24_u8. + + Module Impl_core_cmp_PartialEq_ref__array_Usize_24_u8_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* + fn $fn(&self, other: &&$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, *other) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.deref (| M.read (| other |) |) |) |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ] ] + ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_ref__array_Usize_24_u8_for_alloy_primitives_bits_function_Function. + + Module Impl_core_cmp_PartialEq_alloy_primitives_bits_function_Function_for_ref__array_Usize_24_u8. + Definition Self : Ty.t := + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ] ]. + + (* + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn( *self, &other.0 $([$e])?) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::function::Function" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_bits_function_Function_for_ref__array_Usize_24_u8. + + Module Impl_core_cmp_PartialEq_array_Usize_24_u8_for_ref__alloy_primitives_bits_function_Function. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::function::Function" ]. + + (* + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_array_Usize_24_u8_for_ref__alloy_primitives_bits_function_Function. + + Module Impl_core_cmp_PartialEq_ref__alloy_primitives_bits_function_Function_for_array_Usize_24_u8. + Definition Self : Ty.t := + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ]. + + (* + fn $fn(&self, other: &&$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 24 ] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| other |) |) |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::function::Function" ] ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_ref__alloy_primitives_bits_function_Function_for_array_Usize_24_u8. + + Module Impl_core_cmp_PartialOrd_slice_u8_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_slice_u8_for_alloy_primitives_bits_function_Function. + + Module Impl_core_cmp_PartialOrd_alloy_primitives_bits_function_Function_for_slice_u8. + Definition Self : Ty.t := Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ]. + + (* + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::function::Function" ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_alloy_primitives_bits_function_Function_for_slice_u8. + + Module Impl_core_cmp_PartialOrd_ref__slice_u8_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* + fn $fn(&self, other: &&$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, *other) + } + *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.deref (| M.read (| other |) |) |) |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_ref__slice_u8_for_alloy_primitives_bits_function_Function. + + Module Impl_core_cmp_PartialOrd_alloy_primitives_bits_function_Function_for_ref__slice_u8. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ]. + + (* + fn $fn(&self, other: &$b) -> $ret { + $crate::private::$tr::$fn( *self, &other.0 $([$e])?) + } + *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::function::Function" ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_alloy_primitives_bits_function_Function_for_ref__slice_u8. + + Module Impl_core_cmp_PartialOrd_slice_u8_for_ref__alloy_primitives_bits_function_Function. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::function::Function" ]. + + (* + fn $fn(&self, other: &$a) -> $ret { + $crate::private::$tr::$fn(&self.0 $([$e])?, other) + } + *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| self |) |) |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_slice_u8_for_ref__alloy_primitives_bits_function_Function. + + Module Impl_core_cmp_PartialOrd_ref__alloy_primitives_bits_function_Function_for_slice_u8. + Definition Self : Ty.t := Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ]. + + (* + fn $fn(&self, other: &&$b) -> $ret { + $crate::private::$tr::$fn(self, &other.0 $([$e])?) + } + *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| M.deref (| M.read (| other |) |) |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::function::Function" ] ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_ref__alloy_primitives_bits_function_Function_for_slice_u8. + + Module Impl_const_hex_traits_FromHex_for_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* type Error = $crate::hex::FromHexError; *) + Definition _Error : Ty.t := Ty.path "const_hex::error::FromHexError". + + (* + fn from_hex>(hex: T) -> Result { + $crate::hex::decode_to_array(hex).map(Self::new) + } + *) + Definition from_hex (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ hex ] => + ltac:(M.monadic + (let hex := M.alloc (| hex |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::bits::function::Function"; + Ty.path "const_hex::error::FromHexError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ]; + Ty.path "const_hex::error::FromHexError" + ], + "map", + [], + [ + Ty.path "alloy_primitives::bits::function::Function"; + Ty.function + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ] + ] + (Ty.path "alloy_primitives::bits::function::Function") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 24 ] + [ Ty.path "u8" ]; + Ty.path "const_hex::error::FromHexError" + ], + M.get_function (| + "const_hex::decode_to_array", + [ Value.Integer IntegerKind.Usize 24 ], + [ T ] + |), + [ M.read (| hex |) ] + |); + M.get_associated_function (| + Ty.path "alloy_primitives::bits::function::Function", + "new", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "const_hex::traits::FromHex" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("from_hex", InstanceField.Method from_hex) ]. + End Impl_const_hex_traits_FromHex_for_alloy_primitives_bits_function_Function. + + Module Impl_alloy_primitives_bits_function_Function. + Definition Self : Ty.t := Ty.path "alloy_primitives::bits::function::Function". + + (* pub const ZERO: Self = Self($crate::FixedBytes::ZERO); *) + (* Ty.path "alloy_primitives::bits::function::Function" *) + Definition value_ZERO : Value.t := + M.run + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "alloy_primitives::bits::function::Function" + [ M.read (| M.get_constant "alloy_primitives::bits::fixed::ZERO" |) ] + |))). + + Global Instance AssociatedConstant_value_ZERO : + M.IsAssociatedConstant.Trait Self "value_ZERO" value_ZERO. + Admitted. + Global Typeclasses Opaque value_ZERO. + + (* + pub const fn new(bytes: [u8; $n]) -> Self { + Self($crate::FixedBytes(bytes)) + } + *) + Definition new (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ bytes ] => + ltac:(M.monadic + (let bytes := M.alloc (| bytes |) in + Value.StructTuple + "alloy_primitives::bits::function::Function" + [ Value.StructTuple "alloy_primitives::bits::fixed::FixedBytes" [ M.read (| bytes |) ] + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : M.IsAssociatedFunction.Trait Self "new" new. + Admitted. + Global Typeclasses Opaque new. + + (* + pub const fn with_last_byte(x: u8) -> Self { + Self($crate::FixedBytes::with_last_byte(x)) + } + *) + Definition with_last_byte (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ x ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + Value.StructTuple + "alloy_primitives::bits::function::Function" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + "with_last_byte", + [], + [] + |), + [ M.read (| x |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_with_last_byte : + M.IsAssociatedFunction.Trait Self "with_last_byte" with_last_byte. + Admitted. + Global Typeclasses Opaque with_last_byte. + + (* + pub const fn repeat_byte(byte: u8) -> Self { + Self($crate::FixedBytes::repeat_byte(byte)) + } + *) + Definition repeat_byte (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ byte ] => + ltac:(M.monadic + (let byte := M.alloc (| byte |) in + Value.StructTuple + "alloy_primitives::bits::function::Function" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + "repeat_byte", + [], + [] + |), + [ M.read (| byte |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_repeat_byte : + M.IsAssociatedFunction.Trait Self "repeat_byte" repeat_byte. + Admitted. + Global Typeclasses Opaque repeat_byte. + + (* + pub const fn len_bytes() -> usize { + $n + } + *) + Definition len_bytes (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => ltac:(M.monadic (Value.Integer IntegerKind.Usize 24)) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_len_bytes : + M.IsAssociatedFunction.Trait Self "len_bytes" len_bytes. + Admitted. + Global Typeclasses Opaque len_bytes. + + (* + pub fn from_slice(src: &[u8]) -> Self { + match Self::try_from(src) { + Ok(x) => x, + Err(_) => panic!("cannot convert a slice of length {} to {}", src.len(), stringify!($name)), + } + } + *) + Definition from_slice (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ src ] => + ltac:(M.monadic + (let src := M.alloc (| src |) in + M.read (| + M.match_operator (| + Some (Ty.path "alloy_primitives::bits::function::Function"), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::bits::function::Function"; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "alloy_primitives::bits::function::Function", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ], + "try_from", + [], + [] + |), + [ M.read (| src |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::result::Result::Ok", + 0 + |) in + let x := M.copy (| γ0_0 |) in + x)); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::result::Result::Err", + 0 + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "cannot convert a slice of length " |); + mk_str (| " to Function" |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "usize" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "slice") + [] + [ Ty.path "u8" ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| src |) |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_slice : + M.IsAssociatedFunction.Trait Self "from_slice" from_slice. + Admitted. + Global Typeclasses Opaque from_slice. + + (* + pub fn left_padding_from(value: &[u8]) -> Self { + Self($crate::FixedBytes::left_padding_from(value)) + } + *) + Definition left_padding_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::function::Function" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + "left_padding_from", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| value |) |) |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_left_padding_from : + M.IsAssociatedFunction.Trait Self "left_padding_from" left_padding_from. + Admitted. + Global Typeclasses Opaque left_padding_from. + + (* + pub fn right_padding_from(value: &[u8]) -> Self { + Self($crate::FixedBytes::right_padding_from(value)) + } + *) + Definition right_padding_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bits::function::Function" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + "right_padding_from", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| value |) |) |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_right_padding_from : + M.IsAssociatedFunction.Trait Self "right_padding_from" right_padding_from. + Admitted. + Global Typeclasses Opaque right_padding_from. + + (* + pub const fn into_array(self) -> [u8; $n] { + self.0 .0 + } + *) + Definition into_array (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_tuple_field (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::function::Function", + 0 + |), + "alloy_primitives::bits::fixed::FixedBytes", + 0 + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_into_array : + M.IsAssociatedFunction.Trait Self "into_array" into_array. + Admitted. + Global Typeclasses Opaque into_array. + + (* + pub fn covers(&self, b: &Self) -> bool { + &( *b & *self) == b + } + *) + Definition covers (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; b ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let b := M.alloc (| b |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::function::Function" ], + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::function::Function" ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::bits::function::Function", + M.get_trait_method (| + "core::ops::bit::BitAnd", + Ty.path "alloy_primitives::bits::function::Function", + [], + [ Ty.path "alloy_primitives::bits::function::Function" ], + "bitand", + [], + [] + |), + [ + M.read (| M.deref (| M.read (| b |) |) |); + M.read (| M.deref (| M.read (| self |) |) |) + ] + |) + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, b |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_covers : M.IsAssociatedFunction.Trait Self "covers" covers. + Admitted. + Global Typeclasses Opaque covers. + + (* + pub const fn const_eq(&self, other: &Self) -> bool { + self.0.const_eq(&other.0) + } + *) + Definition const_eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + "const_eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bits::function::Function", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_const_eq : + M.IsAssociatedFunction.Trait Self "const_eq" const_eq. + Admitted. + Global Typeclasses Opaque const_eq. + + (* + pub const fn bit_and(self, rhs: Self) -> Self { + Self(self.0.bit_and(rhs.0)) + } + *) + Definition bit_and (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + Value.StructTuple + "alloy_primitives::bits::function::Function" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + "bit_and", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::function::Function", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::function::Function", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_bit_and : + M.IsAssociatedFunction.Trait Self "bit_and" bit_and. + Admitted. + Global Typeclasses Opaque bit_and. + + (* + pub const fn bit_or(self, rhs: Self) -> Self { + Self(self.0.bit_or(rhs.0)) + } + *) + Definition bit_or (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + Value.StructTuple + "alloy_primitives::bits::function::Function" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + "bit_or", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::function::Function", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::function::Function", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_bit_or : M.IsAssociatedFunction.Trait Self "bit_or" bit_or. + Admitted. + Global Typeclasses Opaque bit_or. + + (* + pub const fn bit_xor(self, rhs: Self) -> Self { + Self(self.0.bit_xor(rhs.0)) + } + *) + Definition bit_xor (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + Value.StructTuple + "alloy_primitives::bits::function::Function" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 24 ] + [], + "bit_xor", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::bits::function::Function", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::bits::function::Function", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_bit_xor : + M.IsAssociatedFunction.Trait Self "bit_xor" bit_xor. + Admitted. + Global Typeclasses Opaque bit_xor. + End Impl_alloy_primitives_bits_function_Function. + End function. +End bits. diff --git a/CoqOfRust/alloy_primitives/bits/mod.rs b/CoqOfRust/alloy_primitives/bits/mod.rs new file mode 100644 index 000000000..be6568574 --- /dev/null +++ b/CoqOfRust/alloy_primitives/bits/mod.rs @@ -0,0 +1,20 @@ +#[macro_use] +mod macros; + +mod address; +pub use address::{Address, AddressChecksumBuffer, AddressError}; + +mod bloom; +pub use bloom::{Bloom, BloomInput, BLOOM_BITS_PER_ITEM, BLOOM_SIZE_BITS, BLOOM_SIZE_BYTES}; + +mod fixed; +pub use fixed::FixedBytes; + +mod function; +pub use function::Function; + +#[cfg(feature = "rlp")] +mod rlp; + +#[cfg(feature = "serde")] +mod serde; diff --git a/CoqOfRust/alloy_primitives/bits/rlp.rs b/CoqOfRust/alloy_primitives/bits/rlp.rs new file mode 100644 index 000000000..c3dd5bbfd --- /dev/null +++ b/CoqOfRust/alloy_primitives/bits/rlp.rs @@ -0,0 +1,35 @@ +use super::FixedBytes; +use alloy_rlp::{length_of_length, Decodable, Encodable, MaxEncodedLen, MaxEncodedLenAssoc}; + +impl Decodable for FixedBytes { + #[inline] + fn decode(buf: &mut &[u8]) -> alloy_rlp::Result { + Decodable::decode(buf).map(Self) + } +} + +impl Encodable for FixedBytes { + #[inline] + fn length(&self) -> usize { + self.0.length() + } + + #[inline] + fn encode(&self, out: &mut dyn bytes::BufMut) { + self.0.encode(out); + } +} + +// cannot implement this with const generics due to Rust issue #76560: +// https://github.com/rust-lang/rust/issues/76560 +macro_rules! fixed_bytes_max_encoded_len { + ($($sz:literal),+) => {$( + unsafe impl MaxEncodedLen<{ $sz + length_of_length($sz) }> for FixedBytes<$sz> {} + )+}; +} + +fixed_bytes_max_encoded_len!(0, 1, 2, 4, 8, 16, 20, 32, 64, 128, 256, 512, 1024); + +unsafe impl MaxEncodedLenAssoc for FixedBytes { + const LEN: usize = N + length_of_length(N); +} diff --git a/CoqOfRust/alloy_primitives/bits/serde.rs b/CoqOfRust/alloy_primitives/bits/serde.rs new file mode 100644 index 000000000..2e77dcd67 --- /dev/null +++ b/CoqOfRust/alloy_primitives/bits/serde.rs @@ -0,0 +1,112 @@ +use super::FixedBytes; +use core::fmt; +use serde::{ + de::{self, Visitor}, + Deserialize, Deserializer, Serialize, Serializer, +}; + +impl Serialize for FixedBytes { + fn serialize(&self, serializer: S) -> Result { + if serializer.is_human_readable() { + let mut buf = hex::Buffer::::new(); + serializer.serialize_str(buf.format(&self.0)) + } else { + serializer.serialize_bytes(self.as_slice()) + } + } +} + +impl<'de, const N: usize> Deserialize<'de> for FixedBytes { + fn deserialize>(deserializer: D) -> Result { + struct FixedVisitor; + + impl<'de, const N: usize> Visitor<'de> for FixedVisitor { + type Value = FixedBytes; + + fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { + write!( + formatter, + "{} bytes, represented as a hex string of length {}, an array of u8, or raw bytes", + N, + N * 2 + ) + } + + fn visit_bytes(self, v: &[u8]) -> Result { + FixedBytes::try_from(v).map_err(de::Error::custom) + } + + fn visit_seq>(self, mut seq: A) -> Result { + let len_error = + |i| de::Error::invalid_length(i, &format!("exactly {N} bytes").as_str()); + let mut bytes = [0u8; N]; + + for (i, byte) in bytes.iter_mut().enumerate() { + *byte = seq.next_element()?.ok_or_else(|| len_error(i))?; + } + + if let Ok(Some(_)) = seq.next_element::() { + return Err(len_error(N + 1)); + } + + Ok(FixedBytes(bytes)) + } + + fn visit_str(self, v: &str) -> Result { + as hex::FromHex>::from_hex(v).map_err(de::Error::custom) + } + } + + if deserializer.is_human_readable() { + deserializer.deserialize_any(FixedVisitor::) + } else { + deserializer.deserialize_bytes(FixedVisitor::) + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + use alloc::string::ToString; + use serde::Deserialize; + + #[derive(Debug, Deserialize)] + struct TestCase { + fixed: FixedBytes, + } + + #[test] + fn serde() { + let bytes = FixedBytes([0, 0, 0, 0, 1, 35, 69, 103, 137, 171, 205, 239]); + let ser = serde_json::to_string(&bytes).unwrap(); + assert_eq!(ser, "\"0x000000000123456789abcdef\""); + assert_eq!(serde_json::from_str::>(&ser).unwrap(), bytes); + + let val = serde_json::to_value(bytes).unwrap(); + assert_eq!(val, serde_json::json! {"0x000000000123456789abcdef"}); + assert_eq!(serde_json::from_value::>(val).unwrap(), bytes); + } + + #[test] + fn serde_num_array() { + let json = serde_json::json! {{"fixed": [0,1,2,3,4]}}; + + assert_eq!( + serde_json::from_value::>(json.clone()).unwrap().fixed, + FixedBytes([0, 1, 2, 3, 4]) + ); + + let e = serde_json::from_value::>(json).unwrap_err(); + let es = e.to_string(); + assert!(es.contains("invalid length 5, expected exactly 4 bytes"), "{es}"); + } + + #[test] + fn test_bincode_roundtrip() { + let bytes = FixedBytes([0, 0, 0, 0, 1, 35, 69, 103, 137, 171, 205, 239]); + + let bin = bincode::serialize(&bytes).unwrap(); + assert_eq!(bincode::deserialize::>(&bin).unwrap(), bytes); + } +} diff --git a/CoqOfRust/alloy_primitives/bytes/mod.rs b/CoqOfRust/alloy_primitives/bytes/mod.rs new file mode 100644 index 000000000..0b5aee34b --- /dev/null +++ b/CoqOfRust/alloy_primitives/bytes/mod.rs @@ -0,0 +1,404 @@ +use crate::FixedBytes; +use alloc::{boxed::Box, string::String, vec::Vec}; +use core::{ + borrow::Borrow, + fmt, + ops::{Deref, DerefMut, RangeBounds}, +}; + +#[cfg(feature = "rlp")] +mod rlp; + +#[cfg(feature = "serde")] +mod serde; + +/// Wrapper type around [`bytes::Bytes`] to support "0x" prefixed hex strings. +#[derive(Clone, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[repr(transparent)] +pub struct Bytes(pub bytes::Bytes); + +impl Default for &Bytes { + #[inline] + fn default() -> Self { + static EMPTY: Bytes = Bytes::new(); + &EMPTY + } +} + +impl fmt::Debug for Bytes { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::LowerHex::fmt(self, f) + } +} + +impl fmt::Display for Bytes { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::LowerHex::fmt(self, f) + } +} + +impl fmt::LowerHex for Bytes { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.pad(&hex::encode_prefixed(self.as_ref())) + } +} + +impl fmt::UpperHex for Bytes { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.pad(&hex::encode_upper_prefixed(self.as_ref())) + } +} + +impl Deref for Bytes { + type Target = bytes::Bytes; + + #[inline] + fn deref(&self) -> &Self::Target { + &self.0 + } +} + +impl DerefMut for Bytes { + #[inline] + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } +} + +impl AsRef<[u8]> for Bytes { + #[inline] + fn as_ref(&self) -> &[u8] { + self.0.as_ref() + } +} + +impl Borrow<[u8]> for Bytes { + #[inline] + fn borrow(&self) -> &[u8] { + self.as_ref() + } +} + +impl FromIterator for Bytes { + #[inline] + fn from_iter>(iter: T) -> Self { + Self(bytes::Bytes::from_iter(iter)) + } +} + +impl<'a> FromIterator<&'a u8> for Bytes { + #[inline] + fn from_iter>(iter: T) -> Self { + Self(iter.into_iter().copied().collect::()) + } +} + +impl IntoIterator for Bytes { + type Item = u8; + type IntoIter = bytes::buf::IntoIter; + + #[inline] + fn into_iter(self) -> Self::IntoIter { + self.0.into_iter() + } +} + +impl<'a> IntoIterator for &'a Bytes { + type Item = &'a u8; + type IntoIter = core::slice::Iter<'a, u8>; + + #[inline] + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} + +impl From for Bytes { + #[inline] + fn from(value: bytes::Bytes) -> Self { + Self(value) + } +} + +impl From for bytes::Bytes { + #[inline] + fn from(value: Bytes) -> Self { + value.0 + } +} + +impl From> for Bytes { + #[inline] + fn from(value: Vec) -> Self { + Self(value.into()) + } +} + +impl From> for Bytes { + #[inline] + fn from(value: FixedBytes) -> Self { + value.to_vec().into() + } +} + +impl From<&'static FixedBytes> for Bytes { + #[inline] + fn from(value: &'static FixedBytes) -> Self { + Self::from_static(value.as_slice()) + } +} + +impl From<[u8; N]> for Bytes { + #[inline] + fn from(value: [u8; N]) -> Self { + value.to_vec().into() + } +} + +impl From<&'static [u8; N]> for Bytes { + #[inline] + fn from(value: &'static [u8; N]) -> Self { + Self::from_static(value) + } +} + +impl From<&'static [u8]> for Bytes { + #[inline] + fn from(value: &'static [u8]) -> Self { + Self::from_static(value) + } +} + +impl From<&'static str> for Bytes { + #[inline] + fn from(value: &'static str) -> Self { + Self::from_static(value.as_bytes()) + } +} + +impl From> for Bytes { + #[inline] + fn from(value: Box<[u8]>) -> Self { + Self(value.into()) + } +} + +impl From for Bytes { + #[inline] + fn from(value: String) -> Self { + Self(value.into()) + } +} + +impl From for Vec { + #[inline] + fn from(value: Bytes) -> Self { + value.0.into() + } +} + +impl PartialEq<[u8]> for Bytes { + #[inline] + fn eq(&self, other: &[u8]) -> bool { + self[..] == *other + } +} + +impl PartialEq for [u8] { + #[inline] + fn eq(&self, other: &Bytes) -> bool { + *self == other[..] + } +} + +impl PartialEq> for Bytes { + #[inline] + fn eq(&self, other: &Vec) -> bool { + self[..] == other[..] + } +} + +impl PartialEq for Vec { + #[inline] + fn eq(&self, other: &Bytes) -> bool { + *other == *self + } +} + +impl PartialEq for Bytes { + #[inline] + fn eq(&self, other: &bytes::Bytes) -> bool { + other == self.as_ref() + } +} + +impl core::str::FromStr for Bytes { + type Err = hex::FromHexError; + + #[inline] + fn from_str(value: &str) -> Result { + hex::decode(value).map(Into::into) + } +} + +impl hex::FromHex for Bytes { + type Error = hex::FromHexError; + + #[inline] + fn from_hex>(hex: T) -> Result { + hex::decode(hex).map(Self::from) + } +} + +impl bytes::Buf for Bytes { + #[inline] + fn remaining(&self) -> usize { + self.0.len() + } + + #[inline] + fn chunk(&self) -> &[u8] { + self.0.chunk() + } + + #[inline] + fn advance(&mut self, cnt: usize) { + self.0.advance(cnt) + } + + #[inline] + fn copy_to_bytes(&mut self, len: usize) -> bytes::Bytes { + self.0.copy_to_bytes(len) + } +} + +impl Bytes { + /// Creates a new empty `Bytes`. + /// + /// This will not allocate and the returned `Bytes` handle will be empty. + /// + /// # Examples + /// + /// ``` + /// use alloy_primitives::Bytes; + /// + /// let b = Bytes::new(); + /// assert_eq!(&b[..], b""); + /// ``` + #[inline] + pub const fn new() -> Self { + Self(bytes::Bytes::new()) + } + + /// Creates a new `Bytes` from a static slice. + /// + /// The returned `Bytes` will point directly to the static slice. There is + /// no allocating or copying. + /// + /// # Examples + /// + /// ``` + /// use alloy_primitives::Bytes; + /// + /// let b = Bytes::from_static(b"hello"); + /// assert_eq!(&b[..], b"hello"); + /// ``` + #[inline] + pub const fn from_static(bytes: &'static [u8]) -> Self { + Self(bytes::Bytes::from_static(bytes)) + } + + /// Creates a new `Bytes` instance from a slice by copying it. + #[inline] + pub fn copy_from_slice(data: &[u8]) -> Self { + Self(bytes::Bytes::copy_from_slice(data)) + } + + /// Returns a slice of self for the provided range. + #[inline] + pub fn slice(&self, range: impl RangeBounds) -> Self { + Self(self.0.slice(range)) + } + + /// Returns a slice of self that is equivalent to the given `subset`. + #[inline] + pub fn slice_ref(&self, subset: &[u8]) -> Self { + Self(self.0.slice_ref(subset)) + } + + /// Splits the bytes into two at the given index. + #[must_use = "consider Bytes::truncate if you don't need the other half"] + #[inline] + pub fn split_off(&mut self, at: usize) -> Self { + Self(self.0.split_off(at)) + } + + /// Splits the bytes into two at the given index. + #[must_use = "consider Bytes::advance if you don't need the other half"] + #[inline] + pub fn split_to(&mut self, at: usize) -> Self { + Self(self.0.split_to(at)) + } +} + +#[cfg(feature = "arbitrary")] +impl<'a> arbitrary::Arbitrary<'a> for Bytes { + #[inline] + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + u.arbitrary_iter()?.collect::>>().map(Into::into) + } + + #[inline] + fn arbitrary_take_rest(u: arbitrary::Unstructured<'a>) -> arbitrary::Result { + Ok(Self(u.take_rest().to_vec().into())) + } + + #[inline] + fn size_hint(_depth: usize) -> (usize, Option) { + (0, None) + } +} + +#[cfg(feature = "arbitrary")] +impl proptest::arbitrary::Arbitrary for Bytes { + type Parameters = proptest::arbitrary::ParamsFor>; + type Strategy = proptest::arbitrary::Mapped, Self>; + + #[inline] + fn arbitrary() -> Self::Strategy { + use proptest::strategy::Strategy; + proptest::arbitrary::any::>().prop_map(|vec| Self(vec.into())) + } + + #[inline] + fn arbitrary_with(args: Self::Parameters) -> Self::Strategy { + use proptest::strategy::Strategy; + proptest::arbitrary::any_with::>(args).prop_map(|vec| Self(vec.into())) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn parse() { + let expected = Bytes::from_static(&[0x12, 0x13, 0xab, 0xcd]); + assert_eq!("1213abcd".parse::().unwrap(), expected); + assert_eq!("0x1213abcd".parse::().unwrap(), expected); + assert_eq!("1213ABCD".parse::().unwrap(), expected); + assert_eq!("0x1213ABCD".parse::().unwrap(), expected); + } + + #[test] + fn format() { + let b = Bytes::from_static(&[1, 35, 69, 103, 137, 171, 205, 239]); + assert_eq!(format!("{b}"), "0x0123456789abcdef"); + assert_eq!(format!("{b:x}"), "0x0123456789abcdef"); + assert_eq!(format!("{b:?}"), "0x0123456789abcdef"); + assert_eq!(format!("{b:#?}"), "0x0123456789abcdef"); + assert_eq!(format!("{b:#x}"), "0x0123456789abcdef"); + assert_eq!(format!("{b:X}"), "0x0123456789ABCDEF"); + assert_eq!(format!("{b:#X}"), "0x0123456789ABCDEF"); + } +} diff --git a/CoqOfRust/alloy_primitives/bytes/mod.v b/CoqOfRust/alloy_primitives/bytes/mod.v new file mode 100644 index 000000000..bf16babcf --- /dev/null +++ b/CoqOfRust/alloy_primitives/bytes/mod.v @@ -0,0 +1,2766 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module bytes_. + (* StructTuple + { + name := "Bytes"; + const_params := []; + ty_params := []; + fields := [ Ty.path "bytes::bytes::Bytes" ]; + } *) + + Module Impl_core_clone_Clone_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple + "alloy_primitives::bytes_::Bytes" + [ + M.call_closure (| + Ty.path "bytes::bytes::Bytes", + M.get_trait_method (| + "core::clone::Clone", + Ty.path "bytes::bytes::Bytes", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bytes_::Bytes", + 0 + |) + |) + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_default_Default_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* Default *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::bytes_::Bytes" + [ + M.call_closure (| + Ty.path "bytes::bytes::Bytes", + M.get_trait_method (| + "core::default::Default", + Ty.path "bytes::bytes::Bytes", + [], + [], + "default", + [], + [] + |), + [] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_marker_StructuralPartialEq_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + Axiom Implements : + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_cmp_PartialEq_alloy_primitives_bytes__Bytes_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* PartialEq *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.path "bytes::bytes::Bytes", + [], + [ Ty.path "bytes::bytes::Bytes" ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bytes_::Bytes", + 0 + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bytes_::Bytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bytes_::Bytes" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_bytes__Bytes_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_cmp_Eq_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* Eq *) + Definition assert_receiver_is_total_eq + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method assert_receiver_is_total_eq) ]. + End Impl_core_cmp_Eq_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_cmp_PartialOrd_alloy_primitives_bytes__Bytes_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* PartialOrd *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "bytes::bytes::Bytes", + [], + [ Ty.path "bytes::bytes::Bytes" ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bytes_::Bytes", + 0 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bytes_::Bytes", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bytes_::Bytes" ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_alloy_primitives_bytes__Bytes_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_cmp_Ord_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* Ord *) + Definition cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "core::cmp::Ordering", + M.get_trait_method (| + "core::cmp::Ord", + Ty.path "bytes::bytes::Bytes", + [], + [], + "cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bytes_::Bytes", + 0 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::bytes_::Bytes", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Ord" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("cmp", InstanceField.Method cmp) ]. + End Impl_core_cmp_Ord_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_hash_Hash_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* Hash *) + Definition hash (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ __H ], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.path "bytes::bytes::Bytes", + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bytes_::Bytes", + 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::hash::Hash" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("hash", InstanceField.Method hash) ]. + End Impl_core_hash_Hash_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_default_Default_for_ref__alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bytes_::Bytes" ]. + + (* + fn default() -> Self { + static EMPTY: Bytes = Bytes::new(); + &EMPTY + } + *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.get_constant "alloy_primitives::bytes_::default::EMPTY" |) |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_ref__alloy_primitives_bytes__Bytes. + + Module Impl_core_fmt_Debug_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::LowerHex::fmt(self, f) + } + *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::LowerHex", + Ty.path "alloy_primitives::bytes_::Bytes", + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_fmt_Display_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::LowerHex::fmt(self, f) + } + *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::LowerHex", + Ty.path "alloy_primitives::bytes_::Bytes", + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Display" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Display_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_fmt_LowerHex_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.pad(&hex::encode_prefixed(self.as_ref())) + } + *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "pad", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloc::string::String", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| + "const_hex::encode_prefixed", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.path "alloy_primitives::bytes_::Bytes", + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "as_ref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::LowerHex" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_LowerHex_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_fmt_UpperHex_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.pad(&hex::encode_upper_prefixed(self.as_ref())) + } + *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "pad", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloc::string::String", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| + "const_hex::encode_upper_prefixed", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.path "alloy_primitives::bytes_::Bytes", + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "as_ref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::UpperHex" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_UpperHex_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_ops_deref_Deref_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* type Target = bytes::Bytes; *) + Definition _Target : Ty.t := Ty.path "bytes::bytes::Bytes". + + (* + fn deref(&self) -> &Self::Target { + &self.0 + } + *) + Definition deref (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bytes_::Bytes", + 0 + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::deref::Deref" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("Target", InstanceField.Ty _Target); ("deref", InstanceField.Method deref) ]. + End Impl_core_ops_deref_Deref_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_ops_deref_DerefMut_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.0 + } + *) + Definition deref_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bytes_::Bytes", + 0 + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::deref::DerefMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("deref_mut", InstanceField.Method deref_mut) ]. + End Impl_core_ops_deref_DerefMut_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_convert_AsRef_slice_u8_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* + fn as_ref(&self) -> &[u8] { + self.0.as_ref() + } + *) + Definition as_ref (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.path "bytes::bytes::Bytes", + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "as_ref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bytes_::Bytes", + 0 + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::AsRef" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("as_ref", InstanceField.Method as_ref) ]. + End Impl_core_convert_AsRef_slice_u8_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_borrow_Borrow_slice_u8_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* + fn borrow(&self) -> &[u8] { + self.as_ref() + } + *) + Definition borrow (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.path "alloy_primitives::bytes_::Bytes", + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "as_ref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::borrow::Borrow" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("borrow", InstanceField.Method borrow) ]. + End Impl_core_borrow_Borrow_slice_u8_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_iter_traits_collect_FromIterator_u8_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* + fn from_iter>(iter: T) -> Self { + Self(bytes::Bytes::from_iter(iter)) + } + *) + Definition from_iter (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + Value.StructTuple + "alloy_primitives::bytes_::Bytes" + [ + M.call_closure (| + Ty.path "bytes::bytes::Bytes", + M.get_trait_method (| + "core::iter::traits::collect::FromIterator", + Ty.path "bytes::bytes::Bytes", + [], + [ Ty.path "u8" ], + "from_iter", + [], + [ T ] + |), + [ M.read (| iter |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::iter::traits::collect::FromIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u8" ] + Self + (* Instance *) [ ("from_iter", InstanceField.Method from_iter) ]. + End Impl_core_iter_traits_collect_FromIterator_u8_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_iter_traits_collect_FromIterator_ref__u8_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* + fn from_iter>(iter: T) -> Self { + Self(iter.into_iter().copied().collect::()) + } + *) + Definition from_iter (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + Value.StructTuple + "alloy_primitives::bytes_::Bytes" + [ + M.call_closure (| + Ty.path "bytes::bytes::Bytes", + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + T + "IntoIter" + ], + [], + [], + "collect", + [], + [ Ty.path "bytes::bytes::Bytes" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::iter::adapters::copied::Copied") + [] + [ + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + T + "IntoIter" + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + T + "IntoIter", + [], + [], + "copied", + [], + [ Ty.path "u8" ] + |), + [ + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + T + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + T, + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| iter |) ] + |) + ] + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::iter::traits::collect::FromIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "&") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("from_iter", InstanceField.Method from_iter) ]. + End Impl_core_iter_traits_collect_FromIterator_ref__u8_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_iter_traits_collect_IntoIterator_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* type Item = u8; *) + Definition _Item : Ty.t := Ty.path "u8". + + (* type IntoIter = bytes::buf::IntoIter; *) + Definition _IntoIter : Ty.t := + Ty.apply (Ty.path "bytes::buf::iter::IntoIter") [] [ Ty.path "bytes::bytes::Bytes" ]. + + (* + fn into_iter(self) -> Self::IntoIter { + self.0.into_iter() + } + *) + Definition into_iter (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply (Ty.path "bytes::buf::iter::IntoIter") [] [ Ty.path "bytes::bytes::Bytes" ], + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + Ty.path "bytes::bytes::Bytes", + [], + [], + "into_iter", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| self, "alloy_primitives::bytes_::Bytes", 0 |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::iter::traits::collect::IntoIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("Item", InstanceField.Ty _Item); + ("IntoIter", InstanceField.Ty _IntoIter); + ("into_iter", InstanceField.Method into_iter) + ]. + End Impl_core_iter_traits_collect_IntoIterator_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_iter_traits_collect_IntoIterator_for_ref__alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := + Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bytes_::Bytes" ]. + + (* type Item = &'a u8; *) + Definition _Item : Ty.t := Ty.apply (Ty.path "&") [] [ Ty.path "u8" ]. + + (* type IntoIter = core::slice::Iter<'a, u8>; *) + Definition _IntoIter : Ty.t := Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u8" ]. + + (* + fn into_iter(self) -> Self::IntoIter { + self.iter() + } + *) + Definition into_iter (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply (Ty.path "core::slice::iter::Iter") [] [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "iter", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "bytes::bytes::Bytes", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "bytes::bytes::Bytes" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloy_primitives::bytes_::Bytes", + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |) + ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::iter::traits::collect::IntoIterator" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("Item", InstanceField.Ty _Item); + ("IntoIter", InstanceField.Ty _IntoIter); + ("into_iter", InstanceField.Method into_iter) + ]. + End Impl_core_iter_traits_collect_IntoIterator_for_ref__alloy_primitives_bytes__Bytes. + + Module Impl_core_convert_From_bytes_bytes_Bytes_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* + fn from(value: bytes::Bytes) -> Self { + Self(value) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple "alloy_primitives::bytes_::Bytes" [ M.read (| value |) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "bytes::bytes::Bytes" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_bytes_bytes_Bytes_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_convert_From_alloy_primitives_bytes__Bytes_for_bytes_bytes_Bytes. + Definition Self : Ty.t := Ty.path "bytes::bytes::Bytes". + + (* + fn from(value: Bytes) -> Self { + value.0 + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.read (| + M.SubPointer.get_struct_tuple_field (| value, "alloy_primitives::bytes_::Bytes", 0 |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bytes_::Bytes" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bytes__Bytes_for_bytes_bytes_Bytes. + + Module Impl_core_convert_From_alloc_vec_Vec_u8_alloc_alloc_Global_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* + fn from(value: Vec) -> Self { + Self(value.into()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bytes_::Bytes" + [ + M.call_closure (| + Ty.path "bytes::bytes::Bytes", + M.get_trait_method (| + "core::convert::Into", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "bytes::bytes::Bytes" ], + "into", + [], + [] + |), + [ M.read (| value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ] ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloc_vec_Vec_u8_alloc_alloc_Global_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_N_for_alloy_primitives_bytes__Bytes. + Definition Self (N : Value.t) : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* + fn from(value: FixedBytes) -> Self { + value.to_vec().into() + } + *) + Definition from (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.path "alloy_primitives::bytes_::Bytes", + M.get_trait_method (| + "core::convert::Into", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "alloy_primitives::bytes_::Bytes" ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "to_vec", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [], + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + |) + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ] + (Self N) + (* Instance *) [ ("from", InstanceField.Method (from N)) ]. + End Impl_core_convert_From_alloy_primitives_bits_fixed_FixedBytes_N_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_convert_From_ref__alloy_primitives_bits_fixed_FixedBytes_N_for_alloy_primitives_bytes__Bytes. + Definition Self (N : Value.t) : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* + fn from(value: &'static FixedBytes) -> Self { + Self::from_static(value.as_slice()) + } + *) + Definition from (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.path "alloy_primitives::bytes_::Bytes", + M.get_associated_function (| + Ty.path "alloy_primitives::bytes_::Bytes", + "from_static", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [], + "as_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| value |) |) |) ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] [] ] + ] + (Self N) + (* Instance *) [ ("from", InstanceField.Method (from N)) ]. + End Impl_core_convert_From_ref__alloy_primitives_bits_fixed_FixedBytes_N_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_convert_From_array_N_u8_for_alloy_primitives_bytes__Bytes. + Definition Self (N : Value.t) : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* + fn from(value: [u8; N]) -> Self { + value.to_vec().into() + } + *) + Definition from (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.path "alloy_primitives::bytes_::Bytes", + M.get_trait_method (| + "core::convert::Into", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "alloy_primitives::bytes_::Bytes" ], + "into", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "to_vec", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] + (Self N) + (* Instance *) [ ("from", InstanceField.Method (from N)) ]. + End Impl_core_convert_From_array_N_u8_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_convert_From_ref__array_N_u8_for_alloy_primitives_bytes__Bytes. + Definition Self (N : Value.t) : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* + fn from(value: &'static [u8; N]) -> Self { + Self::from_static(value) + } + *) + Definition from (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.path "alloy_primitives::bytes_::Bytes", + M.get_associated_function (| + Ty.path "alloy_primitives::bytes_::Bytes", + "from_static", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| value |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ N ] [ Ty.path "u8" ] ] ] + (Self N) + (* Instance *) [ ("from", InstanceField.Method (from N)) ]. + End Impl_core_convert_From_ref__array_N_u8_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_convert_From_ref__slice_u8_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* + fn from(value: &'static [u8]) -> Self { + Self::from_static(value) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.path "alloy_primitives::bytes_::Bytes", + M.get_associated_function (| + Ty.path "alloy_primitives::bytes_::Bytes", + "from_static", + [], + [] + |), + [ M.read (| value |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref__slice_u8_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_convert_From_ref__str_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* + fn from(value: &'static str) -> Self { + Self::from_static(value.as_bytes()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.path "alloy_primitives::bytes_::Bytes", + M.get_associated_function (| + Ty.path "alloy_primitives::bytes_::Bytes", + "from_static", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_associated_function (| Ty.path "str", "as_bytes", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| value |) |) |) ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref__str_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_convert_From_alloc_boxed_Box_slice_u8_alloc_alloc_Global_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* + fn from(value: Box<[u8]>) -> Self { + Self(value.into()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bytes_::Bytes" + [ + M.call_closure (| + Ty.path "bytes::bytes::Bytes", + M.get_trait_method (| + "core::convert::Into", + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ]; Ty.path "alloc::alloc::Global" + ], + [], + [ Ty.path "bytes::bytes::Bytes" ], + "into", + [], + [] + |), + [ M.read (| value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ]; Ty.path "alloc::alloc::Global" ] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloc_boxed_Box_slice_u8_alloc_alloc_Global_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_convert_From_alloc_string_String_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* + fn from(value: String) -> Self { + Self(value.into()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::bytes_::Bytes" + [ + M.call_closure (| + Ty.path "bytes::bytes::Bytes", + M.get_trait_method (| + "core::convert::Into", + Ty.path "alloc::string::String", + [], + [ Ty.path "bytes::bytes::Bytes" ], + "into", + [], + [] + |), + [ M.read (| value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloc::string::String" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloc_string_String_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_convert_From_alloy_primitives_bytes__Bytes_for_alloc_vec_Vec_u8_alloc_alloc_Global. + Definition Self : Ty.t := + Ty.apply (Ty.path "alloc::vec::Vec") [] [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ]. + + (* + fn from(value: Bytes) -> Self { + value.0.into() + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + M.get_trait_method (| + "core::convert::Into", + Ty.path "bytes::bytes::Bytes", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ] + ], + "into", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::bytes_::Bytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bytes_::Bytes" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bytes__Bytes_for_alloc_vec_Vec_u8_alloc_alloc_Global. + + Module Impl_core_cmp_PartialEq_slice_u8_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* + fn eq(&self, other: &[u8]) -> bool { + self[..] == *other + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "bytes::bytes::Bytes", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "bytes::bytes::Bytes" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloy_primitives::bytes_::Bytes", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_slice_u8_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_cmp_PartialEq_alloy_primitives_bytes__Bytes_for_slice_u8. + Definition Self : Ty.t := Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ]. + + (* + fn eq(&self, other: &Bytes) -> bool { + *self == other[..] + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "bytes::bytes::Bytes", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "bytes::bytes::Bytes" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloy_primitives::bytes_::Bytes", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| other |) |) + |) + ] + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bytes_::Bytes" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_bytes__Bytes_for_slice_u8. + + Module Impl_core_cmp_PartialEq_alloc_vec_Vec_u8_alloc_alloc_Global_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* + fn eq(&self, other: &Vec) -> bool { + self[..] == other[..] + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "bytes::bytes::Bytes", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "bytes::bytes::Bytes" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloy_primitives::bytes_::Bytes", + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) + |) + ] + |) + |) + |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ] ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloc_vec_Vec_u8_alloc_alloc_Global_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_cmp_PartialEq_alloy_primitives_bytes__Bytes_for_alloc_vec_Vec_u8_alloc_alloc_Global. + Definition Self : Ty.t := + Ty.apply (Ty.path "alloc::vec::Vec") [] [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ]. + + (* + fn eq(&self, other: &Bytes) -> bool { + *other == *self + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.path "alloy_primitives::bytes_::Bytes", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bytes_::Bytes" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_bytes__Bytes_for_alloc_vec_Vec_u8_alloc_alloc_Global. + + Module Impl_core_cmp_PartialEq_bytes_bytes_Bytes_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* + fn eq(&self, other: &bytes::Bytes) -> bool { + other == self.as_ref() + } + *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "&") [] [ Ty.path "bytes::bytes::Bytes" ], + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, other |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.path "alloy_primitives::bytes_::Bytes", + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "as_ref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "bytes::bytes::Bytes" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_bytes_bytes_Bytes_for_alloy_primitives_bytes__Bytes. + + Module Impl_core_str_traits_FromStr_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* type Err = hex::FromHexError; *) + Definition _Err : Ty.t := Ty.path "const_hex::error::FromHexError". + + (* + fn from_str(value: &str) -> Result { + hex::decode(value).map(Into::into) + } + *) + Definition from_str (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "alloy_primitives::bytes_::Bytes"; Ty.path "const_hex::error::FromHexError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ]; + Ty.path "const_hex::error::FromHexError" + ], + "map", + [], + [ + Ty.path "alloy_primitives::bytes_::Bytes"; + Ty.function + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ] + ] + (Ty.path "alloy_primitives::bytes_::Bytes") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ]; + Ty.path "const_hex::error::FromHexError" + ], + M.get_function (| + "const_hex::decode", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + |), + [ M.read (| value |) ] + |); + M.get_trait_method (| + "core::convert::Into", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "alloy_primitives::bytes_::Bytes" ], + "into", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::str::traits::FromStr" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("Err", InstanceField.Ty _Err); ("from_str", InstanceField.Method from_str) ]. + End Impl_core_str_traits_FromStr_for_alloy_primitives_bytes__Bytes. + + Module Impl_const_hex_traits_FromHex_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* type Error = hex::FromHexError; *) + Definition _Error : Ty.t := Ty.path "const_hex::error::FromHexError". + + (* + fn from_hex>(hex: T) -> Result { + hex::decode(hex).map(Self::from) + } + *) + Definition from_hex (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ hex ] => + ltac:(M.monadic + (let hex := M.alloc (| hex |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "alloy_primitives::bytes_::Bytes"; Ty.path "const_hex::error::FromHexError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ]; + Ty.path "const_hex::error::FromHexError" + ], + "map", + [], + [ + Ty.path "alloy_primitives::bytes_::Bytes"; + Ty.function + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ] + ] + (Ty.path "alloy_primitives::bytes_::Bytes") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ]; + Ty.path "const_hex::error::FromHexError" + ], + M.get_function (| "const_hex::decode", [], [ T ] |), + [ M.read (| hex |) ] + |); + M.get_trait_method (| + "core::convert::From", + Ty.path "alloy_primitives::bytes_::Bytes", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ] + ], + "from", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "const_hex::traits::FromHex" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("from_hex", InstanceField.Method from_hex) ]. + End Impl_const_hex_traits_FromHex_for_alloy_primitives_bytes__Bytes. + + Module Impl_bytes_buf_buf_impl_Buf_for_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* + fn remaining(&self) -> usize { + self.0.len() + } + *) + Definition remaining (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| Ty.path "bytes::bytes::Bytes", "len", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bytes_::Bytes", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn chunk(&self) -> &[u8] { + self.0.chunk() + } + *) + Definition chunk (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "bytes::buf::buf_impl::Buf", + Ty.path "bytes::bytes::Bytes", + [], + [], + "chunk", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bytes_::Bytes", + 0 + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn advance(&mut self, cnt: usize) { + self.0.advance(cnt) + } + *) + Definition advance (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; cnt ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let cnt := M.alloc (| cnt |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "bytes::buf::buf_impl::Buf", + Ty.path "bytes::bytes::Bytes", + [], + [], + "advance", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bytes_::Bytes", + 0 + |) + |); + M.read (| cnt |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn copy_to_bytes(&mut self, len: usize) -> bytes::Bytes { + self.0.copy_to_bytes(len) + } + *) + Definition copy_to_bytes (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; len ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let len := M.alloc (| len |) in + M.call_closure (| + Ty.path "bytes::bytes::Bytes", + M.get_trait_method (| + "bytes::buf::buf_impl::Buf", + Ty.path "bytes::bytes::Bytes", + [], + [], + "copy_to_bytes", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bytes_::Bytes", + 0 + |) + |); + M.read (| len |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "bytes::buf::buf_impl::Buf" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("remaining", InstanceField.Method remaining); + ("chunk", InstanceField.Method chunk); + ("advance", InstanceField.Method advance); + ("copy_to_bytes", InstanceField.Method copy_to_bytes) + ]. + End Impl_bytes_buf_buf_impl_Buf_for_alloy_primitives_bytes__Bytes. + + Module Impl_alloy_primitives_bytes__Bytes. + Definition Self : Ty.t := Ty.path "alloy_primitives::bytes_::Bytes". + + (* + pub const fn new() -> Self { + Self(bytes::Bytes::new()) + } + *) + Definition new (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::bytes_::Bytes" + [ + M.call_closure (| + Ty.path "bytes::bytes::Bytes", + M.get_associated_function (| Ty.path "bytes::bytes::Bytes", "new", [], [] |), + [] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : M.IsAssociatedFunction.Trait Self "new" new. + Admitted. + Global Typeclasses Opaque new. + + (* + pub const fn from_static(bytes: &'static [u8]) -> Self { + Self(bytes::Bytes::from_static(bytes)) + } + *) + Definition from_static (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ bytes ] => + ltac:(M.monadic + (let bytes := M.alloc (| bytes |) in + Value.StructTuple + "alloy_primitives::bytes_::Bytes" + [ + M.call_closure (| + Ty.path "bytes::bytes::Bytes", + M.get_associated_function (| + Ty.path "bytes::bytes::Bytes", + "from_static", + [], + [] + |), + [ M.read (| bytes |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_static : + M.IsAssociatedFunction.Trait Self "from_static" from_static. + Admitted. + Global Typeclasses Opaque from_static. + + (* + pub fn copy_from_slice(data: &[u8]) -> Self { + Self(bytes::Bytes::copy_from_slice(data)) + } + *) + Definition copy_from_slice (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ data ] => + ltac:(M.monadic + (let data := M.alloc (| data |) in + Value.StructTuple + "alloy_primitives::bytes_::Bytes" + [ + M.call_closure (| + Ty.path "bytes::bytes::Bytes", + M.get_associated_function (| + Ty.path "bytes::bytes::Bytes", + "copy_from_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| data |) |) |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_copy_from_slice : + M.IsAssociatedFunction.Trait Self "copy_from_slice" copy_from_slice. + Admitted. + Global Typeclasses Opaque copy_from_slice. + + (* + pub fn slice(&self, range: impl RangeBounds) -> Self { + Self(self.0.slice(range)) + } + *) + Definition slice (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ impl_RangeBounds_usize_ ], [ self; range ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let range := M.alloc (| range |) in + Value.StructTuple + "alloy_primitives::bytes_::Bytes" + [ + M.call_closure (| + Ty.path "bytes::bytes::Bytes", + M.get_associated_function (| + Ty.path "bytes::bytes::Bytes", + "slice", + [], + [ impl_RangeBounds_usize_ ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bytes_::Bytes", + 0 + |) + |); + M.read (| range |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_slice : M.IsAssociatedFunction.Trait Self "slice" slice. + Admitted. + Global Typeclasses Opaque slice. + + (* + pub fn slice_ref(&self, subset: &[u8]) -> Self { + Self(self.0.slice_ref(subset)) + } + *) + Definition slice_ref (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; subset ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let subset := M.alloc (| subset |) in + Value.StructTuple + "alloy_primitives::bytes_::Bytes" + [ + M.call_closure (| + Ty.path "bytes::bytes::Bytes", + M.get_associated_function (| Ty.path "bytes::bytes::Bytes", "slice_ref", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bytes_::Bytes", + 0 + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| subset |) |) |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_slice_ref : + M.IsAssociatedFunction.Trait Self "slice_ref" slice_ref. + Admitted. + Global Typeclasses Opaque slice_ref. + + (* + pub fn split_off(&mut self, at: usize) -> Self { + Self(self.0.split_off(at)) + } + *) + Definition split_off (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; at_ ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let at_ := M.alloc (| at_ |) in + Value.StructTuple + "alloy_primitives::bytes_::Bytes" + [ + M.call_closure (| + Ty.path "bytes::bytes::Bytes", + M.get_associated_function (| Ty.path "bytes::bytes::Bytes", "split_off", [], [] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bytes_::Bytes", + 0 + |) + |); + M.read (| at_ |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_split_off : + M.IsAssociatedFunction.Trait Self "split_off" split_off. + Admitted. + Global Typeclasses Opaque split_off. + + (* + pub fn split_to(&mut self, at: usize) -> Self { + Self(self.0.split_to(at)) + } + *) + Definition split_to (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; at_ ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let at_ := M.alloc (| at_ |) in + Value.StructTuple + "alloy_primitives::bytes_::Bytes" + [ + M.call_closure (| + Ty.path "bytes::bytes::Bytes", + M.get_associated_function (| Ty.path "bytes::bytes::Bytes", "split_to", [], [] |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::bytes_::Bytes", + 0 + |) + |); + M.read (| at_ |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_split_to : + M.IsAssociatedFunction.Trait Self "split_to" split_to. + Admitted. + Global Typeclasses Opaque split_to. + End Impl_alloy_primitives_bytes__Bytes. +End bytes_. diff --git a/CoqOfRust/alloy_primitives/bytes/rlp.rs b/CoqOfRust/alloy_primitives/bytes/rlp.rs new file mode 100644 index 000000000..4c8ed63d4 --- /dev/null +++ b/CoqOfRust/alloy_primitives/bytes/rlp.rs @@ -0,0 +1,21 @@ +use super::Bytes; +use alloy_rlp::{Decodable, Encodable}; + +impl Encodable for Bytes { + #[inline] + fn length(&self) -> usize { + self.0.length() + } + + #[inline] + fn encode(&self, out: &mut dyn bytes::BufMut) { + self.0.encode(out); + } +} + +impl Decodable for Bytes { + #[inline] + fn decode(buf: &mut &[u8]) -> Result { + bytes::Bytes::decode(buf).map(Self) + } +} diff --git a/CoqOfRust/alloy_primitives/bytes/serde.rs b/CoqOfRust/alloy_primitives/bytes/serde.rs new file mode 100644 index 000000000..7f0cc566b --- /dev/null +++ b/CoqOfRust/alloy_primitives/bytes/serde.rs @@ -0,0 +1,103 @@ +use crate::Bytes; +use alloc::vec::Vec; +use core::fmt; +use serde::de::{self, Visitor}; + +impl serde::Serialize for Bytes { + #[inline] + fn serialize(&self, serializer: S) -> Result { + if serializer.is_human_readable() { + hex::serialize(self, serializer) + } else { + serializer.serialize_bytes(self.as_ref()) + } + } +} + +impl<'de> serde::Deserialize<'de> for Bytes { + #[inline] + fn deserialize>(deserializer: D) -> Result { + struct BytesVisitor; + + impl<'de> Visitor<'de> for BytesVisitor { + type Value = Bytes; + + fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { + formatter.write_str("a variable number of bytes represented as a hex string, an array of u8, or raw bytes") + } + + fn visit_bytes(self, v: &[u8]) -> Result { + Ok(Bytes::from(v.to_vec())) + } + + fn visit_byte_buf(self, v: Vec) -> Result { + Ok(Bytes::from(v)) + } + + fn visit_seq>(self, mut seq: A) -> Result { + let mut bytes = Vec::with_capacity(seq.size_hint().unwrap_or(0)); + + while let Some(byte) = seq.next_element()? { + bytes.push(byte); + } + + Ok(Bytes::from(bytes)) + } + + fn visit_str(self, v: &str) -> Result { + hex::decode(v) + .map_err(|_| { + de::Error::invalid_value(de::Unexpected::Str(v), &"a valid hex string") + }) + .map(From::from) + } + } + + if deserializer.is_human_readable() { + deserializer.deserialize_any(BytesVisitor) + } else { + deserializer.deserialize_byte_buf(BytesVisitor) + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + use serde::Deserialize; + + #[derive(Debug, Deserialize)] + struct TestCase { + variable: Bytes, + } + + #[test] + fn serde() { + let bytes = Bytes::from_static(&[1, 35, 69, 103, 137, 171, 205, 239]); + let ser = serde_json::to_string(&bytes).unwrap(); + assert_eq!(ser, "\"0x0123456789abcdef\""); + assert_eq!(serde_json::from_str::(&ser).unwrap(), bytes); + + let val = serde_json::to_value(&bytes).unwrap(); + assert_eq!(val, serde_json::json! {"0x0123456789abcdef"}); + assert_eq!(serde_json::from_value::(val).unwrap(), bytes); + } + + #[test] + fn serde_num_array() { + let json = serde_json::json! {{"variable": [0,1,2,3,4]}}; + + assert_eq!( + serde_json::from_value::(json).unwrap().variable, + Bytes::from_static(&[0, 1, 2, 3, 4]) + ); + } + + #[test] + fn test_bincode_roundtrip() { + let bytes = Bytes::from_static(&[1, 35, 69, 103, 137, 171, 205, 239]); + + let bin = bincode::serialize(&bytes).unwrap(); + assert_eq!(bincode::deserialize::(&bin).unwrap(), bytes); + } +} diff --git a/CoqOfRust/alloy_primitives/common.rs b/CoqOfRust/alloy_primitives/common.rs new file mode 100644 index 000000000..355165173 --- /dev/null +++ b/CoqOfRust/alloy_primitives/common.rs @@ -0,0 +1,120 @@ +use crate::Address; + +#[cfg(feature = "rlp")] +use alloy_rlp::{Buf, BufMut, Decodable, Encodable, EMPTY_STRING_CODE}; + +/// The `to` field of a transaction. Either a target address, or empty for a +/// contract creation. +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "arbitrary", derive(derive_arbitrary::Arbitrary, proptest_derive::Arbitrary))] +#[doc(alias = "TransactionKind")] +pub enum TxKind { + /// A transaction that creates a contract. + #[default] + Create, + /// A transaction that calls a contract or transfer. + Call(Address), +} + +impl From> for TxKind { + /// Creates a `TxKind::Call` with the `Some` address, `None` otherwise. + #[inline] + fn from(value: Option
) -> Self { + match value { + None => Self::Create, + Some(addr) => Self::Call(addr), + } + } +} + +impl From
for TxKind { + /// Creates a `TxKind::Call` with the given address. + #[inline] + fn from(value: Address) -> Self { + Self::Call(value) + } +} + +impl From for Option
{ + /// Returns the address of the contract that will be called or will receive the transfer. + #[inline] + fn from(value: TxKind) -> Self { + value.to().copied() + } +} + +impl TxKind { + /// Returns the address of the contract that will be called or will receive the transfer. + pub const fn to(&self) -> Option<&Address> { + match self { + Self::Create => None, + Self::Call(to) => Some(to), + } + } + + /// Returns true if the transaction is a contract creation. + #[inline] + pub const fn is_create(&self) -> bool { + matches!(self, Self::Create) + } + + /// Returns true if the transaction is a contract call. + #[inline] + pub const fn is_call(&self) -> bool { + matches!(self, Self::Call(_)) + } + + /// Calculates a heuristic for the in-memory size of this object. + #[inline] + pub const fn size(&self) -> usize { + core::mem::size_of::() + } +} + +#[cfg(feature = "rlp")] +impl Encodable for TxKind { + fn encode(&self, out: &mut dyn BufMut) { + match self { + Self::Call(to) => to.encode(out), + Self::Create => out.put_u8(EMPTY_STRING_CODE), + } + } + + fn length(&self) -> usize { + match self { + Self::Call(to) => to.length(), + Self::Create => 1, // EMPTY_STRING_CODE is a single byte + } + } +} + +#[cfg(feature = "rlp")] +impl Decodable for TxKind { + fn decode(buf: &mut &[u8]) -> alloy_rlp::Result { + if let Some(&first) = buf.first() { + if first == EMPTY_STRING_CODE { + buf.advance(1); + Ok(Self::Create) + } else { + let addr =
::decode(buf)?; + Ok(Self::Call(addr)) + } + } else { + Err(alloy_rlp::Error::InputTooShort) + } + } +} + +#[cfg(feature = "serde")] +impl serde::Serialize for TxKind { + fn serialize(&self, serializer: S) -> Result { + self.to().serialize(serializer) + } +} + +#[cfg(feature = "serde")] +impl<'de> serde::Deserialize<'de> for TxKind { + fn deserialize>(deserializer: D) -> Result { + Ok(Option::
::deserialize(deserializer)?.into()) + } +} diff --git a/CoqOfRust/alloy_primitives/common.v b/CoqOfRust/alloy_primitives/common.v new file mode 100644 index 000000000..0d7638cbd --- /dev/null +++ b/CoqOfRust/alloy_primitives/common.v @@ -0,0 +1,724 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module common. + (* + Enum TxKind + { + const_params := []; + ty_params := []; + variants := + [ + { + name := "Create"; + item := StructTuple []; + }; + { + name := "Call"; + item := StructTuple [ Ty.path "alloy_primitives::bits::address::Address" ]; + } + ]; + } + *) + + Axiom IsDiscriminant_TxKind_Create : + M.IsDiscriminant "alloy_primitives::common::TxKind::Create" 0. + Axiom IsDiscriminant_TxKind_Call : M.IsDiscriminant "alloy_primitives::common::TxKind::Call" 1. + + Module Impl_core_clone_Clone_for_alloy_primitives_common_TxKind. + Definition Self : Ty.t := Ty.path "alloy_primitives::common::TxKind". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.deref (| M.read (| self |) |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_alloy_primitives_common_TxKind. + + Module Impl_core_marker_Copy_for_alloy_primitives_common_TxKind. + Definition Self : Ty.t := Ty.path "alloy_primitives::common::TxKind". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_alloy_primitives_common_TxKind. + + Module Impl_core_fmt_Debug_for_alloy_primitives_common_TxKind. + Definition Self : Ty.t := Ty.path "alloy_primitives::common::TxKind". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ]), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| γ, "alloy_primitives::common::TxKind::Create" |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Create" |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::common::TxKind::Call", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Call" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_alloy_primitives_common_TxKind. + + Module Impl_core_default_Default_for_alloy_primitives_common_TxKind. + Definition Self : Ty.t := Ty.path "alloy_primitives::common::TxKind". + + (* Default *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic (Value.StructTuple "alloy_primitives::common::TxKind::Create" [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_alloy_primitives_common_TxKind. + + Module Impl_core_marker_StructuralPartialEq_for_alloy_primitives_common_TxKind. + Definition Self : Ty.t := Ty.path "alloy_primitives::common::TxKind". + + Axiom Implements : + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_alloy_primitives_common_TxKind. + + Module Impl_core_cmp_PartialEq_alloy_primitives_common_TxKind_for_alloy_primitives_common_TxKind. + Definition Self : Ty.t := Ty.path "alloy_primitives::common::TxKind". + + (* PartialEq *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.read (| + let~ __self_discr : Ty.path "isize" := + M.alloc (| + M.call_closure (| + Ty.path "isize", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "alloy_primitives::common::TxKind" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ __arg1_discr : Ty.path "isize" := + M.alloc (| + M.call_closure (| + Ty.path "isize", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "alloy_primitives::common::TxKind" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) ] + |) + |) in + M.alloc (| + LogicalOp.and (| + BinOp.eq (| M.read (| __self_discr |), M.read (| __arg1_discr |) |), + ltac:(M.monadic + (M.read (| + M.match_operator (| + Some (Ty.path "bool"), + M.alloc (| Value.Tuple [ M.read (| self |); M.read (| other |) ] |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_0 := M.read (| γ0_0 |) in + let γ2_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_0, + "alloy_primitives::common::TxKind::Call", + 0 + |) in + let __self_0 := M.alloc (| γ2_0 |) in + let γ0_1 := M.read (| γ0_1 |) in + let γ2_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_1, + "alloy_primitives::common::TxKind::Call", + 0 + |) in + let __arg1_0 := M.alloc (| γ2_0 |) in + M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::address::Address" ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::bits::address::Address" ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, __self_0 |); + M.borrow (| Pointer.Kind.Ref, __arg1_0 |) + ] + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Bool true |))) + ] + |) + |))) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::common::TxKind" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_common_TxKind_for_alloy_primitives_common_TxKind. + + Module Impl_core_cmp_Eq_for_alloy_primitives_common_TxKind. + Definition Self : Ty.t := Ty.path "alloy_primitives::common::TxKind". + + (* Eq *) + Definition assert_receiver_is_total_eq + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method assert_receiver_is_total_eq) ]. + End Impl_core_cmp_Eq_for_alloy_primitives_common_TxKind. + + Module Impl_core_hash_Hash_for_alloy_primitives_common_TxKind. + Definition Self : Ty.t := Ty.path "alloy_primitives::common::TxKind". + + (* Hash *) + Definition hash (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ __H ], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ __self_discr : Ty.path "isize" := + M.alloc (| + M.call_closure (| + Ty.path "isize", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "alloy_primitives::common::TxKind" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.path "isize", + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_discr |) |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) in + M.match_operator (| + Some (Ty.tuple []), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::common::TxKind::Call", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.path "alloy_primitives::bits::address::Address", + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_0 |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::hash::Hash" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("hash", InstanceField.Method hash) ]. + End Impl_core_hash_Hash_for_alloy_primitives_common_TxKind. + + Module Impl_core_convert_From_core_option_Option_alloy_primitives_bits_address_Address_for_alloy_primitives_common_TxKind. + Definition Self : Ty.t := Ty.path "alloy_primitives::common::TxKind". + + (* + fn from(value: Option
) -> Self { + match value { + None => Self::Create, + Some(addr) => Self::Call(addr), + } + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.read (| + M.match_operator (| + Some (Ty.path "alloy_primitives::common::TxKind"), + value, + [ + fun γ => + ltac:(M.monadic + (let _ := M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| Value.StructTuple "alloy_primitives::common::TxKind::Create" [] |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let addr := M.copy (| γ0_0 |) in + M.alloc (| + Value.StructTuple + "alloy_primitives::common::TxKind::Call" + [ M.read (| addr |) ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "alloy_primitives::bits::address::Address" ] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_core_option_Option_alloy_primitives_bits_address_Address_for_alloy_primitives_common_TxKind. + + Module Impl_core_convert_From_alloy_primitives_bits_address_Address_for_alloy_primitives_common_TxKind. + Definition Self : Ty.t := Ty.path "alloy_primitives::common::TxKind". + + (* + fn from(value: Address) -> Self { + Self::Call(value) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple "alloy_primitives::common::TxKind::Call" [ M.read (| value |) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::bits::address::Address" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_bits_address_Address_for_alloy_primitives_common_TxKind. + + Module Impl_core_convert_From_alloy_primitives_common_TxKind_for_core_option_Option_alloy_primitives_bits_address_Address. + Definition Self : Ty.t := + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "alloy_primitives::bits::address::Address" ]. + + (* + fn from(value: TxKind) -> Self { + value.to().copied() + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "alloy_primitives::bits::address::Address" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::address::Address" ] + ], + "copied", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::address::Address" ] + ], + M.get_associated_function (| + Ty.path "alloy_primitives::common::TxKind", + "to", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::common::TxKind" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_common_TxKind_for_core_option_Option_alloy_primitives_bits_address_Address. + + Module Impl_alloy_primitives_common_TxKind. + Definition Self : Ty.t := Ty.path "alloy_primitives::common::TxKind". + + (* + pub const fn to(&self) -> Option<&Address> { + match self { + Self::Create => None, + Self::Call(to) => Some(to), + } + } + *) + Definition to (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::bits::address::Address" ] + ]), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| γ, "alloy_primitives::common::TxKind::Create" |) in + M.alloc (| Value.StructTuple "core::option::Option::None" [] |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::common::TxKind::Call", + 0 + |) in + let to := M.alloc (| γ1_0 |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| to |) |) |) ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_to : M.IsAssociatedFunction.Trait Self "to" to. + Admitted. + Global Typeclasses Opaque to. + + (* + pub const fn is_create(&self) -> bool { + matches!(self, Self::Create) + } + *) + Definition is_create (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some (Ty.path "bool"), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| γ, "alloy_primitives::common::TxKind::Create" |) in + M.alloc (| Value.Bool true |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Bool false |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_is_create : + M.IsAssociatedFunction.Trait Self "is_create" is_create. + Admitted. + Global Typeclasses Opaque is_create. + + (* + pub const fn is_call(&self) -> bool { + matches!(self, Self::Call(_)) + } + *) + Definition is_call (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some (Ty.path "bool"), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::common::TxKind::Call", + 0 + |) in + M.alloc (| Value.Bool true |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Bool false |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_is_call : + M.IsAssociatedFunction.Trait Self "is_call" is_call. + Admitted. + Global Typeclasses Opaque is_call. + + (* + pub const fn size(&self) -> usize { + core::mem::size_of::() + } + *) + Definition size (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "usize", + M.get_function (| + "core::mem::size_of", + [], + [ Ty.path "alloy_primitives::common::TxKind" ] + |), + [] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_size : M.IsAssociatedFunction.Trait Self "size" size. + Admitted. + Global Typeclasses Opaque size. + End Impl_alloy_primitives_common_TxKind. +End common. diff --git a/CoqOfRust/alloy_primitives/lib.rs b/CoqOfRust/alloy_primitives/lib.rs new file mode 100644 index 000000000..a4ad0ea93 --- /dev/null +++ b/CoqOfRust/alloy_primitives/lib.rs @@ -0,0 +1,121 @@ +#![doc = include_str!("../README.md")] +#![doc( + html_logo_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/alloy.jpg", + html_favicon_url = "https://raw.githubusercontent.com/alloy-rs/core/main/assets/favicon.ico" +)] +#![cfg_attr(not(test), warn(unused_crate_dependencies))] +#![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(feature = "nightly", feature(hasher_prefixfree_extras))] +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] + +#[macro_use] +extern crate alloc; + +use paste as _; +#[cfg(feature = "sha3-keccak")] +use sha3 as _; +use tiny_keccak as _; + +#[cfg(feature = "postgres")] +pub mod postgres; + +pub mod aliases; +#[doc(no_inline)] +pub use aliases::{ + BlockHash, BlockNumber, BlockTimestamp, ChainId, Selector, StorageKey, StorageValue, TxHash, + TxIndex, TxNonce, TxNumber, B128, B256, B512, B64, I128, I16, I160, I256, I32, I64, I8, U128, + U16, U160, U256, U32, U512, U64, U8, +}; + +#[macro_use] +mod bits; +pub use bits::{ + Address, AddressChecksumBuffer, AddressError, Bloom, BloomInput, FixedBytes, Function, + BLOOM_BITS_PER_ITEM, BLOOM_SIZE_BITS, BLOOM_SIZE_BYTES, +}; + +#[path = "bytes/mod.rs"] +mod bytes_; +pub use self::bytes_::Bytes; + +mod common; +pub use common::TxKind; + +mod log; +pub use log::{logs_bloom, IntoLogData, Log, LogData}; + +#[cfg(feature = "map")] +pub mod map; + +mod sealed; +pub use sealed::{Sealable, Sealed}; + +mod signed; +pub use signed::{BigIntConversionError, ParseSignedError, Sign, Signed}; + +mod signature; +pub use signature::{ + normalize_v, to_eip155_v, Parity, PrimitiveSignature, Signature, SignatureError, +}; + +pub mod utils; +pub use utils::{eip191_hash_message, keccak256, Keccak256}; + +#[doc(no_inline)] +pub use { + ::bytes, + ::hex, + hex_literal::{self, hex}, + ruint::{self, uint, Uint}, +}; + +#[cfg(feature = "serde")] +#[doc(no_inline)] +pub use ::hex::serde as serde_hex; + +/// 20-byte [fixed byte-array][FixedBytes] type. +/// +/// You'll likely want to use [`Address`] instead, as it is a different type +/// from `FixedBytes<20>`, and implements methods useful for working with +/// Ethereum addresses. +/// +/// If you are sure you want to use this type, and you don't want the +/// deprecation warning, you can use `aliases::B160`. +#[deprecated( + since = "0.3.2", + note = "you likely want to use `Address` instead. \ + `B160` and `Address` are different types, \ + see this type's documentation for more." +)] +pub type B160 = FixedBytes<20>; + +// Not public API. +#[doc(hidden)] +pub mod private { + pub use alloc::vec::Vec; + pub use core::{ + self, + borrow::{Borrow, BorrowMut}, + cmp::Ordering, + prelude::rust_2021::*, + }; + pub use derive_more; + + #[cfg(feature = "getrandom")] + pub use getrandom; + + #[cfg(feature = "rand")] + pub use rand; + + #[cfg(feature = "rlp")] + pub use alloy_rlp; + + #[cfg(feature = "allocative")] + pub use allocative; + + #[cfg(feature = "serde")] + pub use serde; + + #[cfg(feature = "arbitrary")] + pub use {arbitrary, derive_arbitrary, proptest, proptest_derive}; +} diff --git a/CoqOfRust/alloy_primitives/lib.v b/CoqOfRust/alloy_primitives/lib.v new file mode 100644 index 000000000..0769dabfe --- /dev/null +++ b/CoqOfRust/alloy_primitives/lib.v @@ -0,0 +1,9 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Axiom B160 : + (Ty.path "alloy_primitives::B160") = + (Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 20 ] + []). diff --git a/CoqOfRust/alloy_primitives/log/mod.rs b/CoqOfRust/alloy_primitives/log/mod.rs new file mode 100644 index 000000000..4d6612b11 --- /dev/null +++ b/CoqOfRust/alloy_primitives/log/mod.rs @@ -0,0 +1,249 @@ +use crate::{Address, Bloom, Bytes, B256}; +use alloc::vec::Vec; + +#[cfg(feature = "serde")] +mod serde; + +/// Compute the logs bloom filter for the given logs. +pub fn logs_bloom<'a>(logs: impl IntoIterator) -> Bloom { + let mut bloom = Bloom::ZERO; + for log in logs { + bloom.accrue_log(log); + } + bloom +} + +/// An Ethereum event log object. +#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "serde", derive(::serde::Serialize, ::serde::Deserialize))] +#[cfg_attr(feature = "arbitrary", derive(derive_arbitrary::Arbitrary, proptest_derive::Arbitrary))] +pub struct LogData { + /// The indexed topic list. + topics: Vec, + /// The plain data. + pub data: Bytes, +} + +impl LogData { + /// Creates a new log, without length-checking. This allows creation of + /// invalid logs. May be safely used when the length of the topic list is + /// known to be 4 or less. + #[inline] + pub const fn new_unchecked(topics: Vec, data: Bytes) -> Self { + Self { topics, data } + } + + /// Creates a new log. + #[inline] + pub fn new(topics: Vec, data: Bytes) -> Option { + let this = Self::new_unchecked(topics, data); + this.is_valid().then_some(this) + } + + /// Creates a new empty log. + #[inline] + pub const fn empty() -> Self { + Self { topics: Vec::new(), data: Bytes::new() } + } + + /// True if valid, false otherwise. + #[inline] + pub fn is_valid(&self) -> bool { + self.topics.len() <= 4 + } + + /// Get the topic list. + #[inline] + pub fn topics(&self) -> &[B256] { + &self.topics + } + + /// Get the topic list, mutably. This gives access to the internal + /// array, without allowing extension of that array. + #[inline] + pub fn topics_mut(&mut self) -> &mut [B256] { + &mut self.topics + } + + /// Get a mutable reference to the topic list. This allows creation of + /// invalid logs. + #[inline] + pub fn topics_mut_unchecked(&mut self) -> &mut Vec { + &mut self.topics + } + + /// Set the topic list, without length-checking. This allows creation of + /// invalid logs. + #[inline] + pub fn set_topics_unchecked(&mut self, topics: Vec) { + self.topics = topics; + } + + /// Set the topic list, truncating to 4 topics. + #[inline] + pub fn set_topics_truncating(&mut self, mut topics: Vec) { + topics.truncate(4); + self.set_topics_unchecked(topics); + } + + /// Consumes the log data, returning the topic list and the data. + #[inline] + pub fn split(self) -> (Vec, Bytes) { + (self.topics, self.data) + } +} + +/// Trait for an object that can be converted into a log data object. +pub trait IntoLogData { + /// Convert into a [`LogData`] object. + fn to_log_data(&self) -> LogData; + /// Consume and convert into a [`LogData`] object. + fn into_log_data(self) -> LogData; +} + +impl IntoLogData for LogData { + #[inline] + fn to_log_data(&self) -> LogData { + self.clone() + } + + #[inline] + fn into_log_data(self) -> LogData { + self + } +} + +/// A log consists of an address, and some log data. +#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "arbitrary", derive(derive_arbitrary::Arbitrary, proptest_derive::Arbitrary))] +pub struct Log { + /// The address which emitted this log. + pub address: Address, + /// The log data. + pub data: T, +} + +impl core::ops::Deref for Log { + type Target = T; + + #[inline] + fn deref(&self) -> &Self::Target { + &self.data + } +} + +impl core::ops::DerefMut for Log { + #[inline] + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.data + } +} + +impl Log { + /// Creates a new log. + #[inline] + pub fn new(address: Address, topics: Vec, data: Bytes) -> Option { + LogData::new(topics, data).map(|data| Self { address, data }) + } + + /// Creates a new log. + #[inline] + pub const fn new_unchecked(address: Address, topics: Vec, data: Bytes) -> Self { + Self { address, data: LogData::new_unchecked(topics, data) } + } + + /// Creates a new empty log. + #[inline] + pub const fn empty() -> Self { + Self { address: Address::ZERO, data: LogData::empty() } + } +} + +impl Log +where + for<'a> &'a T: Into, +{ + /// Creates a new log. + #[inline] + pub const fn new_from_event_unchecked(address: Address, data: T) -> Self { + Self { address, data } + } + + /// Creates a new log from an deserialized event. + pub fn new_from_event(address: Address, data: T) -> Option { + let this = Self::new_from_event_unchecked(address, data); + (&this.data).into().is_valid().then_some(this) + } + + /// Reserialize the data. + #[inline] + pub fn reserialize(&self) -> Log { + Log { address: self.address, data: (&self.data).into() } + } +} + +#[cfg(feature = "rlp")] +impl alloy_rlp::Encodable for Log { + fn encode(&self, out: &mut dyn alloy_rlp::BufMut) { + let payload_length = + self.address.length() + self.data.data.length() + self.data.topics.length(); + + alloy_rlp::Header { list: true, payload_length }.encode(out); + self.address.encode(out); + self.data.topics.encode(out); + self.data.data.encode(out); + } + + fn length(&self) -> usize { + let payload_length = + self.address.length() + self.data.data.length() + self.data.topics.length(); + payload_length + alloy_rlp::length_of_length(payload_length) + } +} + +#[cfg(feature = "rlp")] +impl alloy_rlp::Encodable for Log +where + for<'a> &'a T: Into, +{ + fn encode(&self, out: &mut dyn alloy_rlp::BufMut) { + self.reserialize().encode(out) + } + + fn length(&self) -> usize { + self.reserialize().length() + } +} + +#[cfg(feature = "rlp")] +impl alloy_rlp::Decodable for Log { + fn decode(buf: &mut &[u8]) -> Result { + let h = alloy_rlp::Header::decode(buf)?; + let pre = buf.len(); + + let address = alloy_rlp::Decodable::decode(buf)?; + let topics = alloy_rlp::Decodable::decode(buf)?; + let data = alloy_rlp::Decodable::decode(buf)?; + + if h.payload_length != pre - buf.len() { + return Err(alloy_rlp::Error::Custom("did not consume exact payload")); + } + + Ok(Self { address, data: LogData { topics, data } }) + } +} + +#[cfg(feature = "rlp")] +#[cfg(test)] +mod tests { + use super::*; + use alloy_rlp::{Decodable, Encodable}; + + #[test] + fn test_roundtrip_rlp_log_data() { + let log = Log::::default(); + let mut buf = Vec::::new(); + log.encode(&mut buf); + assert_eq!(Log::decode(&mut &buf[..]).unwrap(), log); + } +} diff --git a/CoqOfRust/alloy_primitives/log/mod.v b/CoqOfRust/alloy_primitives/log/mod.v new file mode 100644 index 000000000..c2073a65d --- /dev/null +++ b/CoqOfRust/alloy_primitives/log/mod.v @@ -0,0 +1,2094 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module log. + (* + pub fn logs_bloom<'a>(logs: impl IntoIterator) -> Bloom { + let mut bloom = Bloom::ZERO; + for log in logs { + bloom.accrue_log(log); + } + bloom + } + *) + Definition logs_bloom (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ impl_IntoIterator_Item____'a_Log_ ], [ logs ] => + ltac:(M.monadic + (let logs := M.alloc (| logs |) in + M.read (| + let~ bloom : Ty.path "alloy_primitives::bits::bloom::Bloom" := + M.copy (| M.get_constant "alloy_primitives::bits::bloom::ZERO" |) in + let~ _ : Ty.tuple [] := + M.use + (M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + M.call_closure (| + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + impl_IntoIterator_Item____'a_Log_ + "IntoIter", + M.get_trait_method (| + "core::iter::traits::collect::IntoIterator", + impl_IntoIterator_Item____'a_Log_, + [], + [], + "into_iter", + [], + [] + |), + [ M.read (| logs |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let iter := M.copy (| γ |) in + M.loop (| + Ty.tuple [], + ltac:(M.monadic + (let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::log::Log") + [] + [ Ty.path "alloy_primitives::log::LogData" ] + ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + Ty.associated_in_trait + "core::iter::traits::collect::IntoIterator" + [] + [] + impl_IntoIterator_Item____'a_Log_ + "IntoIter", + [], + [], + "next", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.borrow (| Pointer.Kind.MutRef, iter |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| γ, "core::option::Option::None" |) in + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let log := M.copy (| γ0_0 |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "alloy_primitives::bits::bloom::Bloom", + "accrue_log", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, bloom |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| log |) |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))) + |))) + ] + |)) in + bloom + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_logs_bloom : + M.IsFunction.Trait "alloy_primitives::log::logs_bloom" logs_bloom. + Admitted. + Global Typeclasses Opaque logs_bloom. + + (* StructRecord + { + name := "LogData"; + const_params := []; + ty_params := []; + fields := + [ + ("topics", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + []; + Ty.path "alloc::alloc::Global" + ]); + ("data", Ty.path "alloy_primitives::bytes_::Bytes") + ]; + } *) + + Module Impl_core_clone_Clone_for_alloy_primitives_log_LogData. + Definition Self : Ty.t := Ty.path "alloy_primitives::log::LogData". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "alloy_primitives::log::LogData" + [ + ("topics", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + []; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + []; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::log::LogData", + "topics" + |) + |) + |) + |) + ] + |)); + ("data", + M.call_closure (| + Ty.path "alloy_primitives::bytes_::Bytes", + M.get_trait_method (| + "core::clone::Clone", + Ty.path "alloy_primitives::bytes_::Bytes", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::log::LogData", + "data" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_alloy_primitives_log_LogData. + + Module Impl_core_fmt_Debug_for_alloy_primitives_log_LogData. + Definition Self : Ty.t := Ty.path "alloy_primitives::log::LogData". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field2_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "LogData" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "topics" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::log::LogData", + "topics" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "data" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::log::LogData", + "data" + |) + |) + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_alloy_primitives_log_LogData. + + Module Impl_core_default_Default_for_alloy_primitives_log_LogData. + Definition Self : Ty.t := Ty.path "alloy_primitives::log::LogData". + + (* Default *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructRecord + "alloy_primitives::log::LogData" + [ + ("topics", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + []; + Ty.path "alloc::alloc::Global" + ], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + []; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "default", + [], + [] + |), + [] + |)); + ("data", + M.call_closure (| + Ty.path "alloy_primitives::bytes_::Bytes", + M.get_trait_method (| + "core::default::Default", + Ty.path "alloy_primitives::bytes_::Bytes", + [], + [], + "default", + [], + [] + |), + [] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_alloy_primitives_log_LogData. + + Module Impl_core_marker_StructuralPartialEq_for_alloy_primitives_log_LogData. + Definition Self : Ty.t := Ty.path "alloy_primitives::log::LogData". + + Axiom Implements : + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_alloy_primitives_log_LogData. + + Module Impl_core_cmp_PartialEq_alloy_primitives_log_LogData_for_alloy_primitives_log_LogData. + Definition Self : Ty.t := Ty.path "alloy_primitives::log::LogData". + + (* PartialEq *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + []; + Ty.path "alloc::alloc::Global" + ], + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + []; + Ty.path "alloc::alloc::Global" + ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::log::LogData", + "topics" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::log::LogData", + "topics" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.path "alloy_primitives::bytes_::Bytes", + [], + [ Ty.path "alloy_primitives::bytes_::Bytes" ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::log::LogData", + "data" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::log::LogData", + "data" + |) + |) + ] + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::log::LogData" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_log_LogData_for_alloy_primitives_log_LogData. + + Module Impl_core_cmp_Eq_for_alloy_primitives_log_LogData. + Definition Self : Ty.t := Ty.path "alloy_primitives::log::LogData". + + (* Eq *) + Definition assert_receiver_is_total_eq + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ + fun γ => + ltac:(M.monadic + (M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method assert_receiver_is_total_eq) ]. + End Impl_core_cmp_Eq_for_alloy_primitives_log_LogData. + + Module Impl_core_hash_Hash_for_alloy_primitives_log_LogData. + Definition Self : Ty.t := Ty.path "alloy_primitives::log::LogData". + + (* Hash *) + Definition hash (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ __H ], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + []; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::log::LogData", + "topics" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.path "alloy_primitives::bytes_::Bytes", + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::log::LogData", + "data" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::hash::Hash" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("hash", InstanceField.Method hash) ]. + End Impl_core_hash_Hash_for_alloy_primitives_log_LogData. + + Module Impl_alloy_primitives_log_LogData. + Definition Self : Ty.t := Ty.path "alloy_primitives::log::LogData". + + (* + pub const fn new_unchecked(topics: Vec, data: Bytes) -> Self { + Self { topics, data } + } + *) + Definition new_unchecked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ topics; data ] => + ltac:(M.monadic + (let topics := M.alloc (| topics |) in + let data := M.alloc (| data |) in + Value.StructRecord + "alloy_primitives::log::LogData" + [ ("topics", M.read (| topics |)); ("data", M.read (| data |)) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new_unchecked : + M.IsAssociatedFunction.Trait Self "new_unchecked" new_unchecked. + Admitted. + Global Typeclasses Opaque new_unchecked. + + (* + pub fn new(topics: Vec, data: Bytes) -> Option { + let this = Self::new_unchecked(topics, data); + this.is_valid().then_some(this) + } + *) + Definition new (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ topics; data ] => + ltac:(M.monadic + (let topics := M.alloc (| topics |) in + let data := M.alloc (| data |) in + M.read (| + let~ this : Ty.path "alloy_primitives::log::LogData" := + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::log::LogData", + M.get_associated_function (| + Ty.path "alloy_primitives::log::LogData", + "new_unchecked", + [], + [] + |), + [ M.read (| topics |); M.read (| data |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "alloy_primitives::log::LogData" ], + M.get_associated_function (| + Ty.path "bool", + "then_some", + [], + [ Ty.path "alloy_primitives::log::LogData" ] + |), + [ + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "alloy_primitives::log::LogData", + "is_valid", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, this |) ] + |); + M.read (| this |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : M.IsAssociatedFunction.Trait Self "new" new. + Admitted. + Global Typeclasses Opaque new. + + (* + pub const fn empty() -> Self { + Self { topics: Vec::new(), data: Bytes::new() } + } + *) + Definition empty (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructRecord + "alloy_primitives::log::LogData" + [ + ("topics", + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + []; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + []; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [] + |)); + ("data", + M.call_closure (| + Ty.path "alloy_primitives::bytes_::Bytes", + M.get_associated_function (| + Ty.path "alloy_primitives::bytes_::Bytes", + "new", + [], + [] + |), + [] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_empty : M.IsAssociatedFunction.Trait Self "empty" empty. + Admitted. + Global Typeclasses Opaque empty. + + (* + pub fn is_valid(&self) -> bool { + self.topics.len() <= 4 + } + *) + Definition is_valid (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + BinOp.le (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + []; + Ty.path "alloc::alloc::Global" + ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::log::LogData", + "topics" + |) + |) + ] + |), + Value.Integer IntegerKind.Usize 4 + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_is_valid : + M.IsAssociatedFunction.Trait Self "is_valid" is_valid. + Admitted. + Global Typeclasses Opaque is_valid. + + (* + pub fn topics(&self) -> &[B256] { + &self.topics + } + *) + Definition topics (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ] + ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + []; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::log::LogData", + "topics" + |) + |) + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_topics : M.IsAssociatedFunction.Trait Self "topics" topics. + Admitted. + Global Typeclasses Opaque topics. + + (* + pub fn topics_mut(&mut self) -> &mut [B256] { + &mut self.topics + } + *) + Definition topics_mut (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "slice") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + []; + Ty.path "alloc::alloc::Global" + ], + [], + [], + "deref_mut", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::log::LogData", + "topics" + |) + |) + |) + |) + ] + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_topics_mut : + M.IsAssociatedFunction.Trait Self "topics_mut" topics_mut. + Admitted. + Global Typeclasses Opaque topics_mut. + + (* + pub fn topics_mut_unchecked(&mut self) -> &mut Vec { + &mut self.topics + } + *) + Definition topics_mut_unchecked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::log::LogData", + "topics" + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_topics_mut_unchecked : + M.IsAssociatedFunction.Trait Self "topics_mut_unchecked" topics_mut_unchecked. + Admitted. + Global Typeclasses Opaque topics_mut_unchecked. + + (* + pub fn set_topics_unchecked(&mut self, topics: Vec) { + self.topics = topics; + } + *) + Definition set_topics_unchecked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; topics ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let topics := M.alloc (| topics |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::log::LogData", + "topics" + |), + M.read (| topics |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_set_topics_unchecked : + M.IsAssociatedFunction.Trait Self "set_topics_unchecked" set_topics_unchecked. + Admitted. + Global Typeclasses Opaque set_topics_unchecked. + + (* + pub fn set_topics_truncating(&mut self, mut topics: Vec) { + topics.truncate(4); + self.set_topics_unchecked(topics); + } + *) + Definition set_topics_truncating (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; topics ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let topics := M.alloc (| topics |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + []; + Ty.path "alloc::alloc::Global" + ], + "truncate", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, topics |); Value.Integer IntegerKind.Usize 4 ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "alloy_primitives::log::LogData", + "set_topics_unchecked", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| self |) |) |); + M.read (| topics |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_set_topics_truncating : + M.IsAssociatedFunction.Trait Self "set_topics_truncating" set_topics_truncating. + Admitted. + Global Typeclasses Opaque set_topics_truncating. + + (* + pub fn split(self) -> (Vec, Bytes) { + (self.topics, self.data) + } + *) + Definition split (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.Tuple + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "alloy_primitives::log::LogData", + "topics" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "alloy_primitives::log::LogData", + "data" + |) + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_split : M.IsAssociatedFunction.Trait Self "split" split. + Admitted. + Global Typeclasses Opaque split. + End Impl_alloy_primitives_log_LogData. + + (* Trait *) + (* Empty module 'IntoLogData' *) + + Module Impl_alloy_primitives_log_IntoLogData_for_alloy_primitives_log_LogData. + Definition Self : Ty.t := Ty.path "alloy_primitives::log::LogData". + + (* + fn to_log_data(&self) -> LogData { + self.clone() + } + *) + Definition to_log_data (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "alloy_primitives::log::LogData", + M.get_trait_method (| + "core::clone::Clone", + Ty.path "alloy_primitives::log::LogData", + [], + [], + "clone", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn into_log_data(self) -> LogData { + self + } + *) + Definition into_log_data (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| self |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "alloy_primitives::log::IntoLogData" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ + ("to_log_data", InstanceField.Method to_log_data); + ("into_log_data", InstanceField.Method into_log_data) + ]. + End Impl_alloy_primitives_log_IntoLogData_for_alloy_primitives_log_LogData. + + (* StructRecord + { + name := "Log"; + const_params := []; + ty_params := [ "T" ]; + fields := [ ("address", Ty.path "alloy_primitives::bits::address::Address"); ("data", T) ]; + } *) + + Module Impl_core_clone_Clone_where_core_clone_Clone_T_for_alloy_primitives_log_Log_T. + Definition Self (T : Ty.t) : Ty.t := Ty.apply (Ty.path "alloy_primitives::log::Log") [] [ T ]. + + (* Clone *) + Definition clone (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "alloy_primitives::log::Log" + [ + ("address", + M.call_closure (| + Ty.path "alloy_primitives::bits::address::Address", + M.get_trait_method (| + "core::clone::Clone", + Ty.path "alloy_primitives::bits::address::Address", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::log::Log", + "address" + |) + |) + |) + |) + ] + |)); + ("data", + M.call_closure (| + T, + M.get_trait_method (| "core::clone::Clone", T, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::log::Log", + "data" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self T) + (* Instance *) [ ("clone", InstanceField.Method (clone T)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_T_for_alloy_primitives_log_Log_T. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_T_for_alloy_primitives_log_Log_T. + Definition Self (T : Ty.t) : Ty.t := Ty.apply (Ty.path "alloy_primitives::log::Log") [] [ T ]. + + (* Debug *) + Definition fmt (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field2_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Log" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "address" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::log::Log", + "address" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "data" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::log::Log", + "data" + |) + |) + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self T) + (* Instance *) [ ("fmt", InstanceField.Method (fmt T)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_T_for_alloy_primitives_log_Log_T. + + Module Impl_core_default_Default_where_core_default_Default_T_for_alloy_primitives_log_Log_T. + Definition Self (T : Ty.t) : Ty.t := Ty.apply (Ty.path "alloy_primitives::log::Log") [] [ T ]. + + (* Default *) + Definition default (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructRecord + "alloy_primitives::log::Log" + [ + ("address", + M.call_closure (| + Ty.path "alloy_primitives::bits::address::Address", + M.get_trait_method (| + "core::default::Default", + Ty.path "alloy_primitives::bits::address::Address", + [], + [], + "default", + [], + [] + |), + [] + |)); + ("data", + M.call_closure (| + T, + M.get_trait_method (| "core::default::Default", T, [], [], "default", [], [] |), + [] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self T) + (* Instance *) [ ("default", InstanceField.Method (default T)) ]. + End Impl_core_default_Default_where_core_default_Default_T_for_alloy_primitives_log_Log_T. + + Module Impl_core_marker_StructuralPartialEq_for_alloy_primitives_log_Log_T. + Definition Self (T : Ty.t) : Ty.t := Ty.apply (Ty.path "alloy_primitives::log::Log") [] [ T ]. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self T) + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_alloy_primitives_log_Log_T. + + Module Impl_core_cmp_PartialEq_where_core_cmp_PartialEq_T_alloy_primitives_log_Log_T_for_alloy_primitives_log_Log_T. + Definition Self (T : Ty.t) : Ty.t := Ty.apply (Ty.path "alloy_primitives::log::Log") [] [ T ]. + + (* PartialEq *) + Definition eq (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.path "alloy_primitives::bits::address::Address", + [], + [ Ty.path "alloy_primitives::bits::address::Address" ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::log::Log", + "address" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::log::Log", + "address" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| "core::cmp::PartialEq", T, [], [ T ], "eq", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::log::Log", + "data" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::log::Log", + "data" + |) + |) + ] + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "alloy_primitives::log::Log") [] [ T ] ] + (Self T) + (* Instance *) [ ("eq", InstanceField.Method (eq T)) ]. + End Impl_core_cmp_PartialEq_where_core_cmp_PartialEq_T_alloy_primitives_log_Log_T_for_alloy_primitives_log_Log_T. + + Module Impl_core_cmp_Eq_where_core_cmp_Eq_T_for_alloy_primitives_log_Log_T. + Definition Self (T : Ty.t) : Ty.t := Ty.apply (Ty.path "alloy_primitives::log::Log") [] [ T ]. + + (* Eq *) + Definition assert_receiver_is_total_eq + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ + fun γ => + ltac:(M.monadic + (M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self T) + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method (assert_receiver_is_total_eq T)) ]. + End Impl_core_cmp_Eq_where_core_cmp_Eq_T_for_alloy_primitives_log_Log_T. + + Module Impl_core_hash_Hash_where_core_hash_Hash_T_for_alloy_primitives_log_Log_T. + Definition Self (T : Ty.t) : Ty.t := Ty.apply (Ty.path "alloy_primitives::log::Log") [] [ T ]. + + (* Hash *) + Definition hash (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [ __H ], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.path "alloy_primitives::bits::address::Address", + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::log::Log", + "address" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| "core::hash::Hash", T, [], [], "hash", [], [ __H ] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::log::Log", + "data" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "core::hash::Hash" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self T) + (* Instance *) [ ("hash", InstanceField.Method (hash T)) ]. + End Impl_core_hash_Hash_where_core_hash_Hash_T_for_alloy_primitives_log_Log_T. + + Module Impl_core_ops_deref_Deref_for_alloy_primitives_log_Log_T. + Definition Self (T : Ty.t) : Ty.t := Ty.apply (Ty.path "alloy_primitives::log::Log") [] [ T ]. + + (* type Target = T; *) + Definition _Target (T : Ty.t) : Ty.t := T. + + (* + fn deref(&self) -> &Self::Target { + &self.data + } + *) + Definition deref (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::log::Log", + "data" + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "core::ops::deref::Deref" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self T) + (* Instance *) + [ ("Target", InstanceField.Ty (_Target T)); ("deref", InstanceField.Method (deref T)) ]. + End Impl_core_ops_deref_Deref_for_alloy_primitives_log_Log_T. + + Module Impl_core_ops_deref_DerefMut_for_alloy_primitives_log_Log_T. + Definition Self (T : Ty.t) : Ty.t := Ty.apply (Ty.path "alloy_primitives::log::Log") [] [ T ]. + + (* + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.data + } + *) + Definition deref_mut (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::log::Log", + "data" + |) + |) + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "core::ops::deref::DerefMut" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self T) + (* Instance *) [ ("deref_mut", InstanceField.Method (deref_mut T)) ]. + End Impl_core_ops_deref_DerefMut_for_alloy_primitives_log_Log_T. + + Module Impl_alloy_primitives_log_Log_alloy_primitives_log_LogData. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::log::Log") + [] + [ Ty.path "alloy_primitives::log::LogData" ]. + + (* + pub fn new(address: Address, topics: Vec, data: Bytes) -> Option { + LogData::new(topics, data).map(|data| Self { address, data }) + } + *) + Definition new (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ address; topics; data ] => + ltac:(M.monadic + (let address := M.alloc (| address |) in + let topics := M.alloc (| topics |) in + let data := M.alloc (| data |) in + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::log::Log") + [] + [ Ty.path "alloy_primitives::log::LogData" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "alloy_primitives::log::LogData" ], + "map", + [], + [ + Ty.apply + (Ty.path "alloy_primitives::log::Log") + [] + [ Ty.path "alloy_primitives::log::LogData" ]; + Ty.function + [ Ty.tuple [ Ty.path "alloy_primitives::log::LogData" ] ] + (Ty.apply + (Ty.path "alloy_primitives::log::Log") + [] + [ Ty.path "alloy_primitives::log::LogData" ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "alloy_primitives::log::LogData" ], + M.get_associated_function (| + Ty.path "alloy_primitives::log::LogData", + "new", + [], + [] + |), + [ M.read (| topics |); M.read (| data |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ Ty.tuple [ Ty.path "alloy_primitives::log::LogData" ] ] + (Ty.apply + (Ty.path "alloy_primitives::log::Log") + [] + [ Ty.path "alloy_primitives::log::LogData" ])), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let data := M.copy (| γ |) in + Value.StructRecord + "alloy_primitives::log::Log" + [ ("address", M.read (| address |)); ("data", M.read (| data |)) + ])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : M.IsAssociatedFunction.Trait Self "new" new. + Admitted. + Global Typeclasses Opaque new. + + (* + pub const fn new_unchecked(address: Address, topics: Vec, data: Bytes) -> Self { + Self { address, data: LogData::new_unchecked(topics, data) } + } + *) + Definition new_unchecked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ address; topics; data ] => + ltac:(M.monadic + (let address := M.alloc (| address |) in + let topics := M.alloc (| topics |) in + let data := M.alloc (| data |) in + Value.StructRecord + "alloy_primitives::log::Log" + [ + ("address", M.read (| address |)); + ("data", + M.call_closure (| + Ty.path "alloy_primitives::log::LogData", + M.get_associated_function (| + Ty.path "alloy_primitives::log::LogData", + "new_unchecked", + [], + [] + |), + [ M.read (| topics |); M.read (| data |) ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new_unchecked : + M.IsAssociatedFunction.Trait Self "new_unchecked" new_unchecked. + Admitted. + Global Typeclasses Opaque new_unchecked. + + (* + pub const fn empty() -> Self { + Self { address: Address::ZERO, data: LogData::empty() } + } + *) + Definition empty (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructRecord + "alloy_primitives::log::Log" + [ + ("address", M.read (| M.get_constant "alloy_primitives::bits::address::ZERO" |)); + ("data", + M.call_closure (| + Ty.path "alloy_primitives::log::LogData", + M.get_associated_function (| + Ty.path "alloy_primitives::log::LogData", + "empty", + [], + [] + |), + [] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_empty : M.IsAssociatedFunction.Trait Self "empty" empty. + Admitted. + Global Typeclasses Opaque empty. + End Impl_alloy_primitives_log_Log_alloy_primitives_log_LogData. + + Module Impl_alloy_primitives_log_Log_T. + Definition Self (T : Ty.t) : Ty.t := Ty.apply (Ty.path "alloy_primitives::log::Log") [] [ T ]. + + (* + pub const fn new_from_event_unchecked(address: Address, data: T) -> Self { + Self { address, data } + } + *) + Definition new_from_event_unchecked + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ address; data ] => + ltac:(M.monadic + (let address := M.alloc (| address |) in + let data := M.alloc (| data |) in + Value.StructRecord + "alloy_primitives::log::Log" + [ ("address", M.read (| address |)); ("data", M.read (| data |)) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new_from_event_unchecked : + forall (T : Ty.t), + M.IsAssociatedFunction.Trait (Self T) "new_from_event_unchecked" (new_from_event_unchecked T). + Admitted. + Global Typeclasses Opaque new_from_event_unchecked. + + (* + pub fn new_from_event(address: Address, data: T) -> Option { + let this = Self::new_from_event_unchecked(address, data); + (&this.data).into().is_valid().then_some(this) + } + *) + Definition new_from_event + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ address; data ] => + ltac:(M.monadic + (let address := M.alloc (| address |) in + let data := M.alloc (| data |) in + M.read (| + let~ this : Ty.apply (Ty.path "alloy_primitives::log::Log") [] [ T ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::log::Log") [] [ T ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::log::Log") [] [ T ], + "new_from_event_unchecked", + [], + [] + |), + [ M.read (| address |); M.read (| data |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "alloy_primitives::log::Log") [] [ T ] ], + M.get_associated_function (| + Ty.path "bool", + "then_some", + [], + [ Ty.apply (Ty.path "alloy_primitives::log::Log") [] [ T ] ] + |), + [ + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "alloy_primitives::log::LogData", + "is_valid", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::log::LogData", + M.get_trait_method (| + "core::convert::Into", + Ty.apply (Ty.path "&") [] [ T ], + [], + [ Ty.path "alloy_primitives::log::LogData" ], + "into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + this, + "alloy_primitives::log::Log", + "data" + |) + |) + |) + |) + ] + |) + |) + |) + ] + |); + M.read (| this |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new_from_event : + forall (T : Ty.t), + M.IsAssociatedFunction.Trait (Self T) "new_from_event" (new_from_event T). + Admitted. + Global Typeclasses Opaque new_from_event. + + (* + pub fn reserialize(&self) -> Log { + Log { address: self.address, data: (&self.data).into() } + } + *) + Definition reserialize (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "alloy_primitives::log::Log" + [ + ("address", + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::log::Log", + "address" + |) + |)); + ("data", + M.call_closure (| + Ty.path "alloy_primitives::log::LogData", + M.get_trait_method (| + "core::convert::Into", + Ty.apply (Ty.path "&") [] [ T ], + [], + [ Ty.path "alloy_primitives::log::LogData" ], + "into", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::log::Log", + "data" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_reserialize : + forall (T : Ty.t), + M.IsAssociatedFunction.Trait (Self T) "reserialize" (reserialize T). + Admitted. + Global Typeclasses Opaque reserialize. + End Impl_alloy_primitives_log_Log_T. +End log. diff --git a/CoqOfRust/alloy_primitives/log/serde.rs b/CoqOfRust/alloy_primitives/log/serde.rs new file mode 100644 index 000000000..70e7c6973 --- /dev/null +++ b/CoqOfRust/alloy_primitives/log/serde.rs @@ -0,0 +1,130 @@ +//! This is an implementation of serde for Log for +//! both human-readable and binary forms. +//! +//! Ethereum JSON RPC requires logs in a flattened form. +//! However `serde(flatten)` breaks binary implementations. +//! +//! This module uses a trick to select a proxy for serde: +//! 1. LogFlattenSerializer for a human-readable (JSON) serializer, +//! 2. LogFlattenDeserializer for a human-readable (JSON) deserializer, +//! 3. LogUnflattenSerializer for a binary serializer, +//! 4. LogUnflattenDeserializer for a binary deserializer. + +use crate::{Address, Log}; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + +#[derive(Serialize)] +#[serde(rename = "Log")] +struct LogFlattenSerializer<'a, T> { + address: &'a Address, + #[serde(flatten)] + data: &'a T, +} + +#[derive(Deserialize)] +#[serde(rename = "Log")] +struct LogFlattenDeserializer { + address: Address, + #[serde(flatten)] + data: T, +} + +#[derive(Serialize)] +#[serde(rename = "Log")] +struct LogUnflattenSerializer<'a, T> { + address: &'a Address, + data: &'a T, +} + +#[derive(Deserialize)] +#[serde(rename = "Log")] +struct LogUnflattenDeserializer { + address: Address, + data: T, +} + +impl Serialize for Log { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let Self { address, data } = self; + if serializer.is_human_readable() { + let replace = LogFlattenSerializer { address, data }; + replace.serialize(serializer) + } else { + let replace = LogUnflattenSerializer { address, data }; + replace.serialize(serializer) + } + } +} + +impl<'de, T: Deserialize<'de>> Deserialize<'de> for Log { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + if deserializer.is_human_readable() { + let LogFlattenDeserializer { address, data } = <_>::deserialize(deserializer)?; + Ok(Self { address, data }) + } else { + let LogUnflattenDeserializer { address, data } = <_>::deserialize(deserializer)?; + Ok(Self { address, data }) + } + } +} + +#[cfg(test)] +mod tests { + use crate::{ + log::{Log, LogData}, + Bytes, + }; + use alloc::vec::Vec; + + #[derive(Debug, PartialEq, serde::Serialize, serde::Deserialize)] + struct TestStruct { + logs: Vec, + } + + fn gen_test_struct() -> TestStruct { + // assume it's random: + TestStruct { + logs: vec![Log { + address: address!("3100000000000000000000000000000000000001"), + data: LogData::new( + vec![b256!("32eff959e2e8d1609edc4b39ccf75900aa6c1da5719f8432752963fdf008234f")], + Bytes::from_static(b"00000000000000000000000000000000000000000000000000000000000000021e9dbc1a11f8e046a72d1296cc2d8bb0d1544d56fd0b9bb8890a0f89b88036541e9dbc1a11f8e046a72d1296cc2d8bb0d1544d56fd0b9bb8890a0f89b8803654"), + ).unwrap(), + }], + } + } + + #[test] + fn test_log_bincode_roundtrip() { + let generated = gen_test_struct(); + + let bytes = bincode::serialize(&generated).unwrap(); + let parsed: TestStruct = bincode::deserialize(&bytes).unwrap(); + assert_eq!(generated, parsed); + } + + #[test] + fn test_log_bcs_roundtrip() { + let generated = gen_test_struct(); + + let bytes = bcs::to_bytes(&generated).unwrap(); + let parsed: TestStruct = bcs::from_bytes(&bytes).unwrap(); + assert_eq!(generated, parsed); + } + + #[test] + fn test_log_json_roundtrip() { + let expected = "{\"logs\":[{\"address\":\"0x3100000000000000000000000000000000000001\",\"topics\":[\"0x32eff959e2e8d1609edc4b39ccf75900aa6c1da5719f8432752963fdf008234f\"],\"data\":\"0x303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030323165396462633161313166386530343661373264313239366363326438626230643135343464353666643062396262383839306130663839623838303336353431653964626331613131663865303436613732643132393663633264386262306431353434643536666430623962623838393061306638396238383033363534\"}]}"; + + let parsed: TestStruct = serde_json::from_str(expected).unwrap(); + let dumped = serde_json::to_string(&parsed).unwrap(); + + assert_eq!(expected, dumped); + } +} diff --git a/CoqOfRust/alloy_primitives/map/fixed.rs b/CoqOfRust/alloy_primitives/map/fixed.rs new file mode 100644 index 000000000..6e1af0a10 --- /dev/null +++ b/CoqOfRust/alloy_primitives/map/fixed.rs @@ -0,0 +1,223 @@ +use super::*; +use crate::{Address, FixedBytes, Selector, B256}; +use cfg_if::cfg_if; +use core::{ + fmt, + hash::{BuildHasher, Hasher}, +}; + +/// [`HashMap`] optimized for hashing [fixed-size byte arrays](FixedBytes). +pub type FbHashMap = HashMap, V, FbBuildHasher>; +/// [`HashSet`] optimized for hashing [fixed-size byte arrays](FixedBytes). +pub type FbHashSet = HashSet, FbBuildHasher>; + +cfg_if! { + if #[cfg(feature = "map-indexmap")] { + /// [`IndexMap`] optimized for hashing [fixed-size byte arrays](FixedBytes). + pub type FbIndexMap = + indexmap::IndexMap, V, FbBuildHasher>; + /// [`IndexSet`] optimized for hashing [fixed-size byte arrays](FixedBytes). + pub type FbIndexSet = + indexmap::IndexSet, FbBuildHasher>; + } +} + +macro_rules! fb_alias_maps { + ($($ty:ident < $n:literal >),* $(,)?) => { paste::paste! { + $( + #[doc = concat!("[`HashMap`] optimized for hashing [`", stringify!($ty), "`].")] + pub type [<$ty HashMap>] = HashMap<$ty, V, FbBuildHasher<$n>>; + #[doc = concat!("[`HashSet`] optimized for hashing [`", stringify!($ty), "`].")] + pub type [<$ty HashSet>] = HashSet<$ty, FbBuildHasher<$n>>; + + cfg_if! { + if #[cfg(feature = "map-indexmap")] { + #[doc = concat!("[`IndexMap`] optimized for hashing [`", stringify!($ty), "`].")] + pub type [<$ty IndexMap>] = IndexMap<$ty, V, FbBuildHasher<$n>>; + #[doc = concat!("[`IndexSet`] optimized for hashing [`", stringify!($ty), "`].")] + pub type [<$ty IndexSet>] = IndexSet<$ty, FbBuildHasher<$n>>; + } + } + )* + } }; +} + +fb_alias_maps!(Selector<4>, Address<20>, B256<32>); + +#[allow(unused_macros)] +macro_rules! assert_unchecked { + ($e:expr) => { assert_unchecked!($e,); }; + ($e:expr, $($t:tt)*) => { + if cfg!(debug_assertions) { + assert!($e, $($t)*); + } else if !$e { + unsafe { core::hint::unreachable_unchecked() } + } + }; +} + +macro_rules! assert_eq_unchecked { + ($a:expr, $b:expr) => { assert_eq_unchecked!($a, $b,); }; + ($a:expr, $b:expr, $($t:tt)*) => { + if cfg!(debug_assertions) { + assert_eq!($a, $b, $($t)*); + } else if $a != $b { + unsafe { core::hint::unreachable_unchecked() } + } + }; +} + +/// [`BuildHasher`] optimized for hashing [fixed-size byte arrays](FixedBytes). +/// +/// Works best with `fxhash`, enabled by default with the "map-fxhash" feature. +/// +/// **NOTE:** this hasher accepts only `N`-length byte arrays! It is invalid to hash anything else. +#[derive(Clone, Default)] +pub struct FbBuildHasher { + inner: DefaultHashBuilder, + _marker: core::marker::PhantomData<[(); N]>, +} + +impl fmt::Debug for FbBuildHasher { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("FbBuildHasher").finish_non_exhaustive() + } +} + +impl BuildHasher for FbBuildHasher { + type Hasher = FbHasher; + + #[inline] + fn build_hasher(&self) -> Self::Hasher { + FbHasher { inner: self.inner.build_hasher(), _marker: core::marker::PhantomData } + } +} + +/// [`Hasher`] optimized for hashing [fixed-size byte arrays](FixedBytes). +/// +/// Works best with `fxhash`, enabled by default with the "map-fxhash" feature. +/// +/// **NOTE:** this hasher accepts only `N`-length byte arrays! It is invalid to hash anything else. +#[derive(Clone)] +pub struct FbHasher { + inner: DefaultHasher, + _marker: core::marker::PhantomData<[(); N]>, +} + +impl Default for FbHasher { + #[inline] + fn default() -> Self { + Self { + inner: DefaultHashBuilder::default().build_hasher(), + _marker: core::marker::PhantomData, + } + } +} + +impl fmt::Debug for FbHasher { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("FbHasher").finish_non_exhaustive() + } +} + +impl Hasher for FbHasher { + #[inline] + fn finish(&self) -> u64 { + self.inner.finish() + } + + #[inline] + fn write(&mut self, bytes: &[u8]) { + assert_eq_unchecked!(bytes.len(), N); + // Threshold decided by some basic micro-benchmarks with fxhash. + if N > 32 { + self.inner.write(bytes); + } else { + write_bytes_unrolled(&mut self.inner, bytes); + } + } + + // We can just skip hashing the length prefix entirely since we know it's always `N`. + + // `write_length_prefix` calls `write_usize` by default. + #[cfg(not(feature = "nightly"))] + #[inline] + fn write_usize(&mut self, i: usize) { + debug_assert_eq!(i, N); + } + + #[cfg(feature = "nightly")] + #[inline] + fn write_length_prefix(&mut self, len: usize) { + debug_assert_eq!(len, N); + } +} + +#[inline(always)] +fn write_bytes_unrolled(hasher: &mut impl Hasher, mut bytes: &[u8]) { + while let Some((chunk, rest)) = bytes.split_first_chunk() { + hasher.write_usize(usize::from_ne_bytes(*chunk)); + bytes = rest; + } + if usize::BITS > 64 { + if let Some((chunk, rest)) = bytes.split_first_chunk() { + hasher.write_u64(u64::from_ne_bytes(*chunk)); + bytes = rest; + } + } + if usize::BITS > 32 { + if let Some((chunk, rest)) = bytes.split_first_chunk() { + hasher.write_u32(u32::from_ne_bytes(*chunk)); + bytes = rest; + } + } + if usize::BITS > 16 { + if let Some((chunk, rest)) = bytes.split_first_chunk() { + hasher.write_u16(u16::from_ne_bytes(*chunk)); + bytes = rest; + } + } + if usize::BITS > 8 { + if let Some((chunk, rest)) = bytes.split_first_chunk() { + hasher.write_u8(u8::from_ne_bytes(*chunk)); + bytes = rest; + } + } + + debug_assert!(bytes.is_empty()); +} + +#[cfg(all(test, any(feature = "std", feature = "map-fxhash")))] +mod tests { + use super::*; + + fn hash_zero() -> u64 { + FbBuildHasher::::default().hash_one(&FixedBytes::::ZERO) + } + + #[test] + #[cfg_attr(miri, ignore = "foldhash queries time (orlp/foldhash#4)")] + fn fb_hasher() { + // Just by running it once we test that it compiles and that debug assertions are correct. + ruint::const_for!(N in [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 47, 48, 49, 63, 64, 127, 128, 256, 512, 1024, 2048, 4096] { + let _ = hash_zero::(); + }); + } + + #[test] + #[cfg_attr(miri, ignore = "foldhash queries time (orlp/foldhash#4)")] + fn map() { + let mut map = AddressHashMap::::default(); + map.insert(Address::ZERO, true); + assert_eq!(map.get(&Address::ZERO), Some(&true)); + assert_eq!(map.get(&Address::with_last_byte(1)), None); + + let map2 = map.clone(); + assert_eq!(map.len(), map2.len()); + assert_eq!(map.len(), 1); + assert_eq!(map2.get(&Address::ZERO), Some(&true)); + assert_eq!(map2.get(&Address::with_last_byte(1)), None); + } +} diff --git a/CoqOfRust/alloy_primitives/map/fixed.v b/CoqOfRust/alloy_primitives/map/fixed.v new file mode 100644 index 000000000..c31b86113 --- /dev/null +++ b/CoqOfRust/alloy_primitives/map/fixed.v @@ -0,0 +1,1805 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module map. + Module fixed. + Axiom FbHashMap : + forall (N : Value.t) (V : Ty.t), + (Ty.apply (Ty.path "alloy_primitives::map::fixed::FbHashMap") [ N ] [ V ]) = + (Ty.apply + (Ty.path "std::collections::hash::map::HashMap") + [] + [ + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []; + V; + Ty.apply (Ty.path "alloy_primitives::map::fixed::FbBuildHasher") [ N ] [] + ]). + + Axiom FbHashSet : + forall (N : Value.t), + (Ty.apply (Ty.path "alloy_primitives::map::fixed::FbHashSet") [ N ] []) = + (Ty.apply + (Ty.path "std::collections::hash::set::HashSet") + [] + [ + Ty.apply (Ty.path "alloy_primitives::bits::fixed::FixedBytes") [ N ] []; + Ty.apply (Ty.path "alloy_primitives::map::fixed::FbBuildHasher") [ N ] [] + ]). + + Axiom SelectorHashMap : + forall (V : Ty.t), + (Ty.apply (Ty.path "alloy_primitives::map::fixed::SelectorHashMap") [] [ V ]) = + (Ty.apply + (Ty.path "std::collections::hash::map::HashMap") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 4 ] + []; + V; + Ty.apply + (Ty.path "alloy_primitives::map::fixed::FbBuildHasher") + [ Value.Integer IntegerKind.Usize 4 ] + [] + ]). + + Axiom SelectorHashSet : + (Ty.path "alloy_primitives::map::fixed::SelectorHashSet") = + (Ty.apply + (Ty.path "std::collections::hash::set::HashSet") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 4 ] + []; + Ty.apply + (Ty.path "alloy_primitives::map::fixed::FbBuildHasher") + [ Value.Integer IntegerKind.Usize 4 ] + [] + ]). + + Axiom AddressHashMap : + forall (V : Ty.t), + (Ty.apply (Ty.path "alloy_primitives::map::fixed::AddressHashMap") [] [ V ]) = + (Ty.apply + (Ty.path "std::collections::hash::map::HashMap") + [] + [ + Ty.path "alloy_primitives::bits::address::Address"; + V; + Ty.apply + (Ty.path "alloy_primitives::map::fixed::FbBuildHasher") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ]). + + Axiom AddressHashSet : + (Ty.path "alloy_primitives::map::fixed::AddressHashSet") = + (Ty.apply + (Ty.path "std::collections::hash::set::HashSet") + [] + [ + Ty.path "alloy_primitives::bits::address::Address"; + Ty.apply + (Ty.path "alloy_primitives::map::fixed::FbBuildHasher") + [ Value.Integer IntegerKind.Usize 20 ] + [] + ]). + + Axiom B256HashMap : + forall (V : Ty.t), + (Ty.apply (Ty.path "alloy_primitives::map::fixed::B256HashMap") [] [ V ]) = + (Ty.apply + (Ty.path "std::collections::hash::map::HashMap") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + []; + V; + Ty.apply + (Ty.path "alloy_primitives::map::fixed::FbBuildHasher") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ]). + + Axiom B256HashSet : + (Ty.path "alloy_primitives::map::fixed::B256HashSet") = + (Ty.apply + (Ty.path "std::collections::hash::set::HashSet") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + []; + Ty.apply + (Ty.path "alloy_primitives::map::fixed::FbBuildHasher") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ]). + + (* StructRecord + { + name := "FbBuildHasher"; + const_params := [ "N" ]; + ty_params := []; + fields := + [ + ("inner", Ty.path "foldhash::fast::RandomState"); + ("_marker", + Ty.apply + (Ty.path "core::marker::PhantomData") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.tuple [] ] ]) + ]; + } *) + + Module Impl_core_clone_Clone_for_alloy_primitives_map_fixed_FbBuildHasher_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::map::fixed::FbBuildHasher") [ N ] []. + + (* Clone *) + Definition clone (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "alloy_primitives::map::fixed::FbBuildHasher" + [ + ("inner", + M.call_closure (| + Ty.path "foldhash::fast::RandomState", + M.get_trait_method (| + "core::clone::Clone", + Ty.path "foldhash::fast::RandomState", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::map::fixed::FbBuildHasher", + "inner" + |) + |) + |) + |) + ] + |)); + ("_marker", + M.call_closure (| + Ty.apply + (Ty.path "core::marker::PhantomData") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.tuple [] ] ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "core::marker::PhantomData") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.tuple [] ] ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::map::fixed::FbBuildHasher", + "_marker" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) [ ("clone", InstanceField.Method (clone N)) ]. + End Impl_core_clone_Clone_for_alloy_primitives_map_fixed_FbBuildHasher_N. + + Module Impl_core_default_Default_for_alloy_primitives_map_fixed_FbBuildHasher_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::map::fixed::FbBuildHasher") [ N ] []. + + (* Default *) + Definition default (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructRecord + "alloy_primitives::map::fixed::FbBuildHasher" + [ + ("inner", + M.call_closure (| + Ty.path "foldhash::fast::RandomState", + M.get_trait_method (| + "core::default::Default", + Ty.path "foldhash::fast::RandomState", + [], + [], + "default", + [], + [] + |), + [] + |)); + ("_marker", + M.call_closure (| + Ty.apply + (Ty.path "core::marker::PhantomData") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.tuple [] ] ], + M.get_trait_method (| + "core::default::Default", + Ty.apply + (Ty.path "core::marker::PhantomData") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.tuple [] ] ], + [], + [], + "default", + [], + [] + |), + [] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) [ ("default", InstanceField.Method (default N)) ]. + End Impl_core_default_Default_for_alloy_primitives_map_fixed_FbBuildHasher_N. + + Module Impl_core_fmt_Debug_for_alloy_primitives_map_fixed_FbBuildHasher_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::map::fixed::FbBuildHasher") [ N ] []. + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("FbBuildHasher").finish_non_exhaustive() + } + *) + Definition fmt (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::builders::DebugStruct", + "finish_non_exhaustive", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.path "core::fmt::builders::DebugStruct", + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "FbBuildHasher" |) |) |) + ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) [ ("fmt", InstanceField.Method (fmt N)) ]. + End Impl_core_fmt_Debug_for_alloy_primitives_map_fixed_FbBuildHasher_N. + + Module Impl_core_hash_BuildHasher_for_alloy_primitives_map_fixed_FbBuildHasher_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::map::fixed::FbBuildHasher") [ N ] []. + + (* type Hasher = FbHasher; *) + Definition _Hasher (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::map::fixed::FbHasher") [ N ] []. + + (* + fn build_hasher(&self) -> Self::Hasher { + FbHasher { inner: self.inner.build_hasher(), _marker: core::marker::PhantomData } + } + *) + Definition build_hasher + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "alloy_primitives::map::fixed::FbHasher" + [ + ("inner", + M.call_closure (| + Ty.path "foldhash::fast::FoldHasher", + M.get_trait_method (| + "core::hash::BuildHasher", + Ty.path "foldhash::fast::RandomState", + [], + [], + "build_hasher", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::map::fixed::FbBuildHasher", + "inner" + |) + |) + ] + |)); + ("_marker", Value.StructTuple "core::marker::PhantomData" []) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::hash::BuildHasher" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) + [ + ("Hasher", InstanceField.Ty (_Hasher N)); + ("build_hasher", InstanceField.Method (build_hasher N)) + ]. + End Impl_core_hash_BuildHasher_for_alloy_primitives_map_fixed_FbBuildHasher_N. + + (* StructRecord + { + name := "FbHasher"; + const_params := [ "N" ]; + ty_params := []; + fields := + [ + ("inner", + Ty.associated_in_trait + "core::hash::BuildHasher" + [] + [] + (Ty.path "foldhash::fast::RandomState") + "Hasher"); + ("_marker", + Ty.apply + (Ty.path "core::marker::PhantomData") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.tuple [] ] ]) + ]; + } *) + + Module Impl_core_clone_Clone_for_alloy_primitives_map_fixed_FbHasher_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::map::fixed::FbHasher") [ N ] []. + + (* Clone *) + Definition clone (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "alloy_primitives::map::fixed::FbHasher" + [ + ("inner", + M.call_closure (| + Ty.path "foldhash::fast::FoldHasher", + M.get_trait_method (| + "core::clone::Clone", + Ty.path "foldhash::fast::FoldHasher", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::map::fixed::FbHasher", + "inner" + |) + |) + |) + |) + ] + |)); + ("_marker", + M.call_closure (| + Ty.apply + (Ty.path "core::marker::PhantomData") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.tuple [] ] ], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "core::marker::PhantomData") + [] + [ Ty.apply (Ty.path "array") [ N ] [ Ty.tuple [] ] ], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::map::fixed::FbHasher", + "_marker" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) [ ("clone", InstanceField.Method (clone N)) ]. + End Impl_core_clone_Clone_for_alloy_primitives_map_fixed_FbHasher_N. + + Module Impl_core_default_Default_for_alloy_primitives_map_fixed_FbHasher_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::map::fixed::FbHasher") [ N ] []. + + (* + fn default() -> Self { + Self { + inner: DefaultHashBuilder::default().build_hasher(), + _marker: core::marker::PhantomData, + } + } + *) + Definition default (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructRecord + "alloy_primitives::map::fixed::FbHasher" + [ + ("inner", + M.call_closure (| + Ty.path "foldhash::fast::FoldHasher", + M.get_trait_method (| + "core::hash::BuildHasher", + Ty.path "foldhash::fast::RandomState", + [], + [], + "build_hasher", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "foldhash::fast::RandomState", + M.get_trait_method (| + "core::default::Default", + Ty.path "foldhash::fast::RandomState", + [], + [], + "default", + [], + [] + |), + [] + |) + |) + |) + ] + |)); + ("_marker", Value.StructTuple "core::marker::PhantomData" []) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) [ ("default", InstanceField.Method (default N)) ]. + End Impl_core_default_Default_for_alloy_primitives_map_fixed_FbHasher_N. + + Module Impl_core_fmt_Debug_for_alloy_primitives_map_fixed_FbHasher_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::map::fixed::FbHasher") [ N ] []. + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("FbHasher").finish_non_exhaustive() + } + *) + Definition fmt (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::builders::DebugStruct", + "finish_non_exhaustive", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.path "core::fmt::builders::DebugStruct", + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "FbHasher" |) |) |) + ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) [ ("fmt", InstanceField.Method (fmt N)) ]. + End Impl_core_fmt_Debug_for_alloy_primitives_map_fixed_FbHasher_N. + + Module Impl_core_hash_Hasher_for_alloy_primitives_map_fixed_FbHasher_N. + Definition Self (N : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::map::fixed::FbHasher") [ N ] []. + + (* + fn finish(&self) -> u64 { + self.inner.finish() + } + *) + Definition finish (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "u64", + M.get_trait_method (| + "core::hash::Hasher", + Ty.path "foldhash::fast::FoldHasher", + [], + [], + "finish", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::map::fixed::FbHasher", + "inner" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn write(&mut self, bytes: &[u8]) { + assert_eq_unchecked!(bytes.len(), N); + // Threshold decided by some basic micro-benchmarks with fxhash. + if N > 32 { + self.inner.write(bytes); + } else { + write_bytes_unrolled(&mut self.inner, bytes); + } + } + *) + Definition write (N : Value.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; bytes ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let bytes := M.alloc (| bytes |) in + M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| bytes |) |) + |) + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::map::fixed::N" + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + BinOp.eq (| + M.read (| + M.deref (| M.read (| left_val |) |) + |), + M.read (| + M.deref (| M.read (| right_val |) |) + |) + |) + |) + |)) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : Ty.path "core::panicking::AssertKind" := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.ne (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| bytes |) |) + |) + ] + |), + M.read (| + M.get_constant "alloy_primitives::map::fixed::N" + |) + |) + |)) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::hint::unreachable_unchecked", + [], + [] + |), + [] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.gt (| + M.read (| M.get_constant "alloy_primitives::map::fixed::N" |), + Value.Integer IntegerKind.Usize 32 + |) + |)) in + let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hasher", + Ty.path "foldhash::fast::FoldHasher", + [], + [], + "write", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::map::fixed::FbHasher", + "inner" + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| bytes |) |) |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_function (| + "alloy_primitives::map::fixed::write_bytes_unrolled", + [], + [ Ty.path "foldhash::fast::FoldHasher" ] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::map::fixed::FbHasher", + "inner" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| bytes |) |) |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + (* + fn write_usize(&mut self, i: usize) { + debug_assert_eq!(i, N); + } + *) + Definition write_usize + (N : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self N in + match ε, τ, α with + | [], [], [ self; i ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let i := M.alloc (| i |) in + M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + Value.Tuple + [ + M.borrow (| Pointer.Kind.Ref, i |); + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::map::fixed::N" + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let left_val := M.copy (| γ0_0 |) in + let right_val := M.copy (| γ0_1 |) in + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + BinOp.eq (| + M.read (| + M.deref (| M.read (| left_val |) |) + |), + M.read (| + M.deref (| M.read (| right_val |) |) + |) + |) + |) + |)) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + let~ kind : Ty.path "core::panicking::AssertKind" := + M.alloc (| + Value.StructTuple + "core::panicking::AssertKind::Eq" + [] + |) in + M.alloc (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::assert_failed", + [], + [ Ty.path "usize"; Ty.path "usize" ] + |), + [ + M.read (| kind |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| left_val |) |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| right_val |) |) + |) + |) + |); + Value.StructTuple + "core::option::Option::None" + [] + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (N : Value.t), + M.IsTraitInstance + "core::hash::Hasher" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self N) + (* Instance *) + [ + ("finish", InstanceField.Method (finish N)); + ("write", InstanceField.Method (write N)); + ("write_usize", InstanceField.Method (write_usize N)) + ]. + End Impl_core_hash_Hasher_for_alloy_primitives_map_fixed_FbHasher_N. + + (* + fn write_bytes_unrolled(hasher: &mut impl Hasher, mut bytes: &[u8]) { + while let Some((chunk, rest)) = bytes.split_first_chunk() { + hasher.write_usize(usize::from_ne_bytes( *chunk)); + bytes = rest; + } + if usize::BITS > 64 { + if let Some((chunk, rest)) = bytes.split_first_chunk() { + hasher.write_u64(u64::from_ne_bytes( *chunk)); + bytes = rest; + } + } + if usize::BITS > 32 { + if let Some((chunk, rest)) = bytes.split_first_chunk() { + hasher.write_u32(u32::from_ne_bytes( *chunk)); + bytes = rest; + } + } + if usize::BITS > 16 { + if let Some((chunk, rest)) = bytes.split_first_chunk() { + hasher.write_u16(u16::from_ne_bytes( *chunk)); + bytes = rest; + } + } + if usize::BITS > 8 { + if let Some((chunk, rest)) = bytes.split_first_chunk() { + hasher.write_u8(u8::from_ne_bytes( *chunk)); + bytes = rest; + } + } + + debug_assert!(bytes.is_empty()); + } + *) + Definition write_bytes_unrolled (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ impl_Hasher ], [ hasher; bytes ] => + ltac:(M.monadic + (let hasher := M.alloc (| hasher |) in + let bytes := M.alloc (| bytes |) in + M.read (| + let~ _ : Ty.tuple [] := + M.loop (| + Ty.tuple [], + ltac:(M.monadic + (M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "u8" ] + ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "split_first_chunk", + [ Value.Integer IntegerKind.Usize 8 ], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| bytes |) |) |) + ] + |) + |) in + let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let chunk := M.copy (| γ1_0 |) in + let rest := M.copy (| γ1_1 |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hasher", + impl_Hasher, + [], + [], + "write_usize", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| hasher |) |) + |); + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.path "usize", + "from_ne_bytes", + [], + [] + |), + [ M.read (| M.deref (| M.read (| chunk |) |) |) ] + |) + ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + bytes, + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| rest |) |) |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |) in + M.alloc (| Value.Tuple [] |) + |) + |) + |))) + ] + |))) + |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.gt (| + M.read (| M.get_constant "core::num::BITS" |), + Value.Integer IntegerKind.U32 64 + |) + |)) in + let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 8 ] + [ Ty.path "u8" ] + ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "split_first_chunk", + [ Value.Integer IntegerKind.Usize 8 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| bytes |) |) + |) + ] + |) + |) in + let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let chunk := M.copy (| γ1_0 |) in + let rest := M.copy (| γ1_1 |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hasher", + impl_Hasher, + [], + [], + "write_u64", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| hasher |) |) + |); + M.call_closure (| + Ty.path "u64", + M.get_associated_function (| + Ty.path "u64", + "from_ne_bytes", + [], + [] + |), + [ M.read (| M.deref (| M.read (| chunk |) |) |) ] + |) + ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + bytes, + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| rest |) |) |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.gt (| + M.read (| M.get_constant "core::num::BITS" |), + Value.Integer IntegerKind.U32 32 + |) + |)) in + let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 4 ] + [ Ty.path "u8" ] + ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "split_first_chunk", + [ Value.Integer IntegerKind.Usize 4 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| bytes |) |) + |) + ] + |) + |) in + let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let chunk := M.copy (| γ1_0 |) in + let rest := M.copy (| γ1_1 |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hasher", + impl_Hasher, + [], + [], + "write_u32", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| hasher |) |) + |); + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| + Ty.path "u32", + "from_ne_bytes", + [], + [] + |), + [ M.read (| M.deref (| M.read (| chunk |) |) |) ] + |) + ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + bytes, + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| rest |) |) |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.gt (| + M.read (| M.get_constant "core::num::BITS" |), + Value.Integer IntegerKind.U32 16 + |) + |)) in + let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u8" ] + ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "split_first_chunk", + [ Value.Integer IntegerKind.Usize 2 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| bytes |) |) + |) + ] + |) + |) in + let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let chunk := M.copy (| γ1_0 |) in + let rest := M.copy (| γ1_1 |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hasher", + impl_Hasher, + [], + [], + "write_u16", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| hasher |) |) + |); + M.call_closure (| + Ty.path "u16", + M.get_associated_function (| + Ty.path "u16", + "from_ne_bytes", + [], + [] + |), + [ M.read (| M.deref (| M.read (| chunk |) |) |) ] + |) + ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + bytes, + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| rest |) |) |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.gt (| + M.read (| M.get_constant "core::num::BITS" |), + Value.Integer IntegerKind.U32 8 + |) + |)) in + let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.tuple + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 ] + [ Ty.path "u8" ] + ]; + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "split_first_chunk", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| bytes |) |) + |) + ] + |) + |) in + let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let chunk := M.copy (| γ1_0 |) in + let rest := M.copy (| γ1_1 |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hasher", + impl_Hasher, + [], + [], + "write_u8", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| hasher |) |) + |); + M.call_closure (| + Ty.path "u8", + M.get_associated_function (| + Ty.path "u8", + "from_ne_bytes", + [], + [] + |), + [ M.read (| M.deref (| M.read (| chunk |) |) |) ] + |) + ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + bytes, + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| rest |) |) |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "is_empty", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| bytes |) |) + |) + ] + |) + |) + |)) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "assertion failed: bytes.is_empty()" |) ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_write_bytes_unrolled : + M.IsFunction.Trait "alloy_primitives::map::fixed::write_bytes_unrolled" write_bytes_unrolled. + Admitted. + Global Typeclasses Opaque write_bytes_unrolled. + End fixed. +End map. diff --git a/CoqOfRust/alloy_primitives/map/mod.rs b/CoqOfRust/alloy_primitives/map/mod.rs new file mode 100644 index 000000000..7126a1a42 --- /dev/null +++ b/CoqOfRust/alloy_primitives/map/mod.rs @@ -0,0 +1,170 @@ +//! Re-exports of map types and utilities. +//! +//! This module exports the following types: +//! - [`HashMap`] and [`HashSet`] from the standard library or `hashbrown` crate. The +//! "map-hashbrown" feature can be used to force the use of `hashbrown`, and is required in +//! `no_std` environments. +//! - [`IndexMap`] and [`IndexSet`] from the `indexmap` crate, if the "map-indexmap" feature is +//! enabled. +//! - The previously-listed hash map types prefixed with `Fb`. These are type aliases with +//! [`FixedBytes`][fb] as the key, and [`FbBuildHasher`] as the hasher builder. This hasher is +//! optimized for hashing fixed-size byte arrays, and wraps around the default hasher builder. It +//! performs best when the hasher is `fxhash`, which is enabled by default with the "map-fxhash" +//! feature. +//! - The previously-listed hash map types prefixed with [`Selector`], [`Address`], and [`B256`]. +//! These use [`FbBuildHasher`] with the respective fixed-size byte array as the key. See the +//! previous point for more information. +//! +//! Unless specified otherwise, the default hasher builder used by these types is +//! [`DefaultHashBuilder`]. This hasher prioritizes speed over security. Users who require HashDoS +//! resistance should enable the "rand" feature so that the hasher is initialized using a random +//! seed. +//! +//! Note that using the types provided in this module may require using different APIs than the +//! standard library as they might not be generic over the hasher state, such as using +//! `HashMap::default()` instead of `HashMap::new()`. +//! +//! [fb]: crate::FixedBytes +//! [`Selector`]: crate::Selector +//! [`Address`]: crate::Address +//! [`B256`]: crate::B256 + +use cfg_if::cfg_if; + +mod fixed; +pub use fixed::*; + +// The `HashMap` implementation. +// Use `hashbrown` if requested with "map-hashbrown" or required by `no_std`. +cfg_if! { + if #[cfg(any(feature = "map-hashbrown", not(feature = "std")))] { + use hashbrown as imp; + } else { + use hashbrown as _; + use std::collections as imp; + } +} + +#[doc(no_inline)] +pub use imp::{hash_map, hash_map::Entry, hash_set}; + +/// A [`HashMap`](imp::HashMap) using the [default hasher](DefaultHasher). +/// +/// See [`HashMap`](imp::HashMap) for more information. +pub type HashMap = imp::HashMap; +/// A [`HashSet`](imp::HashSet) using the [default hasher](DefaultHasher). +/// +/// See [`HashSet`](imp::HashSet) for more information. +pub type HashSet = imp::HashSet; + +// Faster hashers. +cfg_if! { + if #[cfg(feature = "map-fxhash")] { + #[doc(no_inline)] + pub use rustc_hash::{self, FxHasher}; + + cfg_if! { + if #[cfg(all(feature = "std", feature = "rand"))] { + // use rustc_hash::FxRandomState as FxBuildHasherInner; + + // TODO: Polyfill for https://github.com/rust-lang/rustc-hash/pull/52/ + #[allow(missing_debug_implementations, missing_copy_implementations)] + #[doc(hidden)] + #[derive(Clone)] + pub struct FxBuildHasherInner(usize); + + impl Default for FxBuildHasherInner { + // Copied from `FxRandomState::new`. + fn default() -> Self { + use rand::Rng; + use std::{cell::Cell, thread_local}; + + thread_local!(static SEED: Cell = { + Cell::new(rand::thread_rng().gen()) + }); + + SEED.with(|seed| { + let s = seed.get(); + seed.set(s.wrapping_add(1)); + Self(s) + }) + } + } + + impl core::hash::BuildHasher for FxBuildHasherInner { + type Hasher = rustc_hash::FxHasher; + + #[inline] + fn build_hasher(&self) -> Self::Hasher { + rustc_hash::FxHasher::with_seed(self.0) + } + } + } else { + use rustc_hash::FxBuildHasher as FxBuildHasherInner; + } + } + + /// The [`FxHasher`] hasher builder. + /// + /// This is [`rustc_hash::FxBuildHasher`], unless both the "std" and "rand" features are + /// enabled, in which case it will be [`rustc_hash::FxRandomState`] for better security at + /// very little cost. + pub type FxBuildHasher = FxBuildHasherInner; + } +} + +// Default hasher. +cfg_if! { + // TODO: Use `foldhash` in zkVM when it's supported. + if #[cfg(all(feature = "map-foldhash", not(target_os = "zkvm")))] { + type DefaultHashBuilderInner = foldhash::fast::RandomState; + } else if #[cfg(feature = "map-fxhash")] { + type DefaultHashBuilderInner = FxBuildHasher; + } else if #[cfg(any(feature = "map-hashbrown", not(feature = "std")))] { + type DefaultHashBuilderInner = hashbrown::DefaultHashBuilder; + } else { + type DefaultHashBuilderInner = std::collections::hash_map::RandomState; + } +} +/// The default [`BuildHasher`](core::hash::BuildHasher) used by [`HashMap`] and [`HashSet`]. +/// +/// See [the module documentation](self) for more information on the default hasher. +pub type DefaultHashBuilder = DefaultHashBuilderInner; +/// The default [`Hasher`](core::hash::Hasher) used by [`HashMap`] and [`HashSet`]. +/// +/// See [the module documentation](self) for more information on the default hasher. +pub type DefaultHasher = ::Hasher; + +// `indexmap` re-exports. +cfg_if! { + if #[cfg(feature = "map-indexmap")] { + #[doc(no_inline)] + pub use indexmap::{self, map::Entry as IndexEntry}; + + /// [`IndexMap`](indexmap::IndexMap) using the [default hasher](DefaultHasher). + /// + /// See [`IndexMap`](indexmap::IndexMap) for more information. + pub type IndexMap = indexmap::IndexMap; + /// [`IndexSet`](indexmap::IndexSet) using the [default hasher](DefaultHasher). + /// + /// See [`IndexSet`](indexmap::IndexSet) for more information. + pub type IndexSet = indexmap::IndexSet; + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + #[cfg_attr(miri, ignore = "foldhash queries time (orlp/foldhash#4)")] + fn default_hasher_builder_traits() { + let hash_builder = ::default(); + let _hash_builder2 = ::clone(&hash_builder); + let mut hasher = + ::build_hasher(&hash_builder); + + ::write_u8(&mut hasher, 0); + let _hasher2 = ::clone(&hasher); + } +} diff --git a/CoqOfRust/alloy_primitives/map/mod.v b/CoqOfRust/alloy_primitives/map/mod.v new file mode 100644 index 000000000..a0b735e23 --- /dev/null +++ b/CoqOfRust/alloy_primitives/map/mod.v @@ -0,0 +1,30 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module map. + Axiom HashMap : + forall (K V S : Ty.t), + (Ty.apply (Ty.path "alloy_primitives::map::HashMap") [] [ K; V; S ]) = + (Ty.apply (Ty.path "std::collections::hash::map::HashMap") [] [ K; V; S ]). + + Axiom HashSet : + forall (V S : Ty.t), + (Ty.apply (Ty.path "alloy_primitives::map::HashSet") [] [ V; S ]) = + (Ty.apply (Ty.path "std::collections::hash::set::HashSet") [] [ V; S ]). + + Axiom DefaultHashBuilderInner : + (Ty.path "alloy_primitives::map::DefaultHashBuilderInner") = + (Ty.path "foldhash::fast::RandomState"). + + Axiom DefaultHashBuilder : + (Ty.path "alloy_primitives::map::DefaultHashBuilder") = (Ty.path "foldhash::fast::RandomState"). + + Axiom DefaultHasher : + (Ty.path "alloy_primitives::map::DefaultHasher") = + (Ty.associated_in_trait + "core::hash::BuildHasher" + [] + [] + (Ty.path "foldhash::fast::RandomState") + "Hasher"). +End map. diff --git a/CoqOfRust/alloy_primitives/postgres.rs b/CoqOfRust/alloy_primitives/postgres.rs new file mode 100644 index 000000000..05fc29f50 --- /dev/null +++ b/CoqOfRust/alloy_primitives/postgres.rs @@ -0,0 +1,423 @@ +//! Support for the [`postgres_types`] crate. +//! +//! **WARNING**: this module depends entirely on [`postgres_types`, which is not yet stable, +//! therefore this module is exempt from the semver guarantees of this crate. + +use super::{FixedBytes, Sign, Signed}; +use bytes::{BufMut, BytesMut}; +use derive_more::Display; +use postgres_types::{accepts, to_sql_checked, FromSql, IsNull, ToSql, Type, WrongType}; +use std::{ + error::Error, + iter, + str::{from_utf8, FromStr}, +}; + +/// Converts `FixedBytes` to Postgres Bytea Type. +impl ToSql for FixedBytes { + fn to_sql(&self, _: &Type, out: &mut BytesMut) -> Result { + out.put_slice(&self[..]); + Ok(IsNull::No) + } + + accepts!(BYTEA); + + to_sql_checked!(); +} + +/// Converts `FixedBytes` From Postgres Bytea Type. +impl<'a, const BITS: usize> FromSql<'a> for FixedBytes { + accepts!(BYTEA); + + fn from_sql(_: &Type, raw: &'a [u8]) -> Result> { + Ok(Self::try_from(raw)?) + } +} + +// https://github.com/recmo/uint/blob/6c755ad7cd54a0706d20f11f3f63b0d977af0226/src/support/postgres.rs#L22 + +type BoxedError = Box; + +const fn rem_up(a: usize, b: usize) -> usize { + let rem = a % b; + if rem > 0 { + rem + } else { + b + } +} + +fn last_idx(x: &[T], value: &T) -> usize { + x.iter().rposition(|b| b != value).map_or(0, |idx| idx + 1) +} + +fn trim_end_vec(vec: &mut Vec, value: &T) { + vec.truncate(last_idx(vec, value)); +} + +/// Error when converting to Postgres types. +#[derive(Clone, Debug, PartialEq, Eq, Display)] +pub enum ToSqlError { + /// The value is too large for the type. + #[display("Signed<{_0}> value too large to fit target type {_1}")] + Overflow(usize, Type), +} + +impl std::error::Error for ToSqlError {} + +/// Convert to Postgres types. +/// +/// Compatible [Postgres data types][dt] are: +/// +/// * `BOOL`, `SMALLINT`, `INTEGER`, `BIGINT` which are 1, 16, 32 and 64 bit signed integers +/// respectively. +/// * `OID` which is a 32 bit unsigned integer. +/// * `DECIMAL` and `NUMERIC`, which are variable length. +/// * `MONEY` which is a 64 bit integer with two decimals. +/// * `BYTEA`, `BIT`, `VARBIT` interpreted as a big-endian binary number. +/// * `CHAR`, `VARCHAR`, `TEXT` as `0x`-prefixed big-endian hex strings. +/// * `JSON`, `JSONB` as a hex string compatible with the Serde serialization. +/// +/// # Errors +/// +/// Returns an error when trying to convert to a value that is too small to fit +/// the number. Note that this depends on the value, not the type, so a +/// [`Signed<256>`] can be stored in a `SMALLINT` column, as long as the values +/// are less than $2^{16}$. +/// +/// # Implementation details +/// +/// The Postgres binary formats are used in the wire-protocol and the +/// the `COPY BINARY` command, but they have very little documentation. You are +/// pointed to the source code, for example this is the implementation of the +/// the `NUMERIC` type serializer: [`numeric.c`][numeric]. +/// +/// [dt]:https://www.postgresql.org/docs/9.5/datatype.html +/// [numeric]: https://github.com/postgres/postgres/blob/05a5a1775c89f6beb326725282e7eea1373cbec8/src/backend/utils/adt/numeric.c#L1082 +impl ToSql for Signed { + fn to_sql(&self, ty: &Type, out: &mut BytesMut) -> Result { + match *ty { + // Big-endian simple types + // Note `BufMut::put_*` methods write big-endian by default. + Type::BOOL => out.put_u8(u8::from(bool::try_from(self.0)?)), + Type::INT2 => out.put_i16(self.0.try_into()?), + Type::INT4 => out.put_i32(self.0.try_into()?), + Type::OID => out.put_u32(self.0.try_into()?), + Type::INT8 => out.put_i64(self.0.try_into()?), + + Type::MONEY => { + // Like i64, but with two decimals. + out.put_i64( + i64::try_from(self.0)? + .checked_mul(100) + .ok_or(ToSqlError::Overflow(BITS, ty.clone()))?, + ); + } + + // Binary strings + Type::BYTEA => out.put_slice(&self.0.to_be_bytes_vec()), + Type::BIT | Type::VARBIT => { + // Bit in little-endian so the first bit is the least significant. + // Length must be at least one bit. + if BITS == 0 { + if *ty == Type::BIT { + // `bit(0)` is not a valid type, but varbit can be empty. + return Err(Box::new(WrongType::new::(ty.clone()))); + } + out.put_i32(0); + } else { + // Bits are output in big-endian order, but padded at the + // least significant end. + let padding = 8 - rem_up(BITS, 8); + out.put_i32(Self::BITS.try_into()?); + let bytes = self.0.as_le_bytes(); + let mut bytes = bytes.iter().rev(); + let mut shifted = bytes.next().unwrap() << padding; + for byte in bytes { + shifted |= if padding > 0 { byte >> (8 - padding) } else { 0 }; + out.put_u8(shifted); + shifted = byte << padding; + } + out.put_u8(shifted); + } + } + + // Hex strings + Type::CHAR | Type::TEXT | Type::VARCHAR => { + out.put_slice(format!("{self:#x}").as_bytes()); + } + Type::JSON | Type::JSONB => { + if *ty == Type::JSONB { + // Version 1 of JSONB is just plain text JSON. + out.put_u8(1); + } + out.put_slice(format!("\"{self:#x}\"").as_bytes()); + } + + // Binary coded decimal types + // See + Type::NUMERIC => { + // Everything is done in big-endian base 1000 digits. + const BASE: u64 = 10000; + + let sign = match self.sign() { + Sign::Positive => 0x0000, + _ => 0x4000, + }; + + let mut digits: Vec<_> = self.abs().0.to_base_be(BASE).collect(); + let exponent = digits.len().saturating_sub(1).try_into()?; + + // Trailing zeros are removed. + trim_end_vec(&mut digits, &0); + + out.put_i16(digits.len().try_into()?); // Number of digits. + out.put_i16(exponent); // Exponent of first digit. + + out.put_i16(sign); + out.put_i16(0); // dscale: Number of digits to the right of the decimal point. + for digit in digits { + debug_assert!(digit < BASE); + #[allow(clippy::cast_possible_truncation)] // 10000 < i16::MAX + out.put_i16(digit as i16); + } + } + + // Unsupported types + _ => { + return Err(Box::new(WrongType::new::(ty.clone()))); + } + }; + Ok(IsNull::No) + } + + fn accepts(ty: &Type) -> bool { + matches!(*ty, |Type::BOOL| Type::CHAR + | Type::INT2 + | Type::INT4 + | Type::INT8 + | Type::OID + | Type::FLOAT4 + | Type::FLOAT8 + | Type::MONEY + | Type::NUMERIC + | Type::BYTEA + | Type::TEXT + | Type::VARCHAR + | Type::JSON + | Type::JSONB + | Type::BIT + | Type::VARBIT) + } + + to_sql_checked!(); +} + +/// Error when converting from Postgres types. +#[derive(Clone, Debug, PartialEq, Eq, Display)] +pub enum FromSqlError { + /// The value is too large for the type. + #[display("the value is too large for the Signed type")] + Overflow, + + /// The value is not valid for the type. + #[display("unexpected data for type {_0}")] + ParseError(Type), +} + +impl std::error::Error for FromSqlError {} + +impl<'a, const BITS: usize, const LIMBS: usize> FromSql<'a> for Signed { + fn accepts(ty: &Type) -> bool { + ::accepts(ty) + } + + fn from_sql(ty: &Type, raw: &'a [u8]) -> Result> { + Ok(match *ty { + Type::BOOL => match raw { + [0] => Self::ZERO, + [1] => Self::try_from(1)?, + _ => return Err(Box::new(FromSqlError::ParseError(ty.clone()))), + }, + Type::INT2 => i16::from_be_bytes(raw.try_into()?).try_into()?, + Type::INT4 => i32::from_be_bytes(raw.try_into()?).try_into()?, + Type::OID => u32::from_be_bytes(raw.try_into()?).try_into()?, + Type::INT8 => i64::from_be_bytes(raw.try_into()?).try_into()?, + Type::MONEY => (i64::from_be_bytes(raw.try_into()?) / 100).try_into()?, + + // Binary strings + Type::BYTEA => Self::try_from_be_slice(raw).ok_or(FromSqlError::Overflow)?, + Type::BIT | Type::VARBIT => { + // Parse header + if raw.len() < 4 { + return Err(Box::new(FromSqlError::ParseError(ty.clone()))); + } + let len: usize = i32::from_be_bytes(raw[..4].try_into()?).try_into()?; + let raw = &raw[4..]; + + // Shift padding to the other end + let padding = 8 - rem_up(len, 8); + let mut raw = raw.to_owned(); + if padding > 0 { + for i in (1..raw.len()).rev() { + raw[i] = raw[i] >> padding | raw[i - 1] << (8 - padding); + } + raw[0] >>= padding; + } + // Construct from bits + Self::try_from_be_slice(&raw).ok_or(FromSqlError::Overflow)? + } + + // Hex strings + Type::CHAR | Type::TEXT | Type::VARCHAR => Self::from_str(from_utf8(raw)?)?, + + // Hex strings + Type::JSON | Type::JSONB => { + let raw = if *ty == Type::JSONB { + if raw[0] == 1 { + &raw[1..] + } else { + // Unsupported version + return Err(Box::new(FromSqlError::ParseError(ty.clone()))); + } + } else { + raw + }; + let str = from_utf8(raw)?; + let str = if str.starts_with('"') && str.ends_with('"') { + // Stringified number + &str[1..str.len() - 1] + } else { + str + }; + Self::from_str(str)? + } + + // Numeric types + Type::NUMERIC => { + // Parse header + if raw.len() < 8 { + return Err(Box::new(FromSqlError::ParseError(ty.clone()))); + } + let digits = i16::from_be_bytes(raw[0..2].try_into()?); + let exponent = i16::from_be_bytes(raw[2..4].try_into()?); + let sign = i16::from_be_bytes(raw[4..6].try_into()?); + let dscale = i16::from_be_bytes(raw[6..8].try_into()?); + let raw = &raw[8..]; + #[allow(clippy::cast_sign_loss)] // Signs are checked + if digits < 0 + || exponent < 0 + || dscale != 0 + || digits > exponent + 1 + || raw.len() != digits as usize * 2 + { + return Err(Box::new(FromSqlError::ParseError(ty.clone()))); + } + let mut error = false; + let iter = raw.chunks_exact(2).filter_map(|raw| { + if error { + return None; + } + let digit = i16::from_be_bytes(raw.try_into().unwrap()); + if !(0..10000).contains(&digit) { + error = true; + return None; + } + #[allow(clippy::cast_sign_loss)] // Signs are checked + Some(digit as u64) + }); + #[allow(clippy::cast_sign_loss)] + // Expression can not be negative due to checks above + let iter = iter.chain(iter::repeat(0).take((exponent + 1 - digits) as usize)); + + let mut value = Self::from_base_be(10000, iter)?; + if sign == 0x4000 { + value = -value; + } + if error { + return Err(Box::new(FromSqlError::ParseError(ty.clone()))); + } + + value + } + + // Unsupported types + _ => return Err(Box::new(WrongType::new::(ty.clone()))), + }) + } +} + +#[cfg(test)] +mod test { + use super::*; + + use crate::I256; + + #[test] + fn positive_i256_from_sql() { + assert_eq!( + I256::from_sql( + &Type::NUMERIC, + &[ + 0x00, 0x01, // ndigits: 1 + 0x00, 0x00, // weight: 0 + 0x00, 0x00, // sign: 0x0000 (positive) + 0x00, 0x00, // scale: 0 + 0x00, 0x01, // digit: 1 + ] + ) + .unwrap(), + I256::ONE + ); + } + + #[test] + fn positive_i256_to_sql() { + let mut bytes = BytesMut::with_capacity(64); + I256::ONE.to_sql(&Type::NUMERIC, &mut bytes).unwrap(); + assert_eq!( + *bytes.freeze(), + [ + 0x00, 0x01, // ndigits: 1 + 0x00, 0x00, // weight: 0 + 0x00, 0x00, // sign: 0x0000 (positive) + 0x00, 0x00, // scale: 0 + 0x00, 0x01, // digit: 1 + ], + ); + } + + #[test] + fn negative_i256_from_sql() { + assert_eq!( + I256::from_sql( + &Type::NUMERIC, + &[ + 0x00, 0x01, // ndigits: 1 + 0x00, 0x00, // weight: 0 + 0x40, 0x00, // sign: 0x4000 (negative) + 0x00, 0x00, // scale: 0 + 0x00, 0x01, // digit: 1 + ] + ) + .unwrap(), + I256::MINUS_ONE + ); + } + + #[test] + fn negative_i256_to_sql() { + let mut bytes = BytesMut::with_capacity(64); + I256::MINUS_ONE.to_sql(&Type::NUMERIC, &mut bytes).unwrap(); + assert_eq!( + *bytes.freeze(), + [ + 0x00, 0x01, // ndigits: 1 + 0x00, 0x00, // weight: 0 + 0x40, 0x00, // sign: 0x4000 (negative) + 0x00, 0x00, // scale: 0 + 0x00, 0x01, // digit: 1 + ], + ); + } +} diff --git a/CoqOfRust/alloy_primitives/sealed.rs b/CoqOfRust/alloy_primitives/sealed.rs new file mode 100644 index 000000000..6c896d78b --- /dev/null +++ b/CoqOfRust/alloy_primitives/sealed.rs @@ -0,0 +1,155 @@ +use crate::B256; +use derive_more::{AsRef, Deref}; + +/// A consensus hashable item, with its memoized hash. +/// +/// We do not implement any specific hashing algorithm here. Instead types +/// implement the [`Sealable`] trait to provide define their own hash. +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, AsRef, Deref)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "arbitrary", derive(proptest_derive::Arbitrary))] +pub struct Sealed { + /// The inner item. + #[as_ref] + #[deref] + #[cfg_attr(feature = "serde", serde(flatten))] + inner: T, + #[cfg_attr(feature = "serde", serde(rename = "hash"))] + /// Its hash. + seal: B256, +} + +impl Sealed { + /// Seal the inner item. + pub fn new(inner: T) -> Self + where + T: Sealable, + { + let seal = inner.hash_slow(); + Self { inner, seal } + } + + /// Seal the inner item, by reference. + pub fn new_ref(inner: &T) -> Sealed<&T> + where + T: Sealable, + { + let seal = inner.hash_slow(); + Sealed { inner, seal } + } + + /// Seal the inner item with some function. + pub fn new_with(inner: T, f: F) -> Self + where + T: Sized, + F: FnOnce(&T) -> B256, + { + let seal = f(&inner); + Self::new_unchecked(inner, seal) + } + + /// Seal a reference to the inner item with some function. + pub fn new_ref_with(inner: &T, f: F) -> Sealed<&T> + where + T: Sized, + F: FnOnce(&T) -> B256, + { + let seal = f(inner); + Sealed::new_unchecked(inner, seal) + } + + /// Instantiate without performing the hash. This should be used carefully. + pub const fn new_unchecked(inner: T, seal: B256) -> Self { + Self { inner, seal } + } + + /// Decompose into parts. + #[allow(clippy::missing_const_for_fn)] // false positive + pub fn into_parts(self) -> (T, B256) { + (self.inner, self.seal) + } + + /// Decompose into parts. Alias for [`Self::into_parts`]. + #[allow(clippy::missing_const_for_fn)] // false positive + pub fn split(self) -> (T, B256) { + self.into_parts() + } + + /// Get the inner item. + #[inline(always)] + pub const fn inner(&self) -> &T { + &self.inner + } + + /// Get the hash. + #[inline(always)] + pub const fn seal(&self) -> B256 { + self.seal + } + + /// Get the hash. + #[inline(always)] + pub const fn hash(&self) -> B256 { + self.seal + } + + /// Unseal the inner item, discarding the hash. + #[inline(always)] + #[allow(clippy::missing_const_for_fn)] // false positive + pub fn into_inner(self) -> T { + self.inner + } + + /// Unseal the inner item, discarding the hash. Alias for + /// [`Self::into_inner`]. + #[inline(always)] + #[allow(clippy::missing_const_for_fn)] // false positive + pub fn unseal(self) -> T { + self.into_inner() + } +} + +impl Default for Sealed +where + T: Sealable + Default, +{ + fn default() -> Self { + T::default().seal_slow() + } +} + +#[cfg(feature = "arbitrary")] +impl<'a, T> arbitrary::Arbitrary<'a> for Sealed +where + T: for<'b> arbitrary::Arbitrary<'b> + Sealable, +{ + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + Ok(T::arbitrary(u)?.seal_slow()) + } +} + +/// Sealeable objects. +pub trait Sealable: Sized { + /// Calculate the seal hash, this may be slow. + fn hash_slow(&self) -> B256; + + /// Seal the object by calculating the hash. This may be slow. + fn seal_slow(self) -> Sealed { + Sealed::new(self) + } + + /// Seal a borrowed object by calculating the hash. This may be slow. + fn seal_ref_slow(&self) -> Sealed<&Self> { + Sealed::new_ref(self) + } + + /// Instantiate an unchecked seal. This should be used with caution. + fn seal_unchecked(self, seal: B256) -> Sealed { + Sealed::new_unchecked(self, seal) + } + + /// Instantiate an unchecked seal. This should be used with caution. + fn seal_ref_unchecked(&self, seal: B256) -> Sealed<&Self> { + Sealed::new_unchecked(self, seal) + } +} diff --git a/CoqOfRust/alloy_primitives/sealed.v b/CoqOfRust/alloy_primitives/sealed.v new file mode 100644 index 000000000..630aa60e2 --- /dev/null +++ b/CoqOfRust/alloy_primitives/sealed.v @@ -0,0 +1,1164 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module sealed. + (* StructRecord + { + name := "Sealed"; + const_params := []; + ty_params := [ "T" ]; + fields := + [ + ("inner", T); + ("seal", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + []) + ]; + } *) + + Module Impl_core_clone_Clone_where_core_clone_Clone_T_for_alloy_primitives_sealed_Sealed_T. + Definition Self (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::sealed::Sealed") [] [ T ]. + + (* Clone *) + Definition clone (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "alloy_primitives::sealed::Sealed" + [ + ("inner", + M.call_closure (| + T, + M.get_trait_method (| "core::clone::Clone", T, [], [], "clone", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::sealed::Sealed", + "inner" + |) + |) + |) + |) + ] + |)); + ("seal", + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + M.get_trait_method (| + "core::clone::Clone", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::sealed::Sealed", + "seal" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self T) + (* Instance *) [ ("clone", InstanceField.Method (clone T)) ]. + End Impl_core_clone_Clone_where_core_clone_Clone_T_for_alloy_primitives_sealed_Sealed_T. + + Module Impl_core_marker_Copy_where_core_marker_Copy_T_for_alloy_primitives_sealed_Sealed_T. + Definition Self (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::sealed::Sealed") [] [ T ]. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self T) + (* Instance *) []. + End Impl_core_marker_Copy_where_core_marker_Copy_T_for_alloy_primitives_sealed_Sealed_T. + + Module Impl_core_fmt_Debug_where_core_fmt_Debug_T_for_alloy_primitives_sealed_Sealed_T. + Definition Self (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::sealed::Sealed") [] [ T ]. + + (* Debug *) + Definition fmt (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field2_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Sealed" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "inner" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::sealed::Sealed", + "inner" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "seal" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::sealed::Sealed", + "seal" + |) + |) + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self T) + (* Instance *) [ ("fmt", InstanceField.Method (fmt T)) ]. + End Impl_core_fmt_Debug_where_core_fmt_Debug_T_for_alloy_primitives_sealed_Sealed_T. + + Module Impl_core_marker_StructuralPartialEq_for_alloy_primitives_sealed_Sealed_T. + Definition Self (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::sealed::Sealed") [] [ T ]. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self T) + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_alloy_primitives_sealed_Sealed_T. + + Module Impl_core_cmp_PartialEq_where_core_cmp_PartialEq_T_alloy_primitives_sealed_Sealed_T_for_alloy_primitives_sealed_Sealed_T. + Definition Self (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::sealed::Sealed") [] [ T ]. + + (* PartialEq *) + Definition eq (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| "core::cmp::PartialEq", T, [], [ T ], "eq", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::sealed::Sealed", + "inner" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::sealed::Sealed", + "inner" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::sealed::Sealed", + "seal" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::sealed::Sealed", + "seal" + |) + |) + ] + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::sealed::Sealed") [] [ T ] ] + (Self T) + (* Instance *) [ ("eq", InstanceField.Method (eq T)) ]. + End Impl_core_cmp_PartialEq_where_core_cmp_PartialEq_T_alloy_primitives_sealed_Sealed_T_for_alloy_primitives_sealed_Sealed_T. + + Module Impl_core_cmp_Eq_where_core_cmp_Eq_T_for_alloy_primitives_sealed_Sealed_T. + Definition Self (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::sealed::Sealed") [] [ T ]. + + (* Eq *) + Definition assert_receiver_is_total_eq + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ + fun γ => + ltac:(M.monadic + (M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self T) + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method (assert_receiver_is_total_eq T)) ]. + End Impl_core_cmp_Eq_where_core_cmp_Eq_T_for_alloy_primitives_sealed_Sealed_T. + + Module Impl_core_hash_Hash_where_core_hash_Hash_T_for_alloy_primitives_sealed_Sealed_T. + Definition Self (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::sealed::Sealed") [] [ T ]. + + (* Hash *) + Definition hash (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [ __H ], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| "core::hash::Hash", T, [], [], "hash", [], [ __H ] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::sealed::Sealed", + "inner" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::sealed::Sealed", + "seal" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "core::hash::Hash" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self T) + (* Instance *) [ ("hash", InstanceField.Method (hash T)) ]. + End Impl_core_hash_Hash_where_core_hash_Hash_T_for_alloy_primitives_sealed_Sealed_T. + + Module Impl_core_convert_AsRef_T_for_alloy_primitives_sealed_Sealed_T. + Definition Self (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::sealed::Sealed") [] [ T ]. + + (* AsRef *) + Definition as_ref (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::sealed::Sealed", + "inner" + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "core::convert::AsRef" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self T) + (* Instance *) [ ("as_ref", InstanceField.Method (as_ref T)) ]. + End Impl_core_convert_AsRef_T_for_alloy_primitives_sealed_Sealed_T. + + Module Impl_core_ops_deref_Deref_for_alloy_primitives_sealed_Sealed_T. + Definition Self (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::sealed::Sealed") [] [ T ]. + + (* Deref *) + Definition _Target (T : Ty.t) : Ty.t := T. + + (* Deref *) + Definition deref (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::sealed::Sealed", + "inner" + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "core::ops::deref::Deref" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self T) + (* Instance *) + [ ("Target", InstanceField.Ty (_Target T)); ("deref", InstanceField.Method (deref T)) ]. + End Impl_core_ops_deref_Deref_for_alloy_primitives_sealed_Sealed_T. + + Module Impl_alloy_primitives_sealed_Sealed_T. + Definition Self (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::sealed::Sealed") [] [ T ]. + + (* + pub fn new(inner: T) -> Self + where + T: Sealable, + { + let seal = inner.hash_slow(); + Self { inner, seal } + } + *) + Definition new (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ inner ] => + ltac:(M.monadic + (let inner := M.alloc (| inner |) in + M.read (| + let~ seal : + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + M.get_trait_method (| + "alloy_primitives::sealed::Sealable", + T, + [], + [], + "hash_slow", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, inner |) ] + |) + |) in + M.alloc (| + Value.StructRecord + "alloy_primitives::sealed::Sealed" + [ ("inner", M.read (| inner |)); ("seal", M.read (| seal |)) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : + forall (T : Ty.t), + M.IsAssociatedFunction.Trait (Self T) "new" (new T). + Admitted. + Global Typeclasses Opaque new. + + (* + pub fn new_ref(inner: &T) -> Sealed<&T> + where + T: Sealable, + { + let seal = inner.hash_slow(); + Sealed { inner, seal } + } + *) + Definition new_ref (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ inner ] => + ltac:(M.monadic + (let inner := M.alloc (| inner |) in + M.read (| + let~ seal : + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + M.get_trait_method (| + "alloy_primitives::sealed::Sealable", + T, + [], + [], + "hash_slow", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| inner |) |) |) ] + |) + |) in + M.alloc (| + Value.StructRecord + "alloy_primitives::sealed::Sealed" + [ + ("inner", M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| inner |) |) |)); + ("seal", M.read (| seal |)) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new_ref : + forall (T : Ty.t), + M.IsAssociatedFunction.Trait (Self T) "new_ref" (new_ref T). + Admitted. + Global Typeclasses Opaque new_ref. + + (* + pub fn new_with(inner: T, f: F) -> Self + where + T: Sized, + F: FnOnce(&T) -> B256, + { + let seal = f(&inner); + Self::new_unchecked(inner, seal) + } + *) + Definition new_with (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [ F ], [ inner; f ] => + ltac:(M.monadic + (let inner := M.alloc (| inner |) in + let f := M.alloc (| f |) in + M.read (| + let~ seal : + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + M.get_trait_method (| + "core::ops::function::FnOnce", + F, + [], + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ T ] ] ], + "call_once", + [], + [] + |), + [ + M.read (| f |); + Value.Tuple + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, inner |) |) + |) + ] + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::sealed::Sealed") [] [ T ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::sealed::Sealed") [] [ T ], + "new_unchecked", + [], + [] + |), + [ M.read (| inner |); M.read (| seal |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new_with : + forall (T : Ty.t), + M.IsAssociatedFunction.Trait (Self T) "new_with" (new_with T). + Admitted. + Global Typeclasses Opaque new_with. + + (* + pub fn new_ref_with(inner: &T, f: F) -> Sealed<&T> + where + T: Sized, + F: FnOnce(&T) -> B256, + { + let seal = f(inner); + Sealed::new_unchecked(inner, seal) + } + *) + Definition new_ref_with (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [ F ], [ inner; f ] => + ltac:(M.monadic + (let inner := M.alloc (| inner |) in + let f := M.alloc (| f |) in + M.read (| + let~ seal : + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + M.get_trait_method (| + "core::ops::function::FnOnce", + F, + [], + [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ T ] ] ], + "call_once", + [], + [] + |), + [ + M.read (| f |); + Value.Tuple + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| inner |) |) |) ] + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::sealed::Sealed") + [] + [ Ty.apply (Ty.path "&") [] [ T ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::sealed::Sealed") + [] + [ Ty.apply (Ty.path "&") [] [ T ] ], + "new_unchecked", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| inner |) |) |); + M.read (| seal |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new_ref_with : + forall (T : Ty.t), + M.IsAssociatedFunction.Trait (Self T) "new_ref_with" (new_ref_with T). + Admitted. + Global Typeclasses Opaque new_ref_with. + + (* + pub const fn new_unchecked(inner: T, seal: B256) -> Self { + Self { inner, seal } + } + *) + Definition new_unchecked (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ inner; seal ] => + ltac:(M.monadic + (let inner := M.alloc (| inner |) in + let seal := M.alloc (| seal |) in + Value.StructRecord + "alloy_primitives::sealed::Sealed" + [ ("inner", M.read (| inner |)); ("seal", M.read (| seal |)) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new_unchecked : + forall (T : Ty.t), + M.IsAssociatedFunction.Trait (Self T) "new_unchecked" (new_unchecked T). + Admitted. + Global Typeclasses Opaque new_unchecked. + + (* + pub fn into_parts(self) -> (T, B256) { + (self.inner, self.seal) + } + *) + Definition into_parts (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.Tuple + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "alloy_primitives::sealed::Sealed", + "inner" + |) + |); + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "alloy_primitives::sealed::Sealed", + "seal" + |) + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_into_parts : + forall (T : Ty.t), + M.IsAssociatedFunction.Trait (Self T) "into_parts" (into_parts T). + Admitted. + Global Typeclasses Opaque into_parts. + + (* + pub fn split(self) -> (T, B256) { + self.into_parts() + } + *) + Definition split (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.tuple + [ + T; + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::sealed::Sealed") [] [ T ], + "into_parts", + [], + [] + |), + [ M.read (| self |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_split : + forall (T : Ty.t), + M.IsAssociatedFunction.Trait (Self T) "split" (split T). + Admitted. + Global Typeclasses Opaque split. + + (* + pub const fn inner(&self) -> &T { + &self.inner + } + *) + Definition inner (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::sealed::Sealed", + "inner" + |) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_inner : + forall (T : Ty.t), + M.IsAssociatedFunction.Trait (Self T) "inner" (inner T). + Admitted. + Global Typeclasses Opaque inner. + + (* + pub const fn seal(&self) -> B256 { + self.seal + } + *) + Definition seal (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::sealed::Sealed", + "seal" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_seal : + forall (T : Ty.t), + M.IsAssociatedFunction.Trait (Self T) "seal" (seal T). + Admitted. + Global Typeclasses Opaque seal. + + (* + pub const fn hash(&self) -> B256 { + self.seal + } + *) + Definition hash (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::sealed::Sealed", + "seal" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_hash : + forall (T : Ty.t), + M.IsAssociatedFunction.Trait (Self T) "hash" (hash T). + Admitted. + Global Typeclasses Opaque hash. + + (* + pub fn into_inner(self) -> T { + self.inner + } + *) + Definition into_inner (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "alloy_primitives::sealed::Sealed", + "inner" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_into_inner : + forall (T : Ty.t), + M.IsAssociatedFunction.Trait (Self T) "into_inner" (into_inner T). + Admitted. + Global Typeclasses Opaque into_inner. + + (* + pub fn unseal(self) -> T { + self.into_inner() + } + *) + Definition unseal (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + T, + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::sealed::Sealed") [] [ T ], + "into_inner", + [], + [] + |), + [ M.read (| self |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_unseal : + forall (T : Ty.t), + M.IsAssociatedFunction.Trait (Self T) "unseal" (unseal T). + Admitted. + Global Typeclasses Opaque unseal. + End Impl_alloy_primitives_sealed_Sealed_T. + + Module Impl_core_default_Default_where_alloy_primitives_sealed_Sealable_T_where_core_default_Default_T_for_alloy_primitives_sealed_Sealed_T. + Definition Self (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::sealed::Sealed") [] [ T ]. + + (* + fn default() -> Self { + T::default().seal_slow() + } + *) + Definition default (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + let Self : Ty.t := Self T in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::sealed::Sealed") [] [ T ], + M.get_trait_method (| + "alloy_primitives::sealed::Sealable", + T, + [], + [], + "seal_slow", + [], + [] + |), + [ + M.call_closure (| + T, + M.get_trait_method (| "core::default::Default", T, [], [], "default", [], [] |), + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (T : Ty.t), + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self T) + (* Instance *) [ ("default", InstanceField.Method (default T)) ]. + End Impl_core_default_Default_where_alloy_primitives_sealed_Sealable_T_where_core_default_Default_T_for_alloy_primitives_sealed_Sealed_T. + + (* Trait *) + Module Sealable. + Definition seal_slow (Self : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::sealed::Sealed") [] [ Self ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::sealed::Sealed") [] [ Self ], + "new", + [], + [] + |), + [ M.read (| self |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_seal_slow : + M.IsProvidedMethod "alloy_primitives::sealed::Sealable" "seal_slow" seal_slow. + Definition seal_ref_slow + (Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::sealed::Sealed") + [] + [ Ty.apply (Ty.path "&") [] [ Self ] ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::sealed::Sealed") [] [ Self ], + "new_ref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_seal_ref_slow : + M.IsProvidedMethod "alloy_primitives::sealed::Sealable" "seal_ref_slow" seal_ref_slow. + Definition seal_unchecked + (Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; seal ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let seal := M.alloc (| seal |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::sealed::Sealed") [] [ Self ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::sealed::Sealed") [] [ Self ], + "new_unchecked", + [], + [] + |), + [ M.read (| self |); M.read (| seal |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_seal_unchecked : + M.IsProvidedMethod "alloy_primitives::sealed::Sealable" "seal_unchecked" seal_unchecked. + Definition seal_ref_unchecked + (Self : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self; seal ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let seal := M.alloc (| seal |) in + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::sealed::Sealed") + [] + [ Ty.apply (Ty.path "&") [] [ Self ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::sealed::Sealed") + [] + [ Ty.apply (Ty.path "&") [] [ Self ] ], + "new_unchecked", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); M.read (| seal |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom ProvidedMethod_seal_ref_unchecked : + M.IsProvidedMethod + "alloy_primitives::sealed::Sealable" + "seal_ref_unchecked" + seal_ref_unchecked. + End Sealable. +End sealed. diff --git a/CoqOfRust/alloy_primitives/signature/error.rs b/CoqOfRust/alloy_primitives/signature/error.rs new file mode 100644 index 000000000..a1e3dd226 --- /dev/null +++ b/CoqOfRust/alloy_primitives/signature/error.rs @@ -0,0 +1,62 @@ +use core::convert::Infallible; + +/// Errors in signature parsing or verification. +#[derive(Debug)] +#[cfg_attr(not(feature = "k256"), derive(Copy, Clone))] +pub enum SignatureError { + /// Error converting from bytes. + FromBytes(&'static str), + + /// Error converting hex to bytes. + FromHex(hex::FromHexError), + + /// Invalid parity. + InvalidParity(u64), + + /// k256 error + #[cfg(feature = "k256")] + K256(k256::ecdsa::Error), +} + +#[cfg(feature = "k256")] +impl From for SignatureError { + fn from(err: k256::ecdsa::Error) -> Self { + Self::K256(err) + } +} + +impl From for SignatureError { + fn from(err: hex::FromHexError) -> Self { + Self::FromHex(err) + } +} + +#[cfg(feature = "std")] +impl std::error::Error for SignatureError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + #[cfg(feature = "k256")] + Self::K256(e) => Some(e), + Self::FromHex(e) => Some(e), + _ => None, + } + } +} + +impl core::fmt::Display for SignatureError { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + #[cfg(feature = "k256")] + Self::K256(e) => e.fmt(f), + Self::FromBytes(e) => f.write_str(e), + Self::FromHex(e) => e.fmt(f), + Self::InvalidParity(v) => write!(f, "invalid parity: {v}"), + } + } +} + +impl From for SignatureError { + fn from(_: Infallible) -> Self { + unreachable!() + } +} diff --git a/CoqOfRust/alloy_primitives/signature/error.v b/CoqOfRust/alloy_primitives/signature/error.v new file mode 100644 index 000000000..d90f77760 --- /dev/null +++ b/CoqOfRust/alloy_primitives/signature/error.v @@ -0,0 +1,537 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module signature. + Module error. + (* + Enum SignatureError + { + const_params := []; + ty_params := []; + variants := + [ + { + name := "FromBytes"; + item := StructTuple [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ]; + }; + { + name := "FromHex"; + item := StructTuple [ Ty.path "const_hex::error::FromHexError" ]; + }; + { + name := "InvalidParity"; + item := StructTuple [ Ty.path "u64" ]; + } + ]; + } + *) + + Axiom IsDiscriminant_SignatureError_FromBytes : + M.IsDiscriminant "alloy_primitives::signature::error::SignatureError::FromBytes" 0. + Axiom IsDiscriminant_SignatureError_FromHex : + M.IsDiscriminant "alloy_primitives::signature::error::SignatureError::FromHex" 1. + Axiom IsDiscriminant_SignatureError_InvalidParity : + M.IsDiscriminant "alloy_primitives::signature::error::SignatureError::InvalidParity" 2. + + Module Impl_core_marker_Copy_for_alloy_primitives_signature_error_SignatureError. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::error::SignatureError". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_alloy_primitives_signature_error_SignatureError. + + Module Impl_core_clone_Clone_for_alloy_primitives_signature_error_SignatureError. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::error::SignatureError". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ + fun γ => + ltac:(M.monadic + (M.match_operator (| + None, + Value.DeclaredButUndefined, + [ + fun γ => + ltac:(M.monadic + (M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.deref (| M.read (| self |) |))) ] + |))) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_alloy_primitives_signature_error_SignatureError. + + Module Impl_core_fmt_Debug_for_alloy_primitives_signature_error_SignatureError. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::error::SignatureError". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ]), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::error::SignatureError::FromBytes", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "FromBytes" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::error::SignatureError::FromHex", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "FromHex" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::error::SignatureError::InvalidParity", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "InvalidParity" |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_alloy_primitives_signature_error_SignatureError. + + Module Impl_core_convert_From_const_hex_error_FromHexError_for_alloy_primitives_signature_error_SignatureError. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::error::SignatureError". + + (* + fn from(err: hex::FromHexError) -> Self { + Self::FromHex(err) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ err ] => + ltac:(M.monadic + (let err := M.alloc (| err |) in + Value.StructTuple + "alloy_primitives::signature::error::SignatureError::FromHex" + [ M.read (| err |) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "const_hex::error::FromHexError" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_const_hex_error_FromHexError_for_alloy_primitives_signature_error_SignatureError. + + Module Impl_core_error_Error_for_alloy_primitives_signature_error_SignatureError. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::error::SignatureError". + + (* + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + #[cfg(feature = "k256")] + Self::K256(e) => Some(e), + Self::FromHex(e) => Some(e), + _ => None, + } + } + *) + Definition source (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.dyn [ ("core::error::Error::Trait", []) ] ] ]), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::error::SignatureError::FromHex", + 0 + |) in + let e := M.alloc (| γ1_0 |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| e |) |) |) ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.StructTuple "core::option::Option::None" [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::error::Error" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("source", InstanceField.Method source) ]. + End Impl_core_error_Error_for_alloy_primitives_signature_error_SignatureError. + + Module Impl_core_fmt_Display_for_alloy_primitives_signature_error_SignatureError. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::error::SignatureError". + + (* + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + match self { + #[cfg(feature = "k256")] + Self::K256(e) => e.fmt(f), + Self::FromBytes(e) => f.write_str(e), + Self::FromHex(e) => e.fmt(f), + Self::InvalidParity(v) => write!(f, "invalid parity: {v}"), + } + } + *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ]), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::error::SignatureError::FromBytes", + 0 + |) in + let e := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| M.deref (| M.read (| e |) |) |) |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::error::SignatureError::FromHex", + 0 + |) in + let e := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::Display", + Ty.path "const_hex::error::FromHexError", + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| e |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::error::SignatureError::InvalidParity", + 0 + |) in + let v := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_fmt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 1; + Value.Integer IntegerKind.Usize 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [ mk_str (| "invalid parity: " |) ] |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "u64" ] ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, v |) |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Display" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Display_for_alloy_primitives_signature_error_SignatureError. + + Module Impl_core_convert_From_core_convert_Infallible_for_alloy_primitives_signature_error_SignatureError. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::error::SignatureError". + + (* + fn from(_: Infallible) -> Self { + unreachable!() + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ β0 ] => + ltac:(M.monadic + (let β0 := M.alloc (| β0 |) in + M.match_operator (| + None, + β0, + [ + fun γ => + ltac:(M.monadic + (M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic", [], [] |), + [ mk_str (| "internal error: entered unreachable code" |) ] + |) + |))) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "core::convert::Infallible" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_core_convert_Infallible_for_alloy_primitives_signature_error_SignatureError. + End error. +End signature. diff --git a/CoqOfRust/alloy_primitives/signature/mod.rs b/CoqOfRust/alloy_primitives/signature/mod.rs new file mode 100644 index 000000000..815b32cdf --- /dev/null +++ b/CoqOfRust/alloy_primitives/signature/mod.rs @@ -0,0 +1,14 @@ +mod error; +pub use error::SignatureError; + +mod parity; +pub use parity::Parity; + +mod sig; +pub use sig::Signature; + +mod utils; +pub use utils::{normalize_v, to_eip155_v}; + +mod primitive_sig; +pub use primitive_sig::PrimitiveSignature; diff --git a/CoqOfRust/alloy_primitives/signature/parity.rs b/CoqOfRust/alloy_primitives/signature/parity.rs new file mode 100644 index 000000000..b16011b0d --- /dev/null +++ b/CoqOfRust/alloy_primitives/signature/parity.rs @@ -0,0 +1,280 @@ +use crate::{ + signature::{utils::normalize_v_to_byte, SignatureError}, + to_eip155_v, ChainId, Uint, U64, +}; + +/// The parity of the signature, stored as either a V value (which may include +/// a chain id), or the y-parity. +#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)] +#[cfg_attr(feature = "arbitrary", derive(derive_arbitrary::Arbitrary, proptest_derive::Arbitrary))] +pub enum Parity { + /// Explicit V value. May be EIP-155 modified. + Eip155(u64), + /// Non-EIP155. 27 or 28. + NonEip155(bool), + /// Parity flag. True for odd. + Parity(bool), +} + +impl Default for Parity { + fn default() -> Self { + Self::Parity(false) + } +} + +#[cfg(feature = "k256")] +impl From for Parity { + fn from(value: k256::ecdsa::RecoveryId) -> Self { + Self::Parity(value.is_y_odd()) + } +} + +impl TryFrom for Parity { + type Error = >::Error; + fn try_from(value: U64) -> Result { + value.as_limbs()[0].try_into() + } +} + +impl From> for Parity { + fn from(value: Uint<1, 1>) -> Self { + Self::Parity(!value.is_zero()) + } +} + +impl From for Parity { + fn from(value: bool) -> Self { + Self::Parity(value) + } +} + +impl TryFrom for Parity { + type Error = SignatureError; + + fn try_from(value: u64) -> Result { + match value { + 0 | 1 => Ok(Self::Parity(value != 0)), + 27 | 28 => Ok(Self::NonEip155((value - 27) != 0)), + value @ 35..=u64::MAX => Ok(Self::Eip155(value)), + _ => Err(SignatureError::InvalidParity(value)), + } + } +} + +impl Parity { + /// Returns the chain ID associated with the V value, if this signature is + /// replay-protected by [EIP-155]. + /// + /// [EIP-155]: https://eips.ethereum.org/EIPS/eip-155 + pub const fn chain_id(&self) -> Option { + match *self { + Self::Eip155(mut v @ 35..) => { + if v % 2 == 0 { + v -= 1; + } + v -= 35; + Some(v / 2) + } + _ => None, + } + } + + /// Returns true if the signature is replay-protected by [EIP-155]. + /// + /// This is true if the V value is 35 or greater. Values less than 35 are + /// either not replay protected (27/28), or are invalid. + /// + /// [EIP-155]: https://eips.ethereum.org/EIPS/eip-155 + pub const fn has_eip155_value(&self) -> bool { + self.chain_id().is_some() + } + + /// Return the y-parity as a boolean. + pub const fn y_parity(&self) -> bool { + match self { + Self::Eip155(v @ 0..=34) => *v % 2 == 1, + Self::Eip155(v) => (*v ^ 1) % 2 == 1, + Self::NonEip155(b) | Self::Parity(b) => *b, + } + } + + /// Return the y-parity as 0 or 1 + pub const fn y_parity_byte(&self) -> u8 { + self.y_parity() as u8 + } + + /// Return the y-parity byte as 27 or 28, + /// in the case of a non-EIP155 signature. + pub const fn y_parity_byte_non_eip155(&self) -> Option { + match self { + Self::NonEip155(v) | Self::Parity(v) => Some(*v as u8 + 27), + _ => None, + } + } + + /// Return the corresponding u64 V value. + pub const fn to_u64(&self) -> u64 { + match self { + Self::Eip155(v) => *v, + Self::NonEip155(b) => *b as u64 + 27, + Self::Parity(b) => *b as u64, + } + } + + /// Inverts the parity. + pub const fn inverted(&self) -> Self { + match *self { + Self::Parity(b) => Self::Parity(!b), + Self::NonEip155(b) => Self::NonEip155(!b), + Self::Eip155(0) => Self::Eip155(1), + Self::Eip155(v @ 1..=34) => Self::Eip155(if v % 2 == 0 { v - 1 } else { v + 1 }), + Self::Eip155(v @ 35..) => Self::Eip155(v ^ 1), + } + } + + /// Converts an EIP-155 V value to a non-EIP-155 V value. + /// + /// This is a nop for non-EIP-155 values. + pub const fn strip_chain_id(&self) -> Self { + match *self { + Self::Eip155(v) => Self::NonEip155(v % 2 == 1), + this => this, + } + } + + /// Applies EIP-155 with the given chain ID. + pub const fn with_chain_id(self, chain_id: ChainId) -> Self { + let parity = match self { + Self::Eip155(v) => normalize_v_to_byte(v) == 1, + Self::NonEip155(b) | Self::Parity(b) => b, + }; + + Self::Eip155(to_eip155_v(parity as u8, chain_id)) + } + + /// Determines the recovery ID. + #[cfg(feature = "k256")] + pub const fn recid(&self) -> k256::ecdsa::RecoveryId { + let recid_opt = match self { + Self::Eip155(v) => Some(crate::signature::utils::normalize_v_to_recid(*v)), + Self::NonEip155(b) | Self::Parity(b) => k256::ecdsa::RecoveryId::from_byte(*b as u8), + }; + + // manual unwrap for const fn + match recid_opt { + Some(recid) => recid, + None => unreachable!(), + } + } + + /// Convert to a parity bool, dropping any V information. + pub const fn to_parity_bool(self) -> Self { + Self::Parity(self.y_parity()) + } +} + +#[cfg(feature = "rlp")] +impl alloy_rlp::Encodable for Parity { + fn encode(&self, out: &mut dyn alloy_rlp::BufMut) { + match self { + Self::Eip155(v) => v.encode(out), + Self::NonEip155(v) => (*v as u8 + 27).encode(out), + Self::Parity(b) => b.encode(out), + } + } + + fn length(&self) -> usize { + match self { + Self::Eip155(v) => v.length(), + Self::NonEip155(_) => 0u8.length(), + Self::Parity(v) => v.length(), + } + } +} + +#[cfg(feature = "rlp")] +impl alloy_rlp::Decodable for Parity { + fn decode(buf: &mut &[u8]) -> Result { + let v = u64::decode(buf)?; + Ok(match v { + 0 => Self::Parity(false), + 1 => Self::Parity(true), + 27 => Self::NonEip155(false), + 28 => Self::NonEip155(true), + v @ 35..=u64::MAX => Self::try_from(v).expect("checked range"), + _ => return Err(alloy_rlp::Error::Custom("Invalid parity value")), + }) + } +} + +#[cfg(test)] +mod test { + use crate::Parity; + + #[cfg(feature = "rlp")] + #[test] + fn basic_rlp() { + use crate::hex; + use alloy_rlp::{Decodable, Encodable}; + + let vector = vec![ + (hex!("01").as_slice(), Parity::Parity(true)), + (hex!("1b").as_slice(), Parity::NonEip155(false)), + (hex!("25").as_slice(), Parity::Eip155(37)), + (hex!("26").as_slice(), Parity::Eip155(38)), + (hex!("81ff").as_slice(), Parity::Eip155(255)), + ]; + + for test in vector.into_iter() { + let mut buf = vec![]; + test.1.encode(&mut buf); + assert_eq!(test.0, buf.as_slice()); + + assert_eq!(test.1, Parity::decode(&mut buf.as_slice()).unwrap()); + } + } + + #[test] + fn u64_round_trip() { + let parity = Parity::Eip155(37); + assert_eq!(parity, Parity::try_from(parity.to_u64()).unwrap()); + let parity = Parity::Eip155(38); + assert_eq!(parity, Parity::try_from(parity.to_u64()).unwrap()); + let parity = Parity::NonEip155(false); + assert_eq!(parity, Parity::try_from(parity.to_u64()).unwrap()); + let parity = Parity::NonEip155(true); + assert_eq!(parity, Parity::try_from(parity.to_u64()).unwrap()); + let parity = Parity::Parity(false); + assert_eq!(parity, Parity::try_from(parity.to_u64()).unwrap()); + let parity = Parity::Parity(true); + assert_eq!(parity, Parity::try_from(parity.to_u64()).unwrap()); + } + + #[test] + fn round_trip() { + // with chain ID 1 + let p = Parity::Eip155(37); + + assert_eq!(p.to_parity_bool(), Parity::Parity(false)); + + assert_eq!(p.with_chain_id(1), Parity::Eip155(37)); + } + + #[test] + fn invert_parity() { + let p = Parity::Eip155(0); + assert_eq!(p.inverted(), Parity::Eip155(1)); + + let p = Parity::Eip155(22); + assert_eq!(p.inverted(), Parity::Eip155(21)); + + let p = Parity::Eip155(58); + assert_eq!(p.inverted(), Parity::Eip155(59)); + + let p = Parity::NonEip155(false); + assert_eq!(p.inverted(), Parity::NonEip155(true)); + + let p = Parity::Parity(true); + assert_eq!(p.inverted(), Parity::Parity(false)); + } +} diff --git a/CoqOfRust/alloy_primitives/signature/parity.v b/CoqOfRust/alloy_primitives/signature/parity.v new file mode 100644 index 000000000..e715243b7 --- /dev/null +++ b/CoqOfRust/alloy_primitives/signature/parity.v @@ -0,0 +1,1731 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module signature. + Module parity. + (* + Enum Parity + { + const_params := []; + ty_params := []; + variants := + [ + { + name := "Eip155"; + item := StructTuple [ Ty.path "u64" ]; + }; + { + name := "NonEip155"; + item := StructTuple [ Ty.path "bool" ]; + }; + { + name := "Parity"; + item := StructTuple [ Ty.path "bool" ]; + } + ]; + } + *) + + Axiom IsDiscriminant_Parity_Eip155 : + M.IsDiscriminant "alloy_primitives::signature::parity::Parity::Eip155" 0. + Axiom IsDiscriminant_Parity_NonEip155 : + M.IsDiscriminant "alloy_primitives::signature::parity::Parity::NonEip155" 1. + Axiom IsDiscriminant_Parity_Parity : + M.IsDiscriminant "alloy_primitives::signature::parity::Parity::Parity" 2. + + Module Impl_core_clone_Clone_for_alloy_primitives_signature_parity_Parity. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::parity::Parity". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ + fun γ => + ltac:(M.monadic + (M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.deref (| M.read (| self |) |))) ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_alloy_primitives_signature_parity_Parity. + + Module Impl_core_marker_Copy_for_alloy_primitives_signature_parity_Parity. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::parity::Parity". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_alloy_primitives_signature_parity_Parity. + + Module Impl_core_fmt_Debug_for_alloy_primitives_signature_parity_Parity. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::parity::Parity". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ]), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::parity::Parity::Eip155", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Eip155" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::parity::Parity::NonEip155", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "NonEip155" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::parity::Parity::Parity", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Parity" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_alloy_primitives_signature_parity_Parity. + + Module Impl_core_hash_Hash_for_alloy_primitives_signature_parity_Parity. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::parity::Parity". + + (* Hash *) + Definition hash (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ __H ], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ __self_discr : Ty.path "isize" := + M.alloc (| + M.call_closure (| + Ty.path "isize", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "alloy_primitives::signature::parity::Parity" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.path "isize", + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_discr |) |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) in + M.match_operator (| + Some (Ty.tuple []), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::parity::Parity::Eip155", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.path "u64", + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_0 |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::parity::Parity::NonEip155", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.path "bool", + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_0 |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::parity::Parity::Parity", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.path "bool", + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_0 |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::hash::Hash" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("hash", InstanceField.Method hash) ]. + End Impl_core_hash_Hash_for_alloy_primitives_signature_parity_Parity. + + Module Impl_core_marker_StructuralPartialEq_for_alloy_primitives_signature_parity_Parity. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::parity::Parity". + + Axiom Implements : + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_alloy_primitives_signature_parity_Parity. + + Module Impl_core_cmp_PartialEq_alloy_primitives_signature_parity_Parity_for_alloy_primitives_signature_parity_Parity. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::parity::Parity". + + (* PartialEq *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.read (| + let~ __self_discr : Ty.path "isize" := + M.alloc (| + M.call_closure (| + Ty.path "isize", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "alloy_primitives::signature::parity::Parity" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ __arg1_discr : Ty.path "isize" := + M.alloc (| + M.call_closure (| + Ty.path "isize", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "alloy_primitives::signature::parity::Parity" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) ] + |) + |) in + M.alloc (| + LogicalOp.and (| + BinOp.eq (| M.read (| __self_discr |), M.read (| __arg1_discr |) |), + ltac:(M.monadic + (M.read (| + M.match_operator (| + Some (Ty.path "bool"), + M.alloc (| Value.Tuple [ M.read (| self |); M.read (| other |) ] |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_0 := M.read (| γ0_0 |) in + let γ2_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_0, + "alloy_primitives::signature::parity::Parity::Eip155", + 0 + |) in + let __self_0 := M.alloc (| γ2_0 |) in + let γ0_1 := M.read (| γ0_1 |) in + let γ2_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_1, + "alloy_primitives::signature::parity::Parity::Eip155", + 0 + |) in + let __arg1_0 := M.alloc (| γ2_0 |) in + M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "&") [] [ Ty.path "u64" ], + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "u64" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, __self_0 |); + M.borrow (| Pointer.Kind.Ref, __arg1_0 |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_0 := M.read (| γ0_0 |) in + let γ2_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_0, + "alloy_primitives::signature::parity::Parity::NonEip155", + 0 + |) in + let __self_0 := M.alloc (| γ2_0 |) in + let γ0_1 := M.read (| γ0_1 |) in + let γ2_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_1, + "alloy_primitives::signature::parity::Parity::NonEip155", + 0 + |) in + let __arg1_0 := M.alloc (| γ2_0 |) in + M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "&") [] [ Ty.path "bool" ], + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "bool" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, __self_0 |); + M.borrow (| Pointer.Kind.Ref, __arg1_0 |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_0 := M.read (| γ0_0 |) in + let γ2_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_0, + "alloy_primitives::signature::parity::Parity::Parity", + 0 + |) in + let __self_0 := M.alloc (| γ2_0 |) in + let γ0_1 := M.read (| γ0_1 |) in + let γ2_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_1, + "alloy_primitives::signature::parity::Parity::Parity", + 0 + |) in + let __arg1_0 := M.alloc (| γ2_0 |) in + M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "&") [] [ Ty.path "bool" ], + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "bool" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, __self_0 |); + M.borrow (| Pointer.Kind.Ref, __arg1_0 |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::intrinsics::unreachable", [], [] |), + [] + |) + |) + |))) + ] + |) + |))) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::signature::parity::Parity" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_signature_parity_Parity_for_alloy_primitives_signature_parity_Parity. + + Module Impl_core_cmp_Eq_for_alloy_primitives_signature_parity_Parity. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::parity::Parity". + + (* Eq *) + Definition assert_receiver_is_total_eq + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ + fun γ => + ltac:(M.monadic + (M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method assert_receiver_is_total_eq) ]. + End Impl_core_cmp_Eq_for_alloy_primitives_signature_parity_Parity. + + Module Impl_core_default_Default_for_alloy_primitives_signature_parity_Parity. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::parity::Parity". + + (* + fn default() -> Self { + Self::Parity(false) + } + *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::signature::parity::Parity::Parity" + [ Value.Bool false ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_alloy_primitives_signature_parity_Parity. + + Module Impl_core_convert_TryFrom_ruint_Uint_Usize_64_Usize_1_for_alloy_primitives_signature_parity_Parity. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::parity::Parity". + + (* type Error = >::Error; *) + Definition _Error : Ty.t := + Ty.associated_in_trait + "core::convert::TryFrom" + [] + [ Ty.path "u64" ] + (Ty.path "alloy_primitives::signature::parity::Parity") + "Error". + + (* + fn try_from(value: U64) -> Result { + value.as_limbs()[0].try_into() + } + *) + Definition try_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::signature::parity::Parity"; + Ty.path "alloy_primitives::signature::error::SignatureError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.path "u64", + [], + [ Ty.path "alloy_primitives::signature::parity::Parity" ], + "try_into", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 1 ] + [ Ty.path "u64" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 64; Value.Integer IntegerKind.Usize 1 + ] + [], + "as_limbs", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + |), + Value.Integer IntegerKind.Usize 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 64; Value.Integer IntegerKind.Usize 1 ] + [] + ] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("try_from", InstanceField.Method try_from) ]. + End Impl_core_convert_TryFrom_ruint_Uint_Usize_64_Usize_1_for_alloy_primitives_signature_parity_Parity. + + Module Impl_core_convert_From_ruint_Uint_Usize_1_Usize_1_for_alloy_primitives_signature_parity_Parity. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::parity::Parity". + + (* + fn from(value: Uint<1, 1>) -> Self { + Self::Parity(!value.is_zero()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::signature::parity::Parity::Parity" + [ + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 1; Value.Integer IntegerKind.Usize 1 ] + [], + "is_zero", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 1; Value.Integer IntegerKind.Usize 1 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ruint_Uint_Usize_1_Usize_1_for_alloy_primitives_signature_parity_Parity. + + Module Impl_core_convert_From_bool_for_alloy_primitives_signature_parity_Parity. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::parity::Parity". + + (* + fn from(value: bool) -> Self { + Self::Parity(value) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::signature::parity::Parity::Parity" + [ M.read (| value |) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "bool" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_bool_for_alloy_primitives_signature_parity_Parity. + + Module Impl_core_convert_TryFrom_u64_for_alloy_primitives_signature_parity_Parity. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::parity::Parity". + + (* type Error = SignatureError; *) + Definition _Error : Ty.t := Ty.path "alloy_primitives::signature::error::SignatureError". + + (* + fn try_from(value: u64) -> Result { + match value { + 0 | 1 => Ok(Self::Parity(value != 0)), + 27 | 28 => Ok(Self::NonEip155((value - 27) != 0)), + value @ 35..=u64::MAX => Ok(Self::Eip155(value)), + _ => Err(SignatureError::InvalidParity(value)), + } + } + *) + Definition try_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::signature::parity::Parity"; + Ty.path "alloy_primitives::signature::error::SignatureError" + ]), + value, + [ + fun γ => + ltac:(M.monadic + (M.find_or_pattern (| + γ, + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.U64 0 + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.U64 1 + |) in + Value.Tuple [])) + ], + fun γ => + ltac:(M.monadic + match γ with + | [] => + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.StructTuple + "alloy_primitives::signature::parity::Parity::Parity" + [ + BinOp.ne (| + M.read (| value |), + Value.Integer IntegerKind.U64 0 + |) + ] + ] + |))) + | _ => M.impossible "wrong number of arguments" + end) + |))); + fun γ => + ltac:(M.monadic + (M.find_or_pattern (| + γ, + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.U64 27 + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.U64 28 + |) in + Value.Tuple [])) + ], + fun γ => + ltac:(M.monadic + match γ with + | [] => + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.StructTuple + "alloy_primitives::signature::parity::Parity::NonEip155" + [ + BinOp.ne (| + BinOp.Wrap.sub (| + M.read (| value |), + Value.Integer IntegerKind.U64 27 + |), + Value.Integer IntegerKind.U64 0 + |) + ] + ] + |))) + | _ => M.impossible "wrong number of arguments" + end) + |))); + fun γ => + ltac:(M.monadic + (let value := M.copy (| γ |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.StructTuple + "alloy_primitives::signature::parity::Parity::Eip155" + [ M.read (| value |) ] + ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "alloy_primitives::signature::error::SignatureError::InvalidParity" + [ M.read (| value |) ] + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u64" ] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("try_from", InstanceField.Method try_from) ]. + End Impl_core_convert_TryFrom_u64_for_alloy_primitives_signature_parity_Parity. + + Module Impl_alloy_primitives_signature_parity_Parity. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::parity::Parity". + + (* + pub const fn chain_id(&self) -> Option { + match *self { + Self::Eip155(mut v @ 35..) => { + if v % 2 == 0 { + v -= 1; + } + v -= 35; + Some(v / 2) + } + _ => None, + } + } + *) + Definition chain_id (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some (Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "u64" ]), + M.deref (| M.read (| self |) |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::parity::Parity::Eip155", + 0 + |) in + let v := M.copy (| γ0_0 |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.eq (| + BinOp.Wrap.rem (| + M.read (| v |), + Value.Integer IntegerKind.U64 2 + |), + Value.Integer IntegerKind.U64 0 + |) + |)) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + let β := v in + M.write (| + β, + BinOp.Wrap.sub (| + M.read (| β |), + Value.Integer IntegerKind.U64 1 + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + let β := v in + M.write (| + β, + BinOp.Wrap.sub (| M.read (| β |), Value.Integer IntegerKind.U64 35 |) + |) + |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ BinOp.Wrap.div (| M.read (| v |), Value.Integer IntegerKind.U64 2 |) ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.StructTuple "core::option::Option::None" [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_chain_id : + M.IsAssociatedFunction.Trait Self "chain_id" chain_id. + Admitted. + Global Typeclasses Opaque chain_id. + + (* + pub const fn has_eip155_value(&self) -> bool { + self.chain_id().is_some() + } + *) + Definition has_eip155_value (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "u64" ], + "is_some", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "u64" ], + M.get_associated_function (| + Ty.path "alloy_primitives::signature::parity::Parity", + "chain_id", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_has_eip155_value : + M.IsAssociatedFunction.Trait Self "has_eip155_value" has_eip155_value. + Admitted. + Global Typeclasses Opaque has_eip155_value. + + (* + pub const fn y_parity(&self) -> bool { + match self { + Self::Eip155(v @ 0..=34) => *v % 2 == 1, + Self::Eip155(v) => ( *v ^ 1) % 2 == 1, + Self::NonEip155(b) | Self::Parity(b) => *b, + } + } + *) + Definition y_parity (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some (Ty.path "bool"), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::parity::Parity::Eip155", + 0 + |) in + let v := M.alloc (| γ1_0 |) in + M.alloc (| + BinOp.eq (| + BinOp.Wrap.rem (| + M.read (| M.deref (| M.read (| v |) |) |), + Value.Integer IntegerKind.U64 2 + |), + Value.Integer IntegerKind.U64 1 + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::parity::Parity::Eip155", + 0 + |) in + let v := M.alloc (| γ1_0 |) in + M.alloc (| + BinOp.eq (| + BinOp.Wrap.rem (| + BinOp.bit_xor + (M.read (| M.deref (| M.read (| v |) |) |)) + (Value.Integer IntegerKind.U64 1), + Value.Integer IntegerKind.U64 2 + |), + Value.Integer IntegerKind.U64 1 + |) + |))); + fun γ => + ltac:(M.monadic + (M.find_or_pattern (| + γ, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::parity::Parity::NonEip155", + 0 + |) in + let b := M.alloc (| γ1_0 |) in + Value.Tuple [ b ])); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::parity::Parity::Parity", + 0 + |) in + let b := M.alloc (| γ1_0 |) in + Value.Tuple [ b ])) + ], + fun γ => + ltac:(M.monadic + match γ with + | [ b ] => ltac:(M.monadic (M.deref (| M.read (| b |) |))) + | _ => M.impossible "wrong number of arguments" + end) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_y_parity : + M.IsAssociatedFunction.Trait Self "y_parity" y_parity. + Admitted. + Global Typeclasses Opaque y_parity. + + (* + pub const fn y_parity_byte(&self) -> u8 { + self.y_parity() as u8 + } + *) + Definition y_parity_byte (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.cast + (Ty.path "u8") + (M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "alloy_primitives::signature::parity::Parity", + "y_parity", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |)))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_y_parity_byte : + M.IsAssociatedFunction.Trait Self "y_parity_byte" y_parity_byte. + Admitted. + Global Typeclasses Opaque y_parity_byte. + + (* + pub const fn y_parity_byte_non_eip155(&self) -> Option { + match self { + Self::NonEip155(v) | Self::Parity(v) => Some( *v as u8 + 27), + _ => None, + } + } + *) + Definition y_parity_byte_non_eip155 + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some (Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "u8" ]), + self, + [ + fun γ => + ltac:(M.monadic + (M.find_or_pattern (| + γ, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::parity::Parity::NonEip155", + 0 + |) in + let v := M.alloc (| γ1_0 |) in + Value.Tuple [ v ])); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::parity::Parity::Parity", + 0 + |) in + let v := M.alloc (| γ1_0 |) in + Value.Tuple [ v ])) + ], + fun γ => + ltac:(M.monadic + match γ with + | [ v ] => + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + BinOp.Wrap.add (| + M.cast + (Ty.path "u8") + (M.read (| M.deref (| M.read (| v |) |) |)), + Value.Integer IntegerKind.U8 27 + |) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.StructTuple "core::option::Option::None" [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_y_parity_byte_non_eip155 : + M.IsAssociatedFunction.Trait Self "y_parity_byte_non_eip155" y_parity_byte_non_eip155. + Admitted. + Global Typeclasses Opaque y_parity_byte_non_eip155. + + (* + pub const fn to_u64(&self) -> u64 { + match self { + Self::Eip155(v) => *v, + Self::NonEip155(b) => *b as u64 + 27, + Self::Parity(b) => *b as u64, + } + } + *) + Definition to_u64 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some (Ty.path "u64"), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::parity::Parity::Eip155", + 0 + |) in + let v := M.alloc (| γ1_0 |) in + M.deref (| M.read (| v |) |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::parity::Parity::NonEip155", + 0 + |) in + let b := M.alloc (| γ1_0 |) in + M.alloc (| + BinOp.Wrap.add (| + M.cast (Ty.path "u64") (M.read (| M.deref (| M.read (| b |) |) |)), + Value.Integer IntegerKind.U64 27 + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::parity::Parity::Parity", + 0 + |) in + let b := M.alloc (| γ1_0 |) in + M.alloc (| + M.cast (Ty.path "u64") (M.read (| M.deref (| M.read (| b |) |) |)) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_to_u64 : M.IsAssociatedFunction.Trait Self "to_u64" to_u64. + Admitted. + Global Typeclasses Opaque to_u64. + + (* + pub const fn inverted(&self) -> Self { + match *self { + Self::Parity(b) => Self::Parity(!b), + Self::NonEip155(b) => Self::NonEip155(!b), + Self::Eip155(0) => Self::Eip155(1), + Self::Eip155(v @ 1..=34) => Self::Eip155(if v % 2 == 0 { v - 1 } else { v + 1 }), + Self::Eip155(v @ 35..) => Self::Eip155(v ^ 1), + } + } + *) + Definition inverted (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some (Ty.path "alloy_primitives::signature::parity::Parity"), + M.deref (| M.read (| self |) |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::parity::Parity::Parity", + 0 + |) in + let b := M.copy (| γ0_0 |) in + M.alloc (| + Value.StructTuple + "alloy_primitives::signature::parity::Parity::Parity" + [ UnOp.not (| M.read (| b |) |) ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::parity::Parity::NonEip155", + 0 + |) in + let b := M.copy (| γ0_0 |) in + M.alloc (| + Value.StructTuple + "alloy_primitives::signature::parity::Parity::NonEip155" + [ UnOp.not (| M.read (| b |) |) ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::parity::Parity::Eip155", + 0 + |) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.U64 0 + |) in + M.alloc (| + Value.StructTuple + "alloy_primitives::signature::parity::Parity::Eip155" + [ Value.Integer IntegerKind.U64 1 ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::parity::Parity::Eip155", + 0 + |) in + let v := M.copy (| γ0_0 |) in + M.alloc (| + Value.StructTuple + "alloy_primitives::signature::parity::Parity::Eip155" + [ + M.read (| + M.match_operator (| + Some (Ty.path "u64"), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.eq (| + BinOp.Wrap.rem (| + M.read (| v |), + Value.Integer IntegerKind.U64 2 + |), + Value.Integer IntegerKind.U64 0 + |) + |)) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + BinOp.Wrap.sub (| + M.read (| v |), + Value.Integer IntegerKind.U64 1 + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + BinOp.Wrap.add (| + M.read (| v |), + Value.Integer IntegerKind.U64 1 + |) + |))) + ] + |) + |) + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::parity::Parity::Eip155", + 0 + |) in + let v := M.copy (| γ0_0 |) in + M.alloc (| + Value.StructTuple + "alloy_primitives::signature::parity::Parity::Eip155" + [ BinOp.bit_xor (M.read (| v |)) (Value.Integer IntegerKind.U64 1) ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_inverted : + M.IsAssociatedFunction.Trait Self "inverted" inverted. + Admitted. + Global Typeclasses Opaque inverted. + + (* + pub const fn strip_chain_id(&self) -> Self { + match *self { + Self::Eip155(v) => Self::NonEip155(v % 2 == 1), + this => this, + } + } + *) + Definition strip_chain_id (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some (Ty.path "alloy_primitives::signature::parity::Parity"), + M.deref (| M.read (| self |) |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::parity::Parity::Eip155", + 0 + |) in + let v := M.copy (| γ0_0 |) in + M.alloc (| + Value.StructTuple + "alloy_primitives::signature::parity::Parity::NonEip155" + [ + BinOp.eq (| + BinOp.Wrap.rem (| M.read (| v |), Value.Integer IntegerKind.U64 2 |), + Value.Integer IntegerKind.U64 1 + |) + ] + |))); + fun γ => + ltac:(M.monadic + (let this := M.copy (| γ |) in + this)) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_strip_chain_id : + M.IsAssociatedFunction.Trait Self "strip_chain_id" strip_chain_id. + Admitted. + Global Typeclasses Opaque strip_chain_id. + + (* + pub const fn with_chain_id(self, chain_id: ChainId) -> Self { + let parity = match self { + Self::Eip155(v) => normalize_v_to_byte(v) == 1, + Self::NonEip155(b) | Self::Parity(b) => b, + }; + + Self::Eip155(to_eip155_v(parity as u8, chain_id)) + } + *) + Definition with_chain_id (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; chain_id ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let chain_id := M.alloc (| chain_id |) in + M.read (| + let~ parity : Ty.path "bool" := + M.copy (| + M.match_operator (| + Some (Ty.path "bool"), + self, + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::parity::Parity::Eip155", + 0 + |) in + let v := M.copy (| γ0_0 |) in + M.alloc (| + BinOp.eq (| + M.call_closure (| + Ty.path "u8", + M.get_function (| + "alloy_primitives::signature::utils::normalize_v_to_byte", + [], + [] + |), + [ M.read (| v |) ] + |), + Value.Integer IntegerKind.U8 1 + |) + |))); + fun γ => + ltac:(M.monadic + (M.find_or_pattern (| + γ, + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::parity::Parity::NonEip155", + 0 + |) in + let b := M.copy (| γ0_0 |) in + Value.Tuple [ b ])); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signature::parity::Parity::Parity", + 0 + |) in + let b := M.copy (| γ0_0 |) in + Value.Tuple [ b ])) + ], + fun γ => + ltac:(M.monadic + match γ with + | [ b ] => ltac:(M.monadic b) + | _ => M.impossible "wrong number of arguments" + end) + |))) + ] + |) + |) in + M.alloc (| + Value.StructTuple + "alloy_primitives::signature::parity::Parity::Eip155" + [ + M.call_closure (| + Ty.path "u64", + M.get_function (| + "alloy_primitives::signature::utils::to_eip155_v", + [], + [] + |), + [ M.cast (Ty.path "u8") (M.read (| parity |)); M.read (| chain_id |) ] + |) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_with_chain_id : + M.IsAssociatedFunction.Trait Self "with_chain_id" with_chain_id. + Admitted. + Global Typeclasses Opaque with_chain_id. + + (* + pub const fn to_parity_bool(self) -> Self { + Self::Parity(self.y_parity()) + } + *) + Definition to_parity_bool (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple + "alloy_primitives::signature::parity::Parity::Parity" + [ + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "alloy_primitives::signature::parity::Parity", + "y_parity", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, self |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_to_parity_bool : + M.IsAssociatedFunction.Trait Self "to_parity_bool" to_parity_bool. + Admitted. + Global Typeclasses Opaque to_parity_bool. + End Impl_alloy_primitives_signature_parity_Parity. + End parity. +End signature. diff --git a/CoqOfRust/alloy_primitives/signature/primitive_sig.rs b/CoqOfRust/alloy_primitives/signature/primitive_sig.rs new file mode 100644 index 000000000..1193ab86d --- /dev/null +++ b/CoqOfRust/alloy_primitives/signature/primitive_sig.rs @@ -0,0 +1,584 @@ +#![allow(unknown_lints, unnameable_types)] + +use crate::{hex, normalize_v, signature::SignatureError, uint, U256}; +use alloc::vec::Vec; +use core::str::FromStr; + +/// The order of the secp256k1 curve +const SECP256K1N_ORDER: U256 = + uint!(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141_U256); + +/// An Ethereum ECDSA signature. +#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)] +pub struct PrimitiveSignature { + y_parity: bool, + r: U256, + s: U256, +} + +impl<'a> TryFrom<&'a [u8]> for PrimitiveSignature { + type Error = SignatureError; + + /// Parses a raw signature which is expected to be 65 bytes long where + /// the first 32 bytes is the `r` value, the second 32 bytes the `s` value + /// and the final byte is the `v` value in 'Electrum' notation. + fn try_from(bytes: &'a [u8]) -> Result { + if bytes.len() != 65 { + return Err(SignatureError::FromBytes("expected exactly 65 bytes")); + } + let parity = + normalize_v(bytes[64] as u64).ok_or(SignatureError::InvalidParity(bytes[64] as u64))?; + Ok(Self::from_bytes_and_parity(&bytes[..64], parity)) + } +} + +impl FromStr for PrimitiveSignature { + type Err = SignatureError; + + fn from_str(s: &str) -> Result { + let bytes = hex::decode(s)?; + Self::try_from(&bytes[..]) + } +} + +impl From<&PrimitiveSignature> for [u8; 65] { + #[inline] + fn from(value: &PrimitiveSignature) -> [u8; 65] { + value.as_bytes() + } +} + +impl From for [u8; 65] { + #[inline] + fn from(value: PrimitiveSignature) -> [u8; 65] { + value.as_bytes() + } +} + +impl From<&PrimitiveSignature> for Vec { + #[inline] + fn from(value: &PrimitiveSignature) -> Self { + value.as_bytes().to_vec() + } +} + +impl From for Vec { + #[inline] + fn from(value: PrimitiveSignature) -> Self { + value.as_bytes().to_vec() + } +} + +#[cfg(feature = "k256")] +impl From<(k256::ecdsa::Signature, k256::ecdsa::RecoveryId)> for PrimitiveSignature { + fn from(value: (k256::ecdsa::Signature, k256::ecdsa::RecoveryId)) -> Self { + Self::from_signature_and_parity(value.0, value.1.is_y_odd()) + } +} + +#[cfg(feature = "k256")] +impl TryFrom for k256::ecdsa::Signature { + type Error = k256::ecdsa::Error; + + fn try_from(value: PrimitiveSignature) -> Result { + value.to_k256() + } +} + +#[cfg(feature = "rlp")] +impl PrimitiveSignature { + /// Decode an RLP-encoded VRS signature. Accepts `decode_parity` closure which allows to + /// customize parity decoding and possibly extract additional data from it (e.g chain_id for + /// legacy signature). + pub fn decode_rlp_vrs( + buf: &mut &[u8], + decode_parity: impl FnOnce(&mut &[u8]) -> alloy_rlp::Result, + ) -> Result { + use alloy_rlp::Decodable; + + let parity = decode_parity(buf)?; + let r = Decodable::decode(buf)?; + let s = Decodable::decode(buf)?; + + Ok(Self::new(r, s, parity)) + } +} + +impl PrimitiveSignature { + #[doc(hidden)] + pub fn test_signature() -> Self { + Self::from_scalars_and_parity( + b256!("840cfc572845f5786e702984c2a582528cad4b49b2a10b9db1be7fca90058565"), + b256!("25e7109ceb98168d95b09b18bbf6b685130e0562f233877d492b94eee0c5b6d1"), + false, + ) + } + + /// Instantiate a new signature from `r`, `s`, and `v` values. + #[allow(clippy::missing_const_for_fn)] + pub fn new(r: U256, s: U256, v: bool) -> Self { + Self { r, s, y_parity: v } + } + + /// Returns the inner ECDSA signature. + #[cfg(feature = "k256")] + #[deprecated(note = "use `Signature::to_k256` instead")] + #[inline] + pub fn into_inner(self) -> k256::ecdsa::Signature { + self.try_into().expect("signature conversion failed") + } + + /// Returns the inner ECDSA signature. + #[cfg(feature = "k256")] + #[inline] + pub fn to_k256(self) -> Result { + k256::ecdsa::Signature::from_scalars(self.r.to_be_bytes(), self.s.to_be_bytes()) + } + + /// Instantiate from a signature and recovery id + #[cfg(feature = "k256")] + pub fn from_signature_and_parity(sig: k256::ecdsa::Signature, v: bool) -> Self { + let r = U256::from_be_slice(sig.r().to_bytes().as_ref()); + let s = U256::from_be_slice(sig.s().to_bytes().as_ref()); + Self { y_parity: v, r, s } + } + + /// Creates a [`PrimitiveSignature`] from the serialized `r` and `s` scalar values, which + /// comprise the ECDSA signature, alongside a `v` value, used to determine the recovery ID. + #[inline] + pub fn from_scalars_and_parity(r: crate::B256, s: crate::B256, parity: bool) -> Self { + Self::new(U256::from_be_slice(r.as_ref()), U256::from_be_slice(s.as_ref()), parity) + } + + /// Normalizes the signature into "low S" form as described in + /// [BIP 0062: Dealing with Malleability][1]. + /// + /// [1]: https://github.com/bitcoin/bips/blob/master/bip-0062.mediawiki + #[inline] + pub fn normalize_s(&self) -> Option { + let s = self.s(); + + if s > SECP256K1N_ORDER >> 1 { + Some(Self { y_parity: !self.y_parity, r: self.r, s: SECP256K1N_ORDER - s }) + } else { + None + } + } + + /// Returns the recovery ID. + #[cfg(feature = "k256")] + #[inline] + pub const fn recid(&self) -> k256::ecdsa::RecoveryId { + k256::ecdsa::RecoveryId::new(self.y_parity, false) + } + + #[cfg(feature = "k256")] + #[doc(hidden)] + #[deprecated(note = "use `Signature::recid` instead")] + pub const fn recovery_id(&self) -> k256::ecdsa::RecoveryId { + self.recid() + } + + /// Recovers an [`Address`] from this signature and the given message by first prefixing and + /// hashing the message according to [EIP-191](crate::eip191_hash_message). + /// + /// [`Address`]: crate::Address + #[cfg(feature = "k256")] + #[inline] + pub fn recover_address_from_msg>( + &self, + msg: T, + ) -> Result { + self.recover_from_msg(msg).map(|vk| crate::Address::from_public_key(&vk)) + } + + /// Recovers an [`Address`] from this signature and the given prehashed message. + /// + /// [`Address`]: crate::Address + #[cfg(feature = "k256")] + #[inline] + pub fn recover_address_from_prehash( + &self, + prehash: &crate::B256, + ) -> Result { + self.recover_from_prehash(prehash).map(|vk| crate::Address::from_public_key(&vk)) + } + + /// Recovers a [`VerifyingKey`] from this signature and the given message by first prefixing and + /// hashing the message according to [EIP-191](crate::eip191_hash_message). + /// + /// [`VerifyingKey`]: k256::ecdsa::VerifyingKey + #[cfg(feature = "k256")] + #[inline] + pub fn recover_from_msg>( + &self, + msg: T, + ) -> Result { + self.recover_from_prehash(&crate::eip191_hash_message(msg)) + } + + /// Recovers a [`VerifyingKey`] from this signature and the given prehashed message. + /// + /// [`VerifyingKey`]: k256::ecdsa::VerifyingKey + #[cfg(feature = "k256")] + #[inline] + pub fn recover_from_prehash( + &self, + prehash: &crate::B256, + ) -> Result { + let this = self.normalize_s().unwrap_or(*self); + k256::ecdsa::VerifyingKey::recover_from_prehash( + prehash.as_slice(), + &this.to_k256()?, + this.recid(), + ) + .map_err(Into::into) + } + + /// Parses a signature from a byte slice, with a v value + /// + /// # Panics + /// + /// If the slice is not at least 64 bytes long. + #[inline] + pub fn from_bytes_and_parity(bytes: &[u8], parity: bool) -> Self { + let r = U256::from_be_slice(&bytes[..32]); + let s = U256::from_be_slice(&bytes[32..64]); + Self::new(r, s, parity) + } + + /// Returns the `r` component of this signature. + #[inline] + pub const fn r(&self) -> U256 { + self.r + } + + /// Returns the `s` component of this signature. + #[inline] + pub const fn s(&self) -> U256 { + self.s + } + + /// Returns the recovery ID as a `bool`. + #[inline] + pub const fn v(&self) -> bool { + self.y_parity + } + + /// Returns the byte-array representation of this signature. + /// + /// The first 32 bytes are the `r` value, the second 32 bytes the `s` value + /// and the final byte is the `v` value in 'Electrum' notation. + #[inline] + pub fn as_bytes(&self) -> [u8; 65] { + let mut sig = [0u8; 65]; + sig[..32].copy_from_slice(&self.r.to_be_bytes::<32>()); + sig[32..64].copy_from_slice(&self.s.to_be_bytes::<32>()); + sig[64] = 27 + self.y_parity as u8; + sig + } + + /// Sets the recovery ID by normalizing a `v` value. + #[inline] + pub const fn with_parity(self, v: bool) -> Self { + Self { y_parity: v, r: self.r, s: self.s } + } + + /// Length of RLP RS field encoding + #[cfg(feature = "rlp")] + pub fn rlp_rs_len(&self) -> usize { + alloy_rlp::Encodable::length(&self.r) + alloy_rlp::Encodable::length(&self.s) + } + + /// Write R and S to an RLP buffer in progress. + #[cfg(feature = "rlp")] + pub fn write_rlp_rs(&self, out: &mut dyn alloy_rlp::BufMut) { + alloy_rlp::Encodable::encode(&self.r, out); + alloy_rlp::Encodable::encode(&self.s, out); + } + + /// Write the VRS to the output. + #[cfg(feature = "rlp")] + pub fn write_rlp_vrs(&self, out: &mut dyn alloy_rlp::BufMut, v: impl alloy_rlp::Encodable) { + v.encode(out); + self.write_rlp_rs(out); + } +} + +#[cfg(feature = "arbitrary")] +impl<'a> arbitrary::Arbitrary<'a> for PrimitiveSignature { + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + Ok(Self::new(u.arbitrary()?, u.arbitrary()?, u.arbitrary()?)) + } +} + +#[cfg(feature = "arbitrary")] +impl proptest::arbitrary::Arbitrary for PrimitiveSignature { + type Parameters = (); + type Strategy = proptest::strategy::Map< + <(U256, U256, bool) as proptest::arbitrary::Arbitrary>::Strategy, + fn((U256, U256, bool)) -> Self, + >; + + fn arbitrary_with((): Self::Parameters) -> Self::Strategy { + use proptest::strategy::Strategy; + proptest::arbitrary::any::<(U256, U256, bool)>() + .prop_map(|(r, s, parity)| Self::new(r, s, parity)) + } +} + +#[cfg(feature = "serde")] +mod signature_serde { + use serde::{Deserialize, Deserializer, Serialize}; + + use crate::{U256, U64}; + + use super::PrimitiveSignature; + + #[derive(Serialize, Deserialize)] + struct HumanReadableRepr { + r: U256, + s: U256, + #[serde(rename = "yParity")] + y_parity: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + v: Option, + } + + #[derive(Serialize, Deserialize)] + #[serde(transparent)] + struct NonHumanReadableRepr((U256, U256, U64)); + + impl Serialize for PrimitiveSignature { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + // if the serializer is human readable, serialize as a map, otherwise as a tuple + if serializer.is_human_readable() { + HumanReadableRepr { + y_parity: Some(U64::from(self.y_parity as u64)), + v: Some(U64::from(self.y_parity as u64)), + r: self.r, + s: self.s, + } + .serialize(serializer) + } else { + NonHumanReadableRepr((self.r, self.s, U64::from(self.y_parity as u64))) + .serialize(serializer) + } + } + } + + impl<'de> Deserialize<'de> for PrimitiveSignature { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let (y_parity, r, s) = if deserializer.is_human_readable() { + let HumanReadableRepr { y_parity, v, r, s } = <_>::deserialize(deserializer)?; + let y_parity = y_parity + .or(v) + .ok_or_else(|| serde::de::Error::custom("missing `yParity` or `v`"))?; + (y_parity, r, s) + } else { + let NonHumanReadableRepr((r, s, y_parity)) = <_>::deserialize(deserializer)?; + (y_parity, r, s) + }; + + if y_parity > U64::from(1) { + Err(serde::de::Error::custom("invalid y_parity")) + } else { + Ok(Self::new(r, s, y_parity == U64::from(1))) + } + } + } +} + +#[cfg(test)] +#[allow(unused_imports)] +mod tests { + use super::*; + use crate::Bytes; + use core::str::FromStr; + use hex::FromHex; + + #[cfg(feature = "rlp")] + use alloy_rlp::{Decodable, Encodable}; + + #[test] + #[cfg(feature = "k256")] + fn can_recover_tx_sender_not_normalized() { + let sig = PrimitiveSignature::from_str("48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c8041b").unwrap(); + let hash = b256!("5eb4f5a33c621f32a8622d5f943b6b102994dfe4e5aebbefe69bb1b2aa0fc93e"); + let expected = address!("0f65fe9276bc9a24ae7083ae28e2660ef72df99e"); + assert_eq!(sig.recover_address_from_prehash(&hash).unwrap(), expected); + } + + #[test] + #[cfg(feature = "k256")] + fn recover_web3_signature() { + // test vector taken from: + // https://web3js.readthedocs.io/en/v1.2.2/web3-eth-accounts.html#sign + let sig = PrimitiveSignature::from_str( + "b91467e570a6466aa9e9876cbcd013baba02900b8979d43fe208a4a4f339f5fd6007e74cd82e037b800186422fc2da167c747ef045e5d18a5f5d4300f8e1a0291c" + ).expect("could not parse signature"); + let expected = address!("2c7536E3605D9C16a7a3D7b1898e529396a65c23"); + assert_eq!(sig.recover_address_from_msg("Some data").unwrap(), expected); + } + + #[test] + fn signature_from_str() { + let s1 = PrimitiveSignature::from_str( + "0xaa231fbe0ed2b5418e6ba7c19bee2522852955ec50996c02a2fe3e71d30ddaf1645baf4823fea7cb4fcc7150842493847cfb6a6d63ab93e8ee928ee3f61f503500" + ).expect("could not parse 0x-prefixed signature"); + + let s2 = PrimitiveSignature::from_str( + "aa231fbe0ed2b5418e6ba7c19bee2522852955ec50996c02a2fe3e71d30ddaf1645baf4823fea7cb4fcc7150842493847cfb6a6d63ab93e8ee928ee3f61f503500" + ).expect("could not parse non-prefixed signature"); + + assert_eq!(s1, s2); + } + + #[cfg(feature = "serde")] + #[test] + fn deserialize_with_parity() { + let raw_signature_with_y_parity = serde_json::json!({ + "r": "0xc569c92f176a3be1a6352dd5005bfc751dcb32f57623dd2a23693e64bf4447b0", + "s": "0x1a891b566d369e79b7a66eecab1e008831e22daa15f91a0a0cf4f9f28f47ee05", + "v": "0x1", + "yParity": "0x1" + }); + + let signature: PrimitiveSignature = + serde_json::from_value(raw_signature_with_y_parity).unwrap(); + + let expected = PrimitiveSignature::new( + U256::from_str("0xc569c92f176a3be1a6352dd5005bfc751dcb32f57623dd2a23693e64bf4447b0") + .unwrap(), + U256::from_str("0x1a891b566d369e79b7a66eecab1e008831e22daa15f91a0a0cf4f9f28f47ee05") + .unwrap(), + true, + ); + + assert_eq!(signature, expected); + } + + #[cfg(feature = "serde")] + #[test] + fn serialize_both_parity() { + // this test should be removed if the struct moves to an enum based on tx type + let signature = PrimitiveSignature::new( + U256::from_str("0xc569c92f176a3be1a6352dd5005bfc751dcb32f57623dd2a23693e64bf4447b0") + .unwrap(), + U256::from_str("0x1a891b566d369e79b7a66eecab1e008831e22daa15f91a0a0cf4f9f28f47ee05") + .unwrap(), + true, + ); + + let serialized = serde_json::to_string(&signature).unwrap(); + assert_eq!( + serialized, + r#"{"r":"0xc569c92f176a3be1a6352dd5005bfc751dcb32f57623dd2a23693e64bf4447b0","s":"0x1a891b566d369e79b7a66eecab1e008831e22daa15f91a0a0cf4f9f28f47ee05","yParity":"0x1","v":"0x1"}"# + ); + } + + #[cfg(feature = "serde")] + #[test] + fn serialize_v_only() { + // this test should be removed if the struct moves to an enum based on tx type + let signature = PrimitiveSignature::new( + U256::from_str("0xc569c92f176a3be1a6352dd5005bfc751dcb32f57623dd2a23693e64bf4447b0") + .unwrap(), + U256::from_str("0x1a891b566d369e79b7a66eecab1e008831e22daa15f91a0a0cf4f9f28f47ee05") + .unwrap(), + true, + ); + + let expected = r#"{"r":"0xc569c92f176a3be1a6352dd5005bfc751dcb32f57623dd2a23693e64bf4447b0","s":"0x1a891b566d369e79b7a66eecab1e008831e22daa15f91a0a0cf4f9f28f47ee05","yParity":"0x1","v":"0x1"}"#; + + let serialized = serde_json::to_string(&signature).unwrap(); + assert_eq!(serialized, expected); + } + + #[cfg(feature = "serde")] + #[test] + fn test_bincode_roundtrip() { + let signature = PrimitiveSignature::new( + U256::from_str("0xc569c92f176a3be1a6352dd5005bfc751dcb32f57623dd2a23693e64bf4447b0") + .unwrap(), + U256::from_str("0x1a891b566d369e79b7a66eecab1e008831e22daa15f91a0a0cf4f9f28f47ee05") + .unwrap(), + true, + ); + + let bin = bincode::serialize(&signature).unwrap(); + assert_eq!(bincode::deserialize::(&bin).unwrap(), signature); + } + + #[cfg(feature = "rlp")] + #[test] + fn signature_rlp_encode() { + // Given a Signature instance + let sig = PrimitiveSignature::from_str("48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c8041b").unwrap(); + + // Initialize an empty buffer + let mut buf = vec![]; + + // Encode the Signature into the buffer + sig.write_rlp_vrs(&mut buf, sig.v()); + + // Define the expected hex-encoded string + let expected = "80a048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a0efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804"; + + // Assert that the encoded buffer matches the expected hex-encoded string + assert_eq!(hex::encode(&buf), expected); + } + + #[cfg(feature = "rlp")] + #[test] + fn signature_rlp_length() { + // Given a Signature instance + let sig = PrimitiveSignature::from_str("48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c8041b").unwrap(); + + // Assert that the length of the Signature matches the expected length + assert_eq!(sig.rlp_rs_len() + sig.v().length(), 67); + } + + #[cfg(feature = "rlp")] + #[test] + fn test_rlp_vrs_len() { + let signature = PrimitiveSignature::test_signature(); + assert_eq!(67, signature.rlp_rs_len() + 1); + } + + #[cfg(feature = "rlp")] + #[test] + fn test_encode_and_decode() { + let signature = PrimitiveSignature::test_signature(); + + let mut encoded = Vec::new(); + signature.write_rlp_vrs(&mut encoded, signature.v()); + assert_eq!(encoded.len(), signature.rlp_rs_len() + signature.v().length()); + let decoded = PrimitiveSignature::decode_rlp_vrs(&mut &*encoded, bool::decode).unwrap(); + assert_eq!(signature, decoded); + } + + #[test] + fn test_as_bytes() { + let signature = PrimitiveSignature::new( + U256::from_str( + "18515461264373351373200002665853028612451056578545711640558177340181847433846", + ) + .unwrap(), + U256::from_str( + "46948507304638947509940763649030358759909902576025900602547168820602576006531", + ) + .unwrap(), + false, + ); + + let expected = Bytes::from_hex("0x28ef61340bd939bc2195fe537567866003e1a15d3c71ff63e1590620aa63627667cbe9d8997f761aecb703304b3800ccf555c9f3dc64214b297fb1966a3b6d831b").unwrap(); + assert_eq!(signature.as_bytes(), **expected); + } +} diff --git a/CoqOfRust/alloy_primitives/signature/primitive_sig.v b/CoqOfRust/alloy_primitives/signature/primitive_sig.v new file mode 100644 index 000000000..932e90ad0 --- /dev/null +++ b/CoqOfRust/alloy_primitives/signature/primitive_sig.v @@ -0,0 +1,2141 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module signature. + Module primitive_sig. + Definition value_SECP256K1N_ORDER : Value.t := + M.run_constant + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + "from_limbs", + [], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.U64 13822214165235122497; + Value.Integer IntegerKind.U64 13451932020343611451; + Value.Integer IntegerKind.U64 18446744073709551614; + Value.Integer IntegerKind.U64 18446744073709551615 + ] + ] + |) + |))). + + Axiom Constant_value_SECP256K1N_ORDER : + (M.get_constant "alloy_primitives::signature::primitive_sig::SECP256K1N_ORDER") = + value_SECP256K1N_ORDER. + Global Hint Rewrite Constant_value_SECP256K1N_ORDER : constant_rewrites. + + (* StructRecord + { + name := "PrimitiveSignature"; + const_params := []; + ty_params := []; + fields := + [ + ("y_parity", Ty.path "bool"); + ("r", + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []); + ("s", + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []) + ]; + } *) + + Module Impl_core_clone_Clone_for_alloy_primitives_signature_primitive_sig_PrimitiveSignature. + Definition Self : Ty.t := + Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ + fun γ => + ltac:(M.monadic + (M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.deref (| M.read (| self |) |))) ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_alloy_primitives_signature_primitive_sig_PrimitiveSignature. + + Module Impl_core_marker_Copy_for_alloy_primitives_signature_primitive_sig_PrimitiveSignature. + Definition Self : Ty.t := + Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_alloy_primitives_signature_primitive_sig_PrimitiveSignature. + + Module Impl_core_fmt_Debug_for_alloy_primitives_signature_primitive_sig_PrimitiveSignature. + Definition Self : Ty.t := + Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field3_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "PrimitiveSignature" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "y_parity" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "y_parity" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "r" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "r" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "s" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "s" + |) + |) + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_alloy_primitives_signature_primitive_sig_PrimitiveSignature. + + Module Impl_core_hash_Hash_for_alloy_primitives_signature_primitive_sig_PrimitiveSignature. + Definition Self : Ty.t := + Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature". + + (* Hash *) + Definition hash (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ __H ], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.path "bool", + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "y_parity" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "r" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "s" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::hash::Hash" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("hash", InstanceField.Method hash) ]. + End Impl_core_hash_Hash_for_alloy_primitives_signature_primitive_sig_PrimitiveSignature. + + Module Impl_core_marker_StructuralPartialEq_for_alloy_primitives_signature_primitive_sig_PrimitiveSignature. + Definition Self : Ty.t := + Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature". + + Axiom Implements : + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_alloy_primitives_signature_primitive_sig_PrimitiveSignature. + + Module Impl_core_cmp_PartialEq_alloy_primitives_signature_primitive_sig_PrimitiveSignature_for_alloy_primitives_signature_primitive_sig_PrimitiveSignature. + Definition Self : Ty.t := + Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature". + + (* PartialEq *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + LogicalOp.and (| + LogicalOp.and (| + BinOp.eq (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "y_parity" + |) + |), + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "y_parity" + |) + |) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + [], + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "r" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "r" + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + [], + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "s" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "s" + |) + |) + ] + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_signature_primitive_sig_PrimitiveSignature_for_alloy_primitives_signature_primitive_sig_PrimitiveSignature. + + Module Impl_core_cmp_Eq_for_alloy_primitives_signature_primitive_sig_PrimitiveSignature. + Definition Self : Ty.t := + Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature". + + (* Eq *) + Definition assert_receiver_is_total_eq + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ + fun γ => + ltac:(M.monadic + (M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method assert_receiver_is_total_eq) ]. + End Impl_core_cmp_Eq_for_alloy_primitives_signature_primitive_sig_PrimitiveSignature. + + Module Impl_core_convert_TryFrom_ref__slice_u8_for_alloy_primitives_signature_primitive_sig_PrimitiveSignature. + Definition Self : Ty.t := + Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature". + + (* type Error = SignatureError; *) + Definition _Error : Ty.t := Ty.path "alloy_primitives::signature::error::SignatureError". + + (* + fn try_from(bytes: &'a [u8]) -> Result { + if bytes.len() != 65 { + return Err(SignatureError::FromBytes("expected exactly 65 bytes")); + } + let parity = + normalize_v(bytes[64] as u64).ok_or(SignatureError::InvalidParity(bytes[64] as u64))?; + Ok(Self::from_bytes_and_parity(&bytes[..64], parity)) + } + *) + Definition try_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ bytes ] => + ltac:(M.monadic + (let bytes := M.alloc (| bytes |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.ne (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| bytes |) |) + |) + ] + |), + Value.Integer IntegerKind.Usize 65 + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "alloy_primitives::signature::error::SignatureError::FromBytes" + [ mk_str (| "expected exactly 65 bytes" |) ] + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ parity : Ty.path "bool" := + M.copy (| + M.match_operator (| + Some (Ty.path "bool"), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "alloy_primitives::signature::error::SignatureError" + ]; + Ty.path "bool" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "bool"; + Ty.path "alloy_primitives::signature::error::SignatureError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "bool"; + Ty.path "alloy_primitives::signature::error::SignatureError" + ], + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "bool" ], + "ok_or", + [], + [ Ty.path "alloy_primitives::signature::error::SignatureError" ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "bool" ], + M.get_function (| + "alloy_primitives::signature::utils::normalize_v", + [], + [] + |), + [ + M.cast + (Ty.path "u64") + (M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| bytes |) |), + Value.Integer IntegerKind.Usize 64 + |) + |)) + ] + |); + Value.StructTuple + "alloy_primitives::signature::error::SignatureError::InvalidParity" + [ + M.cast + (Ty.path "u64") + (M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| bytes |) |), + Value.Integer IntegerKind.Usize 64 + |) + |)) + ] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "alloy_primitives::signature::primitive_sig::PrimitiveSignature"; + Ty.path + "alloy_primitives::signature::error::SignatureError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "alloy_primitives::signature::primitive_sig::PrimitiveSignature"; + Ty.path + "alloy_primitives::signature::error::SignatureError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signature::error::SignatureError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + M.call_closure (| + Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + M.get_associated_function (| + Ty.path + "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "from_bytes_and_parity", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| bytes |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 64) ] + ] + |) + |) + |) + |) + |); + M.read (| parity |) + ] + |) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("try_from", InstanceField.Method try_from) ]. + End Impl_core_convert_TryFrom_ref__slice_u8_for_alloy_primitives_signature_primitive_sig_PrimitiveSignature. + + Module Impl_core_str_traits_FromStr_for_alloy_primitives_signature_primitive_sig_PrimitiveSignature. + Definition Self : Ty.t := + Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature". + + (* type Err = SignatureError; *) + Definition _Err : Ty.t := Ty.path "alloy_primitives::signature::error::SignatureError". + + (* + fn from_str(s: &str) -> Result { + let bytes = hex::decode(s)?; + Self::try_from(&bytes[..]) + } + *) + Definition from_str (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ s ] => + ltac:(M.monadic + (let s := M.alloc (| s |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ bytes : + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ] := + M.copy (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ]), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "const_hex::error::FromHexError" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ]; + Ty.path "const_hex::error::FromHexError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ]; + Ty.path "const_hex::error::FromHexError" + ], + M.get_function (| + "const_hex::decode", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + |), + [ M.read (| s |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "alloy_primitives::signature::primitive_sig::PrimitiveSignature"; + Ty.path + "alloy_primitives::signature::error::SignatureError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "alloy_primitives::signature::primitive_sig::PrimitiveSignature"; + Ty.path + "alloy_primitives::signature::error::SignatureError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "const_hex::error::FromHexError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature"; + Ty.path "alloy_primitives::signature::error::SignatureError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ], + "try_from", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, bytes |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::str::traits::FromStr" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("Err", InstanceField.Ty _Err); ("from_str", InstanceField.Method from_str) ]. + End Impl_core_str_traits_FromStr_for_alloy_primitives_signature_primitive_sig_PrimitiveSignature. + + Module Impl_core_convert_From_ref__alloy_primitives_signature_primitive_sig_PrimitiveSignature_for_array_Usize_65_u8. + Definition Self : Ty.t := + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 65 ] [ Ty.path "u8" ]. + + (* + fn from(value: &PrimitiveSignature) -> [u8; 65] { + value.as_bytes() + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 65 ] [ Ty.path "u8" ], + M.get_associated_function (| + Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "as_bytes", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| value |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature" ] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref__alloy_primitives_signature_primitive_sig_PrimitiveSignature_for_array_Usize_65_u8. + + Module Impl_core_convert_From_alloy_primitives_signature_primitive_sig_PrimitiveSignature_for_array_Usize_65_u8. + Definition Self : Ty.t := + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 65 ] [ Ty.path "u8" ]. + + (* + fn from(value: PrimitiveSignature) -> [u8; 65] { + value.as_bytes() + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 65 ] [ Ty.path "u8" ], + M.get_associated_function (| + Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "as_bytes", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_signature_primitive_sig_PrimitiveSignature_for_array_Usize_65_u8. + + Module Impl_core_convert_From_ref__alloy_primitives_signature_primitive_sig_PrimitiveSignature_for_alloc_vec_Vec_u8_alloc_alloc_Global. + Definition Self : Ty.t := + Ty.apply (Ty.path "alloc::vec::Vec") [] [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ]. + + (* + fn from(value: &PrimitiveSignature) -> Self { + value.as_bytes().to_vec() + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "to_vec", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 65 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "as_bytes", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| value |) |) |) ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature" ] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref__alloy_primitives_signature_primitive_sig_PrimitiveSignature_for_alloc_vec_Vec_u8_alloc_alloc_Global. + + Module Impl_core_convert_From_alloy_primitives_signature_primitive_sig_PrimitiveSignature_for_alloc_vec_Vec_u8_alloc_alloc_Global. + Definition Self : Ty.t := + Ty.apply (Ty.path "alloc::vec::Vec") [] [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ]. + + (* + fn from(value: PrimitiveSignature) -> Self { + value.as_bytes().to_vec() + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "to_vec", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 65 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "as_bytes", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_signature_primitive_sig_PrimitiveSignature_for_alloc_vec_Vec_u8_alloc_alloc_Global. + + Module Impl_alloy_primitives_signature_primitive_sig_PrimitiveSignature. + Definition Self : Ty.t := + Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature". + + (* + pub fn test_signature() -> Self { + Self::from_scalars_and_parity( + b256!("840cfc572845f5786e702984c2a582528cad4b49b2a10b9db1be7fca90058565"), + b256!("25e7109ceb98168d95b09b18bbf6b685130e0562f233877d492b94eee0c5b6d1"), + false, + ) + } + *) + Definition test_signature (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.call_closure (| + Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + M.get_associated_function (| + Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "from_scalars_and_parity", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + "new", + [], + [] + |), + [ + M.read (| + M.get_constant + "alloy_primitives::signature::primitive_sig::test_signature::RES" + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + "new", + [], + [] + |), + [ + M.read (| + M.get_constant + "alloy_primitives::signature::primitive_sig::test_signature::RES'1" + |) + ] + |); + Value.Bool false + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_test_signature : + M.IsAssociatedFunction.Trait Self "test_signature" test_signature. + Admitted. + Global Typeclasses Opaque test_signature. + + (* + pub fn new(r: U256, s: U256, v: bool) -> Self { + Self { r, s, y_parity: v } + } + *) + Definition new (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ r; s; v ] => + ltac:(M.monadic + (let r := M.alloc (| r |) in + let s := M.alloc (| s |) in + let v := M.alloc (| v |) in + Value.StructRecord + "alloy_primitives::signature::primitive_sig::PrimitiveSignature" + [ ("r", M.read (| r |)); ("s", M.read (| s |)); ("y_parity", M.read (| v |)) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : M.IsAssociatedFunction.Trait Self "new" new. + Admitted. + Global Typeclasses Opaque new. + + (* + pub fn from_scalars_and_parity(r: crate::B256, s: crate::B256, parity: bool) -> Self { + Self::new(U256::from_be_slice(r.as_ref()), U256::from_be_slice(s.as_ref()), parity) + } + *) + Definition from_scalars_and_parity + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ r; s; parity ] => + ltac:(M.monadic + (let r := M.alloc (| r |) in + let s := M.alloc (| s |) in + let parity := M.alloc (| parity |) in + M.call_closure (| + Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + M.get_associated_function (| + Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + "from_be_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "as_ref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, r |) ] + |) + |) + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + "from_be_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "as_ref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, s |) ] + |) + |) + |) + ] + |); + M.read (| parity |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_scalars_and_parity : + M.IsAssociatedFunction.Trait Self "from_scalars_and_parity" from_scalars_and_parity. + Admitted. + Global Typeclasses Opaque from_scalars_and_parity. + + (* + pub fn normalize_s(&self) -> Option { + let s = self.s(); + + if s > SECP256K1N_ORDER >> 1 { + Some(Self { y_parity: !self.y_parity, r: self.r, s: SECP256K1N_ORDER - s }) + } else { + None + } + } + *) + Definition normalize_s (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ s : + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "s", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature" ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + [], + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ], + "gt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, s |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + M.get_trait_method (| + "core::ops::bit::Shr", + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + [], + [ Ty.path "i32" ], + "shr", + [], + [] + |), + [ + M.read (| + M.get_constant + "alloy_primitives::signature::primitive_sig::SECP256K1N_ORDER" + |); + Value.Integer IntegerKind.I32 1 + ] + |) + |) + |) + ] + |) + |)) in + let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + Value.StructRecord + "alloy_primitives::signature::primitive_sig::PrimitiveSignature" + [ + ("y_parity", + UnOp.not (| + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "y_parity" + |) + |) + |)); + ("r", + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "r" + |) + |)); + ("s", + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + [], + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ], + "sub", + [], + [] + |), + [ + M.read (| + M.get_constant + "alloy_primitives::signature::primitive_sig::SECP256K1N_ORDER" + |); + M.read (| s |) + ] + |)) + ] + ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.StructTuple "core::option::Option::None" [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_normalize_s : + M.IsAssociatedFunction.Trait Self "normalize_s" normalize_s. + Admitted. + Global Typeclasses Opaque normalize_s. + + (* + pub fn from_bytes_and_parity(bytes: &[u8], parity: bool) -> Self { + let r = U256::from_be_slice(&bytes[..32]); + let s = U256::from_be_slice(&bytes[32..64]); + Self::new(r, s, parity) + } + *) + Definition from_bytes_and_parity (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ bytes; parity ] => + ltac:(M.monadic + (let bytes := M.alloc (| bytes |) in + let parity := M.alloc (| parity |) in + M.read (| + let~ r : + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + "from_be_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| bytes |) |) |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 32) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) in + let~ s : + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + "from_be_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| bytes |) |) |); + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 32); + ("end_", Value.Integer IntegerKind.Usize 64) + ] + ] + |) + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + M.get_associated_function (| + Ty.path "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "new", + [], + [] + |), + [ M.read (| r |); M.read (| s |); M.read (| parity |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_bytes_and_parity : + M.IsAssociatedFunction.Trait Self "from_bytes_and_parity" from_bytes_and_parity. + Admitted. + Global Typeclasses Opaque from_bytes_and_parity. + + (* + pub const fn r(&self) -> U256 { + self.r + } + *) + Definition r (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "r" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_r : M.IsAssociatedFunction.Trait Self "r" r. + Admitted. + Global Typeclasses Opaque r. + + (* + pub const fn s(&self) -> U256 { + self.s + } + *) + Definition s (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "s" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_s : M.IsAssociatedFunction.Trait Self "s" s. + Admitted. + Global Typeclasses Opaque s. + + (* + pub const fn v(&self) -> bool { + self.y_parity + } + *) + Definition v (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "y_parity" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_v : M.IsAssociatedFunction.Trait Self "v" v. + Admitted. + Global Typeclasses Opaque v. + + (* + pub fn as_bytes(&self) -> [u8; 65] { + let mut sig = [0u8; 65]; + sig[..32].copy_from_slice(&self.r.to_be_bytes::<32>()); + sig[32..64].copy_from_slice(&self.s.to_be_bytes::<32>()); + sig[64] = 27 + self.y_parity as u8; + sig + } + *) + Definition as_bytes (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ sig : + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 65 ] + [ Ty.path "u8" ] := + M.alloc (| + repeat (| Value.Integer IntegerKind.U8 0, Value.Integer IntegerKind.Usize 65 |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "copy_from_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 65 ] + [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, sig |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 32) ] + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + "to_be_bytes", + [ Value.Integer IntegerKind.Usize 32 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "r" + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "copy_from_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 65 ] + [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, sig |); + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 32); + ("end_", Value.Integer IntegerKind.Usize 64) + ] + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + "to_be_bytes", + [ Value.Integer IntegerKind.Usize 32 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "s" + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| sig, Value.Integer IntegerKind.Usize 64 |), + BinOp.Wrap.add (| + Value.Integer IntegerKind.U8 27, + M.cast + (Ty.path "u8") + (M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "y_parity" + |) + |)) + |) + |) + |) in + sig + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_as_bytes : + M.IsAssociatedFunction.Trait Self "as_bytes" as_bytes. + Admitted. + Global Typeclasses Opaque as_bytes. + + (* + pub const fn with_parity(self, v: bool) -> Self { + Self { y_parity: v, r: self.r, s: self.s } + } + *) + Definition with_parity (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; v ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let v := M.alloc (| v |) in + Value.StructRecord + "alloy_primitives::signature::primitive_sig::PrimitiveSignature" + [ + ("y_parity", M.read (| v |)); + ("r", + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "r" + |) + |)); + ("s", + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "alloy_primitives::signature::primitive_sig::PrimitiveSignature", + "s" + |) + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_with_parity : + M.IsAssociatedFunction.Trait Self "with_parity" with_parity. + Admitted. + Global Typeclasses Opaque with_parity. + End Impl_alloy_primitives_signature_primitive_sig_PrimitiveSignature. + End primitive_sig. +End signature. diff --git a/CoqOfRust/alloy_primitives/signature/sig.rs b/CoqOfRust/alloy_primitives/signature/sig.rs new file mode 100644 index 000000000..f121c4730 --- /dev/null +++ b/CoqOfRust/alloy_primitives/signature/sig.rs @@ -0,0 +1,840 @@ +#![allow(unknown_lints, unnameable_types)] + +use crate::{ + hex, + signature::{Parity, SignatureError}, + uint, U256, +}; +use alloc::vec::Vec; +use core::str::FromStr; + +/// The order of the secp256k1 curve +const SECP256K1N_ORDER: U256 = + uint!(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141_U256); + +/// An Ethereum ECDSA signature. +#[derive(Clone, Copy, Debug, Hash, PartialEq, Eq)] +pub struct Signature { + v: Parity, + r: U256, + s: U256, +} + +impl<'a> TryFrom<&'a [u8]> for Signature { + type Error = SignatureError; + + /// Parses a raw signature which is expected to be 65 bytes long where + /// the first 32 bytes is the `r` value, the second 32 bytes the `s` value + /// and the final byte is the `v` value in 'Electrum' notation. + fn try_from(bytes: &'a [u8]) -> Result { + if bytes.len() != 65 { + return Err(SignatureError::FromBytes("expected exactly 65 bytes")); + } + Self::from_bytes_and_parity(&bytes[..64], bytes[64] as u64) + } +} + +impl FromStr for Signature { + type Err = SignatureError; + + fn from_str(s: &str) -> Result { + let bytes = hex::decode(s)?; + Self::try_from(&bytes[..]) + } +} + +impl From<&Signature> for [u8; 65] { + #[inline] + fn from(value: &Signature) -> [u8; 65] { + value.as_bytes() + } +} + +impl From for [u8; 65] { + #[inline] + fn from(value: Signature) -> [u8; 65] { + value.as_bytes() + } +} + +impl From<&Signature> for Vec { + #[inline] + fn from(value: &Signature) -> Self { + value.as_bytes().to_vec() + } +} + +impl From for Vec { + #[inline] + fn from(value: Signature) -> Self { + value.as_bytes().to_vec() + } +} + +#[cfg(feature = "k256")] +impl From<(k256::ecdsa::Signature, k256::ecdsa::RecoveryId)> for Signature { + fn from(value: (k256::ecdsa::Signature, k256::ecdsa::RecoveryId)) -> Self { + Self::from_signature_and_parity(value.0, value.1).unwrap() + } +} + +#[cfg(feature = "k256")] +impl TryFrom for k256::ecdsa::Signature { + type Error = k256::ecdsa::Error; + + fn try_from(value: Signature) -> Result { + value.to_k256() + } +} + +#[cfg(feature = "rlp")] +impl Signature { + /// Decode an RLP-encoded VRS signature. + pub fn decode_rlp_vrs(buf: &mut &[u8]) -> Result { + use alloy_rlp::Decodable; + + let parity: Parity = Decodable::decode(buf)?; + let r = Decodable::decode(buf)?; + let s = Decodable::decode(buf)?; + + Self::from_rs_and_parity(r, s, parity) + .map_err(|_| alloy_rlp::Error::Custom("attempted to decode invalid field element")) + } +} + +impl Signature { + #[doc(hidden)] + pub fn test_signature() -> Self { + Self::from_scalars_and_parity( + b256!("840cfc572845f5786e702984c2a582528cad4b49b2a10b9db1be7fca90058565"), + b256!("25e7109ceb98168d95b09b18bbf6b685130e0562f233877d492b94eee0c5b6d1"), + false, + ) + .unwrap() + } + + /// Instantiate a new signature from `r`, `s`, and `v` values. + #[allow(clippy::missing_const_for_fn)] + pub fn new(r: U256, s: U256, v: Parity) -> Self { + Self { r, s, v } + } + + /// Returns the inner ECDSA signature. + #[cfg(feature = "k256")] + #[deprecated(note = "use `Signature::to_k256` instead")] + #[inline] + pub fn into_inner(self) -> k256::ecdsa::Signature { + self.try_into().expect("signature conversion failed") + } + + /// Returns the inner ECDSA signature. + #[cfg(feature = "k256")] + #[inline] + pub fn to_k256(self) -> Result { + k256::ecdsa::Signature::from_scalars(self.r.to_be_bytes(), self.s.to_be_bytes()) + } + + /// Instantiate from a signature and recovery id + #[cfg(feature = "k256")] + pub fn from_signature_and_parity, E: Into>( + sig: k256::ecdsa::Signature, + parity: T, + ) -> Result { + let r = U256::from_be_slice(sig.r().to_bytes().as_ref()); + let s = U256::from_be_slice(sig.s().to_bytes().as_ref()); + Ok(Self { v: parity.try_into().map_err(Into::into)?, r, s }) + } + + /// Creates a [`Signature`] from the serialized `r` and `s` scalar values, which comprise the + /// ECDSA signature, alongside a `v` value, used to determine the recovery ID. + #[inline] + pub fn from_scalars_and_parity, E: Into>( + r: crate::B256, + s: crate::B256, + parity: T, + ) -> Result { + Self::from_rs_and_parity( + U256::from_be_slice(r.as_ref()), + U256::from_be_slice(s.as_ref()), + parity, + ) + } + + /// Normalizes the signature into "low S" form as described in + /// [BIP 0062: Dealing with Malleability][1]. + /// + /// [1]: https://github.com/bitcoin/bips/blob/master/bip-0062.mediawiki + #[inline] + pub fn normalize_s(&self) -> Option { + let s = self.s(); + + if s > SECP256K1N_ORDER >> 1 { + Some(Self { v: self.v.inverted(), r: self.r, s: SECP256K1N_ORDER - s }) + } else { + None + } + } + + /// Returns the recovery ID. + #[cfg(feature = "k256")] + #[inline] + pub const fn recid(&self) -> k256::ecdsa::RecoveryId { + self.v.recid() + } + + #[cfg(feature = "k256")] + #[doc(hidden)] + #[deprecated(note = "use `Signature::recid` instead")] + pub const fn recovery_id(&self) -> k256::ecdsa::RecoveryId { + self.recid() + } + + /// Recovers an [`Address`] from this signature and the given message by first prefixing and + /// hashing the message according to [EIP-191](crate::eip191_hash_message). + /// + /// [`Address`]: crate::Address + #[cfg(feature = "k256")] + #[inline] + pub fn recover_address_from_msg>( + &self, + msg: T, + ) -> Result { + self.recover_from_msg(msg).map(|vk| crate::Address::from_public_key(&vk)) + } + + /// Recovers an [`Address`] from this signature and the given prehashed message. + /// + /// [`Address`]: crate::Address + #[cfg(feature = "k256")] + #[inline] + pub fn recover_address_from_prehash( + &self, + prehash: &crate::B256, + ) -> Result { + self.recover_from_prehash(prehash).map(|vk| crate::Address::from_public_key(&vk)) + } + + /// Recovers a [`VerifyingKey`] from this signature and the given message by first prefixing and + /// hashing the message according to [EIP-191](crate::eip191_hash_message). + /// + /// [`VerifyingKey`]: k256::ecdsa::VerifyingKey + #[cfg(feature = "k256")] + #[inline] + pub fn recover_from_msg>( + &self, + msg: T, + ) -> Result { + self.recover_from_prehash(&crate::eip191_hash_message(msg)) + } + + /// Recovers a [`VerifyingKey`] from this signature and the given prehashed message. + /// + /// [`VerifyingKey`]: k256::ecdsa::VerifyingKey + #[cfg(feature = "k256")] + #[inline] + pub fn recover_from_prehash( + &self, + prehash: &crate::B256, + ) -> Result { + let this = self.normalize_s().unwrap_or(*self); + k256::ecdsa::VerifyingKey::recover_from_prehash( + prehash.as_slice(), + &this.to_k256()?, + this.recid(), + ) + .map_err(Into::into) + } + + /// Parses a signature from a byte slice, with a v value + /// + /// # Panics + /// + /// If the slice is not at least 64 bytes long. + #[inline] + pub fn from_bytes_and_parity, E: Into>( + bytes: &[u8], + parity: T, + ) -> Result { + let r = U256::from_be_slice(&bytes[..32]); + let s = U256::from_be_slice(&bytes[32..64]); + Self::from_rs_and_parity(r, s, parity) + } + + /// Instantiate from v, r, s. + pub fn from_rs_and_parity, E: Into>( + r: U256, + s: U256, + parity: T, + ) -> Result { + Ok(Self { v: parity.try_into().map_err(Into::into)?, r, s }) + } + + /// Modifies the recovery ID by applying [EIP-155] to a `v` value. + /// + /// [EIP-155]: https://eips.ethereum.org/EIPS/eip-155 + #[inline] + pub fn with_chain_id(self, chain_id: u64) -> Self { + self.with_parity(self.v.with_chain_id(chain_id)) + } + + /// Modifies the recovery ID by dropping any [EIP-155] v value, converting + /// to a simple parity bool. + pub fn with_parity_bool(self) -> Self { + self.with_parity(self.v.to_parity_bool()) + } + + /// Returns the `r` component of this signature. + #[inline] + pub const fn r(&self) -> U256 { + self.r + } + + /// Returns the `s` component of this signature. + #[inline] + pub const fn s(&self) -> U256 { + self.s + } + + /// Returns the recovery ID as a `u8`. + #[inline] + pub const fn v(&self) -> Parity { + self.v + } + + /// Returns the chain ID associated with the V value, if this signature is + /// replay-protected by [EIP-155]. + /// + /// [EIP-155]: https://eips.ethereum.org/EIPS/eip-155 + pub const fn chain_id(&self) -> Option { + self.v.chain_id() + } + + /// Returns true if the signature is replay-protected by [EIP-155]. + /// + /// This is true if the V value is 35 or greater. Values less than 35 are + /// either not replay protected (27/28), or are invalid. + /// + /// [EIP-155]: https://eips.ethereum.org/EIPS/eip-155 + #[inline] + pub const fn has_eip155_value(&self) -> bool { + self.v().has_eip155_value() + } + + /// Returns the byte-array representation of this signature. + /// + /// The first 32 bytes are the `r` value, the second 32 bytes the `s` value + /// and the final byte is the `v` value in 'Electrum' notation. + #[inline] + pub fn as_bytes(&self) -> [u8; 65] { + let mut sig = [0u8; 65]; + sig[..32].copy_from_slice(&self.r.to_be_bytes::<32>()); + sig[32..64].copy_from_slice(&self.s.to_be_bytes::<32>()); + sig[64] = self.v.y_parity_byte_non_eip155().unwrap_or(self.v.y_parity_byte()); + sig + } + + /// Sets the recovery ID by normalizing a `v` value. + #[inline] + pub fn with_parity>(self, parity: T) -> Self { + Self { v: parity.into(), r: self.r, s: self.s } + } + + /// Length of RLP RS field encoding + #[cfg(feature = "rlp")] + pub fn rlp_rs_len(&self) -> usize { + alloy_rlp::Encodable::length(&self.r) + alloy_rlp::Encodable::length(&self.s) + } + + #[cfg(feature = "rlp")] + /// Length of RLP V field encoding + pub fn rlp_vrs_len(&self) -> usize { + self.rlp_rs_len() + alloy_rlp::Encodable::length(&self.v) + } + + /// Write R and S to an RLP buffer in progress. + #[cfg(feature = "rlp")] + pub fn write_rlp_rs(&self, out: &mut dyn alloy_rlp::BufMut) { + alloy_rlp::Encodable::encode(&self.r, out); + alloy_rlp::Encodable::encode(&self.s, out); + } + + /// Write the V to an RLP buffer without using EIP-155. + #[cfg(feature = "rlp")] + pub fn write_rlp_v(&self, out: &mut dyn alloy_rlp::BufMut) { + alloy_rlp::Encodable::encode(&self.v, out); + } + + /// Write the VRS to the output. The V will always be 27 or 28. + #[cfg(feature = "rlp")] + pub fn write_rlp_vrs(&self, out: &mut dyn alloy_rlp::BufMut) { + self.write_rlp_v(out); + self.write_rlp_rs(out); + } +} + +#[cfg(feature = "rlp")] +impl alloy_rlp::Encodable for Signature { + fn encode(&self, out: &mut dyn alloy_rlp::BufMut) { + alloy_rlp::Header { list: true, payload_length: self.rlp_vrs_len() }.encode(out); + self.write_rlp_vrs(out); + } + + fn length(&self) -> usize { + let payload_length = self.rlp_vrs_len(); + payload_length + alloy_rlp::length_of_length(payload_length) + } +} + +#[cfg(feature = "rlp")] +impl alloy_rlp::Decodable for Signature { + fn decode(buf: &mut &[u8]) -> Result { + let header = alloy_rlp::Header::decode(buf)?; + let pre_len = buf.len(); + let decoded = Self::decode_rlp_vrs(buf)?; + let consumed = pre_len - buf.len(); + if consumed != header.payload_length { + return Err(alloy_rlp::Error::Custom("consumed incorrect number of bytes")); + } + + Ok(decoded) + } +} + +#[cfg(feature = "serde")] +impl serde::Serialize for Signature { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + // if the serializer is human readable, serialize as a map, otherwise as a tuple + if serializer.is_human_readable() { + use serde::ser::SerializeMap; + + let mut map = serializer.serialize_map(Some(3))?; + + map.serialize_entry("r", &self.r)?; + map.serialize_entry("s", &self.s)?; + + match self.v { + Parity::Eip155(v) => map.serialize_entry("v", &crate::U64::from(v))?, + Parity::NonEip155(b) => { + map.serialize_entry("v", &crate::U64::from(b as u8 + 27))? + } + Parity::Parity(true) => map.serialize_entry("yParity", "0x1")?, + Parity::Parity(false) => map.serialize_entry("yParity", "0x0")?, + } + map.end() + } else { + use serde::ser::SerializeTuple; + + let mut tuple = serializer.serialize_tuple(3)?; + tuple.serialize_element(&self.r)?; + tuple.serialize_element(&self.s)?; + tuple.serialize_element(&crate::U64::from(self.v.to_u64()))?; + tuple.end() + } + } +} + +#[cfg(feature = "serde")] +impl<'de> serde::Deserialize<'de> for Signature { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + use serde::de::MapAccess; + + enum Field { + R, + S, + V, + YParity, + Unknown, + } + + impl<'de> serde::Deserialize<'de> for Field { + fn deserialize(deserializer: D) -> Result + where + D: serde::Deserializer<'de>, + { + struct FieldVisitor; + + impl serde::de::Visitor<'_> for FieldVisitor { + type Value = Field; + + fn expecting( + &self, + formatter: &mut core::fmt::Formatter<'_>, + ) -> core::fmt::Result { + formatter.write_str("v, r, s, or yParity") + } + + fn visit_str(self, value: &str) -> Result + where + E: serde::de::Error, + { + match value { + "r" => Ok(Field::R), + "s" => Ok(Field::S), + "v" => Ok(Field::V), + "yParity" => Ok(Field::YParity), + _ => Ok(Field::Unknown), + } + } + } + deserializer.deserialize_identifier(FieldVisitor) + } + } + + struct MapVisitor; + impl<'de> serde::de::Visitor<'de> for MapVisitor { + type Value = Signature; + + fn expecting(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + formatter.write_str("a JSON signature object containing r, s, and v or yParity") + } + + fn visit_map(self, mut map: A) -> Result + where + A: MapAccess<'de>, + { + let mut v: Option = None; + let mut r = None; + let mut s = None; + + while let Some(key) = map.next_key()? { + match key { + Field::V => { + let value: crate::U64 = map.next_value()?; + let parity = value.try_into().map_err(|_| { + serde::de::Error::invalid_value( + serde::de::Unexpected::Unsigned(value.as_limbs()[0]), + &"a valid v value matching the range 0 | 1 | 27 | 28 | 35..", + ) + })?; + v = Some(parity); + } + Field::YParity => { + let value: crate::Uint<1, 1> = map.next_value()?; + if v.is_none() { + v = Some(value.into()); + } + } + Field::R => { + let value: U256 = map.next_value()?; + r = Some(value); + } + Field::S => { + let value: U256 = map.next_value()?; + s = Some(value); + } + _ => {} + } + } + + let v = v.ok_or_else(|| serde::de::Error::missing_field("v"))?; + let r = r.ok_or_else(|| serde::de::Error::missing_field("r"))?; + let s = s.ok_or_else(|| serde::de::Error::missing_field("s"))?; + + Signature::from_rs_and_parity(r, s, v).map_err(serde::de::Error::custom) + } + } + + struct TupleVisitor; + impl<'de> serde::de::Visitor<'de> for TupleVisitor { + type Value = Signature; + + fn expecting(&self, formatter: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + formatter.write_str("a tuple containing r, s, and v") + } + + fn visit_seq(self, mut seq: A) -> Result + where + A: serde::de::SeqAccess<'de>, + { + let r = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(0, &self))?; + let s = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(1, &self))?; + let v: crate::U64 = seq + .next_element()? + .ok_or_else(|| serde::de::Error::invalid_length(2, &self))?; + + Signature::from_rs_and_parity(r, s, v).map_err(serde::de::Error::custom) + } + } + + if deserializer.is_human_readable() { + deserializer.deserialize_map(MapVisitor) + } else { + deserializer.deserialize_tuple(3, TupleVisitor) + } + } +} + +#[cfg(feature = "arbitrary")] +impl<'a> arbitrary::Arbitrary<'a> for Signature { + fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { + Self::from_rs_and_parity(u.arbitrary()?, u.arbitrary()?, u.arbitrary::()?) + .map_err(|_| arbitrary::Error::IncorrectFormat) + } +} + +#[cfg(feature = "arbitrary")] +impl proptest::arbitrary::Arbitrary for Signature { + type Parameters = (); + type Strategy = proptest::strategy::FilterMap< + <(U256, U256, Parity) as proptest::arbitrary::Arbitrary>::Strategy, + fn((U256, U256, Parity)) -> Option, + >; + + fn arbitrary_with((): Self::Parameters) -> Self::Strategy { + use proptest::strategy::Strategy; + proptest::arbitrary::any::<(U256, U256, Parity)>() + .prop_filter_map("invalid signature", |(r, s, parity)| { + Self::from_rs_and_parity(r, s, parity).ok() + }) + } +} + +#[cfg(test)] +#[allow(unused_imports)] +mod tests { + use super::*; + use crate::Bytes; + use core::str::FromStr; + use hex::FromHex; + + #[cfg(feature = "rlp")] + use alloy_rlp::{Decodable, Encodable}; + + #[test] + #[cfg(feature = "k256")] + fn can_recover_tx_sender_not_normalized() { + let sig = Signature::from_str("48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c8041b").unwrap(); + let hash = b256!("5eb4f5a33c621f32a8622d5f943b6b102994dfe4e5aebbefe69bb1b2aa0fc93e"); + let expected = address!("0f65fe9276bc9a24ae7083ae28e2660ef72df99e"); + assert_eq!(sig.recover_address_from_prehash(&hash).unwrap(), expected); + } + + #[test] + #[cfg(feature = "k256")] + fn recover_web3_signature() { + // test vector taken from: + // https://web3js.readthedocs.io/en/v1.2.2/web3-eth-accounts.html#sign + let sig = Signature::from_str( + "b91467e570a6466aa9e9876cbcd013baba02900b8979d43fe208a4a4f339f5fd6007e74cd82e037b800186422fc2da167c747ef045e5d18a5f5d4300f8e1a0291c" + ).expect("could not parse signature"); + let expected = address!("2c7536E3605D9C16a7a3D7b1898e529396a65c23"); + assert_eq!(sig.recover_address_from_msg("Some data").unwrap(), expected); + } + + #[test] + fn signature_from_str() { + let s1 = Signature::from_str( + "0xaa231fbe0ed2b5418e6ba7c19bee2522852955ec50996c02a2fe3e71d30ddaf1645baf4823fea7cb4fcc7150842493847cfb6a6d63ab93e8ee928ee3f61f503500" + ).expect("could not parse 0x-prefixed signature"); + + let s2 = Signature::from_str( + "aa231fbe0ed2b5418e6ba7c19bee2522852955ec50996c02a2fe3e71d30ddaf1645baf4823fea7cb4fcc7150842493847cfb6a6d63ab93e8ee928ee3f61f503500" + ).expect("could not parse non-prefixed signature"); + + assert_eq!(s1, s2); + } + + #[cfg(feature = "serde")] + #[test] + fn deserialize_without_parity() { + let raw_signature_without_y_parity = r#"{ + "r":"0xc569c92f176a3be1a6352dd5005bfc751dcb32f57623dd2a23693e64bf4447b0", + "s":"0x1a891b566d369e79b7a66eecab1e008831e22daa15f91a0a0cf4f9f28f47ee05", + "v":"0x1" + }"#; + + let signature: Signature = serde_json::from_str(raw_signature_without_y_parity).unwrap(); + + let expected = Signature::from_rs_and_parity( + U256::from_str("0xc569c92f176a3be1a6352dd5005bfc751dcb32f57623dd2a23693e64bf4447b0") + .unwrap(), + U256::from_str("0x1a891b566d369e79b7a66eecab1e008831e22daa15f91a0a0cf4f9f28f47ee05") + .unwrap(), + 1, + ) + .unwrap(); + + assert_eq!(signature, expected); + } + + #[cfg(feature = "serde")] + #[test] + fn deserialize_with_parity() { + let raw_signature_with_y_parity = serde_json::json!({ + "r": "0xc569c92f176a3be1a6352dd5005bfc751dcb32f57623dd2a23693e64bf4447b0", + "s": "0x1a891b566d369e79b7a66eecab1e008831e22daa15f91a0a0cf4f9f28f47ee05", + "v": "0x1", + "yParity": "0x1" + }); + + let signature: Signature = serde_json::from_value(raw_signature_with_y_parity).unwrap(); + + let expected = Signature::from_rs_and_parity( + U256::from_str("0xc569c92f176a3be1a6352dd5005bfc751dcb32f57623dd2a23693e64bf4447b0") + .unwrap(), + U256::from_str("0x1a891b566d369e79b7a66eecab1e008831e22daa15f91a0a0cf4f9f28f47ee05") + .unwrap(), + 1, + ) + .unwrap(); + + assert_eq!(signature, expected); + } + + #[cfg(feature = "serde")] + #[test] + fn serialize_both_parity() { + // this test should be removed if the struct moves to an enum based on tx type + let signature = Signature::from_rs_and_parity( + U256::from_str("0xc569c92f176a3be1a6352dd5005bfc751dcb32f57623dd2a23693e64bf4447b0") + .unwrap(), + U256::from_str("0x1a891b566d369e79b7a66eecab1e008831e22daa15f91a0a0cf4f9f28f47ee05") + .unwrap(), + 1, + ) + .unwrap(); + + let serialized = serde_json::to_string(&signature).unwrap(); + assert_eq!( + serialized, + r#"{"r":"0xc569c92f176a3be1a6352dd5005bfc751dcb32f57623dd2a23693e64bf4447b0","s":"0x1a891b566d369e79b7a66eecab1e008831e22daa15f91a0a0cf4f9f28f47ee05","yParity":"0x1"}"# + ); + } + + #[cfg(feature = "serde")] + #[test] + fn serialize_v_only() { + // this test should be removed if the struct moves to an enum based on tx type + let signature = Signature::from_rs_and_parity( + U256::from_str("0xc569c92f176a3be1a6352dd5005bfc751dcb32f57623dd2a23693e64bf4447b0") + .unwrap(), + U256::from_str("0x1a891b566d369e79b7a66eecab1e008831e22daa15f91a0a0cf4f9f28f47ee05") + .unwrap(), + 1, + ) + .unwrap(); + + let expected = r#"{"r":"0xc569c92f176a3be1a6352dd5005bfc751dcb32f57623dd2a23693e64bf4447b0","s":"0x1a891b566d369e79b7a66eecab1e008831e22daa15f91a0a0cf4f9f28f47ee05","yParity":"0x1"}"#; + + let serialized = serde_json::to_string(&signature).unwrap(); + assert_eq!(serialized, expected); + } + + #[cfg(feature = "serde")] + #[test] + fn serialize_v_hex() { + let s = r#"{"r":"0x3d43270611ffb1a10fcab841e636e355a787151969b920cf10fef48d3a61aac3","s":"0x11336489e3050e3ec017079dfe16582ce3d167559bcaa8383b665b3fda4eb963","v":"0x1b"}"#; + + let sig = serde_json::from_str::(s).unwrap(); + let serialized = serde_json::to_string(&sig).unwrap(); + assert_eq!(serialized, s); + } + + #[cfg(feature = "serde")] + #[test] + fn test_bincode_roundtrip() { + let signature = Signature::from_rs_and_parity( + U256::from_str("0xc569c92f176a3be1a6352dd5005bfc751dcb32f57623dd2a23693e64bf4447b0") + .unwrap(), + U256::from_str("0x1a891b566d369e79b7a66eecab1e008831e22daa15f91a0a0cf4f9f28f47ee05") + .unwrap(), + 1, + ) + .unwrap(); + + let bin = bincode::serialize(&signature).unwrap(); + assert_eq!(bincode::deserialize::(&bin).unwrap(), signature); + } + + #[cfg(feature = "rlp")] + #[test] + fn signature_rlp_decode() { + // Given a hex-encoded byte sequence + let bytes = crate::hex!("f84301a048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a010002cef538bc0c8e21c46080634a93e082408b0ad93f4a7207e63ec5463793d"); + + // Decode the byte sequence into a Signature instance + let result = Signature::decode(&mut &bytes[..]).unwrap(); + + // Assert that the decoded Signature matches the expected Signature + assert_eq!( + result, + Signature::from_str("48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a3664935310002cef538bc0c8e21c46080634a93e082408b0ad93f4a7207e63ec5463793d01").unwrap() + ); + } + + #[cfg(feature = "rlp")] + #[test] + fn signature_rlp_encode() { + // Given a Signature instance + let sig = Signature::from_str("48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c8041b").unwrap(); + + // Initialize an empty buffer + let mut buf = vec![]; + + // Encode the Signature into the buffer + sig.encode(&mut buf); + + // Define the expected hex-encoded string + let expected = "f8431ba048b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353a0efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c804"; + + // Assert that the encoded buffer matches the expected hex-encoded string + assert_eq!(hex::encode(&buf), expected); + } + + #[cfg(feature = "rlp")] + #[test] + fn signature_rlp_length() { + // Given a Signature instance + let sig = Signature::from_str("48b55bfa915ac795c431978d8a6a992b628d557da5ff759b307d495a36649353efffd310ac743f371de3b9f7f9cb56c0b28ad43601b4ab949f53faa07bd2c8041b").unwrap(); + + // Assert that the length of the Signature matches the expected length + assert_eq!(sig.length(), 69); + } + + #[cfg(feature = "rlp")] + #[test] + fn test_rlp_vrs_len() { + let signature = Signature::test_signature(); + assert_eq!(67, signature.rlp_vrs_len()); + } + + #[cfg(feature = "rlp")] + #[test] + fn test_encode_and_decode() { + let signature = Signature::test_signature(); + + let mut encoded = Vec::new(); + signature.encode(&mut encoded); + assert_eq!(encoded.len(), signature.length()); + let decoded = Signature::decode(&mut &*encoded).unwrap(); + assert_eq!(signature, decoded); + } + + #[test] + fn test_as_bytes() { + let signature = Signature::new( + U256::from_str( + "18515461264373351373200002665853028612451056578545711640558177340181847433846", + ) + .unwrap(), + U256::from_str( + "46948507304638947509940763649030358759909902576025900602547168820602576006531", + ) + .unwrap(), + Parity::Parity(false), + ); + + let expected = Bytes::from_hex("0x28ef61340bd939bc2195fe537567866003e1a15d3c71ff63e1590620aa63627667cbe9d8997f761aecb703304b3800ccf555c9f3dc64214b297fb1966a3b6d831b").unwrap(); + assert_eq!(signature.as_bytes(), **expected); + } +} diff --git a/CoqOfRust/alloy_primitives/signature/sig.v b/CoqOfRust/alloy_primitives/signature/sig.v new file mode 100644 index 000000000..aa20d9a2b --- /dev/null +++ b/CoqOfRust/alloy_primitives/signature/sig.v @@ -0,0 +1,2475 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module signature. + Module sig. + Definition value_SECP256K1N_ORDER : Value.t := + M.run_constant + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + "from_limbs", + [], + [] + |), + [ + Value.Array + [ + Value.Integer IntegerKind.U64 13822214165235122497; + Value.Integer IntegerKind.U64 13451932020343611451; + Value.Integer IntegerKind.U64 18446744073709551614; + Value.Integer IntegerKind.U64 18446744073709551615 + ] + ] + |) + |))). + + Axiom Constant_value_SECP256K1N_ORDER : + (M.get_constant "alloy_primitives::signature::sig::SECP256K1N_ORDER") = + value_SECP256K1N_ORDER. + Global Hint Rewrite Constant_value_SECP256K1N_ORDER : constant_rewrites. + + (* StructRecord + { + name := "Signature"; + const_params := []; + ty_params := []; + fields := + [ + ("v", Ty.path "alloy_primitives::signature::parity::Parity"); + ("r", + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []); + ("s", + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []) + ]; + } *) + + Module Impl_core_clone_Clone_for_alloy_primitives_signature_sig_Signature. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::sig::Signature". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ + fun γ => + ltac:(M.monadic + (M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.deref (| M.read (| self |) |))) ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_alloy_primitives_signature_sig_Signature. + + Module Impl_core_marker_Copy_for_alloy_primitives_signature_sig_Signature. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::sig::Signature". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_alloy_primitives_signature_sig_Signature. + + Module Impl_core_fmt_Debug_for_alloy_primitives_signature_sig_Signature. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::sig::Signature". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct_field3_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Signature" |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "v" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::sig::Signature", + "v" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "r" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::sig::Signature", + "r" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "s" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::sig::Signature", + "s" + |) + |) + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_alloy_primitives_signature_sig_Signature. + + Module Impl_core_hash_Hash_for_alloy_primitives_signature_sig_Signature. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::sig::Signature". + + (* Hash *) + Definition hash (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ __H ], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.path "alloy_primitives::signature::parity::Parity", + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::sig::Signature", + "v" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::sig::Signature", + "r" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::sig::Signature", + "s" + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::hash::Hash" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("hash", InstanceField.Method hash) ]. + End Impl_core_hash_Hash_for_alloy_primitives_signature_sig_Signature. + + Module Impl_core_marker_StructuralPartialEq_for_alloy_primitives_signature_sig_Signature. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::sig::Signature". + + Axiom Implements : + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_alloy_primitives_signature_sig_Signature. + + Module Impl_core_cmp_PartialEq_alloy_primitives_signature_sig_Signature_for_alloy_primitives_signature_sig_Signature. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::sig::Signature". + + (* PartialEq *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + LogicalOp.and (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.path "alloy_primitives::signature::parity::Parity", + [], + [ Ty.path "alloy_primitives::signature::parity::Parity" ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::sig::Signature", + "v" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::signature::sig::Signature", + "v" + |) + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + [], + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::sig::Signature", + "r" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::signature::sig::Signature", + "r" + |) + |) + ] + |))) + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + [], + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::sig::Signature", + "s" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::signature::sig::Signature", + "s" + |) + |) + ] + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::signature::sig::Signature" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_signature_sig_Signature_for_alloy_primitives_signature_sig_Signature. + + Module Impl_core_cmp_Eq_for_alloy_primitives_signature_sig_Signature. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::sig::Signature". + + (* Eq *) + Definition assert_receiver_is_total_eq + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ + fun γ => + ltac:(M.monadic + (M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method assert_receiver_is_total_eq) ]. + End Impl_core_cmp_Eq_for_alloy_primitives_signature_sig_Signature. + + Module Impl_core_convert_TryFrom_ref__slice_u8_for_alloy_primitives_signature_sig_Signature. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::sig::Signature". + + (* type Error = SignatureError; *) + Definition _Error : Ty.t := Ty.path "alloy_primitives::signature::error::SignatureError". + + (* + fn try_from(bytes: &'a [u8]) -> Result { + if bytes.len() != 65 { + return Err(SignatureError::FromBytes("expected exactly 65 bytes")); + } + Self::from_bytes_and_parity(&bytes[..64], bytes[64] as u64) + } + *) + Definition try_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ bytes ] => + ltac:(M.monadic + (let bytes := M.alloc (| bytes |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.ne (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| bytes |) |) + |) + ] + |), + Value.Integer IntegerKind.Usize 65 + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "alloy_primitives::signature::error::SignatureError::FromBytes" + [ mk_str (| "expected exactly 65 bytes" |) ] + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::signature::sig::Signature"; + Ty.path "alloy_primitives::signature::error::SignatureError" + ], + M.get_associated_function (| + Ty.path "alloy_primitives::signature::sig::Signature", + "from_bytes_and_parity", + [], + [ + Ty.path "u64"; + Ty.path "alloy_primitives::signature::error::SignatureError" + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| bytes |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 64) ] + ] + |) + |) + |) + |) + |); + M.cast + (Ty.path "u64") + (M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| bytes |) |), + Value.Integer IntegerKind.Usize 64 + |) + |)) + ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("try_from", InstanceField.Method try_from) ]. + End Impl_core_convert_TryFrom_ref__slice_u8_for_alloy_primitives_signature_sig_Signature. + + Module Impl_core_str_traits_FromStr_for_alloy_primitives_signature_sig_Signature. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::sig::Signature". + + (* type Err = SignatureError; *) + Definition _Err : Ty.t := Ty.path "alloy_primitives::signature::error::SignatureError". + + (* + fn from_str(s: &str) -> Result { + let bytes = hex::decode(s)?; + Self::try_from(&bytes[..]) + } + *) + Definition from_str (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ s ] => + ltac:(M.monadic + (let s := M.alloc (| s |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ bytes : + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ] := + M.copy (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ]), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "const_hex::error::FromHexError" + ]; + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ]; + Ty.path "const_hex::error::FromHexError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ]; + Ty.path "const_hex::error::FromHexError" + ], + M.get_function (| + "const_hex::decode", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + |), + [ M.read (| s |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::signature::sig::Signature"; + Ty.path + "alloy_primitives::signature::error::SignatureError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::signature::sig::Signature"; + Ty.path + "alloy_primitives::signature::error::SignatureError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "const_hex::error::FromHexError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::signature::sig::Signature"; + Ty.path "alloy_primitives::signature::error::SignatureError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "alloy_primitives::signature::sig::Signature", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] + ], + "try_from", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + [], + [ Ty.path "core::ops::range::RangeFull" ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, bytes |); + Value.StructTuple "core::ops::range::RangeFull" [] + ] + |) + |) + |) + ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::str::traits::FromStr" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("Err", InstanceField.Ty _Err); ("from_str", InstanceField.Method from_str) ]. + End Impl_core_str_traits_FromStr_for_alloy_primitives_signature_sig_Signature. + + Module Impl_core_convert_From_ref__alloy_primitives_signature_sig_Signature_for_array_Usize_65_u8. + Definition Self : Ty.t := + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 65 ] [ Ty.path "u8" ]. + + (* + fn from(value: &Signature) -> [u8; 65] { + value.as_bytes() + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 65 ] [ Ty.path "u8" ], + M.get_associated_function (| + Ty.path "alloy_primitives::signature::sig::Signature", + "as_bytes", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| value |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::signature::sig::Signature" ] ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref__alloy_primitives_signature_sig_Signature_for_array_Usize_65_u8. + + Module Impl_core_convert_From_alloy_primitives_signature_sig_Signature_for_array_Usize_65_u8. + Definition Self : Ty.t := + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 65 ] [ Ty.path "u8" ]. + + (* + fn from(value: Signature) -> [u8; 65] { + value.as_bytes() + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply (Ty.path "array") [ Value.Integer IntegerKind.Usize 65 ] [ Ty.path "u8" ], + M.get_associated_function (| + Ty.path "alloy_primitives::signature::sig::Signature", + "as_bytes", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::signature::sig::Signature" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_signature_sig_Signature_for_array_Usize_65_u8. + + Module Impl_core_convert_From_ref__alloy_primitives_signature_sig_Signature_for_alloc_vec_Vec_u8_alloc_alloc_Global. + Definition Self : Ty.t := + Ty.apply (Ty.path "alloc::vec::Vec") [] [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ]. + + (* + fn from(value: &Signature) -> Self { + value.as_bytes().to_vec() + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "to_vec", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 65 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.path "alloy_primitives::signature::sig::Signature", + "as_bytes", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| value |) |) |) ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.path "alloy_primitives::signature::sig::Signature" ] ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ref__alloy_primitives_signature_sig_Signature_for_alloc_vec_Vec_u8_alloc_alloc_Global. + + Module Impl_core_convert_From_alloy_primitives_signature_sig_Signature_for_alloc_vec_Vec_u8_alloc_alloc_Global. + Definition Self : Ty.t := + Ty.apply (Ty.path "alloc::vec::Vec") [] [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ]. + + (* + fn from(value: Signature) -> Self { + value.as_bytes().to_vec() + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "to_vec", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 65 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.path "alloy_primitives::signature::sig::Signature", + "as_bytes", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::signature::sig::Signature" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_signature_sig_Signature_for_alloc_vec_Vec_u8_alloc_alloc_Global. + + Module Impl_alloy_primitives_signature_sig_Signature. + Definition Self : Ty.t := Ty.path "alloy_primitives::signature::sig::Signature". + + (* + pub fn test_signature() -> Self { + Self::from_scalars_and_parity( + b256!("840cfc572845f5786e702984c2a582528cad4b49b2a10b9db1be7fca90058565"), + b256!("25e7109ceb98168d95b09b18bbf6b685130e0562f233877d492b94eee0c5b6d1"), + false, + ) + .unwrap() + } + *) + Definition test_signature (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.call_closure (| + Ty.path "alloy_primitives::signature::sig::Signature", + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::signature::sig::Signature"; + Ty.path "alloy_primitives::signature::error::SignatureError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::signature::sig::Signature"; + Ty.path "alloy_primitives::signature::error::SignatureError" + ], + M.get_associated_function (| + Ty.path "alloy_primitives::signature::sig::Signature", + "from_scalars_and_parity", + [], + [ Ty.path "bool"; Ty.path "core::convert::Infallible" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + "new", + [], + [] + |), + [ + M.read (| + M.get_constant "alloy_primitives::signature::sig::test_signature::RES" + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + "new", + [], + [] + |), + [ + M.read (| + M.get_constant "alloy_primitives::signature::sig::test_signature::RES'1" + |) + ] + |); + Value.Bool false + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_test_signature : + M.IsAssociatedFunction.Trait Self "test_signature" test_signature. + Admitted. + Global Typeclasses Opaque test_signature. + + (* + pub fn new(r: U256, s: U256, v: Parity) -> Self { + Self { r, s, v } + } + *) + Definition new (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ r; s; v ] => + ltac:(M.monadic + (let r := M.alloc (| r |) in + let s := M.alloc (| s |) in + let v := M.alloc (| v |) in + Value.StructRecord + "alloy_primitives::signature::sig::Signature" + [ ("r", M.read (| r |)); ("s", M.read (| s |)); ("v", M.read (| v |)) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : M.IsAssociatedFunction.Trait Self "new" new. + Admitted. + Global Typeclasses Opaque new. + + (* + pub fn from_scalars_and_parity, E: Into>( + r: crate::B256, + s: crate::B256, + parity: T, + ) -> Result { + Self::from_rs_and_parity( + U256::from_be_slice(r.as_ref()), + U256::from_be_slice(s.as_ref()), + parity, + ) + } + *) + Definition from_scalars_and_parity + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [ T; E ], [ r; s; parity ] => + ltac:(M.monadic + (let r := M.alloc (| r |) in + let s := M.alloc (| s |) in + let parity := M.alloc (| parity |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::signature::sig::Signature"; + Ty.path "alloy_primitives::signature::error::SignatureError" + ], + M.get_associated_function (| + Ty.path "alloy_primitives::signature::sig::Signature", + "from_rs_and_parity", + [], + [ T; E ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + "from_be_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "as_ref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, r |) ] + |) + |) + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + "from_be_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::convert::AsRef", + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "as_ref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, s |) ] + |) + |) + |) + ] + |); + M.read (| parity |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_scalars_and_parity : + M.IsAssociatedFunction.Trait Self "from_scalars_and_parity" from_scalars_and_parity. + Admitted. + Global Typeclasses Opaque from_scalars_and_parity. + + (* + pub fn normalize_s(&self) -> Option { + let s = self.s(); + + if s > SECP256K1N_ORDER >> 1 { + Some(Self { v: self.v.inverted(), r: self.r, s: SECP256K1N_ORDER - s }) + } else { + None + } + } + *) + Definition normalize_s (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ s : + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.path "alloy_primitives::signature::sig::Signature", + "s", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "alloy_primitives::signature::sig::Signature" ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + [], + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ], + "gt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, s |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + M.get_trait_method (| + "core::ops::bit::Shr", + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + [], + [ Ty.path "i32" ], + "shr", + [], + [] + |), + [ + M.read (| + M.get_constant + "alloy_primitives::signature::sig::SECP256K1N_ORDER" + |); + Value.Integer IntegerKind.I32 1 + ] + |) + |) + |) + ] + |) + |)) in + let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + Value.StructRecord + "alloy_primitives::signature::sig::Signature" + [ + ("v", + M.call_closure (| + Ty.path "alloy_primitives::signature::parity::Parity", + M.get_associated_function (| + Ty.path "alloy_primitives::signature::parity::Parity", + "inverted", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::sig::Signature", + "v" + |) + |) + ] + |)); + ("r", + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::sig::Signature", + "r" + |) + |)); + ("s", + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + [], + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ], + "sub", + [], + [] + |), + [ + M.read (| + M.get_constant + "alloy_primitives::signature::sig::SECP256K1N_ORDER" + |); + M.read (| s |) + ] + |)) + ] + ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.StructTuple "core::option::Option::None" [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_normalize_s : + M.IsAssociatedFunction.Trait Self "normalize_s" normalize_s. + Admitted. + Global Typeclasses Opaque normalize_s. + + (* + pub fn from_bytes_and_parity, E: Into>( + bytes: &[u8], + parity: T, + ) -> Result { + let r = U256::from_be_slice(&bytes[..32]); + let s = U256::from_be_slice(&bytes[32..64]); + Self::from_rs_and_parity(r, s, parity) + } + *) + Definition from_bytes_and_parity (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T; E ], [ bytes; parity ] => + ltac:(M.monadic + (let bytes := M.alloc (| bytes |) in + let parity := M.alloc (| parity |) in + M.read (| + let~ r : + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + "from_be_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| bytes |) |) |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 32) ] + ] + |) + |) + |) + |) + |) + ] + |) + |) in + let~ s : + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + "from_be_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::Range") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| bytes |) |) |); + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 32); + ("end_", Value.Integer IntegerKind.Usize 64) + ] + ] + |) + |) + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::signature::sig::Signature"; + Ty.path "alloy_primitives::signature::error::SignatureError" + ], + M.get_associated_function (| + Ty.path "alloy_primitives::signature::sig::Signature", + "from_rs_and_parity", + [], + [ T; E ] + |), + [ M.read (| r |); M.read (| s |); M.read (| parity |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_bytes_and_parity : + M.IsAssociatedFunction.Trait Self "from_bytes_and_parity" from_bytes_and_parity. + Admitted. + Global Typeclasses Opaque from_bytes_and_parity. + + (* + pub fn from_rs_and_parity, E: Into>( + r: U256, + s: U256, + parity: T, + ) -> Result { + Ok(Self { v: parity.try_into().map_err(Into::into)?, r, s }) + } + *) + Definition from_rs_and_parity (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T; E ], [ r; s; parity ] => + ltac:(M.monadic + (let r := M.alloc (| r |) in + let s := M.alloc (| s |) in + let parity := M.alloc (| parity |) in + M.catch_return (| + ltac:(M.monadic + (Value.StructTuple + "core::result::Result::Ok" + [ + Value.StructRecord + "alloy_primitives::signature::sig::Signature" + [ + ("v", + M.read (| + M.match_operator (| + Some (Ty.path "alloy_primitives::signature::parity::Parity"), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signature::error::SignatureError" + ]; + Ty.path "alloy_primitives::signature::parity::Parity" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::signature::parity::Parity"; + Ty.path "alloy_primitives::signature::error::SignatureError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::signature::parity::Parity"; + Ty.path + "alloy_primitives::signature::error::SignatureError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "alloy_primitives::signature::parity::Parity"; E + ], + "map_err", + [], + [ + Ty.path + "alloy_primitives::signature::error::SignatureError"; + Ty.function + [ E ] + (Ty.path + "alloy_primitives::signature::error::SignatureError") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::signature::parity::Parity"; + E + ], + M.get_trait_method (| + "core::convert::TryInto", + T, + [], + [ Ty.path "alloy_primitives::signature::parity::Parity" + ], + "try_into", + [], + [] + |), + [ M.read (| parity |) ] + |); + M.get_trait_method (| + "core::convert::Into", + E, + [], + [ + Ty.path + "alloy_primitives::signature::error::SignatureError" + ], + "into", + [], + [] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "alloy_primitives::signature::sig::Signature"; + Ty.path + "alloy_primitives::signature::error::SignatureError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "alloy_primitives::signature::sig::Signature"; + Ty.path + "alloy_primitives::signature::error::SignatureError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signature::error::SignatureError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |)); + ("r", M.read (| r |)); + ("s", M.read (| s |)) + ] + ])) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_rs_and_parity : + M.IsAssociatedFunction.Trait Self "from_rs_and_parity" from_rs_and_parity. + Admitted. + Global Typeclasses Opaque from_rs_and_parity. + + (* + pub fn with_chain_id(self, chain_id: u64) -> Self { + self.with_parity(self.v.with_chain_id(chain_id)) + } + *) + Definition with_chain_id (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; chain_id ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let chain_id := M.alloc (| chain_id |) in + M.call_closure (| + Ty.path "alloy_primitives::signature::sig::Signature", + M.get_associated_function (| + Ty.path "alloy_primitives::signature::sig::Signature", + "with_parity", + [], + [ Ty.path "alloy_primitives::signature::parity::Parity" ] + |), + [ + M.read (| self |); + M.call_closure (| + Ty.path "alloy_primitives::signature::parity::Parity", + M.get_associated_function (| + Ty.path "alloy_primitives::signature::parity::Parity", + "with_chain_id", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "alloy_primitives::signature::sig::Signature", + "v" + |) + |); + M.read (| chain_id |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_with_chain_id : + M.IsAssociatedFunction.Trait Self "with_chain_id" with_chain_id. + Admitted. + Global Typeclasses Opaque with_chain_id. + + (* + pub fn with_parity_bool(self) -> Self { + self.with_parity(self.v.to_parity_bool()) + } + *) + Definition with_parity_bool (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "alloy_primitives::signature::sig::Signature", + M.get_associated_function (| + Ty.path "alloy_primitives::signature::sig::Signature", + "with_parity", + [], + [ Ty.path "alloy_primitives::signature::parity::Parity" ] + |), + [ + M.read (| self |); + M.call_closure (| + Ty.path "alloy_primitives::signature::parity::Parity", + M.get_associated_function (| + Ty.path "alloy_primitives::signature::parity::Parity", + "to_parity_bool", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "alloy_primitives::signature::sig::Signature", + "v" + |) + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_with_parity_bool : + M.IsAssociatedFunction.Trait Self "with_parity_bool" with_parity_bool. + Admitted. + Global Typeclasses Opaque with_parity_bool. + + (* + pub const fn r(&self) -> U256 { + self.r + } + *) + Definition r (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::sig::Signature", + "r" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_r : M.IsAssociatedFunction.Trait Self "r" r. + Admitted. + Global Typeclasses Opaque r. + + (* + pub const fn s(&self) -> U256 { + self.s + } + *) + Definition s (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::sig::Signature", + "s" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_s : M.IsAssociatedFunction.Trait Self "s" s. + Admitted. + Global Typeclasses Opaque s. + + (* + pub const fn v(&self) -> Parity { + self.v + } + *) + Definition v (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::sig::Signature", + "v" + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_v : M.IsAssociatedFunction.Trait Self "v" v. + Admitted. + Global Typeclasses Opaque v. + + (* + pub const fn chain_id(&self) -> Option { + self.v.chain_id() + } + *) + Definition chain_id (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "u64" ], + M.get_associated_function (| + Ty.path "alloy_primitives::signature::parity::Parity", + "chain_id", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::sig::Signature", + "v" + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_chain_id : + M.IsAssociatedFunction.Trait Self "chain_id" chain_id. + Admitted. + Global Typeclasses Opaque chain_id. + + (* + pub const fn has_eip155_value(&self) -> bool { + self.v().has_eip155_value() + } + *) + Definition has_eip155_value (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "alloy_primitives::signature::parity::Parity", + "has_eip155_value", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::signature::parity::Parity", + M.get_associated_function (| + Ty.path "alloy_primitives::signature::sig::Signature", + "v", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_has_eip155_value : + M.IsAssociatedFunction.Trait Self "has_eip155_value" has_eip155_value. + Admitted. + Global Typeclasses Opaque has_eip155_value. + + (* + pub fn as_bytes(&self) -> [u8; 65] { + let mut sig = [0u8; 65]; + sig[..32].copy_from_slice(&self.r.to_be_bytes::<32>()); + sig[32..64].copy_from_slice(&self.s.to_be_bytes::<32>()); + sig[64] = self.v.y_parity_byte_non_eip155().unwrap_or(self.v.y_parity_byte()); + sig + } + *) + Definition as_bytes (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ sig : + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 65 ] + [ Ty.path "u8" ] := + M.alloc (| + repeat (| Value.Integer IntegerKind.U8 0, Value.Integer IntegerKind.Usize 65 |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "copy_from_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 65 ] + [ Ty.path "u8" ], + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, sig |); + Value.StructRecord + "core::ops::range::RangeTo" + [ ("end_", Value.Integer IntegerKind.Usize 32) ] + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + "to_be_bytes", + [ Value.Integer IntegerKind.Usize 32 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::sig::Signature", + "r" + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "copy_from_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::ops::index::IndexMut", + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 65 ] + [ Ty.path "u8" ], + [], + [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] + ], + "index_mut", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, sig |); + Value.StructRecord + "core::ops::range::Range" + [ + ("start", Value.Integer IntegerKind.Usize 32); + ("end_", Value.Integer IntegerKind.Usize 64) + ] + ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + "to_be_bytes", + [ Value.Integer IntegerKind.Usize 32 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::sig::Signature", + "s" + |) + |) + ] + |) + |) + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| sig, Value.Integer IntegerKind.Usize 64 |), + M.call_closure (| + Ty.path "u8", + M.get_associated_function (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "u8" ], + "unwrap_or", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "u8" ], + M.get_associated_function (| + Ty.path "alloy_primitives::signature::parity::Parity", + "y_parity_byte_non_eip155", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::sig::Signature", + "v" + |) + |) + ] + |); + M.call_closure (| + Ty.path "u8", + M.get_associated_function (| + Ty.path "alloy_primitives::signature::parity::Parity", + "y_parity_byte", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signature::sig::Signature", + "v" + |) + |) + ] + |) + ] + |) + |) + |) in + sig + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_as_bytes : + M.IsAssociatedFunction.Trait Self "as_bytes" as_bytes. + Admitted. + Global Typeclasses Opaque as_bytes. + + (* + pub fn with_parity>(self, parity: T) -> Self { + Self { v: parity.into(), r: self.r, s: self.s } + } + *) + Definition with_parity (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ self; parity ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let parity := M.alloc (| parity |) in + Value.StructRecord + "alloy_primitives::signature::sig::Signature" + [ + ("v", + M.call_closure (| + Ty.path "alloy_primitives::signature::parity::Parity", + M.get_trait_method (| + "core::convert::Into", + T, + [], + [ Ty.path "alloy_primitives::signature::parity::Parity" ], + "into", + [], + [] + |), + [ M.read (| parity |) ] + |)); + ("r", + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "alloy_primitives::signature::sig::Signature", + "r" + |) + |)); + ("s", + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "alloy_primitives::signature::sig::Signature", + "s" + |) + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_with_parity : + M.IsAssociatedFunction.Trait Self "with_parity" with_parity. + Admitted. + Global Typeclasses Opaque with_parity. + End Impl_alloy_primitives_signature_sig_Signature. + End sig. +End signature. diff --git a/CoqOfRust/alloy_primitives/signature/utils.rs b/CoqOfRust/alloy_primitives/signature/utils.rs new file mode 100644 index 000000000..bba5f9d03 --- /dev/null +++ b/CoqOfRust/alloy_primitives/signature/utils.rs @@ -0,0 +1,116 @@ +use crate::ChainId; + +/// Applies [EIP-155](https://eips.ethereum.org/EIPS/eip-155). +#[inline] +pub const fn to_eip155_v(v: u8, chain_id: ChainId) -> ChainId { + (v as u64) + 35 + chain_id * 2 +} + +/// Attempts to normalize the v value to a boolean parity value. +/// +/// Returns `None` if the value is invalid for any of the known Ethereum parity encodings. +pub const fn normalize_v(v: u64) -> Option { + if !is_valid_v(v) { + return None; + } + + // Simplifying: + // 0| 1 => v % 2 == 0 + // 27|28 => (v - 27) % 2 == 0 + // 35.. => (v - 35) % 2 == 0 + // --- + // 0| 1 => v % 2 == 0 + // 27|28 => v % 2 == 1 + // 35.. => v % 2 == 1 + // --- + // ..2 => v % 2 == 0 + // _ => v % 2 == 1 + let cmp = (v <= 1) as u64; + Some(v % 2 == cmp) +} + +/// Returns `true` if the given `v` value is valid for any of the known Ethereum parity encodings. +#[inline] +const fn is_valid_v(v: u64) -> bool { + matches!( + v, + // Case 1: raw/bare + 0 | 1 + // Case 2: non-EIP-155 v value + | 27 | 28 + // Case 3: EIP-155 V value + | 35.. + ) +} + +/// Normalizes a `v` value, respecting raw, legacy, and EIP-155 values. +/// +/// This function covers the entire u64 range, producing v-values as follows: +/// - 0-26 - raw/bare. 0-3 are legal. In order to ensure that all values are covered, we also handle +/// 4-26 here by returning v % 4. +/// - 27-34 - legacy. 27-30 are legal. By legacy bitcoin convention range 27-30 signals uncompressed +/// pubkeys, while 31-34 signals compressed pubkeys. We do not respect the compression convention. +/// All Ethereum keys are uncompressed. +/// - 35+ - EIP-155. By EIP-155 convention, `v = 35 + CHAIN_ID * 2 + 0/1` We return (v-1 % 2) here. +/// +/// NB: raw and legacy support values 2, and 3, while EIP-155 does not. +/// Recovery values of 2 and 3 are unlikely to occur in practice. In the +/// vanishingly unlikely event that you encounter an EIP-155 signature with a +/// recovery value of 2 or 3, you should normalize out of band. +#[cfg(feature = "k256")] +#[inline] +pub(crate) const fn normalize_v_to_recid(v: u64) -> k256::ecdsa::RecoveryId { + let byte = normalize_v_to_byte(v); + debug_assert!(byte <= k256::ecdsa::RecoveryId::MAX); + match k256::ecdsa::RecoveryId::from_byte(byte) { + Some(recid) => recid, + None => unsafe { core::hint::unreachable_unchecked() }, + } +} + +/// Normalize the v value to a single byte. +pub(crate) const fn normalize_v_to_byte(v: u64) -> u8 { + match v { + // Case 1: raw/bare + 0..=26 => (v % 4) as u8, + // Case 2: non-EIP-155 v value + 27..=34 => ((v - 27) % 4) as u8, + // Case 3: EIP-155 V value + 35.. => ((v - 1) % 2) as u8, + } +} + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn normalizes_v() { + assert_eq!(normalize_v(0), Some(false)); + assert_eq!(normalize_v(1), Some(true)); + + for invalid_v in 2..27 { + assert_eq!(normalize_v(invalid_v), None); + } + + assert_eq!(normalize_v(27), Some(false)); + assert_eq!(normalize_v(28), Some(true)); + + for invalid_v in 29..35 { + assert_eq!(normalize_v(invalid_v), None); + } + + assert_eq!(normalize_v(35), Some(false)); + assert_eq!(normalize_v(36), Some(true)); + for v in 35..100 { + assert_eq!(normalize_v(v), Some((v - 35) % 2 != 0)); + } + } + + #[test] + #[cfg(feature = "k256")] + fn normalizes_v_to_recid() { + assert_eq!(normalize_v_to_recid(27), k256::ecdsa::RecoveryId::from_byte(0).unwrap()); + assert_eq!(normalize_v_to_recid(28), k256::ecdsa::RecoveryId::from_byte(1).unwrap()); + } +} diff --git a/CoqOfRust/alloy_primitives/signature/utils.v b/CoqOfRust/alloy_primitives/signature/utils.v new file mode 100644 index 000000000..d386e6446 --- /dev/null +++ b/CoqOfRust/alloy_primitives/signature/utils.v @@ -0,0 +1,264 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module signature. + Module utils. + (* + pub const fn to_eip155_v(v: u8, chain_id: ChainId) -> ChainId { + (v as u64) + 35 + chain_id * 2 + } + *) + Definition to_eip155_v (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ v; chain_id ] => + ltac:(M.monadic + (let v := M.alloc (| v |) in + let chain_id := M.alloc (| chain_id |) in + BinOp.Wrap.add (| + BinOp.Wrap.add (| + M.cast (Ty.path "u64") (M.read (| v |)), + Value.Integer IntegerKind.U64 35 + |), + BinOp.Wrap.mul (| M.read (| chain_id |), Value.Integer IntegerKind.U64 2 |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_to_eip155_v : + M.IsFunction.Trait "alloy_primitives::signature::utils::to_eip155_v" to_eip155_v. + Admitted. + Global Typeclasses Opaque to_eip155_v. + + (* + pub const fn normalize_v(v: u64) -> Option { + if !is_valid_v(v) { + return None; + } + + // Simplifying: + // 0| 1 => v % 2 == 0 + // 27|28 => (v - 27) % 2 == 0 + // 35.. => (v - 35) % 2 == 0 + // --- + // 0| 1 => v % 2 == 0 + // 27|28 => v % 2 == 1 + // 35.. => v % 2 == 1 + // --- + // ..2 => v % 2 == 0 + // _ => v % 2 == 1 + let cmp = (v <= 1) as u64; + Some(v % 2 == cmp) + } + *) + Definition normalize_v (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ v ] => + ltac:(M.monadic + (let v := M.alloc (| v |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_function (| + "alloy_primitives::signature::utils::is_valid_v", + [], + [] + |), + [ M.read (| v |) ] + |) + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| Value.StructTuple "core::option::Option::None" [] |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ cmp : Ty.path "u64" := + M.alloc (| + M.cast + (Ty.path "u64") + (BinOp.le (| M.read (| v |), Value.Integer IntegerKind.U64 1 |)) + |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + BinOp.eq (| + BinOp.Wrap.rem (| M.read (| v |), Value.Integer IntegerKind.U64 2 |), + M.read (| cmp |) + |) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_normalize_v : + M.IsFunction.Trait "alloy_primitives::signature::utils::normalize_v" normalize_v. + Admitted. + Global Typeclasses Opaque normalize_v. + + (* + const fn is_valid_v(v: u64) -> bool { + matches!( + v, + // Case 1: raw/bare + 0 | 1 + // Case 2: non-EIP-155 v value + | 27 | 28 + // Case 3: EIP-155 V value + | 35.. + ) + } + *) + Definition is_valid_v (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ v ] => + ltac:(M.monadic + (let v := M.alloc (| v |) in + M.read (| + M.match_operator (| + Some (Ty.path "bool"), + v, + [ + fun γ => + ltac:(M.monadic + (M.find_or_pattern (| + γ, + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.U64 0 + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.U64 1 + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.U64 27 + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Integer IntegerKind.U64 28 + |) in + Value.Tuple [])); + fun γ => ltac:(M.monadic (Value.Tuple [])) + ], + fun γ => + ltac:(M.monadic + match γ with + | [] => ltac:(M.monadic (M.alloc (| Value.Bool true |))) + | _ => M.impossible "wrong number of arguments" + end) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Bool false |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_is_valid_v : + M.IsFunction.Trait "alloy_primitives::signature::utils::is_valid_v" is_valid_v. + Admitted. + Global Typeclasses Opaque is_valid_v. + + (* + pub(crate) const fn normalize_v_to_byte(v: u64) -> u8 { + match v { + // Case 1: raw/bare + 0..=26 => (v % 4) as u8, + // Case 2: non-EIP-155 v value + 27..=34 => ((v - 27) % 4) as u8, + // Case 3: EIP-155 V value + 35.. => ((v - 1) % 2) as u8, + } + } + *) + Definition normalize_v_to_byte (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ v ] => + ltac:(M.monadic + (let v := M.alloc (| v |) in + M.read (| + M.match_operator (| + Some (Ty.path "u8"), + v, + [ + fun γ => + ltac:(M.monadic + (M.alloc (| + M.cast + (Ty.path "u8") + (BinOp.Wrap.rem (| M.read (| v |), Value.Integer IntegerKind.U64 4 |)) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.cast + (Ty.path "u8") + (BinOp.Wrap.rem (| + BinOp.Wrap.sub (| M.read (| v |), Value.Integer IntegerKind.U64 27 |), + Value.Integer IntegerKind.U64 4 + |)) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.cast + (Ty.path "u8") + (BinOp.Wrap.rem (| + BinOp.Wrap.sub (| M.read (| v |), Value.Integer IntegerKind.U64 1 |), + Value.Integer IntegerKind.U64 2 + |)) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_normalize_v_to_byte : + M.IsFunction.Trait + "alloy_primitives::signature::utils::normalize_v_to_byte" + normalize_v_to_byte. + Admitted. + Global Typeclasses Opaque normalize_v_to_byte. + End utils. +End signature. diff --git a/CoqOfRust/alloy_primitives/signed/conversions.rs b/CoqOfRust/alloy_primitives/signed/conversions.rs new file mode 100644 index 000000000..b7de1adf3 --- /dev/null +++ b/CoqOfRust/alloy_primitives/signed/conversions.rs @@ -0,0 +1,237 @@ +use super::{utils::twos_complement, BigIntConversionError, ParseSignedError, Sign, Signed}; +use alloc::string::String; +use core::str::FromStr; +use ruint::Uint; + +impl TryFrom> for Signed { + type Error = BigIntConversionError; + + #[inline] + fn try_from(from: Uint) -> Result { + let value = Self(from); + match value.sign() { + Sign::Positive => Ok(value), + Sign::Negative => Err(BigIntConversionError), + } + } +} + +impl TryFrom> for Uint { + type Error = BigIntConversionError; + + #[inline] + fn try_from(value: Signed) -> Result { + match value.sign() { + Sign::Positive => Ok(value.0), + Sign::Negative => Err(BigIntConversionError), + } + } +} + +impl TryFrom<&str> for Signed { + type Error = ParseSignedError; + + #[inline] + fn try_from(value: &str) -> Result { + Self::from_str(value) + } +} + +impl TryFrom<&String> for Signed { + type Error = ParseSignedError; + + #[inline] + fn try_from(value: &String) -> Result { + value.parse() + } +} + +impl TryFrom for Signed { + type Error = ParseSignedError; + + #[inline] + fn try_from(value: String) -> Result { + value.parse() + } +} + +impl FromStr for Signed { + type Err = ParseSignedError; + + #[inline] + fn from_str(s: &str) -> Result { + let (sign, s) = match s.as_bytes().first() { + Some(b'+') => (Sign::Positive, &s[1..]), + Some(b'-') => (Sign::Negative, &s[1..]), + _ => (Sign::Positive, s), + }; + let abs = Uint::::from_str(s)?; + Self::checked_from_sign_and_abs(sign, abs).ok_or(ParseSignedError::IntegerOverflow) + } +} + +impl TryFrom> for i128 { + type Error = BigIntConversionError; + + fn try_from(value: Signed) -> Result { + if value.bits() > 128 { + return Err(BigIntConversionError); + } + + if value.is_positive() { + Ok(u128::try_from(value.0).unwrap() as Self) + } else { + let u = twos_complement(value.0); + let u = u128::try_from(u).unwrap() as Self; + Ok((!u).wrapping_add(1)) + } + } +} + +impl TryFrom for Signed { + type Error = BigIntConversionError; + + fn try_from(value: i128) -> Result { + let u = value as u128; + if value >= 0 { + return Self::try_from(u); + } + + // This is a bit messy :( + let tc = (!u).wrapping_add(1); + let stc = Uint::<128, 2>::saturating_from(tc); + let (num, overflow) = Uint::::overflowing_from_limbs_slice(stc.as_limbs()); + if overflow { + return Err(BigIntConversionError); + } + Ok(Self(twos_complement(num))) + } +} + +impl TryFrom> for u128 { + type Error = BigIntConversionError; + + fn try_from(value: Signed) -> Result { + if value.is_negative() { + return Err(BigIntConversionError); + } + + let saturated = Uint::::saturating_from(Self::MAX); + + // if the value is greater than the saturated value, return an error + if value > Signed(saturated) { + return Err(BigIntConversionError); + } + + value.into_raw().try_into().map_err(|_| BigIntConversionError) + } +} + +impl TryFrom for Signed { + type Error = BigIntConversionError; + + fn try_from(value: u128) -> Result { + let saturated = Uint::::saturating_from(value); + + if value != saturated.to::() { + return Err(BigIntConversionError); + } + + Self::try_from(saturated) + } +} + +// conversions +macro_rules! impl_conversions { + ($( + $u:ty [$actual_low_u:ident -> $low_u:ident, $as_u:ident], + $i:ty [$actual_low_i:ident -> $low_i:ident, $as_i:ident]; + )+) => { + // low_*, as_* + impl Signed { + $( + impl_conversions!(@impl_fns $u, $actual_low_u $low_u $as_u); + impl_conversions!(@impl_fns $i, $actual_low_i $low_i $as_i); + )+ + } + + // From<$>, TryFrom + $( + impl TryFrom<$u> for Signed { + type Error = BigIntConversionError; + + #[inline] + fn try_from(value: $u) -> Result { + let u = Uint::::try_from(value).map_err(|_| BigIntConversionError)?; + Signed::checked_from_sign_and_abs(Sign::Positive, u).ok_or(BigIntConversionError) + } + } + + impl TryFrom<$i> for Signed { + type Error = BigIntConversionError; + + #[inline] + fn try_from(value: $i) -> Result { + let uint: $u = value as $u; + + if value.is_positive() { + return Self::try_from(uint); + } + + let abs = (!uint).wrapping_add(1); + let tc = twos_complement(Uint::::from(abs)); + Ok(Self(tc)) + } + } + + impl TryFrom> for $u { + type Error = BigIntConversionError; + + #[inline] + fn try_from(value: Signed) -> Result<$u, Self::Error> { + u128::try_from(value)?.try_into().map_err(|_| BigIntConversionError) + } + } + + impl TryFrom> for $i { + type Error = BigIntConversionError; + + #[inline] + fn try_from(value: Signed) -> Result<$i, Self::Error> { + i128::try_from(value)?.try_into().map_err(|_| BigIntConversionError) + } + } + )+ + }; + + (@impl_fns $t:ty, $actual_low:ident $low:ident $as:ident) => { + /// Low word. + #[inline] + pub const fn $low(&self) -> $t { + if BITS == 0 { + return 0 + } + + self.0.as_limbs()[0] as $t + } + + #[doc = concat!("Conversion to ", stringify!($t) ," with overflow checking.")] + /// + /// # Panics + /// + #[doc = concat!("Panics if the number is outside the ", stringify!($t), " valid range.")] + #[inline] + #[track_caller] + pub fn $as(&self) -> $t { + <$t as TryFrom>::try_from(*self).unwrap() + } + }; +} + +impl_conversions! { + u8 [low_u64 -> low_u8, as_u8], i8 [low_u64 -> low_i8, as_i8]; + u16 [low_u64 -> low_u16, as_u16], i16 [low_u64 -> low_i16, as_i16]; + u32 [low_u64 -> low_u32, as_u32], i32 [low_u64 -> low_i32, as_i32]; + u64 [low_u64 -> low_u64, as_u64], i64 [low_u64 -> low_i64, as_i64]; + usize[low_u64 -> low_usize, as_usize], isize[low_u64 -> low_isize, as_isize]; +} diff --git a/CoqOfRust/alloy_primitives/signed/conversions.v b/CoqOfRust/alloy_primitives/signed/conversions.v new file mode 100644 index 000000000..20223c593 --- /dev/null +++ b/CoqOfRust/alloy_primitives/signed/conversions.v @@ -0,0 +1,8091 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module signed. + Module conversions. + Module Impl_core_convert_TryFrom_ruint_Uint_BITS_LIMBS_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(from: Uint) -> Result { + let value = Self(from); + match value.sign() { + Sign::Positive => Ok(value), + Sign::Negative => Err(BigIntConversionError), + } + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ from ] => + ltac:(M.monadic + (let from := M.alloc (| from |) in + M.read (| + let~ value : + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] := + M.alloc (| + Value.StructTuple "alloy_primitives::signed::int::Signed" [ M.read (| from |) ] + |) in + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ]), + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + M.alloc (| + Value.StructTuple "core::result::Result::Ok" [ M.read (| value |) ] + |))); + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [] + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_ruint_Uint_BITS_LIMBS_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_ruint_Uint_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []. + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(value: Signed) -> Result { + match value.sign() { + Sign::Positive => Ok(value.0), + Sign::Negative => Err(BigIntConversionError), + } + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ]), + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |))); + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [] + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_ruint_Uint_BITS_LIMBS. + + Module Impl_core_convert_TryFrom_ref__str_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Error = ParseSignedError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::ParseSignedError". + + (* + fn try_from(value: &str) -> Result { + Self::from_str(value) + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []; + Ty.path "alloy_primitives::signed::errors::ParseSignedError" + ], + M.get_trait_method (| + "core::str::traits::FromStr", + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + [], + [], + "from_str", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| value |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_ref__str_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_convert_TryFrom_ref__alloc_string_String_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Error = ParseSignedError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::ParseSignedError". + + (* + fn try_from(value: &String) -> Result { + value.parse() + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []; + Ty.path "alloy_primitives::signed::errors::ParseSignedError" + ], + M.get_associated_function (| + Ty.path "str", + "parse", + [], + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloc::string::String", + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| value |) |) |) ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.path "alloc::string::String" ] ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_ref__alloc_string_String_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_convert_TryFrom_alloc_string_String_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Error = ParseSignedError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::ParseSignedError". + + (* + fn try_from(value: String) -> Result { + value.parse() + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []; + Ty.path "alloy_primitives::signed::errors::ParseSignedError" + ], + M.get_associated_function (| + Ty.path "str", + "parse", + [], + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloc::string::String", + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloc::string::String" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_alloc_string_String_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_str_traits_FromStr_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Err = ParseSignedError; *) + Definition _Err (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::ParseSignedError". + + (* + fn from_str(s: &str) -> Result { + let (sign, s) = match s.as_bytes().first() { + Some(b'+') => (Sign::Positive, &s[1..]), + Some(b'-') => (Sign::Negative, &s[1..]), + _ => (Sign::Positive, s), + }; + let abs = Uint::::from_str(s)?; + Self::checked_from_sign_and_abs(sign, abs).ok_or(ParseSignedError::IntegerOverflow) + } + *) + Definition from_str + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ s ] => + ltac:(M.monadic + (let s := M.alloc (| s |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + M.match_operator (| + None, + M.match_operator (| + Some + (Ty.tuple + [ + Ty.path "alloy_primitives::signed::sign::Sign"; + Ty.apply (Ty.path "&") [] [ Ty.path "str" ] + ]), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "u8" ] ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "first", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_associated_function (| Ty.path "str", "as_bytes", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| s |) |) |) ] + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ0_0 := M.read (| γ0_0 |) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.U8 43 + |) in + M.alloc (| + Value.Tuple + [ + Value.StructTuple + "alloy_primitives::signed::sign::Sign::Positive" + []; + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.path "str", + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| s |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ0_0 := M.read (| γ0_0 |) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.U8 45 + |) in + M.alloc (| + Value.Tuple + [ + Value.StructTuple + "alloy_primitives::signed::sign::Sign::Negative" + []; + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.path "str", + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| s |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple + [ + Value.StructTuple + "alloy_primitives::signed::sign::Sign::Positive" + []; + M.read (| s |) + ] + |))) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let sign := M.copy (| γ0_0 |) in + let s := M.copy (| γ0_1 |) in + let~ abs : Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] := + M.copy (| + M.match_operator (| + Some (Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "ruint::string::ParseError" + ]; + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.path "ruint::string::ParseError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.path "ruint::string::ParseError" + ], + M.get_trait_method (| + "core::str::traits::FromStr", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [], + "from_str", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| s |) |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path + "alloy_primitives::signed::errors::ParseSignedError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path + "alloy_primitives::signed::errors::ParseSignedError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "ruint::string::ParseError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "alloy_primitives::signed::errors::ParseSignedError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "ok_or", + [], + [ Ty.path "alloy_primitives::signed::errors::ParseSignedError" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "checked_from_sign_and_abs", + [], + [] + |), + [ M.read (| sign |); M.read (| abs |) ] + |); + Value.StructTuple + "alloy_primitives::signed::errors::ParseSignedError::IntegerOverflow" + [] + ] + |) + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::str::traits::FromStr" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self BITS LIMBS) + (* Instance *) + [ + ("Err", InstanceField.Ty (_Err BITS LIMBS)); + ("from_str", InstanceField.Method (from_str BITS LIMBS)) + ]. + End Impl_core_str_traits_FromStr_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_i128. + Definition Self (BITS LIMBS : Value.t) : Ty.t := Ty.path "i128". + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(value: Signed) -> Result { + if value.bits() > 128 { + return Err(BigIntConversionError); + } + + if value.is_positive() { + Ok(u128::try_from(value.0).unwrap() as Self) + } else { + let u = twos_complement(value.0); + let u = u128::try_from(u).unwrap() as Self; + Ok((!u).wrapping_add(1)) + } + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.gt (| + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "bits", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |), + Value.Integer IntegerKind.U32 128 + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [] + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i128"; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "is_positive", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + M.cast + (Ty.path "i128") + (M.call_closure (| + Ty.path "u128", + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u128"; + Ty.apply + (Ty.path "ruint::from::FromUintError") + [] + [ Ty.path "u128" ] + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u128"; + Ty.apply + (Ty.path "ruint::from::FromUintError") + [] + [ Ty.path "u128" ] + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "u128", + [], + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ], + "try_from", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |) + ] + |)) + ] + |))); + fun γ => + ltac:(M.monadic + (let~ u : Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_function (| + "alloy_primitives::signed::utils::twos_complement", + [ BITS; LIMBS ], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + value, + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |) + |) in + let~ u : Ty.path "i128" := + M.alloc (| + M.cast + (Ty.path "i128") + (M.call_closure (| + Ty.path "u128", + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u128"; + Ty.apply + (Ty.path "ruint::from::FromUintError") + [] + [ Ty.path "u128" ] + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u128"; + Ty.apply + (Ty.path "ruint::from::FromUintError") + [] + [ Ty.path "u128" ] + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "u128", + [], + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ], + "try_from", + [], + [] + |), + [ M.read (| u |) ] + |) + ] + |)) + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + M.call_closure (| + Ty.path "i128", + M.get_associated_function (| + Ty.path "i128", + "wrapping_add", + [], + [] + |), + [ UnOp.not (| M.read (| u |) |); Value.Integer IntegerKind.I128 1 + ] + |) + ] + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_i128. + + Module Impl_core_convert_TryFrom_i128_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(value: i128) -> Result { + let u = value as u128; + if value >= 0 { + return Self::try_from(u); + } + + // This is a bit messy :( + let tc = (!u).wrapping_add(1); + let stc = Uint::<128, 2>::saturating_from(tc); + let (num, overflow) = Uint::::overflowing_from_limbs_slice(stc.as_limbs()); + if overflow { + return Err(BigIntConversionError); + } + Ok(Self(twos_complement(num))) + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ u : Ty.path "u128" := + M.alloc (| M.cast (Ty.path "u128") (M.read (| value |)) |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.ge (| + M.read (| value |), + Value.Integer IntegerKind.I128 0 + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "u128" ], + "try_from", + [], + [] + |), + [ M.read (| u |) ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ tc : Ty.path "u128" := + M.alloc (| + M.call_closure (| + Ty.path "u128", + M.get_associated_function (| Ty.path "u128", "wrapping_add", [], [] |), + [ UnOp.not (| M.read (| u |) |); Value.Integer IntegerKind.U128 1 ] + |) + |) in + let~ stc : + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 128; Value.Integer IntegerKind.Usize 2 ] + [] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 128; Value.Integer IntegerKind.Usize 2 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 128; Value.Integer IntegerKind.Usize 2 + ] + [], + "saturating_from", + [], + [ Ty.path "u128" ] + |), + [ M.read (| tc |) ] + |) + |) in + M.match_operator (| + None, + M.alloc (| + M.call_closure (| + Ty.tuple + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; Ty.path "bool" ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "overflowing_from_limbs_slice", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 2 ] + [ Ty.path "u64" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 128; + Value.Integer IntegerKind.Usize 2 + ] + [], + "as_limbs", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, stc |) ] + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let num := M.copy (| γ0_0 |) in + let overflow := M.copy (| γ0_1 |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use overflow in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [] + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_function (| + "alloy_primitives::signed::utils::twos_complement", + [ BITS; LIMBS ], + [] + |), + [ M.read (| num |) ] + |) + ] + ] + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i128" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_i128_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_u128. + Definition Self (BITS LIMBS : Value.t) : Ty.t := Ty.path "u128". + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(value: Signed) -> Result { + if value.is_negative() { + return Err(BigIntConversionError); + } + + let saturated = Uint::::saturating_from(Self::MAX); + + // if the value is greater than the saturated value, return an error + if value > Signed(saturated) { + return Err(BigIntConversionError); + } + + value.into_raw().try_into().map_err(|_| BigIntConversionError) + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "is_negative", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [] + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ saturated : Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "saturating_from", + [], + [ Ty.path "u128" ] + |), + [ M.read (| M.get_constant "core::num::MAX" |) ] + |) + |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "gt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, value |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ M.read (| saturated |) ] + |) + |) + ] + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [] + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u128"; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u128"; + Ty.apply (Ty.path "ruint::from::FromUintError") [] [ Ty.path "u128" ] + ], + "map_err", + [], + [ + Ty.path "alloy_primitives::signed::errors::BigIntConversionError"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "ruint::from::FromUintError") + [] + [ Ty.path "u128" ] + ] + ] + (Ty.path "alloy_primitives::signed::errors::BigIntConversionError") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u128"; + Ty.apply (Ty.path "ruint::from::FromUintError") [] [ Ty.path "u128" ] + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [ Ty.path "u128" ], + "try_into", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "into_raw", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "ruint::from::FromUintError") + [] + [ Ty.path "u128" ] + ] + ] + (Ty.path + "alloy_primitives::signed::errors::BigIntConversionError")), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_u128. + + Module Impl_core_convert_TryFrom_u128_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(value: u128) -> Result { + let saturated = Uint::::saturating_from(value); + + if value != saturated.to::() { + return Err(BigIntConversionError); + } + + Self::try_from(saturated) + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ saturated : Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "saturating_from", + [], + [ Ty.path "u128" ] + |), + [ M.read (| value |) ] + |) + |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.ne (| + M.read (| value |), + M.call_closure (| + Ty.path "u128", + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "to", + [], + [ Ty.path "u128" ] + |), + [ M.borrow (| Pointer.Kind.Ref, saturated |) ] + |) + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [] + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ], + "try_from", + [], + [] + |), + [ M.read (| saturated |) ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u128" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_u128_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + pub const fn $low(&self) -> $t { + if BITS == 0 { + return 0 + } + + self.0.as_limbs()[0] as $t + } + *) + Definition low_u8 + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.eq (| + M.read (| + M.get_constant "alloy_primitives::signed::conversions::BITS" + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| M.return_ (| Value.Integer IntegerKind.U8 0 |) |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.cast + (Ty.path "u8") + (M.read (| + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ LIMBS ] [ Ty.path "u64" ] ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "as_limbs", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |) + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_low_u8 : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "low_u8" (low_u8 BITS LIMBS). + Admitted. + Global Typeclasses Opaque low_u8. + + (* + pub fn $as(&self) -> $t { + <$t as TryFrom>::try_from( *self).unwrap() + } + *) + Definition as_u8 + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "u8", + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "u8"; Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u8"; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "u8", + [], + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] + ], + "try_from", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_as_u8 : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "as_u8" (as_u8 BITS LIMBS). + Admitted. + Global Typeclasses Opaque as_u8. + + (* + pub const fn $low(&self) -> $t { + if BITS == 0 { + return 0 + } + + self.0.as_limbs()[0] as $t + } + *) + Definition low_i8 + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.eq (| + M.read (| + M.get_constant "alloy_primitives::signed::conversions::BITS" + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| M.return_ (| Value.Integer IntegerKind.I8 0 |) |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.cast + (Ty.path "i8") + (M.read (| + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ LIMBS ] [ Ty.path "u64" ] ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "as_limbs", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |) + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_low_i8 : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "low_i8" (low_i8 BITS LIMBS). + Admitted. + Global Typeclasses Opaque low_i8. + + (* + pub fn $as(&self) -> $t { + <$t as TryFrom>::try_from( *self).unwrap() + } + *) + Definition as_i8 + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "i8", + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "i8"; Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i8"; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "i8", + [], + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] + ], + "try_from", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_as_i8 : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "as_i8" (as_i8 BITS LIMBS). + Admitted. + Global Typeclasses Opaque as_i8. + + (* + pub const fn $low(&self) -> $t { + if BITS == 0 { + return 0 + } + + self.0.as_limbs()[0] as $t + } + *) + Definition low_u16 + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.eq (| + M.read (| + M.get_constant "alloy_primitives::signed::conversions::BITS" + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| M.return_ (| Value.Integer IntegerKind.U16 0 |) |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.cast + (Ty.path "u16") + (M.read (| + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ LIMBS ] [ Ty.path "u64" ] ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "as_limbs", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |) + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_low_u16 : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "low_u16" (low_u16 BITS LIMBS). + Admitted. + Global Typeclasses Opaque low_u16. + + (* + pub fn $as(&self) -> $t { + <$t as TryFrom>::try_from( *self).unwrap() + } + *) + Definition as_u16 + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "u16", + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "u16"; Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u16"; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "u16", + [], + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] + ], + "try_from", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_as_u16 : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "as_u16" (as_u16 BITS LIMBS). + Admitted. + Global Typeclasses Opaque as_u16. + + (* + pub const fn $low(&self) -> $t { + if BITS == 0 { + return 0 + } + + self.0.as_limbs()[0] as $t + } + *) + Definition low_i16 + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.eq (| + M.read (| + M.get_constant "alloy_primitives::signed::conversions::BITS" + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| M.return_ (| Value.Integer IntegerKind.I16 0 |) |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.cast + (Ty.path "i16") + (M.read (| + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ LIMBS ] [ Ty.path "u64" ] ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "as_limbs", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |) + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_low_i16 : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "low_i16" (low_i16 BITS LIMBS). + Admitted. + Global Typeclasses Opaque low_i16. + + (* + pub fn $as(&self) -> $t { + <$t as TryFrom>::try_from( *self).unwrap() + } + *) + Definition as_i16 + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "i16", + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "i16"; Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i16"; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "i16", + [], + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] + ], + "try_from", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_as_i16 : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "as_i16" (as_i16 BITS LIMBS). + Admitted. + Global Typeclasses Opaque as_i16. + + (* + pub const fn $low(&self) -> $t { + if BITS == 0 { + return 0 + } + + self.0.as_limbs()[0] as $t + } + *) + Definition low_u32 + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.eq (| + M.read (| + M.get_constant "alloy_primitives::signed::conversions::BITS" + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| M.return_ (| Value.Integer IntegerKind.U32 0 |) |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.cast + (Ty.path "u32") + (M.read (| + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ LIMBS ] [ Ty.path "u64" ] ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "as_limbs", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |) + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_low_u32 : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "low_u32" (low_u32 BITS LIMBS). + Admitted. + Global Typeclasses Opaque low_u32. + + (* + pub fn $as(&self) -> $t { + <$t as TryFrom>::try_from( *self).unwrap() + } + *) + Definition as_u32 + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "u32"; Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u32"; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "u32", + [], + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] + ], + "try_from", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_as_u32 : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "as_u32" (as_u32 BITS LIMBS). + Admitted. + Global Typeclasses Opaque as_u32. + + (* + pub const fn $low(&self) -> $t { + if BITS == 0 { + return 0 + } + + self.0.as_limbs()[0] as $t + } + *) + Definition low_i32 + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.eq (| + M.read (| + M.get_constant "alloy_primitives::signed::conversions::BITS" + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| M.return_ (| Value.Integer IntegerKind.I32 0 |) |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.cast + (Ty.path "i32") + (M.read (| + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ LIMBS ] [ Ty.path "u64" ] ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "as_limbs", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |) + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_low_i32 : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "low_i32" (low_i32 BITS LIMBS). + Admitted. + Global Typeclasses Opaque low_i32. + + (* + pub fn $as(&self) -> $t { + <$t as TryFrom>::try_from( *self).unwrap() + } + *) + Definition as_i32 + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "i32", + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "i32"; Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i32"; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "i32", + [], + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] + ], + "try_from", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_as_i32 : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "as_i32" (as_i32 BITS LIMBS). + Admitted. + Global Typeclasses Opaque as_i32. + + (* + pub const fn $low(&self) -> $t { + if BITS == 0 { + return 0 + } + + self.0.as_limbs()[0] as $t + } + *) + Definition low_u64 + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.eq (| + M.read (| + M.get_constant "alloy_primitives::signed::conversions::BITS" + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| M.return_ (| Value.Integer IntegerKind.U64 0 |) |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.use + (M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ LIMBS ] [ Ty.path "u64" ] ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "as_limbs", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |) + |), + Value.Integer IntegerKind.Usize 0 + |)) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_low_u64 : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "low_u64" (low_u64 BITS LIMBS). + Admitted. + Global Typeclasses Opaque low_u64. + + (* + pub fn $as(&self) -> $t { + <$t as TryFrom>::try_from( *self).unwrap() + } + *) + Definition as_u64 + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "u64", + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "u64"; Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u64"; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "u64", + [], + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] + ], + "try_from", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_as_u64 : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "as_u64" (as_u64 BITS LIMBS). + Admitted. + Global Typeclasses Opaque as_u64. + + (* + pub const fn $low(&self) -> $t { + if BITS == 0 { + return 0 + } + + self.0.as_limbs()[0] as $t + } + *) + Definition low_i64 + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.eq (| + M.read (| + M.get_constant "alloy_primitives::signed::conversions::BITS" + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| M.return_ (| Value.Integer IntegerKind.I64 0 |) |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.cast + (Ty.path "i64") + (M.read (| + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ LIMBS ] [ Ty.path "u64" ] ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "as_limbs", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |) + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_low_i64 : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "low_i64" (low_i64 BITS LIMBS). + Admitted. + Global Typeclasses Opaque low_i64. + + (* + pub fn $as(&self) -> $t { + <$t as TryFrom>::try_from( *self).unwrap() + } + *) + Definition as_i64 + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "i64", + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "i64"; Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i64"; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "i64", + [], + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] + ], + "try_from", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_as_i64 : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "as_i64" (as_i64 BITS LIMBS). + Admitted. + Global Typeclasses Opaque as_i64. + + (* + pub const fn $low(&self) -> $t { + if BITS == 0 { + return 0 + } + + self.0.as_limbs()[0] as $t + } + *) + Definition low_usize + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.eq (| + M.read (| + M.get_constant "alloy_primitives::signed::conversions::BITS" + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| M.return_ (| Value.Integer IntegerKind.Usize 0 |) |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.cast + (Ty.path "usize") + (M.read (| + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ LIMBS ] [ Ty.path "u64" ] ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "as_limbs", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |) + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_low_usize : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "low_usize" (low_usize BITS LIMBS). + Admitted. + Global Typeclasses Opaque low_usize. + + (* + pub fn $as(&self) -> $t { + <$t as TryFrom>::try_from( *self).unwrap() + } + *) + Definition as_usize + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "usize"; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "usize"; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "usize", + [], + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] + ], + "try_from", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_as_usize : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "as_usize" (as_usize BITS LIMBS). + Admitted. + Global Typeclasses Opaque as_usize. + + (* + pub const fn $low(&self) -> $t { + if BITS == 0 { + return 0 + } + + self.0.as_limbs()[0] as $t + } + *) + Definition low_isize + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.eq (| + M.read (| + M.get_constant "alloy_primitives::signed::conversions::BITS" + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| M.return_ (| Value.Integer IntegerKind.Isize 0 |) |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.cast + (Ty.path "isize") + (M.read (| + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ LIMBS ] [ Ty.path "u64" ] ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "as_limbs", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |) + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_low_isize : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "low_isize" (low_isize BITS LIMBS). + Admitted. + Global Typeclasses Opaque low_isize. + + (* + pub fn $as(&self) -> $t { + <$t as TryFrom>::try_from( *self).unwrap() + } + *) + Definition as_isize + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "isize", + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "isize"; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "isize"; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "isize", + [], + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] + ], + "try_from", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_as_isize : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "as_isize" (as_isize BITS LIMBS). + Admitted. + Global Typeclasses Opaque as_isize. + End Impl_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_convert_TryFrom_u8_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(value: $u) -> Result { + let u = Uint::::try_from(value).map_err(|_| BigIntConversionError)?; + Signed::checked_from_sign_and_abs(Sign::Positive, u).ok_or(BigIntConversionError) + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ u : Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] := + M.copy (| + M.match_operator (| + Some (Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ]; + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ] + ], + "map_err", + [], + [ + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] + ] + ] + ] + (Ty.path + "alloy_primitives::signed::errors::BigIntConversionError") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ] + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [ Ty.path "u8" ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ BITS; LIMBS ] + [] + ] + ] + ] + (Ty.path + "alloy_primitives::signed::errors::BigIntConversionError")), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "ok_or", + [], + [ Ty.path "alloy_primitives::signed::errors::BigIntConversionError" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "checked_from_sign_and_abs", + [], + [] + |), + [ + Value.StructTuple "alloy_primitives::signed::sign::Sign::Positive" []; + M.read (| u |) + ] + |); + Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [] + ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u8" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_u8_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_convert_TryFrom_i8_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(value: $i) -> Result { + let uint: $u = value as $u; + + if value.is_positive() { + return Self::try_from(uint); + } + + let abs = (!uint).wrapping_add(1); + let tc = twos_complement(Uint::::from(abs)); + Ok(Self(tc)) + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ uint : Ty.path "u8" := + M.alloc (| M.cast (Ty.path "u8") (M.read (| value |)) |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "i8", + "is_positive", + [], + [] + |), + [ M.read (| value |) ] + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "u8" ], + "try_from", + [], + [] + |), + [ M.read (| uint |) ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ abs : Ty.path "u8" := + M.alloc (| + M.call_closure (| + Ty.path "u8", + M.get_associated_function (| Ty.path "u8", "wrapping_add", [], [] |), + [ UnOp.not (| M.read (| uint |) |); Value.Integer IntegerKind.U8 1 ] + |) + |) in + let~ tc : Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_function (| + "alloy_primitives::signed::utils::twos_complement", + [ BITS; LIMBS ], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "from", + [], + [ Ty.path "u8" ] + |), + [ M.read (| abs |) ] + |) + ] + |) + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ M.read (| tc |) ] + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i8" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_i8_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_u8. + Definition Self (BITS LIMBS : Value.t) : Ty.t := Ty.path "u8". + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(value: Signed) -> Result<$u, Self::Error> { + u128::try_from(value)?.try_into().map_err(|_| BigIntConversionError) + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u8"; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "u8"; Ty.path "core::num::error::TryFromIntError" ], + "map_err", + [], + [ + Ty.path "alloy_primitives::signed::errors::BigIntConversionError"; + Ty.function + [ Ty.tuple [ Ty.path "core::num::error::TryFromIntError" ] ] + (Ty.path "alloy_primitives::signed::errors::BigIntConversionError") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "u8"; Ty.path "core::num::error::TryFromIntError" ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.path "u128", + [], + [ Ty.path "u8" ], + "try_into", + [], + [] + |), + [ + M.read (| + M.match_operator (| + Some (Ty.path "u128"), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ]; + Ty.path "u128" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u128"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u128"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "u128", + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u8"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u8"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ Ty.tuple [ Ty.path "core::num::error::TryFromIntError" ] ] + (Ty.path + "alloy_primitives::signed::errors::BigIntConversionError")), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_u8. + + Module Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_i8. + Definition Self (BITS LIMBS : Value.t) : Ty.t := Ty.path "i8". + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(value: Signed) -> Result<$i, Self::Error> { + i128::try_from(value)?.try_into().map_err(|_| BigIntConversionError) + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i8"; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "i8"; Ty.path "core::num::error::TryFromIntError" ], + "map_err", + [], + [ + Ty.path "alloy_primitives::signed::errors::BigIntConversionError"; + Ty.function + [ Ty.tuple [ Ty.path "core::num::error::TryFromIntError" ] ] + (Ty.path "alloy_primitives::signed::errors::BigIntConversionError") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "i8"; Ty.path "core::num::error::TryFromIntError" ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.path "i128", + [], + [ Ty.path "i8" ], + "try_into", + [], + [] + |), + [ + M.read (| + M.match_operator (| + Some (Ty.path "i128"), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ]; + Ty.path "i128" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i128"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i128"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "i128", + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i8"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i8"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ Ty.tuple [ Ty.path "core::num::error::TryFromIntError" ] ] + (Ty.path + "alloy_primitives::signed::errors::BigIntConversionError")), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_i8. + + Module Impl_core_convert_TryFrom_u16_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(value: $u) -> Result { + let u = Uint::::try_from(value).map_err(|_| BigIntConversionError)?; + Signed::checked_from_sign_and_abs(Sign::Positive, u).ok_or(BigIntConversionError) + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ u : Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] := + M.copy (| + M.match_operator (| + Some (Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ]; + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ] + ], + "map_err", + [], + [ + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] + ] + ] + ] + (Ty.path + "alloy_primitives::signed::errors::BigIntConversionError") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ] + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [ Ty.path "u16" ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ BITS; LIMBS ] + [] + ] + ] + ] + (Ty.path + "alloy_primitives::signed::errors::BigIntConversionError")), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "ok_or", + [], + [ Ty.path "alloy_primitives::signed::errors::BigIntConversionError" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "checked_from_sign_and_abs", + [], + [] + |), + [ + Value.StructTuple "alloy_primitives::signed::sign::Sign::Positive" []; + M.read (| u |) + ] + |); + Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [] + ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u16" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_u16_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_convert_TryFrom_i16_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(value: $i) -> Result { + let uint: $u = value as $u; + + if value.is_positive() { + return Self::try_from(uint); + } + + let abs = (!uint).wrapping_add(1); + let tc = twos_complement(Uint::::from(abs)); + Ok(Self(tc)) + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ uint : Ty.path "u16" := + M.alloc (| M.cast (Ty.path "u16") (M.read (| value |)) |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "i16", + "is_positive", + [], + [] + |), + [ M.read (| value |) ] + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "u16" ], + "try_from", + [], + [] + |), + [ M.read (| uint |) ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ abs : Ty.path "u16" := + M.alloc (| + M.call_closure (| + Ty.path "u16", + M.get_associated_function (| Ty.path "u16", "wrapping_add", [], [] |), + [ UnOp.not (| M.read (| uint |) |); Value.Integer IntegerKind.U16 1 ] + |) + |) in + let~ tc : Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_function (| + "alloy_primitives::signed::utils::twos_complement", + [ BITS; LIMBS ], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "from", + [], + [ Ty.path "u16" ] + |), + [ M.read (| abs |) ] + |) + ] + |) + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ M.read (| tc |) ] + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i16" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_i16_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_u16. + Definition Self (BITS LIMBS : Value.t) : Ty.t := Ty.path "u16". + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(value: Signed) -> Result<$u, Self::Error> { + u128::try_from(value)?.try_into().map_err(|_| BigIntConversionError) + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u16"; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "u16"; Ty.path "core::num::error::TryFromIntError" ], + "map_err", + [], + [ + Ty.path "alloy_primitives::signed::errors::BigIntConversionError"; + Ty.function + [ Ty.tuple [ Ty.path "core::num::error::TryFromIntError" ] ] + (Ty.path "alloy_primitives::signed::errors::BigIntConversionError") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "u16"; Ty.path "core::num::error::TryFromIntError" ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.path "u128", + [], + [ Ty.path "u16" ], + "try_into", + [], + [] + |), + [ + M.read (| + M.match_operator (| + Some (Ty.path "u128"), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ]; + Ty.path "u128" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u128"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u128"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "u128", + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u16"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u16"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ Ty.tuple [ Ty.path "core::num::error::TryFromIntError" ] ] + (Ty.path + "alloy_primitives::signed::errors::BigIntConversionError")), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_u16. + + Module Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_i16. + Definition Self (BITS LIMBS : Value.t) : Ty.t := Ty.path "i16". + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(value: Signed) -> Result<$i, Self::Error> { + i128::try_from(value)?.try_into().map_err(|_| BigIntConversionError) + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i16"; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "i16"; Ty.path "core::num::error::TryFromIntError" ], + "map_err", + [], + [ + Ty.path "alloy_primitives::signed::errors::BigIntConversionError"; + Ty.function + [ Ty.tuple [ Ty.path "core::num::error::TryFromIntError" ] ] + (Ty.path "alloy_primitives::signed::errors::BigIntConversionError") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "i16"; Ty.path "core::num::error::TryFromIntError" ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.path "i128", + [], + [ Ty.path "i16" ], + "try_into", + [], + [] + |), + [ + M.read (| + M.match_operator (| + Some (Ty.path "i128"), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ]; + Ty.path "i128" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i128"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i128"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "i128", + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i16"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i16"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ Ty.tuple [ Ty.path "core::num::error::TryFromIntError" ] ] + (Ty.path + "alloy_primitives::signed::errors::BigIntConversionError")), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_i16. + + Module Impl_core_convert_TryFrom_u32_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(value: $u) -> Result { + let u = Uint::::try_from(value).map_err(|_| BigIntConversionError)?; + Signed::checked_from_sign_and_abs(Sign::Positive, u).ok_or(BigIntConversionError) + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ u : Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] := + M.copy (| + M.match_operator (| + Some (Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ]; + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ] + ], + "map_err", + [], + [ + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] + ] + ] + ] + (Ty.path + "alloy_primitives::signed::errors::BigIntConversionError") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ] + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [ Ty.path "u32" ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ BITS; LIMBS ] + [] + ] + ] + ] + (Ty.path + "alloy_primitives::signed::errors::BigIntConversionError")), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "ok_or", + [], + [ Ty.path "alloy_primitives::signed::errors::BigIntConversionError" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "checked_from_sign_and_abs", + [], + [] + |), + [ + Value.StructTuple "alloy_primitives::signed::sign::Sign::Positive" []; + M.read (| u |) + ] + |); + Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [] + ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u32" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_u32_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_convert_TryFrom_i32_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(value: $i) -> Result { + let uint: $u = value as $u; + + if value.is_positive() { + return Self::try_from(uint); + } + + let abs = (!uint).wrapping_add(1); + let tc = twos_complement(Uint::::from(abs)); + Ok(Self(tc)) + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ uint : Ty.path "u32" := + M.alloc (| M.cast (Ty.path "u32") (M.read (| value |)) |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "i32", + "is_positive", + [], + [] + |), + [ M.read (| value |) ] + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "u32" ], + "try_from", + [], + [] + |), + [ M.read (| uint |) ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ abs : Ty.path "u32" := + M.alloc (| + M.call_closure (| + Ty.path "u32", + M.get_associated_function (| Ty.path "u32", "wrapping_add", [], [] |), + [ UnOp.not (| M.read (| uint |) |); Value.Integer IntegerKind.U32 1 ] + |) + |) in + let~ tc : Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_function (| + "alloy_primitives::signed::utils::twos_complement", + [ BITS; LIMBS ], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "from", + [], + [ Ty.path "u32" ] + |), + [ M.read (| abs |) ] + |) + ] + |) + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ M.read (| tc |) ] + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i32" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_i32_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_u32. + Definition Self (BITS LIMBS : Value.t) : Ty.t := Ty.path "u32". + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(value: Signed) -> Result<$u, Self::Error> { + u128::try_from(value)?.try_into().map_err(|_| BigIntConversionError) + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u32"; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "u32"; Ty.path "core::num::error::TryFromIntError" ], + "map_err", + [], + [ + Ty.path "alloy_primitives::signed::errors::BigIntConversionError"; + Ty.function + [ Ty.tuple [ Ty.path "core::num::error::TryFromIntError" ] ] + (Ty.path "alloy_primitives::signed::errors::BigIntConversionError") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "u32"; Ty.path "core::num::error::TryFromIntError" ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.path "u128", + [], + [ Ty.path "u32" ], + "try_into", + [], + [] + |), + [ + M.read (| + M.match_operator (| + Some (Ty.path "u128"), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ]; + Ty.path "u128" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u128"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u128"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "u128", + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u32"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u32"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ Ty.tuple [ Ty.path "core::num::error::TryFromIntError" ] ] + (Ty.path + "alloy_primitives::signed::errors::BigIntConversionError")), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_u32. + + Module Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_i32. + Definition Self (BITS LIMBS : Value.t) : Ty.t := Ty.path "i32". + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(value: Signed) -> Result<$i, Self::Error> { + i128::try_from(value)?.try_into().map_err(|_| BigIntConversionError) + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i32"; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "i32"; Ty.path "core::num::error::TryFromIntError" ], + "map_err", + [], + [ + Ty.path "alloy_primitives::signed::errors::BigIntConversionError"; + Ty.function + [ Ty.tuple [ Ty.path "core::num::error::TryFromIntError" ] ] + (Ty.path "alloy_primitives::signed::errors::BigIntConversionError") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "i32"; Ty.path "core::num::error::TryFromIntError" ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.path "i128", + [], + [ Ty.path "i32" ], + "try_into", + [], + [] + |), + [ + M.read (| + M.match_operator (| + Some (Ty.path "i128"), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ]; + Ty.path "i128" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i128"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i128"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "i128", + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i32"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i32"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ Ty.tuple [ Ty.path "core::num::error::TryFromIntError" ] ] + (Ty.path + "alloy_primitives::signed::errors::BigIntConversionError")), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_i32. + + Module Impl_core_convert_TryFrom_u64_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(value: $u) -> Result { + let u = Uint::::try_from(value).map_err(|_| BigIntConversionError)?; + Signed::checked_from_sign_and_abs(Sign::Positive, u).ok_or(BigIntConversionError) + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ u : Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] := + M.copy (| + M.match_operator (| + Some (Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ]; + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ] + ], + "map_err", + [], + [ + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] + ] + ] + ] + (Ty.path + "alloy_primitives::signed::errors::BigIntConversionError") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ] + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [ Ty.path "u64" ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ BITS; LIMBS ] + [] + ] + ] + ] + (Ty.path + "alloy_primitives::signed::errors::BigIntConversionError")), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "ok_or", + [], + [ Ty.path "alloy_primitives::signed::errors::BigIntConversionError" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "checked_from_sign_and_abs", + [], + [] + |), + [ + Value.StructTuple "alloy_primitives::signed::sign::Sign::Positive" []; + M.read (| u |) + ] + |); + Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [] + ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u64" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_u64_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_convert_TryFrom_i64_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(value: $i) -> Result { + let uint: $u = value as $u; + + if value.is_positive() { + return Self::try_from(uint); + } + + let abs = (!uint).wrapping_add(1); + let tc = twos_complement(Uint::::from(abs)); + Ok(Self(tc)) + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ uint : Ty.path "u64" := + M.alloc (| M.cast (Ty.path "u64") (M.read (| value |)) |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "i64", + "is_positive", + [], + [] + |), + [ M.read (| value |) ] + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "u64" ], + "try_from", + [], + [] + |), + [ M.read (| uint |) ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ abs : Ty.path "u64" := + M.alloc (| + M.call_closure (| + Ty.path "u64", + M.get_associated_function (| Ty.path "u64", "wrapping_add", [], [] |), + [ UnOp.not (| M.read (| uint |) |); Value.Integer IntegerKind.U64 1 ] + |) + |) in + let~ tc : Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_function (| + "alloy_primitives::signed::utils::twos_complement", + [ BITS; LIMBS ], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "from", + [], + [ Ty.path "u64" ] + |), + [ M.read (| abs |) ] + |) + ] + |) + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ M.read (| tc |) ] + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i64" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_i64_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_u64. + Definition Self (BITS LIMBS : Value.t) : Ty.t := Ty.path "u64". + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(value: Signed) -> Result<$u, Self::Error> { + u128::try_from(value)?.try_into().map_err(|_| BigIntConversionError) + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u64"; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "u64"; Ty.path "core::num::error::TryFromIntError" ], + "map_err", + [], + [ + Ty.path "alloy_primitives::signed::errors::BigIntConversionError"; + Ty.function + [ Ty.tuple [ Ty.path "core::num::error::TryFromIntError" ] ] + (Ty.path "alloy_primitives::signed::errors::BigIntConversionError") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "u64"; Ty.path "core::num::error::TryFromIntError" ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.path "u128", + [], + [ Ty.path "u64" ], + "try_into", + [], + [] + |), + [ + M.read (| + M.match_operator (| + Some (Ty.path "u128"), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ]; + Ty.path "u128" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u128"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u128"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "u128", + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u64"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u64"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ Ty.tuple [ Ty.path "core::num::error::TryFromIntError" ] ] + (Ty.path + "alloy_primitives::signed::errors::BigIntConversionError")), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_u64. + + Module Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_i64. + Definition Self (BITS LIMBS : Value.t) : Ty.t := Ty.path "i64". + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(value: Signed) -> Result<$i, Self::Error> { + i128::try_from(value)?.try_into().map_err(|_| BigIntConversionError) + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i64"; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "i64"; Ty.path "core::num::error::TryFromIntError" ], + "map_err", + [], + [ + Ty.path "alloy_primitives::signed::errors::BigIntConversionError"; + Ty.function + [ Ty.tuple [ Ty.path "core::num::error::TryFromIntError" ] ] + (Ty.path "alloy_primitives::signed::errors::BigIntConversionError") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "i64"; Ty.path "core::num::error::TryFromIntError" ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.path "i128", + [], + [ Ty.path "i64" ], + "try_into", + [], + [] + |), + [ + M.read (| + M.match_operator (| + Some (Ty.path "i128"), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ]; + Ty.path "i128" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i128"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i128"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "i128", + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i64"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i64"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ Ty.tuple [ Ty.path "core::num::error::TryFromIntError" ] ] + (Ty.path + "alloy_primitives::signed::errors::BigIntConversionError")), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_i64. + + Module Impl_core_convert_TryFrom_usize_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(value: $u) -> Result { + let u = Uint::::try_from(value).map_err(|_| BigIntConversionError)?; + Signed::checked_from_sign_and_abs(Sign::Positive, u).ok_or(BigIntConversionError) + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ u : Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] := + M.copy (| + M.match_operator (| + Some (Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ]; + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ] + ], + "map_err", + [], + [ + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError"; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] + ] + ] + ] + (Ty.path + "alloy_primitives::signed::errors::BigIntConversionError") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ] + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [ Ty.path "usize" ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ BITS; LIMBS ] + [] + ] + ] + ] + (Ty.path + "alloy_primitives::signed::errors::BigIntConversionError")), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "ok_or", + [], + [ Ty.path "alloy_primitives::signed::errors::BigIntConversionError" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "checked_from_sign_and_abs", + [], + [] + |), + [ + Value.StructTuple "alloy_primitives::signed::sign::Sign::Positive" []; + M.read (| u |) + ] + |); + Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [] + ] + |) + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "usize" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_usize_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_convert_TryFrom_isize_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(value: $i) -> Result { + let uint: $u = value as $u; + + if value.is_positive() { + return Self::try_from(uint); + } + + let abs = (!uint).wrapping_add(1); + let tc = twos_complement(Uint::::from(abs)); + Ok(Self(tc)) + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ uint : Ty.path "usize" := + M.alloc (| M.cast (Ty.path "usize") (M.read (| value |)) |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "isize", + "is_positive", + [], + [] + |), + [ M.read (| value |) ] + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "usize" ], + "try_from", + [], + [] + |), + [ M.read (| uint |) ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ abs : Ty.path "usize" := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| Ty.path "usize", "wrapping_add", [], [] |), + [ UnOp.not (| M.read (| uint |) |); Value.Integer IntegerKind.Usize 1 ] + |) + |) in + let~ tc : Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_function (| + "alloy_primitives::signed::utils::twos_complement", + [ BITS; LIMBS ], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "from", + [], + [ Ty.path "usize" ] + |), + [ M.read (| abs |) ] + |) + ] + |) + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ M.read (| tc |) ] + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "isize" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_isize_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_usize. + Definition Self (BITS LIMBS : Value.t) : Ty.t := Ty.path "usize". + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(value: Signed) -> Result<$u, Self::Error> { + u128::try_from(value)?.try_into().map_err(|_| BigIntConversionError) + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "usize"; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "usize"; Ty.path "core::num::error::TryFromIntError" ], + "map_err", + [], + [ + Ty.path "alloy_primitives::signed::errors::BigIntConversionError"; + Ty.function + [ Ty.tuple [ Ty.path "core::num::error::TryFromIntError" ] ] + (Ty.path "alloy_primitives::signed::errors::BigIntConversionError") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "usize"; Ty.path "core::num::error::TryFromIntError" ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.path "u128", + [], + [ Ty.path "usize" ], + "try_into", + [], + [] + |), + [ + M.read (| + M.match_operator (| + Some (Ty.path "u128"), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ]; + Ty.path "u128" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u128"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u128"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "u128", + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "usize"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "usize"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ Ty.tuple [ Ty.path "core::num::error::TryFromIntError" ] ] + (Ty.path + "alloy_primitives::signed::errors::BigIntConversionError")), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_usize. + + Module Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_isize. + Definition Self (BITS LIMBS : Value.t) : Ty.t := Ty.path "isize". + + (* type Error = BigIntConversionError; *) + Definition _Error (BITS LIMBS : Value.t) : Ty.t := + Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn try_from(value: Signed) -> Result<$i, Self::Error> { + i128::try_from(value)?.try_into().map_err(|_| BigIntConversionError) + } + *) + Definition try_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "isize"; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "isize"; Ty.path "core::num::error::TryFromIntError" ], + "map_err", + [], + [ + Ty.path "alloy_primitives::signed::errors::BigIntConversionError"; + Ty.function + [ Ty.tuple [ Ty.path "core::num::error::TryFromIntError" ] ] + (Ty.path "alloy_primitives::signed::errors::BigIntConversionError") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "isize"; Ty.path "core::num::error::TryFromIntError" ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.path "i128", + [], + [ Ty.path "isize" ], + "try_into", + [], + [] + |), + [ + M.read (| + M.match_operator (| + Some (Ty.path "i128"), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ]; + Ty.path "i128" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i128"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "i128"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "i128", + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "isize"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "isize"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ Ty.tuple [ Ty.path "core::num::error::TryFromIntError" ] ] + (Ty.path + "alloy_primitives::signed::errors::BigIntConversionError")), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::signed::errors::BigIntConversionError" + [])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Error", InstanceField.Ty (_Error BITS LIMBS)); + ("try_from", InstanceField.Method (try_from BITS LIMBS)) + ]. + End Impl_core_convert_TryFrom_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_isize. + End conversions. +End signed. diff --git a/CoqOfRust/alloy_primitives/signed/errors.rs b/CoqOfRust/alloy_primitives/signed/errors.rs new file mode 100644 index 000000000..b41c7c80c --- /dev/null +++ b/CoqOfRust/alloy_primitives/signed/errors.rs @@ -0,0 +1,58 @@ +use core::fmt; +use ruint::BaseConvertError; + +/// The error type that is returned when parsing a signed integer. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum ParseSignedError { + /// Error that occurs when an invalid digit is encountered while parsing. + Ruint(ruint::ParseError), + + /// Error that occurs when the number is too large or too small (negative) + /// and does not fit in the target signed integer. + IntegerOverflow, +} + +impl From for ParseSignedError { + fn from(err: ruint::ParseError) -> Self { + // these errors are redundant, so we coerce the more complex one to the + // simpler one + match err { + ruint::ParseError::BaseConvertError(BaseConvertError::Overflow) => { + Self::IntegerOverflow + } + _ => Self::Ruint(err), + } + } +} + +#[cfg(feature = "std")] +impl std::error::Error for ParseSignedError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + Self::Ruint(err) => Some(err), + Self::IntegerOverflow => None, + } + } +} + +impl fmt::Display for ParseSignedError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Ruint(e) => e.fmt(f), + Self::IntegerOverflow => f.write_str("number does not fit in the integer size"), + } + } +} + +/// The error type that is returned when conversion to or from a integer fails. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct BigIntConversionError; + +#[cfg(feature = "std")] +impl std::error::Error for BigIntConversionError {} + +impl fmt::Display for BigIntConversionError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("output of range integer conversion attempted") + } +} diff --git a/CoqOfRust/alloy_primitives/signed/errors.v b/CoqOfRust/alloy_primitives/signed/errors.v new file mode 100644 index 000000000..818140b14 --- /dev/null +++ b/CoqOfRust/alloy_primitives/signed/errors.v @@ -0,0 +1,740 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module signed. + Module errors. + (* + Enum ParseSignedError + { + const_params := []; + ty_params := []; + variants := + [ + { + name := "Ruint"; + item := StructTuple [ Ty.path "ruint::string::ParseError" ]; + }; + { + name := "IntegerOverflow"; + item := StructTuple []; + } + ]; + } + *) + + Axiom IsDiscriminant_ParseSignedError_Ruint : + M.IsDiscriminant "alloy_primitives::signed::errors::ParseSignedError::Ruint" 0. + Axiom IsDiscriminant_ParseSignedError_IntegerOverflow : + M.IsDiscriminant "alloy_primitives::signed::errors::ParseSignedError::IntegerOverflow" 1. + + Module Impl_core_clone_Clone_for_alloy_primitives_signed_errors_ParseSignedError. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::errors::ParseSignedError". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.deref (| M.read (| self |) |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_alloy_primitives_signed_errors_ParseSignedError. + + Module Impl_core_marker_Copy_for_alloy_primitives_signed_errors_ParseSignedError. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::errors::ParseSignedError". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_alloy_primitives_signed_errors_ParseSignedError. + + Module Impl_core_fmt_Debug_for_alloy_primitives_signed_errors_ParseSignedError. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::errors::ParseSignedError". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ]), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signed::errors::ParseSignedError::Ruint", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Ruint" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::errors::ParseSignedError::IntegerOverflow" + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "IntegerOverflow" |) |) + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_alloy_primitives_signed_errors_ParseSignedError. + + Module Impl_core_marker_StructuralPartialEq_for_alloy_primitives_signed_errors_ParseSignedError. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::errors::ParseSignedError". + + Axiom Implements : + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_alloy_primitives_signed_errors_ParseSignedError. + + Module Impl_core_cmp_PartialEq_alloy_primitives_signed_errors_ParseSignedError_for_alloy_primitives_signed_errors_ParseSignedError. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::errors::ParseSignedError". + + (* PartialEq *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.read (| + let~ __self_discr : Ty.path "isize" := + M.alloc (| + M.call_closure (| + Ty.path "isize", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "alloy_primitives::signed::errors::ParseSignedError" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ __arg1_discr : Ty.path "isize" := + M.alloc (| + M.call_closure (| + Ty.path "isize", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "alloy_primitives::signed::errors::ParseSignedError" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) ] + |) + |) in + M.alloc (| + LogicalOp.and (| + BinOp.eq (| M.read (| __self_discr |), M.read (| __arg1_discr |) |), + ltac:(M.monadic + (M.read (| + M.match_operator (| + Some (Ty.path "bool"), + M.alloc (| Value.Tuple [ M.read (| self |); M.read (| other |) ] |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_0 := M.read (| γ0_0 |) in + let γ2_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_0, + "alloy_primitives::signed::errors::ParseSignedError::Ruint", + 0 + |) in + let __self_0 := M.alloc (| γ2_0 |) in + let γ0_1 := M.read (| γ0_1 |) in + let γ2_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_1, + "alloy_primitives::signed::errors::ParseSignedError::Ruint", + 0 + |) in + let __arg1_0 := M.alloc (| γ2_0 |) in + M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "&") + [] + [ Ty.path "ruint::string::ParseError" ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "ruint::string::ParseError" ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, __self_0 |); + M.borrow (| Pointer.Kind.Ref, __arg1_0 |) + ] + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Bool true |))) + ] + |) + |))) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.path "alloy_primitives::signed::errors::ParseSignedError" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_signed_errors_ParseSignedError_for_alloy_primitives_signed_errors_ParseSignedError. + + Module Impl_core_cmp_Eq_for_alloy_primitives_signed_errors_ParseSignedError. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::errors::ParseSignedError". + + (* Eq *) + Definition assert_receiver_is_total_eq + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method assert_receiver_is_total_eq) ]. + End Impl_core_cmp_Eq_for_alloy_primitives_signed_errors_ParseSignedError. + + Module Impl_core_convert_From_ruint_string_ParseError_for_alloy_primitives_signed_errors_ParseSignedError. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::errors::ParseSignedError". + + (* + fn from(err: ruint::ParseError) -> Self { + // these errors are redundant, so we coerce the more complex one to the + // simpler one + match err { + ruint::ParseError::BaseConvertError(BaseConvertError::Overflow) => { + Self::IntegerOverflow + } + _ => Self::Ruint(err), + } + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ err ] => + ltac:(M.monadic + (let err := M.alloc (| err |) in + M.read (| + M.match_operator (| + Some (Ty.path "alloy_primitives::signed::errors::ParseSignedError"), + err, + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "ruint::string::ParseError::BaseConvertError", + 0 + |) in + let _ := + M.is_struct_tuple (| + γ0_0, + "ruint::base_convert::BaseConvertError::Overflow" + |) in + M.alloc (| + Value.StructTuple + "alloy_primitives::signed::errors::ParseSignedError::IntegerOverflow" + [] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "alloy_primitives::signed::errors::ParseSignedError::Ruint" + [ M.read (| err |) ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "ruint::string::ParseError" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ruint_string_ParseError_for_alloy_primitives_signed_errors_ParseSignedError. + + Module Impl_core_error_Error_for_alloy_primitives_signed_errors_ParseSignedError. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::errors::ParseSignedError". + + (* + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + Self::Ruint(err) => Some(err), + Self::IntegerOverflow => None, + } + } + *) + Definition source (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.dyn [ ("core::error::Error::Trait", []) ] ] ]), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signed::errors::ParseSignedError::Ruint", + 0 + |) in + let err := M.alloc (| γ1_0 |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| err |) |) |) ] + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::errors::ParseSignedError::IntegerOverflow" + |) in + M.alloc (| Value.StructTuple "core::option::Option::None" [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::error::Error" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("source", InstanceField.Method source) ]. + End Impl_core_error_Error_for_alloy_primitives_signed_errors_ParseSignedError. + + Module Impl_core_fmt_Display_for_alloy_primitives_signed_errors_ParseSignedError. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::errors::ParseSignedError". + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::Ruint(e) => e.fmt(f), + Self::IntegerOverflow => f.write_str("number does not fit in the integer size"), + } + } + *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ]), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::signed::errors::ParseSignedError::Ruint", + 0 + |) in + let e := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::Display", + Ty.path "ruint::string::ParseError", + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| e |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::errors::ParseSignedError::IntegerOverflow" + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_str", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "number does not fit in the integer size" |) |) + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Display" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Display_for_alloy_primitives_signed_errors_ParseSignedError. + + (* StructTuple + { + name := "BigIntConversionError"; + const_params := []; + ty_params := []; + fields := []; + } *) + + Module Impl_core_clone_Clone_for_alloy_primitives_signed_errors_BigIntConversionError. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| M.deref (| M.read (| self |) |) |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_alloy_primitives_signed_errors_BigIntConversionError. + + Module Impl_core_marker_Copy_for_alloy_primitives_signed_errors_BigIntConversionError. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_alloy_primitives_signed_errors_BigIntConversionError. + + Module Impl_core_fmt_Debug_for_alloy_primitives_signed_errors_BigIntConversionError. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "BigIntConversionError" |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_alloy_primitives_signed_errors_BigIntConversionError. + + Module Impl_core_marker_StructuralPartialEq_for_alloy_primitives_signed_errors_BigIntConversionError. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + Axiom Implements : + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_alloy_primitives_signed_errors_BigIntConversionError. + + Module Impl_core_cmp_PartialEq_alloy_primitives_signed_errors_BigIntConversionError_for_alloy_primitives_signed_errors_BigIntConversionError. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* PartialEq *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + Value.Bool true)) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.path "alloy_primitives::signed::errors::BigIntConversionError" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_signed_errors_BigIntConversionError_for_alloy_primitives_signed_errors_BigIntConversionError. + + Module Impl_core_cmp_Eq_for_alloy_primitives_signed_errors_BigIntConversionError. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* Eq *) + Definition assert_receiver_is_total_eq + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.Tuple [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method assert_receiver_is_total_eq) ]. + End Impl_core_cmp_Eq_for_alloy_primitives_signed_errors_BigIntConversionError. + + Module Impl_core_error_Error_for_alloy_primitives_signed_errors_BigIntConversionError. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + Axiom Implements : + M.IsTraitInstance + "core::error::Error" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_error_Error_for_alloy_primitives_signed_errors_BigIntConversionError. + + Module Impl_core_fmt_Display_for_alloy_primitives_signed_errors_BigIntConversionError. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::errors::BigIntConversionError". + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("output of range integer conversion attempted") + } + *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "output of range integer conversion attempted" |) |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Display" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Display_for_alloy_primitives_signed_errors_BigIntConversionError. + End errors. +End signed. diff --git a/CoqOfRust/alloy_primitives/signed/int.rs b/CoqOfRust/alloy_primitives/signed/int.rs new file mode 100644 index 000000000..59a7363e0 --- /dev/null +++ b/CoqOfRust/alloy_primitives/signed/int.rs @@ -0,0 +1,1667 @@ +use super::{utils::*, ParseSignedError, Sign}; +use alloc::string::String; +use core::fmt; +use ruint::{BaseConvertError, Uint}; + +/// Signed integer wrapping a `ruint::Uint`. +/// +/// This signed integer implementation is fully abstract across the number of +/// bits. It wraps a [`ruint::Uint`], and co-opts the most significant bit to +/// represent the sign. The number is represented in two's complement, using the +/// underlying `Uint`'s `u64` limbs. The limbs can be accessed via the +/// [`Signed::as_limbs()`] method, and are least-significant first. +/// +/// ## Aliases +/// +/// We provide aliases for every bit-width divisble by 8, from 8 to 256. These +/// are located in [`crate::aliases`] and are named `I256`, `I248` etc. Most +/// users will want [`crate::I256`]. +/// +/// # Usage +/// +/// ``` +/// # use alloy_primitives::I256; +/// // Instantiate from a number +/// let a = I256::unchecked_from(1); +/// // Use `try_from` if you're not sure it'll fit +/// let b = I256::try_from(200000382).unwrap(); +/// +/// // Or parse from a string :) +/// let c = "100".parse::().unwrap(); +/// let d = "-0x138f".parse::().unwrap(); +/// +/// // Preceding plus is allowed but not recommended +/// let e = "+0xdeadbeef".parse::().unwrap(); +/// +/// // Underscores are ignored +/// let f = "1_000_000".parse::().unwrap(); +/// +/// // But invalid chars are not +/// assert!("^31".parse::().is_err()); +/// +/// // Math works great :) +/// let g = a * b + c - d; +/// +/// // And so do comparisons! +/// assert!(e > a); +/// +/// // We have some useful constants too +/// assert_eq!(I256::ZERO, I256::unchecked_from(0)); +/// assert_eq!(I256::ONE, I256::unchecked_from(1)); +/// assert_eq!(I256::MINUS_ONE, I256::unchecked_from(-1)); +/// ``` +#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "arbitrary", derive(derive_arbitrary::Arbitrary, proptest_derive::Arbitrary))] +pub struct Signed(pub(crate) Uint); + +// formatting +impl fmt::Debug for Signed { + #[inline] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Display::fmt(self, f) + } +} + +impl fmt::Display for Signed { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let (sign, abs) = self.into_sign_and_abs(); + sign.fmt(f)?; + if f.sign_plus() { + write!(f, "{abs}") + } else { + abs.fmt(f) + } + } +} + +impl fmt::Binary for Signed { + #[inline] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } +} + +impl fmt::Octal for Signed { + #[inline] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } +} + +impl fmt::LowerHex for Signed { + #[inline] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } +} + +impl fmt::UpperHex for Signed { + #[inline] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } +} + +impl Signed { + /// Mask for the highest limb. + pub(crate) const MASK: u64 = ruint::mask(BITS); + + /// Location of the sign bit within the highest limb. + pub(crate) const SIGN_BIT: u64 = sign_bit(BITS); + + /// Number of bits. + pub const BITS: usize = BITS; + + /// The size of this integer type in bytes. Note that some bits may be + /// forced zero if BITS is not cleanly divisible by eight. + pub const BYTES: usize = Uint::::BYTES; + + /// The minimum value. + pub const MIN: Self = min(); + + /// The maximum value. + pub const MAX: Self = max(); + + /// Zero (additive identity) of this type. + pub const ZERO: Self = zero(); + + /// One (multiplicative identity) of this type. + pub const ONE: Self = one(); + + /// Minus one (multiplicative inverse) of this type. + pub const MINUS_ONE: Self = Self(Uint::::MAX); + + /// Coerces an unsigned integer into a signed one. If the unsigned integer is greater than or + /// equal to `1 << 255`, then the result will overflow into a negative value. + #[inline] + pub const fn from_raw(val: Uint) -> Self { + Self(val) + } + + /// Shortcut for `val.try_into().unwrap()`. + /// + /// # Panics + /// + /// Panics if the conversion fails. + #[inline] + #[track_caller] + pub fn unchecked_from(val: T) -> Self + where + T: TryInto, + >::Error: fmt::Debug, + { + val.try_into().unwrap() + } + + /// Shortcut for `self.try_into().unwrap()`. + /// + /// # Panics + /// + /// Panics if the conversion fails. + #[inline] + #[track_caller] + pub fn unchecked_into(self) -> T + where + Self: TryInto, + >::Error: fmt::Debug, + { + self.try_into().unwrap() + } + + /// Returns the signed integer as a unsigned integer. If the value of `self` + /// negative, then the two's complement of its absolute value will be + /// returned. + #[inline] + pub const fn into_raw(self) -> Uint { + self.0 + } + + /// Returns the sign of self. + #[inline] + pub const fn sign(&self) -> Sign { + // if the last limb contains the sign bit, then we're negative + // because we can't set any higher bits to 1, we use >= as a proxy + // check to avoid bit comparison + if let Some(limb) = self.0.as_limbs().last() { + if *limb >= Self::SIGN_BIT { + return Sign::Negative; + } + } + Sign::Positive + } + + /// Determines if the integer is odd. + #[inline] + pub const fn is_odd(&self) -> bool { + if BITS == 0 { + false + } else { + self.as_limbs()[0] % 2 == 1 + } + } + + /// Compile-time equality. NOT constant-time equality. + #[inline] + pub const fn const_eq(&self, other: &Self) -> bool { + const_eq(self, other) + } + + /// Returns `true` if `self` is zero and `false` if the number is negative + /// or positive. + #[inline] + pub const fn is_zero(&self) -> bool { + self.const_eq(&Self::ZERO) + } + + /// Returns `true` if `self` is positive and `false` if the number is zero + /// or negative. + #[inline] + pub const fn is_positive(&self) -> bool { + !self.is_zero() && matches!(self.sign(), Sign::Positive) + } + + /// Returns `true` if `self` is negative and `false` if the number is zero + /// or positive. + #[inline] + pub const fn is_negative(&self) -> bool { + matches!(self.sign(), Sign::Negative) + } + + /// Returns the number of ones in the binary representation of `self`. + #[inline] + pub fn count_ones(&self) -> usize { + self.0.count_ones() + } + + /// Returns the number of zeros in the binary representation of `self`. + #[inline] + pub fn count_zeros(&self) -> usize { + self.0.count_zeros() + } + + /// Returns the number of leading zeros in the binary representation of + /// `self`. + #[inline] + pub fn leading_zeros(&self) -> usize { + self.0.leading_zeros() + } + + /// Returns the number of leading zeros in the binary representation of + /// `self`. + #[inline] + pub fn trailing_zeros(&self) -> usize { + self.0.trailing_zeros() + } + + /// Returns the number of leading ones in the binary representation of + /// `self`. + #[inline] + pub fn trailing_ones(&self) -> usize { + self.0.trailing_ones() + } + + /// Returns whether a specific bit is set. + /// + /// Returns `false` if `index` exceeds the bit width of the number. + #[inline] + pub const fn bit(&self, index: usize) -> bool { + self.0.bit(index) + } + + /// Returns a specific byte. The byte at index `0` is the least significant + /// byte (little endian). + /// + /// # Panics + /// + /// Panics if `index` exceeds the byte width of the number. + #[inline] + #[track_caller] + pub const fn byte(&self, index: usize) -> u8 { + self.0.byte(index) + } + + /// Return the least number of bits needed to represent the number. + #[inline] + pub fn bits(&self) -> u32 { + let unsigned = self.unsigned_abs(); + let unsigned_bits = unsigned.bit_len(); + + // NOTE: We need to deal with two special cases: + // - the number is 0 + // - the number is a negative power of `2`. These numbers are written as `0b11..1100..00`. + // In the case of a negative power of two, the number of bits required + // to represent the negative signed value is equal to the number of + // bits required to represent its absolute value as an unsigned + // integer. This is best illustrated by an example: the number of bits + // required to represent `-128` is `8` since it is equal to `i8::MIN` + // and, therefore, obviously fits in `8` bits. This is equal to the + // number of bits required to represent `128` as an unsigned integer + // (which fits in a `u8`). However, the number of bits required to + // represent `128` as a signed integer is `9`, as it is greater than + // `i8::MAX`. In the general case, an extra bit is needed to + // represent the sign. + let bits = if self.count_zeros() == self.trailing_zeros() { + // `self` is zero or a negative power of two + unsigned_bits + } else { + unsigned_bits + 1 + }; + + bits as u32 + } + + /// Creates a `Signed` from a sign and an absolute value. Returns the value + /// and a bool that is true if the conversion caused an overflow. + #[inline] + pub fn overflowing_from_sign_and_abs(sign: Sign, abs: Uint) -> (Self, bool) { + let value = Self(match sign { + Sign::Positive => abs, + Sign::Negative => twos_complement(abs), + }); + + (value, value.sign() != sign && value != Self::ZERO) + } + + /// Creates a `Signed` from an absolute value and a negative flag. Returns + /// `None` if it would overflow as `Signed`. + #[inline] + pub fn checked_from_sign_and_abs(sign: Sign, abs: Uint) -> Option { + let (result, overflow) = Self::overflowing_from_sign_and_abs(sign, abs); + if overflow { + None + } else { + Some(result) + } + } + + /// Convert from a decimal string. + pub fn from_dec_str(value: &str) -> Result { + let (sign, value) = match value.as_bytes().first() { + Some(b'+') => (Sign::Positive, &value[1..]), + Some(b'-') => (Sign::Negative, &value[1..]), + _ => (Sign::Positive, value), + }; + let abs = Uint::::from_str_radix(value, 10)?; + Self::checked_from_sign_and_abs(sign, abs).ok_or(ParseSignedError::IntegerOverflow) + } + + /// Convert to a decimal string. + pub fn to_dec_string(&self) -> String { + let sign = self.sign(); + let abs = self.unsigned_abs(); + + format!("{sign}{abs}") + } + + /// Convert from a hex string. + pub fn from_hex_str(value: &str) -> Result { + let (sign, value) = match value.as_bytes().first() { + Some(b'+') => (Sign::Positive, &value[1..]), + Some(b'-') => (Sign::Negative, &value[1..]), + _ => (Sign::Positive, value), + }; + + let value = value.strip_prefix("0x").unwrap_or(value); + + if value.len() > 64 { + return Err(ParseSignedError::IntegerOverflow); + } + + let abs = Uint::::from_str_radix(value, 16)?; + Self::checked_from_sign_and_abs(sign, abs).ok_or(ParseSignedError::IntegerOverflow) + } + + /// Convert to a hex string. + pub fn to_hex_string(&self) -> String { + let sign = self.sign(); + let abs = self.unsigned_abs(); + + format!("{sign}0x{abs:x}") + } + + /// Splits a Signed into its absolute value and negative flag. + #[inline] + pub fn into_sign_and_abs(&self) -> (Sign, Uint) { + let sign = self.sign(); + let abs = match sign { + Sign::Positive => self.0, + Sign::Negative => twos_complement(self.0), + }; + (sign, abs) + } + + /// Converts `self` to a big-endian byte array of size exactly + /// [`Self::BYTES`]. + /// + /// # Panics + /// + /// Panics if the generic parameter `BYTES` is not exactly [`Self::BYTES`]. + /// Ideally this would be a compile time error, but this is blocked by + /// Rust issue [#60551]. + /// + /// [#60551]: https://github.com/rust-lang/rust/issues/60551 + #[inline] + pub const fn to_be_bytes(&self) -> [u8; BYTES] { + self.0.to_be_bytes() + } + + /// Converts `self` to a little-endian byte array of size exactly + /// [`Self::BYTES`]. + /// + /// # Panics + /// + /// Panics if the generic parameter `BYTES` is not exactly [`Self::BYTES`]. + /// Ideally this would be a compile time error, but this is blocked by + /// Rust issue [#60551]. + /// + /// [#60551]: https://github.com/rust-lang/rust/issues/60551 + #[inline] + pub const fn to_le_bytes(&self) -> [u8; BYTES] { + self.0.to_le_bytes() + } + + /// Converts a big-endian byte array of size exactly [`Self::BYTES`]. + /// + /// # Panics + /// + /// Panics if the generic parameter `BYTES` is not exactly [`Self::BYTES`]. + /// Ideally this would be a compile time error, but this is blocked by + /// Rust issue [#60551]. + /// + /// [#60551]: https://github.com/rust-lang/rust/issues/60551 + /// + /// Panics if the value is too large for the bit-size of the Uint. + #[inline] + pub const fn from_be_bytes(bytes: [u8; BYTES]) -> Self { + Self(Uint::from_be_bytes::(bytes)) + } + + /// Convert from an array in LE format + /// + /// # Panics + /// + /// Panics if the given array is not the correct length. + #[inline] + #[track_caller] + pub const fn from_le_bytes(bytes: [u8; BYTES]) -> Self { + Self(Uint::from_le_bytes::(bytes)) + } + + /// Creates a new integer from a big endian slice of bytes. + /// + /// The slice is interpreted as a big endian number. Leading zeros + /// are ignored. The slice can be any length. + /// + /// Returns [`None`] if the value is larger than fits the [`Uint`]. + pub fn try_from_be_slice(slice: &[u8]) -> Option { + Uint::try_from_be_slice(slice).map(Self) + } + + /// Creates a new integer from a little endian slice of bytes. + /// + /// The slice is interpreted as a big endian number. Leading zeros + /// are ignored. The slice can be any length. + /// + /// Returns [`None`] if the value is larger than fits the [`Uint`]. + pub fn try_from_le_slice(slice: &[u8]) -> Option { + Uint::try_from_le_slice(slice).map(Self) + } + + /// View the array of limbs. + #[inline(always)] + #[must_use] + pub const fn as_limbs(&self) -> &[u64; LIMBS] { + self.0.as_limbs() + } + + /// Convert to a array of limbs. + /// + /// Limbs are least significant first. + #[inline(always)] + pub const fn into_limbs(self) -> [u64; LIMBS] { + self.0.into_limbs() + } + + /// Construct a new integer from little-endian a array of limbs. + /// + /// # Panics + /// + /// Panics if `LIMBS` is not equal to `nlimbs(BITS)`. + /// + /// Panics if the value is to large for the bit-size of the Uint. + #[inline(always)] + #[track_caller] + #[must_use] + pub const fn from_limbs(limbs: [u64; LIMBS]) -> Self { + Self(Uint::from_limbs(limbs)) + } + + /// Constructs the [`Signed`] from digits in the base `base` in big-endian. + /// Wrapper around ruint's from_base_be + /// + /// # Errors + /// + /// * [`BaseConvertError::InvalidBase`] if the base is less than 2. + /// * [`BaseConvertError::InvalidDigit`] if a digit is out of range. + /// * [`BaseConvertError::Overflow`] if the number is too large to fit. + pub fn from_base_be>( + base: u64, + digits: I, + ) -> Result { + Ok(Self(Uint::from_base_be(base, digits)?)) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::{aliases::*, BigIntConversionError, ParseSignedError}; + use alloc::string::ToString; + use core::ops::Neg; + use ruint::{ + aliases::{U0, U1, U128, U160, U256}, + BaseConvertError, ParseError, + }; + + // type U2 = Uint<2, 1>; + type I96 = Signed<96, 2>; + type U96 = Uint<96, 2>; + + #[test] + fn identities() { + macro_rules! test_identities { + ($signed:ty, $max:literal, $min:literal) => { + assert_eq!(<$signed>::ZERO.to_string(), "0"); + assert_eq!(<$signed>::ONE.to_string(), "1"); + assert_eq!(<$signed>::MINUS_ONE.to_string(), "-1"); + assert_eq!(<$signed>::MAX.to_string(), $max); + assert_eq!(<$signed>::MIN.to_string(), $min); + }; + } + + assert_eq!(I0::ZERO.to_string(), "0"); + assert_eq!(I1::ZERO.to_string(), "0"); + assert_eq!(I1::ONE.to_string(), "-1"); + + test_identities!(I96, "39614081257132168796771975167", "-39614081257132168796771975168"); + test_identities!( + I128, + "170141183460469231731687303715884105727", + "-170141183460469231731687303715884105728" + ); + test_identities!( + I192, + "3138550867693340381917894711603833208051177722232017256447", + "-3138550867693340381917894711603833208051177722232017256448" + ); + test_identities!( + I256, + "57896044618658097711785492504343953926634992332820282019728792003956564819967", + "-57896044618658097711785492504343953926634992332820282019728792003956564819968" + ); + } + + #[test] + fn std_num_conversion() { + // test conversion from basic types + + macro_rules! run_test { + ($i_struct:ty, $u_struct:ty, $i:ty, $u:ty) => { + // Test a specific number + assert_eq!(<$i_struct>::try_from(-42 as $i).unwrap().to_string(), "-42"); + assert_eq!(<$i_struct>::try_from(42 as $i).unwrap().to_string(), "42"); + assert_eq!(<$i_struct>::try_from(42 as $u).unwrap().to_string(), "42"); + + if <$u_struct>::BITS as u32 >= <$u>::BITS { + assert_eq!( + <$i_struct>::try_from(<$i>::MAX).unwrap().to_string(), + <$i>::MAX.to_string(), + ); + assert_eq!( + <$i_struct>::try_from(<$i>::MIN).unwrap().to_string(), + <$i>::MIN.to_string(), + ); + } else { + assert_eq!( + <$i_struct>::try_from(<$i>::MAX).unwrap_err(), + BigIntConversionError, + ); + } + }; + + ($i_struct:ty, $u_struct:ty) => { + run_test!($i_struct, $u_struct, i8, u8); + run_test!($i_struct, $u_struct, i16, u16); + run_test!($i_struct, $u_struct, i32, u32); + run_test!($i_struct, $u_struct, i64, u64); + run_test!($i_struct, $u_struct, i128, u128); + run_test!($i_struct, $u_struct, isize, usize); + }; + } + + // edge cases + assert_eq!(I0::unchecked_from(0), I0::default()); + assert_eq!(I0::try_from(1u8), Err(BigIntConversionError)); + assert_eq!(I0::try_from(1i8), Err(BigIntConversionError)); + assert_eq!(I1::unchecked_from(0), I1::default()); + assert_eq!(I1::try_from(1u8), Err(BigIntConversionError)); + assert_eq!(I1::try_from(1i8), Err(BigIntConversionError)); + assert_eq!(I1::try_from(-1), Ok(I1::MINUS_ONE)); + + run_test!(I96, U96); + run_test!(I128, U128); + run_test!(I160, U160); + run_test!(I192, U192); + run_test!(I256, U256); + } + + #[test] + fn from_dec_str() { + macro_rules! run_test { + ($i_struct:ty, $u_struct:ty) => { + let min_abs: $u_struct = <$i_struct>::MIN.0; + let unsigned = <$u_struct>::from_str_radix("3141592653589793", 10).unwrap(); + + let value = <$i_struct>::from_dec_str(&format!("-{unsigned}")).unwrap(); + assert_eq!(value.into_sign_and_abs(), (Sign::Negative, unsigned)); + + let value = <$i_struct>::from_dec_str(&format!("{unsigned}")).unwrap(); + assert_eq!(value.into_sign_and_abs(), (Sign::Positive, unsigned)); + + let value = <$i_struct>::from_dec_str(&format!("+{unsigned}")).unwrap(); + assert_eq!(value.into_sign_and_abs(), (Sign::Positive, unsigned)); + + let err = <$i_struct>::from_dec_str("invalid string").unwrap_err(); + assert_eq!( + err, + ParseSignedError::Ruint(ParseError::BaseConvertError( + BaseConvertError::InvalidDigit(18, 10) + )) + ); + + let err = <$i_struct>::from_dec_str(&format!("1{}", <$u_struct>::MAX)).unwrap_err(); + assert_eq!(err, ParseSignedError::IntegerOverflow); + + let err = <$i_struct>::from_dec_str(&format!("-{}", <$u_struct>::MAX)).unwrap_err(); + assert_eq!(err, ParseSignedError::IntegerOverflow); + + let value = <$i_struct>::from_dec_str(&format!("-{}", min_abs)).unwrap(); + assert_eq!(value.into_sign_and_abs(), (Sign::Negative, min_abs)); + + let err = <$i_struct>::from_dec_str(&format!("{}", min_abs)).unwrap_err(); + assert_eq!(err, ParseSignedError::IntegerOverflow); + }; + } + + assert_eq!(I0::from_dec_str("0"), Ok(I0::default())); + assert_eq!(I1::from_dec_str("0"), Ok(I1::ZERO)); + assert_eq!(I1::from_dec_str("-1"), Ok(I1::MINUS_ONE)); + assert_eq!(I1::from_dec_str("1"), Err(ParseSignedError::IntegerOverflow)); + + run_test!(I96, U96); + run_test!(I128, U128); + run_test!(I160, U160); + run_test!(I192, U192); + run_test!(I256, U256); + } + + #[test] + fn from_hex_str() { + macro_rules! run_test { + ($i_struct:ty, $u_struct:ty) => { + let min_abs = <$i_struct>::MIN.0; + let unsigned = <$u_struct>::from_str_radix("3141592653589793", 10).unwrap(); + + let value = <$i_struct>::from_hex_str(&format!("-{unsigned:x}")).unwrap(); + assert_eq!(value.into_sign_and_abs(), (Sign::Negative, unsigned)); + + let value = <$i_struct>::from_hex_str(&format!("-0x{unsigned:x}")).unwrap(); + assert_eq!(value.into_sign_and_abs(), (Sign::Negative, unsigned)); + + let value = <$i_struct>::from_hex_str(&format!("{unsigned:x}")).unwrap(); + assert_eq!(value.into_sign_and_abs(), (Sign::Positive, unsigned)); + + let value = <$i_struct>::from_hex_str(&format!("0x{unsigned:x}")).unwrap(); + assert_eq!(value.into_sign_and_abs(), (Sign::Positive, unsigned)); + + let value = <$i_struct>::from_hex_str(&format!("+0x{unsigned:x}")).unwrap(); + assert_eq!(value.into_sign_and_abs(), (Sign::Positive, unsigned)); + + let err = <$i_struct>::from_hex_str("invalid string").unwrap_err(); + assert!(matches!(err, ParseSignedError::Ruint(_))); + + let err = + <$i_struct>::from_hex_str(&format!("1{:x}", <$u_struct>::MAX)).unwrap_err(); + assert!(matches!(err, ParseSignedError::IntegerOverflow)); + + let err = + <$i_struct>::from_hex_str(&format!("-{:x}", <$u_struct>::MAX)).unwrap_err(); + assert!(matches!(err, ParseSignedError::IntegerOverflow)); + + let value = <$i_struct>::from_hex_str(&format!("-{:x}", min_abs)).unwrap(); + assert_eq!(value.into_sign_and_abs(), (Sign::Negative, min_abs)); + + let err = <$i_struct>::from_hex_str(&format!("{:x}", min_abs)).unwrap_err(); + assert!(matches!(err, ParseSignedError::IntegerOverflow)); + }; + } + + assert_eq!(I0::from_hex_str("0x0"), Ok(I0::default())); + assert_eq!(I1::from_hex_str("0x0"), Ok(I1::ZERO)); + assert_eq!(I1::from_hex_str("0x0"), Ok(I1::ZERO)); + assert_eq!(I1::from_hex_str("-0x1"), Ok(I1::MINUS_ONE)); + assert_eq!(I1::from_hex_str("0x1"), Err(ParseSignedError::IntegerOverflow)); + + run_test!(I96, U96); + run_test!(I128, U128); + run_test!(I160, U160); + run_test!(I192, U192); + run_test!(I256, U256); + } + + #[test] + fn parse() { + assert_eq!("0x0".parse::(), Ok(I0::default())); + assert_eq!("+0x0".parse::(), Ok(I0::default())); + assert_eq!("0x0".parse::(), Ok(I1::ZERO)); + assert_eq!("+0x0".parse::(), Ok(I1::ZERO)); + assert_eq!("-0x1".parse::(), Ok(I1::MINUS_ONE)); + assert_eq!("0x1".parse::(), Err(ParseSignedError::IntegerOverflow)); + + assert_eq!("0".parse::(), Ok(I0::default())); + assert_eq!("+0".parse::(), Ok(I0::default())); + assert_eq!("0".parse::(), Ok(I1::ZERO)); + assert_eq!("+0".parse::(), Ok(I1::ZERO)); + assert_eq!("-1".parse::(), Ok(I1::MINUS_ONE)); + assert_eq!("1".parse::(), Err(ParseSignedError::IntegerOverflow)); + } + + #[test] + fn formatting() { + macro_rules! run_test { + ($i_struct:ty, $u_struct:ty) => { + let unsigned = <$u_struct>::from_str_radix("3141592653589793", 10).unwrap(); + let unsigned_negative = -unsigned; + let positive = <$i_struct>::try_from(unsigned).unwrap(); + let negative = -positive; + + assert_eq!(format!("{positive}"), format!("{unsigned}")); + assert_eq!(format!("{negative}"), format!("-{unsigned}")); + assert_eq!(format!("{positive:+}"), format!("+{unsigned}")); + assert_eq!(format!("{negative:+}"), format!("-{unsigned}")); + + assert_eq!(format!("{positive:x}"), format!("{unsigned:x}")); + assert_eq!(format!("{negative:x}"), format!("{unsigned_negative:x}")); + assert_eq!(format!("{positive:+x}"), format!("+{unsigned:x}")); + assert_eq!(format!("{negative:+x}"), format!("+{unsigned_negative:x}")); + + assert_eq!(format!("{positive:X}"), format!("{unsigned:X}")); + assert_eq!(format!("{negative:X}"), format!("{unsigned_negative:X}")); + assert_eq!(format!("{positive:+X}"), format!("+{unsigned:X}")); + assert_eq!(format!("{negative:+X}"), format!("+{unsigned_negative:X}")); + }; + } + + let z = I0::default(); + let o = I1::default(); + let m = I1::MINUS_ONE; + assert_eq!(format!("{z} {o} {m}"), "0 0 -1"); + + run_test!(I96, U96); + run_test!(I128, U128); + run_test!(I160, U160); + run_test!(I192, U192); + run_test!(I256, U256); + } + + #[test] + fn signs() { + macro_rules! run_test { + ($i_struct:ty, $u_struct:ty) => { + assert_eq!(<$i_struct>::MAX.sign(), Sign::Positive); + assert!(<$i_struct>::MAX.is_positive()); + assert!(!<$i_struct>::MAX.is_negative()); + assert!(!<$i_struct>::MAX.is_zero()); + + assert_eq!(<$i_struct>::ONE.sign(), Sign::Positive); + assert!(<$i_struct>::ONE.is_positive()); + assert!(!<$i_struct>::ONE.is_negative()); + assert!(!<$i_struct>::ONE.is_zero()); + + assert_eq!(<$i_struct>::MIN.sign(), Sign::Negative); + assert!(!<$i_struct>::MIN.is_positive()); + assert!(<$i_struct>::MIN.is_negative()); + assert!(!<$i_struct>::MIN.is_zero()); + + assert_eq!(<$i_struct>::MINUS_ONE.sign(), Sign::Negative); + assert!(!<$i_struct>::MINUS_ONE.is_positive()); + assert!(<$i_struct>::MINUS_ONE.is_negative()); + assert!(!<$i_struct>::MINUS_ONE.is_zero()); + + assert_eq!(<$i_struct>::ZERO.sign(), Sign::Positive); + assert!(!<$i_struct>::ZERO.is_positive()); + assert!(!<$i_struct>::ZERO.is_negative()); + assert!(<$i_struct>::ZERO.is_zero()); + }; + } + + let z = I0::default(); + let o = I1::default(); + let m = I1::MINUS_ONE; + assert_eq!(z.sign(), Sign::Positive); + assert_eq!(o.sign(), Sign::Positive); + assert_eq!(m.sign(), Sign::Negative); + + run_test!(I96, U96); + run_test!(I128, U128); + run_test!(I160, U160); + run_test!(I192, U192); + run_test!(I256, U256); + } + + #[test] + fn abs() { + macro_rules! run_test { + ($i_struct:ty, $u_struct:ty) => { + let positive = <$i_struct>::from_dec_str("3141592653589793").unwrap(); + let negative = <$i_struct>::from_dec_str("-27182818284590").unwrap(); + + assert_eq!(positive.sign(), Sign::Positive); + assert_eq!(positive.abs().sign(), Sign::Positive); + assert_eq!(positive, positive.abs()); + assert_ne!(negative, negative.abs()); + assert_eq!(negative.sign(), Sign::Negative); + assert_eq!(negative.abs().sign(), Sign::Positive); + assert_eq!(<$i_struct>::ZERO.abs(), <$i_struct>::ZERO); + assert_eq!(<$i_struct>::MAX.abs(), <$i_struct>::MAX); + assert_eq!((-<$i_struct>::MAX).abs(), <$i_struct>::MAX); + assert_eq!(<$i_struct>::MIN.checked_abs(), None); + }; + } + + let z = I0::default(); + let o = I1::default(); + let m = I1::MINUS_ONE; + assert_eq!(z.abs(), z); + assert_eq!(o.abs(), o); + assert_eq!(m.checked_abs(), None); + + run_test!(I96, U96); + run_test!(I128, U128); + run_test!(I160, U160); + run_test!(I192, U192); + run_test!(I256, U256); + } + + #[test] + fn neg() { + macro_rules! run_test { + ($i_struct:ty, $u_struct:ty) => { + let positive = <$i_struct>::from_dec_str("3141592653589793").unwrap().sign(); + let negative = -positive; + + assert_eq!(-positive, negative); + assert_eq!(-negative, positive); + + assert_eq!(-<$i_struct>::ZERO, <$i_struct>::ZERO); + assert_eq!(-(-<$i_struct>::MAX), <$i_struct>::MAX); + assert_eq!(<$i_struct>::MIN.checked_neg(), None); + }; + } + + let z = I0::default(); + let o = I1::default(); + let m = I1::MINUS_ONE; + assert_eq!(-z, z); + assert_eq!(-o, o); + assert_eq!(m.checked_neg(), None); + + run_test!(I96, U96); + run_test!(I128, U128); + run_test!(I160, U160); + run_test!(I192, U192); + run_test!(I256, U256); + } + + #[test] + fn bits() { + macro_rules! run_test { + ($i_struct:ty, $u_struct:ty) => { + assert_eq!(<$i_struct>::try_from(0b1000).unwrap().bits(), 5); + assert_eq!(<$i_struct>::try_from(-0b1000).unwrap().bits(), 4); + + assert_eq!(<$i_struct>::try_from(i64::MAX).unwrap().bits(), 64); + assert_eq!(<$i_struct>::try_from(i64::MIN).unwrap().bits(), 64); + + assert_eq!(<$i_struct>::MAX.bits(), <$i_struct>::BITS as u32); + assert_eq!(<$i_struct>::MIN.bits(), <$i_struct>::BITS as u32); + + assert_eq!(<$i_struct>::ZERO.bits(), 0); + }; + } + + let z = I0::default(); + let o = I1::default(); + let m = I1::MINUS_ONE; + assert_eq!(z.bits(), 0); + assert_eq!(o.bits(), 0); + assert_eq!(m.bits(), 1); + + run_test!(I96, U96); + run_test!(I128, U128); + run_test!(I160, U160); + run_test!(I192, U192); + run_test!(I256, U256); + } + + #[test] + fn bit_shift() { + macro_rules! run_test { + ($i_struct:ty, $u_struct:ty) => { + assert_eq!(<$i_struct>::ONE << <$i_struct>::BITS - 1, <$i_struct>::MIN); + assert_eq!(<$i_struct>::MIN >> <$i_struct>::BITS - 1, <$i_struct>::ONE); + }; + } + + let z = I0::default(); + let o = I1::default(); + let m = I1::MINUS_ONE; + assert_eq!(z << 1, z >> 1); + assert_eq!(o << 1, o >> 0); + assert_eq!(m << 1, o); + assert_eq!(m >> 1, o); + + run_test!(I96, U96); + run_test!(I128, U128); + run_test!(I160, U160); + run_test!(I192, U192); + run_test!(I256, U256); + } + + #[test] + fn arithmetic_shift_right() { + macro_rules! run_test { + ($i_struct:ty, $u_struct:ty) => { + let exp = <$i_struct>::BITS - 2; + let shift = <$i_struct>::BITS - 3; + + let value = + <$i_struct>::from_raw(<$u_struct>::from(2u8).pow(<$u_struct>::from(exp))).neg(); + + let expected_result = + <$i_struct>::from_raw(<$u_struct>::MAX - <$u_struct>::from(1u8)); + assert_eq!( + value.asr(shift), + expected_result, + "1011...1111 >> 253 was not 1111...1110" + ); + + let value = <$i_struct>::MINUS_ONE; + let expected_result = <$i_struct>::MINUS_ONE; + assert_eq!(value.asr(250), expected_result, "-1 >> any_amount was not -1"); + + let value = <$i_struct>::from_raw( + <$u_struct>::from(2u8).pow(<$u_struct>::from(<$i_struct>::BITS - 2)), + ) + .neg(); + let expected_result = <$i_struct>::MINUS_ONE; + assert_eq!( + value.asr(<$i_struct>::BITS - 1), + expected_result, + "1011...1111 >> 255 was not -1" + ); + + let value = <$i_struct>::from_raw( + <$u_struct>::from(2u8).pow(<$u_struct>::from(<$i_struct>::BITS - 2)), + ) + .neg(); + let expected_result = <$i_struct>::MINUS_ONE; + assert_eq!(value.asr(1024), expected_result, "1011...1111 >> 1024 was not -1"); + + let value = <$i_struct>::try_from(1024i32).unwrap(); + let expected_result = <$i_struct>::try_from(32i32).unwrap(); + assert_eq!(value.asr(5), expected_result, "1024 >> 5 was not 32"); + + let value = <$i_struct>::MAX; + let expected_result = <$i_struct>::ZERO; + assert_eq!(value.asr(255), expected_result, "<$i_struct>::MAX >> 255 was not 0"); + + let value = + <$i_struct>::from_raw(<$u_struct>::from(2u8).pow(<$u_struct>::from(exp))).neg(); + let expected_result = value; + assert_eq!(value.asr(0), expected_result, "1011...1111 >> 0 was not 1011...111"); + }; + } + + let z = I0::default(); + let o = I1::default(); + let m = I1::MINUS_ONE; + assert_eq!(z.asr(1), z); + assert_eq!(o.asr(1), o); + assert_eq!(m.asr(1), m); + assert_eq!(m.asr(1000), m); + + run_test!(I96, U96); + run_test!(I128, U128); + run_test!(I160, U160); + run_test!(I192, U192); + run_test!(I256, U256); + } + + #[test] + fn arithmetic_shift_left() { + macro_rules! run_test { + ($i_struct:ty, $u_struct:ty) => { + let value = <$i_struct>::MINUS_ONE; + let expected_result = Some(value); + assert_eq!(value.asl(0), expected_result, "-1 << 0 was not -1"); + + let value = <$i_struct>::MINUS_ONE; + let expected_result = None; + assert_eq!( + value.asl(256), + expected_result, + "-1 << 256 did not overflow (result should be 0000...0000)" + ); + + let value = <$i_struct>::MINUS_ONE; + let expected_result = Some(<$i_struct>::from_raw( + <$u_struct>::from(2u8).pow(<$u_struct>::from(<$i_struct>::BITS - 1)), + )); + assert_eq!( + value.asl(<$i_struct>::BITS - 1), + expected_result, + "-1 << 255 was not 1000...0000" + ); + + let value = <$i_struct>::try_from(-1024i32).unwrap(); + let expected_result = Some(<$i_struct>::try_from(-32768i32).unwrap()); + assert_eq!(value.asl(5), expected_result, "-1024 << 5 was not -32768"); + + let value = <$i_struct>::try_from(1024i32).unwrap(); + let expected_result = Some(<$i_struct>::try_from(32768i32).unwrap()); + assert_eq!(value.asl(5), expected_result, "1024 << 5 was not 32768"); + + let value = <$i_struct>::try_from(1024i32).unwrap(); + let expected_result = None; + assert_eq!( + value.asl(<$i_struct>::BITS - 11), + expected_result, + "1024 << 245 did not overflow (result should be 1000...0000)" + ); + + let value = <$i_struct>::ZERO; + let expected_result = Some(value); + assert_eq!(value.asl(1024), expected_result, "0 << anything was not 0"); + }; + } + + let z = I0::default(); + let o = I1::default(); + let m = I1::MINUS_ONE; + assert_eq!(z.asl(1), Some(z)); + assert_eq!(o.asl(1), Some(o)); + assert_eq!(m.asl(1), None); + + run_test!(I96, U96); + run_test!(I128, U128); + run_test!(I160, U160); + run_test!(I192, U192); + run_test!(I256, U256); + } + + #[test] + fn addition() { + macro_rules! run_test { + ($i_struct:ty, $u_struct:ty) => { + assert_eq!( + <$i_struct>::MIN.overflowing_add(<$i_struct>::MIN), + (<$i_struct>::ZERO, true) + ); + assert_eq!( + <$i_struct>::MAX.overflowing_add(<$i_struct>::MAX), + (<$i_struct>::try_from(-2).unwrap(), true) + ); + + assert_eq!( + <$i_struct>::MIN.overflowing_add(<$i_struct>::MINUS_ONE), + (<$i_struct>::MAX, true) + ); + assert_eq!( + <$i_struct>::MAX.overflowing_add(<$i_struct>::ONE), + (<$i_struct>::MIN, true) + ); + + assert_eq!(<$i_struct>::MAX + <$i_struct>::MIN, <$i_struct>::MINUS_ONE); + assert_eq!( + <$i_struct>::try_from(2).unwrap() + <$i_struct>::try_from(40).unwrap(), + <$i_struct>::try_from(42).unwrap() + ); + + assert_eq!(<$i_struct>::ZERO + <$i_struct>::ZERO, <$i_struct>::ZERO); + + assert_eq!(<$i_struct>::MAX.saturating_add(<$i_struct>::MAX), <$i_struct>::MAX); + assert_eq!( + <$i_struct>::MIN.saturating_add(<$i_struct>::MINUS_ONE), + <$i_struct>::MIN + ); + }; + } + + let z = I0::default(); + let o = I1::default(); + let m = I1::MINUS_ONE; + assert_eq!(z + z, z); + assert_eq!(o + o, o); + assert_eq!(m + o, m); + assert_eq!(m.overflowing_add(m), (o, true)); + + run_test!(I96, U96); + run_test!(I128, U128); + run_test!(I160, U160); + run_test!(I192, U192); + run_test!(I256, U256); + } + + #[test] + fn subtraction() { + macro_rules! run_test { + ($i_struct:ty, $u_struct:ty) => { + assert_eq!( + <$i_struct>::MIN.overflowing_sub(<$i_struct>::MAX), + (<$i_struct>::ONE, true) + ); + assert_eq!( + <$i_struct>::MAX.overflowing_sub(<$i_struct>::MIN), + (<$i_struct>::MINUS_ONE, true) + ); + + assert_eq!( + <$i_struct>::MIN.overflowing_sub(<$i_struct>::ONE), + (<$i_struct>::MAX, true) + ); + assert_eq!( + <$i_struct>::MAX.overflowing_sub(<$i_struct>::MINUS_ONE), + (<$i_struct>::MIN, true) + ); + + assert_eq!( + <$i_struct>::ZERO.overflowing_sub(<$i_struct>::MIN), + (<$i_struct>::MIN, true) + ); + + assert_eq!(<$i_struct>::MAX - <$i_struct>::MAX, <$i_struct>::ZERO); + assert_eq!( + <$i_struct>::try_from(2).unwrap() - <$i_struct>::try_from(44).unwrap(), + <$i_struct>::try_from(-42).unwrap() + ); + + assert_eq!(<$i_struct>::ZERO - <$i_struct>::ZERO, <$i_struct>::ZERO); + + assert_eq!(<$i_struct>::MAX.saturating_sub(<$i_struct>::MIN), <$i_struct>::MAX); + assert_eq!(<$i_struct>::MIN.saturating_sub(<$i_struct>::ONE), <$i_struct>::MIN); + }; + } + + let z = I0::default(); + let o = I1::default(); + let m = I1::MINUS_ONE; + assert_eq!(z - z, z); + assert_eq!(o - o, o); + assert_eq!(m - o, m); + assert_eq!(m - m, o); + assert_eq!(o.overflowing_sub(m), (m, true)); + + run_test!(I96, U96); + run_test!(I128, U128); + run_test!(I160, U160); + run_test!(I192, U192); + run_test!(I256, U256); + } + + #[test] + fn multiplication() { + macro_rules! run_test { + ($i_struct:ty, $u_struct:ty) => { + assert_eq!( + <$i_struct>::MIN.overflowing_mul(<$i_struct>::MAX), + (<$i_struct>::MIN, true) + ); + assert_eq!( + <$i_struct>::MAX.overflowing_mul(<$i_struct>::MIN), + (<$i_struct>::MIN, true) + ); + + assert_eq!(<$i_struct>::MIN * <$i_struct>::ONE, <$i_struct>::MIN); + assert_eq!( + <$i_struct>::try_from(2).unwrap() * <$i_struct>::try_from(-21).unwrap(), + <$i_struct>::try_from(-42).unwrap() + ); + + assert_eq!(<$i_struct>::MAX.saturating_mul(<$i_struct>::MAX), <$i_struct>::MAX); + assert_eq!( + <$i_struct>::MAX.saturating_mul(<$i_struct>::try_from(2).unwrap()), + <$i_struct>::MAX + ); + assert_eq!( + <$i_struct>::MIN.saturating_mul(<$i_struct>::try_from(-2).unwrap()), + <$i_struct>::MAX + ); + + assert_eq!(<$i_struct>::MIN.saturating_mul(<$i_struct>::MAX), <$i_struct>::MIN); + assert_eq!( + <$i_struct>::MIN.saturating_mul(<$i_struct>::try_from(2).unwrap()), + <$i_struct>::MIN + ); + assert_eq!( + <$i_struct>::MAX.saturating_mul(<$i_struct>::try_from(-2).unwrap()), + <$i_struct>::MIN + ); + + assert_eq!(<$i_struct>::ZERO * <$i_struct>::ZERO, <$i_struct>::ZERO); + assert_eq!(<$i_struct>::ONE * <$i_struct>::ZERO, <$i_struct>::ZERO); + assert_eq!(<$i_struct>::MAX * <$i_struct>::ZERO, <$i_struct>::ZERO); + assert_eq!(<$i_struct>::MIN * <$i_struct>::ZERO, <$i_struct>::ZERO); + }; + } + + let z = I0::default(); + let o = I1::default(); + let m = I1::MINUS_ONE; + assert_eq!(z * z, z); + assert_eq!(o * o, o); + assert_eq!(m * o, o); + assert_eq!(m.overflowing_mul(m), (m, true)); + + run_test!(I96, U96); + run_test!(I128, U128); + run_test!(I160, U160); + run_test!(I192, U192); + run_test!(I256, U256); + } + + #[test] + fn division() { + macro_rules! run_test { + ($i_struct:ty, $u_struct:ty) => { + // The only case for overflow. + assert_eq!( + <$i_struct>::MIN.overflowing_div(<$i_struct>::try_from(-1).unwrap()), + (<$i_struct>::MIN, true) + ); + + assert_eq!(<$i_struct>::MIN / <$i_struct>::MAX, <$i_struct>::try_from(-1).unwrap()); + assert_eq!(<$i_struct>::MAX / <$i_struct>::MIN, <$i_struct>::ZERO); + + assert_eq!(<$i_struct>::MIN / <$i_struct>::ONE, <$i_struct>::MIN); + assert_eq!( + <$i_struct>::try_from(-42).unwrap() / <$i_struct>::try_from(-21).unwrap(), + <$i_struct>::try_from(2).unwrap() + ); + assert_eq!( + <$i_struct>::try_from(-42).unwrap() / <$i_struct>::try_from(2).unwrap(), + <$i_struct>::try_from(-21).unwrap() + ); + assert_eq!( + <$i_struct>::try_from(42).unwrap() / <$i_struct>::try_from(-21).unwrap(), + <$i_struct>::try_from(-2).unwrap() + ); + assert_eq!( + <$i_struct>::try_from(42).unwrap() / <$i_struct>::try_from(21).unwrap(), + <$i_struct>::try_from(2).unwrap() + ); + + // The only saturating corner case. + assert_eq!( + <$i_struct>::MIN.saturating_div(<$i_struct>::try_from(-1).unwrap()), + <$i_struct>::MAX + ); + }; + } + + let z = I0::default(); + let o = I1::default(); + let m = I1::MINUS_ONE; + assert_eq!(z.checked_div(z), None); + assert_eq!(o.checked_div(o), None); + assert_eq!(m.checked_div(o), None); + assert_eq!(m.overflowing_div(m), (m, true)); + + run_test!(I96, U96); + run_test!(I128, U128); + run_test!(I160, U160); + run_test!(I192, U192); + run_test!(I256, U256); + } + + #[test] + #[cfg(feature = "std")] + fn division_by_zero() { + macro_rules! run_test { + ($i_struct:ty, $u_struct:ty) => { + let err = std::panic::catch_unwind(|| { + let _ = <$i_struct>::ONE / <$i_struct>::ZERO; + }); + assert!(err.is_err()); + }; + } + + run_test!(I0, U0); + run_test!(I1, U1); + run_test!(I96, U96); + run_test!(I128, U128); + run_test!(I160, U160); + run_test!(I192, U192); + run_test!(I256, U256); + } + + #[test] + fn div_euclid() { + macro_rules! run_test { + ($i_struct:ty, $u_struct:ty) => { + let a = <$i_struct>::try_from(7).unwrap(); + let b = <$i_struct>::try_from(4).unwrap(); + + assert_eq!(a.div_euclid(b), <$i_struct>::ONE); // 7 >= 4 * 1 + assert_eq!(a.div_euclid(-b), <$i_struct>::MINUS_ONE); // 7 >= -4 * -1 + assert_eq!((-a).div_euclid(b), -<$i_struct>::try_from(2).unwrap()); // -7 >= 4 * -2 + assert_eq!((-a).div_euclid(-b), <$i_struct>::try_from(2).unwrap()); // -7 >= -4 * 2 + + // Overflowing + assert_eq!( + <$i_struct>::MIN.overflowing_div_euclid(<$i_struct>::MINUS_ONE), + (<$i_struct>::MIN, true) + ); + // Wrapping + assert_eq!( + <$i_struct>::MIN.wrapping_div_euclid(<$i_struct>::MINUS_ONE), + <$i_struct>::MIN + ); + // // Checked + assert_eq!(<$i_struct>::MIN.checked_div_euclid(<$i_struct>::MINUS_ONE), None); + assert_eq!(<$i_struct>::ONE.checked_div_euclid(<$i_struct>::ZERO), None); + }; + } + + let z = I0::default(); + let o = I1::default(); + let m = I1::MINUS_ONE; + assert_eq!(z.checked_div_euclid(z), None); + assert_eq!(o.checked_div_euclid(o), None); + assert_eq!(m.checked_div_euclid(o), None); + assert_eq!(m.overflowing_div_euclid(m), (m, true)); + + run_test!(I96, U96); + run_test!(I128, U128); + run_test!(I160, U160); + run_test!(I192, U192); + run_test!(I256, U256); + } + + #[test] + fn rem_euclid() { + macro_rules! run_test { + ($i_struct:ty, $u_struct:ty) => { + let a = <$i_struct>::try_from(7).unwrap(); // or any other integer type + let b = <$i_struct>::try_from(4).unwrap(); + + assert_eq!(a.rem_euclid(b), <$i_struct>::try_from(3).unwrap()); + assert_eq!((-a).rem_euclid(b), <$i_struct>::ONE); + assert_eq!(a.rem_euclid(-b), <$i_struct>::try_from(3).unwrap()); + assert_eq!((-a).rem_euclid(-b), <$i_struct>::ONE); + + // Overflowing + assert_eq!(a.overflowing_rem_euclid(b), (<$i_struct>::try_from(3).unwrap(), false)); + assert_eq!( + <$i_struct>::MIN.overflowing_rem_euclid(<$i_struct>::MINUS_ONE), + (<$i_struct>::ZERO, true) + ); + + // Wrapping + assert_eq!( + <$i_struct>::try_from(100) + .unwrap() + .wrapping_rem_euclid(<$i_struct>::try_from(10).unwrap()), + <$i_struct>::ZERO + ); + assert_eq!( + <$i_struct>::MIN.wrapping_rem_euclid(<$i_struct>::MINUS_ONE), + <$i_struct>::ZERO + ); + + // Checked + assert_eq!(a.checked_rem_euclid(b), Some(<$i_struct>::try_from(3).unwrap())); + assert_eq!(a.checked_rem_euclid(<$i_struct>::ZERO), None); + assert_eq!(<$i_struct>::MIN.checked_rem_euclid(<$i_struct>::MINUS_ONE), None); + }; + } + + let z = I0::default(); + let o = I1::default(); + let m = I1::MINUS_ONE; + assert_eq!(z.checked_rem_euclid(z), None); + assert_eq!(o.checked_rem_euclid(o), None); + assert_eq!(m.checked_rem_euclid(o), None); + assert_eq!(m.overflowing_rem_euclid(m), (o, true)); + + run_test!(I96, U96); + run_test!(I128, U128); + run_test!(I160, U160); + run_test!(I192, U192); + run_test!(I256, U256); + } + + #[test] + #[cfg(feature = "std")] + fn div_euclid_by_zero() { + macro_rules! run_test { + ($i_struct:ty, $u_struct:ty) => { + let err = std::panic::catch_unwind(|| { + let _ = <$i_struct>::ONE.div_euclid(<$i_struct>::ZERO); + }); + assert!(err.is_err()); + + let err = std::panic::catch_unwind(|| { + assert_eq!( + <$i_struct>::MIN.div_euclid(<$i_struct>::MINUS_ONE), + <$i_struct>::MAX + ); + }); + assert!(err.is_err()); + }; + } + + run_test!(I0, U0); + run_test!(I1, U1); + + run_test!(I96, U96); + run_test!(I128, U128); + run_test!(I160, U160); + run_test!(I192, U192); + run_test!(I256, U256); + } + + #[test] + #[cfg(feature = "std")] + fn div_euclid_overflow() { + macro_rules! run_test { + ($i_struct:ty, $u_struct:ty) => { + let err = std::panic::catch_unwind(|| { + let _ = <$i_struct>::MIN.div_euclid(<$i_struct>::MINUS_ONE); + }); + assert!(err.is_err()); + }; + } + run_test!(I96, U96); + run_test!(I128, U128); + run_test!(I160, U160); + run_test!(I192, U192); + run_test!(I256, U256); + } + + #[test] + #[cfg(feature = "std")] + fn mod_by_zero() { + macro_rules! run_test { + ($i_struct:ty, $u_struct:ty) => { + let err = std::panic::catch_unwind(|| { + let _ = <$i_struct>::ONE % <$i_struct>::ZERO; + }); + assert!(err.is_err()); + }; + } + + run_test!(I0, U0); + run_test!(I1, U1); + + run_test!(I96, U96); + run_test!(I128, U128); + run_test!(I160, U160); + run_test!(I192, U192); + run_test!(I256, U256); + } + + #[test] + fn remainder() { + macro_rules! run_test { + ($i_struct:ty, $u_struct:ty) => { + // The only case for overflow. + assert_eq!( + <$i_struct>::MIN.overflowing_rem(<$i_struct>::try_from(-1).unwrap()), + (<$i_struct>::ZERO, true) + ); + assert_eq!( + <$i_struct>::try_from(-5).unwrap() % <$i_struct>::try_from(-2).unwrap(), + <$i_struct>::try_from(-1).unwrap() + ); + assert_eq!( + <$i_struct>::try_from(5).unwrap() % <$i_struct>::try_from(-2).unwrap(), + <$i_struct>::ONE + ); + assert_eq!( + <$i_struct>::try_from(-5).unwrap() % <$i_struct>::try_from(2).unwrap(), + <$i_struct>::try_from(-1).unwrap() + ); + assert_eq!( + <$i_struct>::try_from(5).unwrap() % <$i_struct>::try_from(2).unwrap(), + <$i_struct>::ONE + ); + + assert_eq!(<$i_struct>::MIN.checked_rem(<$i_struct>::try_from(-1).unwrap()), None); + assert_eq!(<$i_struct>::ONE.checked_rem(<$i_struct>::ONE), Some(<$i_struct>::ZERO)); + }; + } + + let z = I0::default(); + let o = I1::default(); + let m = I1::MINUS_ONE; + assert_eq!(z.checked_rem(z), None); + assert_eq!(o.checked_rem(o), None); + assert_eq!(m.checked_rem(o), None); + assert_eq!(m.overflowing_rem(m), (o, true)); + + run_test!(I96, U96); + run_test!(I128, U128); + run_test!(I160, U160); + run_test!(I192, U192); + run_test!(I256, U256); + } + + #[test] + fn exponentiation() { + macro_rules! run_test { + ($i_struct:ty, $u_struct:ty) => { + assert_eq!( + <$i_struct>::unchecked_from(1000).saturating_pow(<$u_struct>::from(1000)), + <$i_struct>::MAX + ); + assert_eq!( + <$i_struct>::unchecked_from(-1000).saturating_pow(<$u_struct>::from(1001)), + <$i_struct>::MIN + ); + + assert_eq!( + <$i_struct>::unchecked_from(2).pow(<$u_struct>::from(64)), + <$i_struct>::unchecked_from(1u128 << 64) + ); + assert_eq!( + <$i_struct>::unchecked_from(-2).pow(<$u_struct>::from(63)), + <$i_struct>::unchecked_from(i64::MIN) + ); + + assert_eq!(<$i_struct>::ZERO.pow(<$u_struct>::from(42)), <$i_struct>::ZERO); + assert_eq!(<$i_struct>::exp10(18).to_string(), "1000000000000000000"); + }; + } + + let z = I0::default(); + let o = I1::default(); + let m = I1::MINUS_ONE; + assert_eq!(z.pow(U0::default()), z); + assert_eq!(o.overflowing_pow(U1::default()), (m, true)); + assert_eq!(o.overflowing_pow(U1::from(1u8)), (o, false)); + assert_eq!(m.overflowing_pow(U1::from(1u8)), (m, false)); + assert_eq!(m.overflowing_pow(U1::default()), (m, true)); + + run_test!(I96, U96); + run_test!(I128, U128); + run_test!(I160, U160); + run_test!(I192, U192); + run_test!(I256, U256); + } + + #[test] + fn iterators() { + macro_rules! run_test { + ($i_struct:ty, $u_struct:ty) => { + assert_eq!( + (1..=5).map(<$i_struct>::try_from).map(Result::unwrap).sum::<$i_struct>(), + <$i_struct>::try_from(15).unwrap() + ); + assert_eq!( + (1..=5).map(<$i_struct>::try_from).map(Result::unwrap).product::<$i_struct>(), + <$i_struct>::try_from(120).unwrap() + ); + }; + } + + let z = I0::default(); + let o = I1::default(); + let m = I1::MINUS_ONE; + assert_eq!([z; 0].into_iter().sum::(), z); + assert_eq!([o; 1].into_iter().sum::(), o); + assert_eq!([m; 1].into_iter().sum::(), m); + + run_test!(I96, U96); + run_test!(I128, U128); + run_test!(I160, U160); + run_test!(I192, U192); + run_test!(I256, U256); + } + + #[test] + fn twos_complement() { + macro_rules! assert_twos_complement { + ($i_struct:ty, $u_struct:ty, $signed:ty, $unsigned:ty) => { + if <$u_struct>::BITS as u32 >= <$unsigned>::BITS { + assert_eq!( + <$i_struct>::try_from(<$signed>::MAX).unwrap().twos_complement(), + <$u_struct>::try_from(<$signed>::MAX).unwrap() + ); + assert_eq!( + <$i_struct>::try_from(<$signed>::MIN).unwrap().twos_complement(), + <$u_struct>::try_from(<$signed>::MIN.unsigned_abs()).unwrap() + ); + } + + assert_eq!( + <$i_struct>::try_from(0 as $signed).unwrap().twos_complement(), + <$u_struct>::try_from(0 as $signed).unwrap() + ); + + assert_eq!( + <$i_struct>::try_from(0 as $unsigned).unwrap().twos_complement(), + <$u_struct>::try_from(0 as $unsigned).unwrap() + ); + }; + } + macro_rules! run_test { + ($i_struct:ty, $u_struct:ty) => { + assert_twos_complement!($i_struct, $u_struct, i8, u8); + assert_twos_complement!($i_struct, $u_struct, i16, u16); + assert_twos_complement!($i_struct, $u_struct, i32, u32); + assert_twos_complement!($i_struct, $u_struct, i64, u64); + assert_twos_complement!($i_struct, $u_struct, i128, u128); + assert_twos_complement!($i_struct, $u_struct, isize, usize); + }; + } + + let z = I0::default(); + let o = I1::default(); + let m = I1::MINUS_ONE; + assert_eq!(z.twos_complement(), U0::default()); + assert_eq!(o.twos_complement(), U1::default()); + assert_eq!(m.twos_complement(), U1::from(1)); + + run_test!(I96, U96); + run_test!(I128, U128); + run_test!(I160, U160); + run_test!(I192, U192); + run_test!(I256, U256); + } + + #[test] + fn test_overflowing_from_sign_and_abs() { + let a = Uint::<8, 1>::ZERO; + let (_, overflow) = Signed::overflowing_from_sign_and_abs(Sign::Negative, a); + assert!(!overflow); + + let a = Uint::<8, 1>::from(128u8); + let (_, overflow) = Signed::overflowing_from_sign_and_abs(Sign::Negative, a); + assert!(!overflow); + + let a = Uint::<8, 1>::from(129u8); + let (_, overflow) = Signed::overflowing_from_sign_and_abs(Sign::Negative, a); + assert!(overflow); + } +} diff --git a/CoqOfRust/alloy_primitives/signed/int.v b/CoqOfRust/alloy_primitives/signed/int.v new file mode 100644 index 000000000..06c411ca9 --- /dev/null +++ b/CoqOfRust/alloy_primitives/signed/int.v @@ -0,0 +1,4316 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module signed. + Module int. + (* StructTuple + { + name := "Signed"; + const_params := [ "BITS"; "LIMBS" ]; + ty_params := []; + fields := [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ]; + } *) + + Module Impl_core_clone_Clone_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* Clone *) + Definition clone + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.deref (| M.read (| self |) |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self BITS LIMBS) + (* Instance *) [ ("clone", InstanceField.Method (clone BITS LIMBS)) ]. + End Impl_core_clone_Clone_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_marker_Copy_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self BITS LIMBS) + (* Instance *) []. + End Impl_core_marker_Copy_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_default_Default_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* Default *) + Definition default + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::default::Default", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [], + "default", + [], + [] + |), + [] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self BITS LIMBS) + (* Instance *) [ ("default", InstanceField.Method (default BITS LIMBS)) ]. + End Impl_core_default_Default_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_marker_StructuralPartialEq_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self BITS LIMBS) + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_cmp_PartialEq_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* PartialEq *) + Definition eq + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ], + "eq", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] ] + (Self BITS LIMBS) + (* Instance *) [ ("eq", InstanceField.Method (eq BITS LIMBS)) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_cmp_Eq_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* Eq *) + Definition assert_receiver_is_total_eq + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self BITS LIMBS) + (* Instance *) + [ + ("assert_receiver_is_total_eq", + InstanceField.Method (assert_receiver_is_total_eq BITS LIMBS)) + ]. + End Impl_core_cmp_Eq_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_hash_Hash_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* Hash *) + Definition hash + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [ __H ], [ self; state ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let state := M.alloc (| state |) in + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::hash::Hash", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [], + "hash", + [], + [ __H ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| state |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::hash::Hash" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self BITS LIMBS) + (* Instance *) [ ("hash", InstanceField.Method (hash BITS LIMBS)) ]. + End Impl_core_hash_Hash_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_fmt_Debug_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt::Display::fmt(self, f) + } + *) + Definition fmt + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::Display", + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self BITS LIMBS) + (* Instance *) [ ("fmt", InstanceField.Method (fmt BITS LIMBS)) ]. + End Impl_core_fmt_Debug_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_fmt_Display_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let (sign, abs) = self.into_sign_and_abs(); + sign.fmt(f)?; + if f.sign_plus() { + write!(f, "{abs}") + } else { + abs.fmt(f) + } + } + *) + Definition fmt + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + M.match_operator (| + None, + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.path "alloy_primitives::signed::sign::Sign"; + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "into_sign_and_abs", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let sign := M.copy (| γ0_0 |) in + let abs := M.copy (| γ0_1 |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "core::fmt::Error" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::Display", + Ty.path "alloy_primitives::signed::sign::Sign", + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, sign |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| f |) |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "core::fmt::Error" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "sign_plus", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| f |) |) + |) + ] + |) + |)) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_fmt", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| f |) |) + |); + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 1; + Value.Integer IntegerKind.Usize 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [ mk_str (| "" |) ] |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.apply + (Ty.path "ruint::Uint") + [ BITS; LIMBS ] + [] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, abs |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::Display", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, abs |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| M.read (| f |) |) + |) + ] + |) + |))) + ] + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::fmt::Display" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self BITS LIMBS) + (* Instance *) [ ("fmt", InstanceField.Method (fmt BITS LIMBS)) ]. + End Impl_core_fmt_Display_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_fmt_Binary_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } + *) + Definition fmt + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::Binary", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::fmt::Binary" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self BITS LIMBS) + (* Instance *) [ ("fmt", InstanceField.Method (fmt BITS LIMBS)) ]. + End Impl_core_fmt_Binary_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_fmt_Octal_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } + *) + Definition fmt + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::Octal", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::fmt::Octal" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self BITS LIMBS) + (* Instance *) [ ("fmt", InstanceField.Method (fmt BITS LIMBS)) ]. + End Impl_core_fmt_Octal_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_fmt_LowerHex_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } + *) + Definition fmt + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::LowerHex", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::fmt::LowerHex" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self BITS LIMBS) + (* Instance *) [ ("fmt", InstanceField.Method (fmt BITS LIMBS)) ]. + End Impl_core_fmt_LowerHex_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_fmt_UpperHex_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.0.fmt(f) + } + *) + Definition fmt + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::UpperHex", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::fmt::UpperHex" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self BITS LIMBS) + (* Instance *) [ ("fmt", InstanceField.Method (fmt BITS LIMBS)) ]. + End Impl_core_fmt_UpperHex_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* pub(crate) const MASK: u64 = ruint::mask(BITS); *) + (* Ty.path "u64" *) + Definition value_MASK (BITS LIMBS : Value.t) : Value.t := + let Self : Ty.t := Self BITS LIMBS in + M.run + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "u64", + M.get_function (| "ruint::mask", [], [] |), + [ M.read (| M.get_constant "alloy_primitives::signed::int::BITS" |) ] + |) + |))). + + Global Instance AssociatedConstant_value_MASK : + forall (BITS LIMBS : Value.t), + M.IsAssociatedConstant.Trait (Self BITS LIMBS) "value_MASK" (value_MASK BITS LIMBS). + Admitted. + Global Typeclasses Opaque value_MASK. + + (* pub(crate) const SIGN_BIT: u64 = sign_bit(BITS); *) + (* Ty.path "u64" *) + Definition value_SIGN_BIT (BITS LIMBS : Value.t) : Value.t := + let Self : Ty.t := Self BITS LIMBS in + M.run + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "u64", + M.get_function (| "alloy_primitives::signed::utils::sign_bit", [], [] |), + [ M.read (| M.get_constant "alloy_primitives::signed::int::BITS" |) ] + |) + |))). + + Global Instance AssociatedConstant_value_SIGN_BIT : + forall (BITS LIMBS : Value.t), + M.IsAssociatedConstant.Trait (Self BITS LIMBS) "value_SIGN_BIT" (value_SIGN_BIT BITS LIMBS). + Admitted. + Global Typeclasses Opaque value_SIGN_BIT. + + (* pub const BITS: usize = BITS; *) + (* Ty.path "usize" *) + Definition value_BITS (BITS LIMBS : Value.t) : Value.t := + let Self : Ty.t := Self BITS LIMBS in + M.run ltac:(M.monadic (M.get_constant "alloy_primitives::signed::int::BITS")). + + Global Instance AssociatedConstant_value_BITS : + forall (BITS LIMBS : Value.t), + M.IsAssociatedConstant.Trait (Self BITS LIMBS) "value_BITS" (value_BITS BITS LIMBS). + Admitted. + Global Typeclasses Opaque value_BITS. + + (* pub const BYTES: usize = Uint::::BYTES; *) + (* Ty.path "usize" *) + Definition value_BYTES (BITS LIMBS : Value.t) : Value.t := + let Self : Ty.t := Self BITS LIMBS in + M.run ltac:(M.monadic (M.get_constant "ruint::bytes::BYTES")). + + Global Instance AssociatedConstant_value_BYTES : + forall (BITS LIMBS : Value.t), + M.IsAssociatedConstant.Trait (Self BITS LIMBS) "value_BYTES" (value_BYTES BITS LIMBS). + Admitted. + Global Typeclasses Opaque value_BYTES. + + (* pub const MIN: Self = min(); *) + (* Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] *) + Definition value_MIN (BITS LIMBS : Value.t) : Value.t := + let Self : Ty.t := Self BITS LIMBS in + M.run + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_function (| "alloy_primitives::signed::utils::min", [ BITS; LIMBS ], [] |), + [] + |) + |))). + + Global Instance AssociatedConstant_value_MIN : + forall (BITS LIMBS : Value.t), + M.IsAssociatedConstant.Trait (Self BITS LIMBS) "value_MIN" (value_MIN BITS LIMBS). + Admitted. + Global Typeclasses Opaque value_MIN. + + (* pub const MAX: Self = max(); *) + (* Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] *) + Definition value_MAX (BITS LIMBS : Value.t) : Value.t := + let Self : Ty.t := Self BITS LIMBS in + M.run + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_function (| "alloy_primitives::signed::utils::max", [ BITS; LIMBS ], [] |), + [] + |) + |))). + + Global Instance AssociatedConstant_value_MAX : + forall (BITS LIMBS : Value.t), + M.IsAssociatedConstant.Trait (Self BITS LIMBS) "value_MAX" (value_MAX BITS LIMBS). + Admitted. + Global Typeclasses Opaque value_MAX. + + (* pub const ZERO: Self = zero(); *) + (* Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] *) + Definition value_ZERO (BITS LIMBS : Value.t) : Value.t := + let Self : Ty.t := Self BITS LIMBS in + M.run + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_function (| "alloy_primitives::signed::utils::zero", [ BITS; LIMBS ], [] |), + [] + |) + |))). + + Global Instance AssociatedConstant_value_ZERO : + forall (BITS LIMBS : Value.t), + M.IsAssociatedConstant.Trait (Self BITS LIMBS) "value_ZERO" (value_ZERO BITS LIMBS). + Admitted. + Global Typeclasses Opaque value_ZERO. + + (* pub const ONE: Self = one(); *) + (* Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] *) + Definition value_ONE (BITS LIMBS : Value.t) : Value.t := + let Self : Ty.t := Self BITS LIMBS in + M.run + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_function (| "alloy_primitives::signed::utils::one", [ BITS; LIMBS ], [] |), + [] + |) + |))). + + Global Instance AssociatedConstant_value_ONE : + forall (BITS LIMBS : Value.t), + M.IsAssociatedConstant.Trait (Self BITS LIMBS) "value_ONE" (value_ONE BITS LIMBS). + Admitted. + Global Typeclasses Opaque value_ONE. + + (* pub const MINUS_ONE: Self = Self(Uint::::MAX); *) + (* Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] *) + Definition value_MINUS_ONE (BITS LIMBS : Value.t) : Value.t := + let Self : Ty.t := Self BITS LIMBS in + M.run + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ M.read (| M.get_constant "ruint::MAX" |) ] + |))). + + Global Instance AssociatedConstant_value_MINUS_ONE : + forall (BITS LIMBS : Value.t), + M.IsAssociatedConstant.Trait + (Self BITS LIMBS) + "value_MINUS_ONE" + (value_MINUS_ONE BITS LIMBS). + Admitted. + Global Typeclasses Opaque value_MINUS_ONE. + + (* + pub const fn from_raw(val: Uint) -> Self { + Self(val) + } + *) + Definition from_raw + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ val ] => + ltac:(M.monadic + (let val := M.alloc (| val |) in + Value.StructTuple "alloy_primitives::signed::int::Signed" [ M.read (| val |) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_raw : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "from_raw" (from_raw BITS LIMBS). + Admitted. + Global Typeclasses Opaque from_raw. + + (* + pub fn unchecked_from(val: T) -> Self + where + T: TryInto, + >::Error: fmt::Debug, + { + val.try_into().unwrap() + } + *) + Definition unchecked_from + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [ T ], [ val ] => + ltac:(M.monadic + (let val := M.alloc (| val |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []; + Ty.associated_in_trait + "core::convert::TryInto" + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ] + T + "Error" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []; + Ty.associated_in_trait + "core::convert::TryInto" + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ] + T + "Error" + ], + M.get_trait_method (| + "core::convert::TryInto", + T, + [], + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] + ], + "try_into", + [], + [] + |), + [ M.read (| val |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_unchecked_from : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "unchecked_from" (unchecked_from BITS LIMBS). + Admitted. + Global Typeclasses Opaque unchecked_from. + + (* + pub fn unchecked_into(self) -> T + where + Self: TryInto, + >::Error: fmt::Debug, + { + self.try_into().unwrap() + } + *) + Definition unchecked_into + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [ T ], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + T, + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + T; + Ty.associated_in_trait + "core::convert::TryInto" + [] + [ T ] + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []) + "Error" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + T; + Ty.associated_in_trait + "core::convert::TryInto" + [] + [ T ] + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []) + "Error" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + [], + [ T ], + "try_into", + [], + [] + |), + [ M.read (| self |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_unchecked_into : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "unchecked_into" (unchecked_into BITS LIMBS). + Admitted. + Global Typeclasses Opaque unchecked_into. + + (* + pub const fn into_raw(self) -> Uint { + self.0 + } + *) + Definition into_raw + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::signed::int::Signed", + 0 + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_into_raw : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "into_raw" (into_raw BITS LIMBS). + Admitted. + Global Typeclasses Opaque into_raw. + + (* + pub const fn sign(&self) -> Sign { + // if the last limb contains the sign bit, then we're negative + // because we can't set any higher bits to 1, we use >= as a proxy + // check to avoid bit comparison + if let Some(limb) = self.0.as_limbs().last() { + if *limb >= Self::SIGN_BIT { + return Sign::Negative; + } + } + Sign::Positive + } + *) + Definition sign + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "u64" ] ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u64" ], + "last", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ LIMBS ] [ Ty.path "u64" ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "as_limbs", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let limb := M.copy (| γ0_0 |) in + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.ge (| + M.read (| M.deref (| M.read (| limb |) |) |), + M.read (| + M.get_constant + "alloy_primitives::signed::int::SIGN_BIT" + |) + |) + |)) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "alloy_primitives::signed::sign::Sign::Negative" + [] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + Value.StructTuple "alloy_primitives::signed::sign::Sign::Positive" [] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_sign : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "sign" (sign BITS LIMBS). + Admitted. + Global Typeclasses Opaque sign. + + (* + pub const fn is_odd(&self) -> bool { + if BITS == 0 { + false + } else { + self.as_limbs()[0] % 2 == 1 + } + } + *) + Definition is_odd + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some (Ty.path "bool"), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.eq (| + M.read (| M.get_constant "alloy_primitives::signed::int::BITS" |), + Value.Integer IntegerKind.Usize 0 + |) + |)) in + let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| Value.Bool false |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + BinOp.eq (| + BinOp.Wrap.rem (| + M.read (| + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ LIMBS ] [ Ty.path "u64" ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "as_limbs", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |), + Value.Integer IntegerKind.Usize 0 + |) + |), + Value.Integer IntegerKind.U64 2 + |), + Value.Integer IntegerKind.U64 1 + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_is_odd : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "is_odd" (is_odd BITS LIMBS). + Admitted. + Global Typeclasses Opaque is_odd. + + (* + pub const fn const_eq(&self, other: &Self) -> bool { + const_eq(self, other) + } + *) + Definition const_eq + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "bool", + M.get_function (| "alloy_primitives::signed::utils::const_eq", [ BITS; LIMBS ], [] |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_const_eq : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "const_eq" (const_eq BITS LIMBS). + Admitted. + Global Typeclasses Opaque const_eq. + + (* + pub const fn is_zero(&self) -> bool { + self.const_eq(&Self::ZERO) + } + *) + Definition is_zero + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "const_eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::signed::int::ZERO" + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_is_zero : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "is_zero" (is_zero BITS LIMBS). + Admitted. + Global Typeclasses Opaque is_zero. + + (* + pub const fn is_positive(&self) -> bool { + !self.is_zero() && matches!(self.sign(), Sign::Positive) + } + *) + Definition is_positive + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + LogicalOp.and (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "is_zero", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |), + ltac:(M.monadic + (M.read (| + M.match_operator (| + Some (Ty.path "bool"), + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + M.alloc (| Value.Bool true |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Bool false |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_is_positive : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "is_positive" (is_positive BITS LIMBS). + Admitted. + Global Typeclasses Opaque is_positive. + + (* + pub const fn is_negative(&self) -> bool { + matches!(self.sign(), Sign::Negative) + } + *) + Definition is_negative + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some (Ty.path "bool"), + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + M.alloc (| Value.Bool true |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Bool false |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_is_negative : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "is_negative" (is_negative BITS LIMBS). + Admitted. + Global Typeclasses Opaque is_negative. + + (* + pub fn count_ones(&self) -> usize { + self.0.count_ones() + } + *) + Definition count_ones + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "count_ones", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_count_ones : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "count_ones" (count_ones BITS LIMBS). + Admitted. + Global Typeclasses Opaque count_ones. + + (* + pub fn count_zeros(&self) -> usize { + self.0.count_zeros() + } + *) + Definition count_zeros + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "count_zeros", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_count_zeros : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "count_zeros" (count_zeros BITS LIMBS). + Admitted. + Global Typeclasses Opaque count_zeros. + + (* + pub fn leading_zeros(&self) -> usize { + self.0.leading_zeros() + } + *) + Definition leading_zeros + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "leading_zeros", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_leading_zeros : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "leading_zeros" (leading_zeros BITS LIMBS). + Admitted. + Global Typeclasses Opaque leading_zeros. + + (* + pub fn trailing_zeros(&self) -> usize { + self.0.trailing_zeros() + } + *) + Definition trailing_zeros + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "trailing_zeros", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_trailing_zeros : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "trailing_zeros" (trailing_zeros BITS LIMBS). + Admitted. + Global Typeclasses Opaque trailing_zeros. + + (* + pub fn trailing_ones(&self) -> usize { + self.0.trailing_ones() + } + *) + Definition trailing_ones + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "trailing_ones", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_trailing_ones : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "trailing_ones" (trailing_ones BITS LIMBS). + Admitted. + Global Typeclasses Opaque trailing_ones. + + (* + pub const fn bit(&self, index: usize) -> bool { + self.0.bit(index) + } + *) + Definition bit + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; index ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let index := M.alloc (| index |) in + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "bit", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |); + M.read (| index |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_bit : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "bit" (bit BITS LIMBS). + Admitted. + Global Typeclasses Opaque bit. + + (* + pub const fn byte(&self, index: usize) -> u8 { + self.0.byte(index) + } + *) + Definition byte + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; index ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let index := M.alloc (| index |) in + M.call_closure (| + Ty.path "u8", + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "byte", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |); + M.read (| index |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_byte : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "byte" (byte BITS LIMBS). + Admitted. + Global Typeclasses Opaque byte. + + (* + pub fn bits(&self) -> u32 { + let unsigned = self.unsigned_abs(); + let unsigned_bits = unsigned.bit_len(); + + // NOTE: We need to deal with two special cases: + // - the number is 0 + // - the number is a negative power of `2`. These numbers are written as `0b11..1100..00`. + // In the case of a negative power of two, the number of bits required + // to represent the negative signed value is equal to the number of + // bits required to represent its absolute value as an unsigned + // integer. This is best illustrated by an example: the number of bits + // required to represent `-128` is `8` since it is equal to `i8::MIN` + // and, therefore, obviously fits in `8` bits. This is equal to the + // number of bits required to represent `128` as an unsigned integer + // (which fits in a `u8`). However, the number of bits required to + // represent `128` as a signed integer is `9`, as it is greater than + // `i8::MAX`. In the general case, an extra bit is needed to + // represent the sign. + let bits = if self.count_zeros() == self.trailing_zeros() { + // `self` is zero or a negative power of two + unsigned_bits + } else { + unsigned_bits + 1 + }; + + bits as u32 + } + *) + Definition bits + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ unsigned : Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "unsigned_abs", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ unsigned_bits : Ty.path "usize" := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "bit_len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, unsigned |) ] + |) + |) in + let~ bits : Ty.path "usize" := + M.copy (| + M.match_operator (| + Some (Ty.path "usize"), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.eq (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "count_zeros", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |), + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "trailing_zeros", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| self |) |) + |) + ] + |) + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + unsigned_bits)); + fun γ => + ltac:(M.monadic + (M.alloc (| + BinOp.Wrap.add (| + M.read (| unsigned_bits |), + Value.Integer IntegerKind.Usize 1 + |) + |))) + ] + |) + |) in + M.alloc (| M.cast (Ty.path "u32") (M.read (| bits |)) |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_bits : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "bits" (bits BITS LIMBS). + Admitted. + Global Typeclasses Opaque bits. + + (* + pub fn overflowing_from_sign_and_abs(sign: Sign, abs: Uint) -> (Self, bool) { + let value = Self(match sign { + Sign::Positive => abs, + Sign::Negative => twos_complement(abs), + }); + + (value, value.sign() != sign && value != Self::ZERO) + } + *) + Definition overflowing_from_sign_and_abs + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ sign; abs ] => + ltac:(M.monadic + (let sign := M.alloc (| sign |) in + let abs := M.alloc (| abs |) in + M.read (| + let~ value : + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] := + M.alloc (| + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ + M.read (| + M.match_operator (| + Some (Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []), + sign, + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + abs)); + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_function (| + "alloy_primitives::signed::utils::twos_complement", + [ BITS; LIMBS ], + [] + |), + [ M.read (| abs |) ] + |) + |))) + ] + |) + |) + ] + |) in + M.alloc (| + Value.Tuple + [ + M.read (| value |); + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.path "alloy_primitives::signed::sign::Sign", + [], + [ Ty.path "alloy_primitives::signed::sign::Sign" ], + "ne", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + |) + |); + M.borrow (| Pointer.Kind.Ref, sign |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "ne", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, value |); + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::signed::int::ZERO" + |) + ] + |))) + |) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_overflowing_from_sign_and_abs : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait + (Self BITS LIMBS) + "overflowing_from_sign_and_abs" + (overflowing_from_sign_and_abs BITS LIMBS). + Admitted. + Global Typeclasses Opaque overflowing_from_sign_and_abs. + + (* + pub fn checked_from_sign_and_abs(sign: Sign, abs: Uint) -> Option { + let (result, overflow) = Self::overflowing_from_sign_and_abs(sign, abs); + if overflow { + None + } else { + Some(result) + } + } + *) + Definition checked_from_sign_and_abs + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ sign; abs ] => + ltac:(M.monadic + (let sign := M.alloc (| sign |) in + let abs := M.alloc (| abs |) in + M.read (| + M.match_operator (| + None, + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_from_sign_and_abs", + [], + [] + |), + [ M.read (| sign |); M.read (| abs |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let result := M.copy (| γ0_0 |) in + let overflow := M.copy (| γ0_1 |) in + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use overflow in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| Value.StructTuple "core::option::Option::None" [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ M.read (| result |) ] + |))) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_checked_from_sign_and_abs : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait + (Self BITS LIMBS) + "checked_from_sign_and_abs" + (checked_from_sign_and_abs BITS LIMBS). + Admitted. + Global Typeclasses Opaque checked_from_sign_and_abs. + + (* + pub fn from_dec_str(value: &str) -> Result { + let (sign, value) = match value.as_bytes().first() { + Some(b'+') => (Sign::Positive, &value[1..]), + Some(b'-') => (Sign::Negative, &value[1..]), + _ => (Sign::Positive, value), + }; + let abs = Uint::::from_str_radix(value, 10)?; + Self::checked_from_sign_and_abs(sign, abs).ok_or(ParseSignedError::IntegerOverflow) + } + *) + Definition from_dec_str + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + M.match_operator (| + None, + M.match_operator (| + Some + (Ty.tuple + [ + Ty.path "alloy_primitives::signed::sign::Sign"; + Ty.apply (Ty.path "&") [] [ Ty.path "str" ] + ]), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "u8" ] ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "first", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_associated_function (| Ty.path "str", "as_bytes", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| value |) |) + |) + ] + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ0_0 := M.read (| γ0_0 |) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.U8 43 + |) in + M.alloc (| + Value.Tuple + [ + Value.StructTuple + "alloy_primitives::signed::sign::Sign::Positive" + []; + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.path "str", + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| value |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ0_0 := M.read (| γ0_0 |) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.U8 45 + |) in + M.alloc (| + Value.Tuple + [ + Value.StructTuple + "alloy_primitives::signed::sign::Sign::Negative" + []; + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.path "str", + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| value |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple + [ + Value.StructTuple + "alloy_primitives::signed::sign::Sign::Positive" + []; + M.read (| value |) + ] + |))) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let sign := M.copy (| γ0_0 |) in + let value := M.copy (| γ0_1 |) in + let~ abs : Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] := + M.copy (| + M.match_operator (| + Some (Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "ruint::string::ParseError" + ]; + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.path "ruint::string::ParseError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.path "ruint::string::ParseError" + ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "from_str_radix", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| value |) |) + |); + Value.Integer IntegerKind.U64 10 + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path + "alloy_primitives::signed::errors::ParseSignedError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path + "alloy_primitives::signed::errors::ParseSignedError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "ruint::string::ParseError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "alloy_primitives::signed::errors::ParseSignedError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "ok_or", + [], + [ Ty.path "alloy_primitives::signed::errors::ParseSignedError" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "checked_from_sign_and_abs", + [], + [] + |), + [ M.read (| sign |); M.read (| abs |) ] + |); + Value.StructTuple + "alloy_primitives::signed::errors::ParseSignedError::IntegerOverflow" + [] + ] + |) + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_dec_str : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "from_dec_str" (from_dec_str BITS LIMBS). + Admitted. + Global Typeclasses Opaque from_dec_str. + + (* + pub fn to_dec_string(&self) -> String { + let sign = self.sign(); + let abs = self.unsigned_abs(); + + format!("{sign}{abs}") + } + *) + Definition to_dec_string + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ sign : Ty.path "alloy_primitives::signed::sign::Sign" := + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ abs : Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "unsigned_abs", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| + "core::hint::must_use", + [], + [ Ty.path "alloc::string::String" ] + |), + [ + M.read (| + let~ res : Ty.path "alloc::string::String" := + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| "alloc::fmt::format", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 2 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array [ mk_str (| "" |); mk_str (| "" |) ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "alloy_primitives::signed::sign::Sign" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, sign |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.apply + (Ty.path "ruint::Uint") + [ BITS; LIMBS ] + [] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, abs |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) in + res + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_to_dec_string : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "to_dec_string" (to_dec_string BITS LIMBS). + Admitted. + Global Typeclasses Opaque to_dec_string. + + (* + pub fn from_hex_str(value: &str) -> Result { + let (sign, value) = match value.as_bytes().first() { + Some(b'+') => (Sign::Positive, &value[1..]), + Some(b'-') => (Sign::Negative, &value[1..]), + _ => (Sign::Positive, value), + }; + + let value = value.strip_prefix("0x").unwrap_or(value); + + if value.len() > 64 { + return Err(ParseSignedError::IntegerOverflow); + } + + let abs = Uint::::from_str_radix(value, 16)?; + Self::checked_from_sign_and_abs(sign, abs).ok_or(ParseSignedError::IntegerOverflow) + } + *) + Definition from_hex_str + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + M.match_operator (| + None, + M.match_operator (| + Some + (Ty.tuple + [ + Ty.path "alloy_primitives::signed::sign::Sign"; + Ty.apply (Ty.path "&") [] [ Ty.path "str" ] + ]), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "u8" ] ], + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "first", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_associated_function (| Ty.path "str", "as_bytes", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| value |) |) + |) + ] + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ0_0 := M.read (| γ0_0 |) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.U8 43 + |) in + M.alloc (| + Value.Tuple + [ + Value.StructTuple + "alloy_primitives::signed::sign::Sign::Positive" + []; + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.path "str", + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| value |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let γ0_0 := M.read (| γ0_0 |) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ0_0 |), + Value.Integer IntegerKind.U8 45 + |) in + M.alloc (| + Value.Tuple + [ + Value.StructTuple + "alloy_primitives::signed::sign::Sign::Negative" + []; + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.path "str", + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| value |) |) + |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", Value.Integer IntegerKind.Usize 1) ] + ] + |) + |) + |) + ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple + [ + Value.StructTuple + "alloy_primitives::signed::sign::Sign::Positive" + []; + M.read (| value |) + ] + |))) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let sign := M.copy (| γ0_0 |) in + let value := M.copy (| γ0_1 |) in + let~ value : Ty.apply (Ty.path "&") [] [ Ty.path "str" ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ], + "unwrap_or", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ], + M.get_associated_function (| + Ty.path "str", + "strip_prefix", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| value |) |) + |); + mk_str (| "0x" |) + ] + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| value |) |) |) + ] + |) + |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.gt (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.path "str", + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| value |) |) + |) + ] + |), + Value.Integer IntegerKind.Usize 64 + |) + |)) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "alloy_primitives::signed::errors::ParseSignedError::IntegerOverflow" + [] + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ abs : Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] := + M.copy (| + M.match_operator (| + Some (Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "ruint::string::ParseError" + ]; + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.path "ruint::string::ParseError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.path "ruint::string::ParseError" + ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "from_str_radix", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| value |) |) + |); + Value.Integer IntegerKind.U64 16 + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path + "alloy_primitives::signed::errors::ParseSignedError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path + "alloy_primitives::signed::errors::ParseSignedError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "ruint::string::ParseError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "alloy_primitives::signed::errors::ParseSignedError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "ok_or", + [], + [ Ty.path "alloy_primitives::signed::errors::ParseSignedError" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "checked_from_sign_and_abs", + [], + [] + |), + [ M.read (| sign |); M.read (| abs |) ] + |); + Value.StructTuple + "alloy_primitives::signed::errors::ParseSignedError::IntegerOverflow" + [] + ] + |) + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_hex_str : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "from_hex_str" (from_hex_str BITS LIMBS). + Admitted. + Global Typeclasses Opaque from_hex_str. + + (* + pub fn to_hex_string(&self) -> String { + let sign = self.sign(); + let abs = self.unsigned_abs(); + + format!("{sign}0x{abs:x}") + } + *) + Definition to_hex_string + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ sign : Ty.path "alloy_primitives::signed::sign::Sign" := + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ abs : Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "unsigned_abs", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| + "core::hint::must_use", + [], + [ Ty.path "alloc::string::String" ] + |), + [ + M.read (| + let~ res : Ty.path "alloc::string::String" := + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| "alloc::fmt::format", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 2 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array [ mk_str (| "" |); mk_str (| "0x" |) ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "alloy_primitives::signed::sign::Sign" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, sign |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_lower_hex", + [], + [ + Ty.apply + (Ty.path "ruint::Uint") + [ BITS; LIMBS ] + [] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, abs |) + |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |) in + res + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_to_hex_string : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "to_hex_string" (to_hex_string BITS LIMBS). + Admitted. + Global Typeclasses Opaque to_hex_string. + + (* + pub fn into_sign_and_abs(&self) -> (Sign, Uint) { + let sign = self.sign(); + let abs = match sign { + Sign::Positive => self.0, + Sign::Negative => twos_complement(self.0), + }; + (sign, abs) + } + *) + Definition into_sign_and_abs + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ sign : Ty.path "alloy_primitives::signed::sign::Sign" := + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ abs : Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] := + M.copy (| + M.match_operator (| + Some (Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []), + sign, + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |))); + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_function (| + "alloy_primitives::signed::utils::twos_complement", + [ BITS; LIMBS ], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |) + |))) + ] + |) + |) in + M.alloc (| Value.Tuple [ M.read (| sign |); M.read (| abs |) ] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_into_sign_and_abs : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait + (Self BITS LIMBS) + "into_sign_and_abs" + (into_sign_and_abs BITS LIMBS). + Admitted. + Global Typeclasses Opaque into_sign_and_abs. + + (* + pub const fn to_be_bytes(&self) -> [u8; BYTES] { + self.0.to_be_bytes() + } + *) + Definition to_be_bytes + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [ BYTES ], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply (Ty.path "array") [ BYTES ] [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "to_be_bytes", + [ BYTES ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_to_be_bytes : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "to_be_bytes" (to_be_bytes BITS LIMBS). + Admitted. + Global Typeclasses Opaque to_be_bytes. + + (* + pub const fn to_le_bytes(&self) -> [u8; BYTES] { + self.0.to_le_bytes() + } + *) + Definition to_le_bytes + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [ BYTES ], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply (Ty.path "array") [ BYTES ] [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "to_le_bytes", + [ BYTES ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_to_le_bytes : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "to_le_bytes" (to_le_bytes BITS LIMBS). + Admitted. + Global Typeclasses Opaque to_le_bytes. + + (* + pub const fn from_be_bytes(bytes: [u8; BYTES]) -> Self { + Self(Uint::from_be_bytes::(bytes)) + } + *) + Definition from_be_bytes + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [ BYTES ], [], [ bytes ] => + ltac:(M.monadic + (let bytes := M.alloc (| bytes |) in + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "from_be_bytes", + [ BYTES ], + [] + |), + [ M.read (| bytes |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_be_bytes : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "from_be_bytes" (from_be_bytes BITS LIMBS). + Admitted. + Global Typeclasses Opaque from_be_bytes. + + (* + pub const fn from_le_bytes(bytes: [u8; BYTES]) -> Self { + Self(Uint::from_le_bytes::(bytes)) + } + *) + Definition from_le_bytes + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [ BYTES ], [], [ bytes ] => + ltac:(M.monadic + (let bytes := M.alloc (| bytes |) in + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "from_le_bytes", + [ BYTES ], + [] + |), + [ M.read (| bytes |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_le_bytes : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "from_le_bytes" (from_le_bytes BITS LIMBS). + Admitted. + Global Typeclasses Opaque from_le_bytes. + + (* + pub fn try_from_be_slice(slice: &[u8]) -> Option { + Uint::try_from_be_slice(slice).map(Self) + } + *) + Definition try_from_be_slice + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ slice ] => + ltac:(M.monadic + (let slice := M.alloc (| slice |) in + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ], + "map", + [], + [ + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []; + Ty.function + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ] + (Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "try_from_be_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| slice |) |) |) ] + |); + M.constructor_as_closure "alloy_primitives::signed::int::Signed" + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_try_from_be_slice : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait + (Self BITS LIMBS) + "try_from_be_slice" + (try_from_be_slice BITS LIMBS). + Admitted. + Global Typeclasses Opaque try_from_be_slice. + + (* + pub fn try_from_le_slice(slice: &[u8]) -> Option { + Uint::try_from_le_slice(slice).map(Self) + } + *) + Definition try_from_le_slice + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ slice ] => + ltac:(M.monadic + (let slice := M.alloc (| slice |) in + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ], + "map", + [], + [ + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []; + Ty.function + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ] + (Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "try_from_le_slice", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| slice |) |) |) ] + |); + M.constructor_as_closure "alloy_primitives::signed::int::Signed" + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_try_from_le_slice : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait + (Self BITS LIMBS) + "try_from_le_slice" + (try_from_le_slice BITS LIMBS). + Admitted. + Global Typeclasses Opaque try_from_le_slice. + + (* + pub const fn as_limbs(&self) -> &[u64; LIMBS] { + self.0.as_limbs() + } + *) + Definition as_limbs + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ LIMBS ] [ Ty.path "u64" ] ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "as_limbs", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_as_limbs : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "as_limbs" (as_limbs BITS LIMBS). + Admitted. + Global Typeclasses Opaque as_limbs. + + (* + pub const fn into_limbs(self) -> [u64; LIMBS] { + self.0.into_limbs() + } + *) + Definition into_limbs + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply (Ty.path "array") [ LIMBS ] [ Ty.path "u64" ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "into_limbs", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_into_limbs : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "into_limbs" (into_limbs BITS LIMBS). + Admitted. + Global Typeclasses Opaque into_limbs. + + (* + pub const fn from_limbs(limbs: [u64; LIMBS]) -> Self { + Self(Uint::from_limbs(limbs)) + } + *) + Definition from_limbs + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ limbs ] => + ltac:(M.monadic + (let limbs := M.alloc (| limbs |) in + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "from_limbs", + [], + [] + |), + [ M.read (| limbs |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_limbs : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "from_limbs" (from_limbs BITS LIMBS). + Admitted. + Global Typeclasses Opaque from_limbs. + + (* + pub fn from_base_be>( + base: u64, + digits: I, + ) -> Result { + Ok(Self(Uint::from_base_be(base, digits)?)) + } + *) + Definition from_base_be + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [ _ as I ], [ base; digits ] => + ltac:(M.monadic + (let base := M.alloc (| base |) in + let digits := M.alloc (| digits |) in + M.catch_return (| + ltac:(M.monadic + (Value.StructTuple + "core::result::Result::Ok" + [ + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ + M.read (| + M.match_operator (| + Some (Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "ruint::base_convert::BaseConvertError" + ]; + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.path "ruint::base_convert::BaseConvertError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; + Ty.path "ruint::base_convert::BaseConvertError" + ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "from_base_be", + [], + [ I ] + |), + [ M.read (| base |); M.read (| digits |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "ruint::base_convert::BaseConvertError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "ruint::base_convert::BaseConvertError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "ruint::base_convert::BaseConvertError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) + ] + ])) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_from_base_be : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "from_base_be" (from_base_be BITS LIMBS). + Admitted. + Global Typeclasses Opaque from_base_be. + End Impl_alloy_primitives_signed_int_Signed_BITS_LIMBS. + End int. +End signed. diff --git a/CoqOfRust/alloy_primitives/signed/mod.rs b/CoqOfRust/alloy_primitives/signed/mod.rs new file mode 100644 index 000000000..8379fef0c --- /dev/null +++ b/CoqOfRust/alloy_primitives/signed/mod.rs @@ -0,0 +1,26 @@ +//! This module contains a 256-bit signed integer implementation. + +/// Conversion implementations. +mod conversions; + +/// Error types for signed integers. +mod errors; +pub use errors::{BigIntConversionError, ParseSignedError}; + +/// Signed integer type wrapping a [`ruint::Uint`]. +mod int; +pub use int::Signed; + +/// Operation implementations. +mod ops; + +/// A simple [`Sign`] enum, for dealing with integer signs. +mod sign; +pub use sign::Sign; + +/// Serde support. +#[cfg(feature = "serde")] +mod serde; + +/// Utility functions used in the signed integer implementation. +pub(crate) mod utils; diff --git a/CoqOfRust/alloy_primitives/signed/ops.rs b/CoqOfRust/alloy_primitives/signed/ops.rs new file mode 100644 index 000000000..d2129dc11 --- /dev/null +++ b/CoqOfRust/alloy_primitives/signed/ops.rs @@ -0,0 +1,1101 @@ +use super::{ + utils::{handle_overflow, twos_complement}, + Sign, Signed, +}; +use core::{cmp, iter, ops}; +use ruint::Uint; + +// ops impl +impl Signed { + /// Computes the absolute value of `self`. + /// + /// # Overflow behavior + /// + /// The absolute value of `Self::MIN` cannot be represented as `Self` and + /// attempting to calculate it will cause an overflow. This means that code + /// in debug mode will trigger a panic on this case and optimized code will + /// return `Self::MIN` without a panic. + #[inline] + #[track_caller] + #[must_use] + pub fn abs(self) -> Self { + handle_overflow(self.overflowing_abs()) + } + + /// Computes the absolute value of `self`. + /// + /// Returns a tuple of the absolute version of self along with a boolean + /// indicating whether an overflow happened. If self is the minimum + /// value then the minimum value will be returned again and true will be + /// returned for an overflow happening. + #[inline] + #[must_use] + pub fn overflowing_abs(self) -> (Self, bool) { + if BITS == 0 { + return (self, false); + } + if self == Self::MIN { + (self, true) + } else { + (Self(self.unsigned_abs()), false) + } + } + + /// Checked absolute value. Computes `self.abs()`, returning `None` if `self + /// == MIN`. + #[inline] + #[must_use] + pub fn checked_abs(self) -> Option { + match self.overflowing_abs() { + (value, false) => Some(value), + _ => None, + } + } + + /// Saturating absolute value. Computes `self.abs()`, returning `MAX` if + /// `self == MIN` instead of overflowing. + #[inline] + #[must_use] + pub fn saturating_abs(self) -> Self { + match self.overflowing_abs() { + (value, false) => value, + _ => Self::MAX, + } + } + + /// Wrapping absolute value. Computes `self.abs()`, wrapping around at the + /// boundary of the type. + #[inline] + #[must_use] + pub fn wrapping_abs(self) -> Self { + self.overflowing_abs().0 + } + + /// Computes the absolute value of `self` without any wrapping or panicking. + #[inline] + #[must_use] + pub fn unsigned_abs(self) -> Uint { + self.into_sign_and_abs().1 + } + + /// Negates self, overflowing if this is equal to the minimum value. + /// + /// Returns a tuple of the negated version of self along with a boolean + /// indicating whether an overflow happened. If `self` is the minimum + /// value, then the minimum value will be returned again and `true` will + /// be returned for an overflow happening. + #[inline] + #[must_use] + pub fn overflowing_neg(self) -> (Self, bool) { + if BITS == 0 { + return (self, false); + } + if self == Self::MIN { + (self, true) + } else { + (Self(twos_complement(self.0)), false) + } + } + + /// Checked negation. Computes `-self`, returning `None` if `self == MIN`. + #[inline] + #[must_use] + pub fn checked_neg(self) -> Option { + match self.overflowing_neg() { + (value, false) => Some(value), + _ => None, + } + } + + /// Saturating negation. Computes `-self`, returning `MAX` if `self == MIN` + /// instead of overflowing. + #[inline] + #[must_use] + pub fn saturating_neg(self) -> Self { + match self.overflowing_neg() { + (value, false) => value, + _ => Self::MAX, + } + } + + /// Wrapping (modular) negation. Computes `-self`, wrapping around at the + /// boundary of the type. + /// + /// The only case where such wrapping can occur is when one negates `MIN` on + /// a signed type (where `MIN` is the negative minimal value for the + /// type); this is a positive value that is too large to represent in + /// the type. In such a case, this function returns `MIN` itself. + #[inline] + #[must_use] + pub fn wrapping_neg(self) -> Self { + self.overflowing_neg().0 + } + + /// Calculates `self` + `rhs` + /// + /// Returns a tuple of the addition along with a boolean indicating whether + /// an arithmetic overflow would occur. If an overflow would have + /// occurred then the wrapped value is returned. + #[inline] + #[must_use] + pub const fn overflowing_add(self, rhs: Self) -> (Self, bool) { + let (unsigned, _) = self.0.overflowing_add(rhs.0); + let result = Self(unsigned); + + // NOTE: Overflow is determined by checking the sign of the operands and + // the result. + let overflow = matches!( + (self.sign(), rhs.sign(), result.sign()), + (Sign::Positive, Sign::Positive, Sign::Negative) + | (Sign::Negative, Sign::Negative, Sign::Positive) + ); + + (result, overflow) + } + + /// Checked integer addition. Computes `self + rhs`, returning `None` if + /// overflow occurred. + #[inline] + #[must_use] + pub const fn checked_add(self, rhs: Self) -> Option { + match self.overflowing_add(rhs) { + (value, false) => Some(value), + _ => None, + } + } + + /// Saturating integer addition. Computes `self + rhs`, saturating at the + /// numeric bounds instead of overflowing. + #[inline] + #[must_use] + pub const fn saturating_add(self, rhs: Self) -> Self { + let (result, overflow) = self.overflowing_add(rhs); + if overflow { + match result.sign() { + Sign::Positive => Self::MIN, + Sign::Negative => Self::MAX, + } + } else { + result + } + } + + /// Wrapping (modular) addition. Computes `self + rhs`, wrapping around at + /// the boundary of the type. + #[inline] + #[must_use] + pub const fn wrapping_add(self, rhs: Self) -> Self { + self.overflowing_add(rhs).0 + } + + /// Calculates `self` - `rhs` + /// + /// Returns a tuple of the subtraction along with a boolean indicating + /// whether an arithmetic overflow would occur. If an overflow would + /// have occurred then the wrapped value is returned. + #[inline] + #[must_use] + pub const fn overflowing_sub(self, rhs: Self) -> (Self, bool) { + // NOTE: We can't just compute the `self + (-rhs)` because `-rhs` does + // not always exist, specifically this would be a problem in case + // `rhs == Self::MIN` + + let (unsigned, _) = self.0.overflowing_sub(rhs.0); + let result = Self(unsigned); + + // NOTE: Overflow is determined by checking the sign of the operands and + // the result. + let overflow = matches!( + (self.sign(), rhs.sign(), result.sign()), + (Sign::Positive, Sign::Negative, Sign::Negative) + | (Sign::Negative, Sign::Positive, Sign::Positive) + ); + + (result, overflow) + } + + /// Checked integer subtraction. Computes `self - rhs`, returning `None` if + /// overflow occurred. + #[inline] + #[must_use] + pub const fn checked_sub(self, rhs: Self) -> Option { + match self.overflowing_sub(rhs) { + (value, false) => Some(value), + _ => None, + } + } + + /// Saturating integer subtraction. Computes `self - rhs`, saturating at the + /// numeric bounds instead of overflowing. + #[inline] + #[must_use] + pub const fn saturating_sub(self, rhs: Self) -> Self { + let (result, overflow) = self.overflowing_sub(rhs); + if overflow { + match result.sign() { + Sign::Positive => Self::MIN, + Sign::Negative => Self::MAX, + } + } else { + result + } + } + + /// Wrapping (modular) subtraction. Computes `self - rhs`, wrapping around + /// at the boundary of the type. + #[inline] + #[must_use] + pub const fn wrapping_sub(self, rhs: Self) -> Self { + self.overflowing_sub(rhs).0 + } + + /// Calculates `self` * `rhs` + /// + /// Returns a tuple of the multiplication along with a boolean indicating + /// whether an arithmetic overflow would occur. If an overflow would + /// have occurred then the wrapped value is returned. + #[inline] + #[must_use] + pub fn overflowing_mul(self, rhs: Self) -> (Self, bool) { + if self.is_zero() || rhs.is_zero() { + return (Self::ZERO, false); + } + let sign = self.sign() * rhs.sign(); + let (unsigned, overflow_mul) = self.unsigned_abs().overflowing_mul(rhs.unsigned_abs()); + let (result, overflow_conv) = Self::overflowing_from_sign_and_abs(sign, unsigned); + + (result, overflow_mul || overflow_conv) + } + + /// Checked integer multiplication. Computes `self * rhs`, returning None if + /// overflow occurred. + #[inline] + #[must_use] + pub fn checked_mul(self, rhs: Self) -> Option { + match self.overflowing_mul(rhs) { + (value, false) => Some(value), + _ => None, + } + } + + /// Saturating integer multiplication. Computes `self * rhs`, saturating at + /// the numeric bounds instead of overflowing. + #[inline] + #[must_use] + pub fn saturating_mul(self, rhs: Self) -> Self { + let (result, overflow) = self.overflowing_mul(rhs); + if overflow { + match self.sign() * rhs.sign() { + Sign::Positive => Self::MAX, + Sign::Negative => Self::MIN, + } + } else { + result + } + } + + /// Wrapping (modular) multiplication. Computes `self * rhs`, wrapping + /// around at the boundary of the type. + #[inline] + #[must_use] + pub fn wrapping_mul(self, rhs: Self) -> Self { + self.overflowing_mul(rhs).0 + } + + /// Calculates `self` / `rhs` + /// + /// Returns a tuple of the divisor along with a boolean indicating whether + /// an arithmetic overflow would occur. If an overflow would occur then + /// self is returned. + /// + /// # Panics + /// + /// If `rhs` is 0. + #[inline] + #[track_caller] + #[must_use] + pub fn overflowing_div(self, rhs: Self) -> (Self, bool) { + assert!(!rhs.is_zero(), "attempt to divide by zero"); + let sign = self.sign() * rhs.sign(); + // Note, signed division can't overflow! + let unsigned = self.unsigned_abs() / rhs.unsigned_abs(); + let (result, overflow_conv) = Self::overflowing_from_sign_and_abs(sign, unsigned); + + (result, overflow_conv && !result.is_zero()) + } + + /// Checked integer division. Computes `self / rhs`, returning `None` if + /// `rhs == 0` or the division results in overflow. + #[inline] + #[must_use] + pub fn checked_div(self, rhs: Self) -> Option { + if rhs.is_zero() || (self == Self::MIN && rhs == Self::MINUS_ONE) { + None + } else { + Some(self.overflowing_div(rhs).0) + } + } + + /// Saturating integer division. Computes `self / rhs`, saturating at the + /// numeric bounds instead of overflowing. + /// + /// # Panics + /// + /// If `rhs` is 0. + #[inline] + #[track_caller] + #[must_use] + pub fn saturating_div(self, rhs: Self) -> Self { + match self.overflowing_div(rhs) { + (value, false) => value, + // MIN / -1 is the only possible saturating overflow + _ => Self::MAX, + } + } + + /// Wrapping (modular) division. Computes `self / rhs`, wrapping around at + /// the boundary of the type. + /// + /// The only case where such wrapping can occur is when one divides `MIN / + /// -1` on a signed type (where `MIN` is the negative minimal value for + /// the type); this is equivalent to `-MIN`, a positive value that is + /// too large to represent in the type. In such a case, this function + /// returns `MIN` itself. + /// + /// # Panics + /// + /// If `rhs` is 0. + #[inline] + #[track_caller] + #[must_use] + pub fn wrapping_div(self, rhs: Self) -> Self { + self.overflowing_div(rhs).0 + } + + /// Calculates `self` % `rhs` + /// + /// Returns a tuple of the remainder after dividing along with a boolean + /// indicating whether an arithmetic overflow would occur. If an + /// overflow would occur then 0 is returned. + /// + /// # Panics + /// + /// If `rhs` is 0. + #[inline] + #[track_caller] + #[must_use] + pub fn overflowing_rem(self, rhs: Self) -> (Self, bool) { + if self == Self::MIN && rhs == Self::MINUS_ONE { + (Self::ZERO, true) + } else { + let div_res = self / rhs; + (self - div_res * rhs, false) + } + } + + /// Checked integer remainder. Computes `self % rhs`, returning `None` if + /// `rhs == 0` or the division results in overflow. + #[inline] + #[must_use] + pub fn checked_rem(self, rhs: Self) -> Option { + if rhs.is_zero() || (self == Self::MIN && rhs == Self::MINUS_ONE) { + None + } else { + Some(self.overflowing_rem(rhs).0) + } + } + + /// Wrapping (modular) remainder. Computes `self % rhs`, wrapping around at + /// the boundary of the type. + /// + /// Such wrap-around never actually occurs mathematically; implementation + /// artifacts make `x % y` invalid for `MIN / -1` on a signed type + /// (where `MIN` is the negative minimal value). In such a case, this + /// function returns `0`. + /// + /// # Panics + /// + /// If `rhs` is 0. + #[inline] + #[track_caller] + #[must_use] + pub fn wrapping_rem(self, rhs: Self) -> Self { + self.overflowing_rem(rhs).0 + } + + /// Calculates the quotient of Euclidean division of `self` by `rhs`. + /// + /// This computes the integer `q` such that `self = q * rhs + r`, with + /// `r = self.rem_euclid(rhs)` and `0 <= r < abs(rhs)`. + /// + /// In other words, the result is `self / rhs` rounded to the integer `q` + /// such that `self >= q * rhs`. + /// If `self > 0`, this is equal to round towards zero (the default in + /// Rust); if `self < 0`, this is equal to round towards +/- infinity. + /// + /// # Panics + /// + /// If `rhs` is 0 or the division results in overflow. + #[inline] + #[track_caller] + #[must_use] + pub fn div_euclid(self, rhs: Self) -> Self { + let q = self / rhs; + if (self % rhs).is_negative() { + if rhs.is_positive() { + q - Self::ONE + } else { + q + Self::ONE + } + } else { + q + } + } + + /// Calculates the quotient of Euclidean division `self.div_euclid(rhs)`. + /// + /// Returns a tuple of the divisor along with a boolean indicating whether + /// an arithmetic overflow would occur. If an overflow would occur then + /// `self` is returned. + /// + /// # Panics + /// + /// If `rhs` is 0. + #[inline] + #[track_caller] + #[must_use] + pub fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool) { + if self == Self::MIN && rhs == Self::MINUS_ONE { + (self, true) + } else { + (self.div_euclid(rhs), false) + } + } + + /// Checked Euclidean division. Computes `self.div_euclid(rhs)`, returning + /// `None` if `rhs == 0` or the division results in overflow. + #[inline] + #[must_use] + pub fn checked_div_euclid(self, rhs: Self) -> Option { + if rhs.is_zero() || (self == Self::MIN && rhs == Self::MINUS_ONE) { + None + } else { + Some(self.div_euclid(rhs)) + } + } + + /// Wrapping Euclidean division. Computes `self.div_euclid(rhs)`, + /// wrapping around at the boundary of the type. + /// + /// Wrapping will only occur in `MIN / -1` on a signed type (where `MIN` is + /// the negative minimal value for the type). This is equivalent to + /// `-MIN`, a positive value that is too large to represent in the type. + /// In this case, this method returns `MIN` itself. + /// + /// # Panics + /// + /// If `rhs` is 0. + #[inline] + #[track_caller] + #[must_use] + pub fn wrapping_div_euclid(self, rhs: Self) -> Self { + self.overflowing_div_euclid(rhs).0 + } + + /// Calculates the least nonnegative remainder of `self (mod rhs)`. + /// + /// This is done as if by the Euclidean division algorithm -- given `r = + /// self.rem_euclid(rhs)`, `self = rhs * self.div_euclid(rhs) + r`, and + /// `0 <= r < abs(rhs)`. + /// + /// # Panics + /// + /// If `rhs` is 0 or the division results in overflow. + #[inline] + #[track_caller] + #[must_use] + pub fn rem_euclid(self, rhs: Self) -> Self { + let r = self % rhs; + if r < Self::ZERO { + if rhs < Self::ZERO { + r - rhs + } else { + r + rhs + } + } else { + r + } + } + + /// Overflowing Euclidean remainder. Calculates `self.rem_euclid(rhs)`. + /// + /// Returns a tuple of the remainder after dividing along with a boolean + /// indicating whether an arithmetic overflow would occur. If an + /// overflow would occur then 0 is returned. + /// + /// # Panics + /// + /// If `rhs` is 0. + #[inline] + #[track_caller] + #[must_use] + pub fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool) { + if self == Self::MIN && rhs == Self::MINUS_ONE { + (Self::ZERO, true) + } else { + (self.rem_euclid(rhs), false) + } + } + + /// Wrapping Euclidean remainder. Computes `self.rem_euclid(rhs)`, wrapping + /// around at the boundary of the type. + /// + /// Wrapping will only occur in `MIN % -1` on a signed type (where `MIN` is + /// the negative minimal value for the type). In this case, this method + /// returns 0. + /// + /// # Panics + /// + /// If `rhs` is 0. + #[inline] + #[track_caller] + #[must_use] + pub fn wrapping_rem_euclid(self, rhs: Self) -> Self { + self.overflowing_rem_euclid(rhs).0 + } + + /// Checked Euclidean remainder. Computes `self.rem_euclid(rhs)`, returning + /// `None` if `rhs == 0` or the division results in overflow. + #[inline] + #[must_use] + pub fn checked_rem_euclid(self, rhs: Self) -> Option { + if rhs.is_zero() || (self == Self::MIN && rhs == Self::MINUS_ONE) { + None + } else { + Some(self.rem_euclid(rhs)) + } + } + + /// Returns the sign of `self` to the exponent `exp`. + /// + /// Note that this method does not actually try to compute the `self` to the + /// exponent `exp`, but instead uses the property that a negative number to + /// an odd exponent will be negative. This means that the sign of the result + /// of exponentiation can be computed even if the actual result is too large + /// to fit in 256-bit signed integer. + #[inline] + pub(crate) const fn pow_sign(self, exp: Uint) -> Sign { + let is_exp_odd = BITS != 0 && exp.as_limbs()[0] % 2 == 1; + if is_exp_odd && self.is_negative() { + Sign::Negative + } else { + Sign::Positive + } + } + + /// Create `10**n` as this type. + /// + /// # Panics + /// + /// If the result overflows the type. + #[inline] + #[track_caller] + #[must_use] + pub fn exp10(n: usize) -> Self { + Uint::::from(10).pow(Uint::from(n)).try_into().expect("overflow") + } + + /// Raises self to the power of `exp`, using exponentiation by squaring. + /// + /// # Panics + /// + /// If the result overflows the type in debug mode. + #[inline] + #[track_caller] + #[must_use] + pub fn pow(self, exp: Uint) -> Self { + handle_overflow(self.overflowing_pow(exp)) + } + + /// Raises self to the power of `exp`, using exponentiation by squaring. + /// + /// Returns a tuple of the exponentiation along with a bool indicating + /// whether an overflow happened. + #[inline] + #[must_use] + pub fn overflowing_pow(self, exp: Uint) -> (Self, bool) { + if BITS == 0 { + return (Self::ZERO, false); + } + + let sign = self.pow_sign(exp); + + let (unsigned, overflow_pow) = self.unsigned_abs().overflowing_pow(exp); + let (result, overflow_conv) = Self::overflowing_from_sign_and_abs(sign, unsigned); + + (result, overflow_pow || overflow_conv) + } + + /// Checked exponentiation. Computes `self.pow(exp)`, returning `None` if + /// overflow occurred. + #[inline] + #[must_use] + pub fn checked_pow(self, exp: Uint) -> Option { + let (result, overflow) = self.overflowing_pow(exp); + if overflow { + None + } else { + Some(result) + } + } + + /// Saturating integer exponentiation. Computes `self.pow(exp)`, saturating + /// at the numeric bounds instead of overflowing. + #[inline] + #[must_use] + pub fn saturating_pow(self, exp: Uint) -> Self { + let (result, overflow) = self.overflowing_pow(exp); + if overflow { + match self.pow_sign(exp) { + Sign::Positive => Self::MAX, + Sign::Negative => Self::MIN, + } + } else { + result + } + } + + /// Raises self to the power of `exp`, wrapping around at the + /// boundary of the type. + #[inline] + #[must_use] + pub fn wrapping_pow(self, exp: Uint) -> Self { + self.overflowing_pow(exp).0 + } + + /// Shifts self left by `rhs` bits. + /// + /// Returns a tuple of the shifted version of self along with a boolean + /// indicating whether the shift value was larger than or equal to the + /// number of bits. + #[inline] + #[must_use] + pub fn overflowing_shl(self, rhs: usize) -> (Self, bool) { + if rhs >= 256 { + (Self::ZERO, true) + } else { + (Self(self.0 << rhs), false) + } + } + + /// Checked shift left. Computes `self << rhs`, returning `None` if `rhs` is + /// larger than or equal to the number of bits in `self`. + #[inline] + #[must_use] + pub fn checked_shl(self, rhs: usize) -> Option { + match self.overflowing_shl(rhs) { + (value, false) => Some(value), + _ => None, + } + } + + /// Wrapping shift left. Computes `self << rhs`, returning 0 if larger than + /// or equal to the number of bits in `self`. + #[inline] + #[must_use] + pub fn wrapping_shl(self, rhs: usize) -> Self { + self.overflowing_shl(rhs).0 + } + + /// Shifts self right by `rhs` bits. + /// + /// Returns a tuple of the shifted version of self along with a boolean + /// indicating whether the shift value was larger than or equal to the + /// number of bits. + #[inline] + #[must_use] + pub fn overflowing_shr(self, rhs: usize) -> (Self, bool) { + if rhs >= 256 { + (Self::ZERO, true) + } else { + (Self(self.0 >> rhs), false) + } + } + + /// Checked shift right. Computes `self >> rhs`, returning `None` if `rhs` + /// is larger than or equal to the number of bits in `self`. + #[inline] + #[must_use] + pub fn checked_shr(self, rhs: usize) -> Option { + match self.overflowing_shr(rhs) { + (value, false) => Some(value), + _ => None, + } + } + + /// Wrapping shift right. Computes `self >> rhs`, returning 0 if larger than + /// or equal to the number of bits in `self`. + #[inline] + #[must_use] + pub fn wrapping_shr(self, rhs: usize) -> Self { + self.overflowing_shr(rhs).0 + } + + /// Arithmetic shift right operation. Computes `self >> rhs` maintaining the + /// original sign. If the number is positive this is the same as logic + /// shift right. + #[inline] + #[must_use] + pub fn asr(self, rhs: usize) -> Self { + // Avoid shifting if we are going to know the result regardless of the value. + if rhs == 0 || BITS == 0 { + return self; + } + + if rhs >= BITS - 1 { + match self.sign() { + Sign::Positive => return Self::ZERO, + Sign::Negative => return Self::MINUS_ONE, + } + } + + match self.sign() { + // Perform the shift. + Sign::Positive => self.wrapping_shr(rhs), + Sign::Negative => { + // We need to do: `for 0..shift { self >> 1 | 2^255 }` + // We can avoid the loop by doing: `self >> shift | ~(2^(255 - shift) - 1)` + // where '~' represents ones complement + let two: Uint = Uint::from(2); + let bitwise_or = Self::from_raw( + !(two.pow(Uint::::from(BITS - rhs)) + - Uint::::from(1)), + ); + (self.wrapping_shr(rhs)) | bitwise_or + } + } + } + + /// Arithmetic shift left operation. Computes `self << rhs`, checking for + /// overflow on the final result. + /// + /// Returns `None` if the operation overflowed (most significant bit + /// changes). + #[inline] + #[must_use] + pub fn asl(self, rhs: usize) -> Option { + if rhs == 0 || BITS == 0 { + Some(self) + } else { + let result = self.wrapping_shl(rhs); + if result.sign() != self.sign() { + // Overflow occurred + None + } else { + Some(result) + } + } + } + + /// Compute the [two's complement](https://en.wikipedia.org/wiki/Two%27s_complement) of this number. + #[inline] + #[must_use] + pub fn twos_complement(self) -> Uint { + let abs = self.into_raw(); + match self.sign() { + Sign::Positive => abs, + Sign::Negative => twos_complement(abs), + } + } +} + +// Implement Shl and Shr only for types <= usize, since U256 uses .as_usize() +// which panics +macro_rules! impl_shift { + ($($t:ty),+) => { + // We are OK with wrapping behaviour here because it's how Rust behaves with the primitive + // integer types. + + // $t <= usize: cast to usize + $( + impl ops::Shl<$t> for Signed { + type Output = Self; + + #[inline] + fn shl(self, rhs: $t) -> Self::Output { + self.wrapping_shl(rhs as usize) + } + } + + impl ops::ShlAssign<$t> for Signed { + #[inline] + fn shl_assign(&mut self, rhs: $t) { + *self = *self << rhs; + } + } + + impl ops::Shr<$t> for Signed { + type Output = Self; + + #[inline] + fn shr(self, rhs: $t) -> Self::Output { + self.wrapping_shr(rhs as usize) + } + } + + impl ops::ShrAssign<$t> for Signed { + #[inline] + fn shr_assign(&mut self, rhs: $t) { + *self = *self >> rhs; + } + } + )+ + }; +} + +#[cfg(target_pointer_width = "16")] +impl_shift!(i8, u8, i16, u16, isize, usize); + +#[cfg(target_pointer_width = "32")] +impl_shift!(i8, u8, i16, u16, i32, u32, isize, usize); + +#[cfg(target_pointer_width = "64")] +impl_shift!(i8, u8, i16, u16, i32, u32, i64, u64, isize, usize); + +// cmp +impl cmp::PartialOrd for Signed { + #[inline] + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl cmp::Ord for Signed { + #[inline] + fn cmp(&self, other: &Self) -> cmp::Ordering { + // TODO(nlordell): Once subtraction is implemented: + // self.saturating_sub(*other).signum64().partial_cmp(&0) + + use cmp::Ordering::*; + use Sign::*; + + match (self.into_sign_and_abs(), other.into_sign_and_abs()) { + ((Positive, _), (Negative, _)) => Greater, + ((Negative, _), (Positive, _)) => Less, + ((Positive, this), (Positive, other)) => this.cmp(&other), + ((Negative, this), (Negative, other)) => other.cmp(&this), + } + } +} + +// arithmetic ops - implemented above +impl ops::Add for Signed +where + T: Into, +{ + type Output = Self; + + #[inline] + #[track_caller] + fn add(self, rhs: T) -> Self::Output { + handle_overflow(self.overflowing_add(rhs.into())) + } +} + +impl ops::AddAssign for Signed +where + T: Into, +{ + #[inline] + #[track_caller] + fn add_assign(&mut self, rhs: T) { + *self = *self + rhs; + } +} + +impl ops::Sub for Signed +where + T: Into, +{ + type Output = Self; + + #[inline] + #[track_caller] + fn sub(self, rhs: T) -> Self::Output { + handle_overflow(self.overflowing_sub(rhs.into())) + } +} + +impl ops::SubAssign for Signed +where + T: Into, +{ + #[inline] + #[track_caller] + fn sub_assign(&mut self, rhs: T) { + *self = *self - rhs; + } +} + +impl ops::Mul for Signed +where + T: Into, +{ + type Output = Self; + + #[inline] + #[track_caller] + fn mul(self, rhs: T) -> Self::Output { + handle_overflow(self.overflowing_mul(rhs.into())) + } +} + +impl ops::MulAssign for Signed +where + T: Into, +{ + #[inline] + #[track_caller] + fn mul_assign(&mut self, rhs: T) { + *self = *self * rhs; + } +} + +impl ops::Div for Signed +where + T: Into, +{ + type Output = Self; + + #[inline] + #[track_caller] + fn div(self, rhs: T) -> Self::Output { + handle_overflow(self.overflowing_div(rhs.into())) + } +} + +impl ops::DivAssign for Signed +where + T: Into, +{ + #[inline] + #[track_caller] + fn div_assign(&mut self, rhs: T) { + *self = *self / rhs; + } +} + +impl ops::Rem for Signed +where + T: Into, +{ + type Output = Self; + + #[inline] + #[track_caller] + fn rem(self, rhs: T) -> Self::Output { + handle_overflow(self.overflowing_rem(rhs.into())) + } +} + +impl ops::RemAssign for Signed +where + T: Into, +{ + #[inline] + #[track_caller] + fn rem_assign(&mut self, rhs: T) { + *self = *self % rhs; + } +} + +impl iter::Sum for Signed +where + T: Into, +{ + #[inline] + #[track_caller] + fn sum>(iter: I) -> Self { + iter.fold(Self::ZERO, |acc, x| acc + x) + } +} + +impl iter::Product for Signed +where + T: Into, +{ + #[inline] + #[track_caller] + fn product>(iter: I) -> Self { + iter.fold(Self::ONE, |acc, x| acc * x) + } +} + +// bitwise ops - delegated to U256 +impl ops::BitAnd for Signed { + type Output = Self; + + #[inline] + fn bitand(self, rhs: Self) -> Self::Output { + Self(self.0 & rhs.0) + } +} + +impl ops::BitAndAssign for Signed { + #[inline] + fn bitand_assign(&mut self, rhs: Self) { + *self = *self & rhs; + } +} + +impl ops::BitOr for Signed { + type Output = Self; + + #[inline] + fn bitor(self, rhs: Self) -> Self::Output { + Self(self.0 | rhs.0) + } +} + +impl ops::BitOrAssign for Signed { + #[inline] + fn bitor_assign(&mut self, rhs: Self) { + *self = *self | rhs; + } +} + +impl ops::BitXor for Signed { + type Output = Self; + + #[inline] + fn bitxor(self, rhs: Self) -> Self::Output { + Self(self.0 ^ rhs.0) + } +} + +impl ops::BitXorAssign for Signed { + #[inline] + fn bitxor_assign(&mut self, rhs: Self) { + *self = *self ^ rhs; + } +} + +// unary ops +impl ops::Neg for Signed { + type Output = Self; + + #[inline] + #[track_caller] + fn neg(self) -> Self::Output { + handle_overflow(self.overflowing_neg()) + } +} + +impl ops::Not for Signed { + type Output = Self; + + #[inline] + fn not(self) -> Self::Output { + Self(!self.0) + } +} diff --git a/CoqOfRust/alloy_primitives/signed/ops.v b/CoqOfRust/alloy_primitives/signed/ops.v new file mode 100644 index 000000000..a9a1d3550 --- /dev/null +++ b/CoqOfRust/alloy_primitives/signed/ops.v @@ -0,0 +1,10045 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module signed. + Module ops. + Module Impl_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + pub fn abs(self) -> Self { + handle_overflow(self.overflowing_abs()) + } + *) + Definition abs + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_function (| + "alloy_primitives::signed::utils::handle_overflow", + [ BITS; LIMBS ], + [] + |), + [ + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_abs", + [], + [] + |), + [ M.read (| self |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_abs : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "abs" (abs BITS LIMBS). + Admitted. + Global Typeclasses Opaque abs. + + (* + pub fn overflowing_abs(self) -> (Self, bool) { + if BITS == 0 { + return (self, false); + } + if self == Self::MIN { + (self, true) + } else { + (Self(self.unsigned_abs()), false) + } + } + *) + Definition overflowing_abs + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.eq (| + M.read (| + M.get_constant "alloy_primitives::signed::ops::BITS" + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.Tuple [ M.read (| self |); Value.Bool false ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.match_operator (| + Some + (Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, self |); + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::signed::int::MIN" + |) + ] + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| Value.Tuple [ M.read (| self |); Value.Bool true ] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple + [ + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "unsigned_abs", + [], + [] + |), + [ M.read (| self |) ] + |) + ]; + Value.Bool false + ] + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_overflowing_abs : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait + (Self BITS LIMBS) + "overflowing_abs" + (overflowing_abs BITS LIMBS). + Admitted. + Global Typeclasses Opaque overflowing_abs. + + (* + pub fn checked_abs(self) -> Option { + match self.overflowing_abs() { + (value, false) => Some(value), + _ => None, + } + } + *) + Definition checked_abs + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] + ]), + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_abs", + [], + [] + |), + [ M.read (| self |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let value := M.copy (| γ0_0 |) in + let _ := + M.is_constant_or_break_match (| M.read (| γ0_1 |), Value.Bool false |) in + M.alloc (| + Value.StructTuple "core::option::Option::Some" [ M.read (| value |) ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.StructTuple "core::option::Option::None" [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_checked_abs : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "checked_abs" (checked_abs BITS LIMBS). + Admitted. + Global Typeclasses Opaque checked_abs. + + (* + pub fn saturating_abs(self) -> Self { + match self.overflowing_abs() { + (value, false) => value, + _ => Self::MAX, + } + } + *) + Definition saturating_abs + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some + (Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []), + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_abs", + [], + [] + |), + [ M.read (| self |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let value := M.copy (| γ0_0 |) in + let _ := + M.is_constant_or_break_match (| M.read (| γ0_1 |), Value.Bool false |) in + value)); + fun γ => ltac:(M.monadic (M.get_constant "alloy_primitives::signed::int::MAX")) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_saturating_abs : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "saturating_abs" (saturating_abs BITS LIMBS). + Admitted. + Global Typeclasses Opaque saturating_abs. + + (* + pub fn wrapping_abs(self) -> Self { + self.overflowing_abs().0 + } + *) + Definition wrapping_abs + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_tuple_field (| + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_abs", + [], + [] + |), + [ M.read (| self |) ] + |) + |), + 0 + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_wrapping_abs : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "wrapping_abs" (wrapping_abs BITS LIMBS). + Admitted. + Global Typeclasses Opaque wrapping_abs. + + (* + pub fn unsigned_abs(self) -> Uint { + self.into_sign_and_abs().1 + } + *) + Definition unsigned_abs + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_tuple_field (| + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.path "alloy_primitives::signed::sign::Sign"; + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "into_sign_and_abs", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, self |) ] + |) + |), + 1 + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_unsigned_abs : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "unsigned_abs" (unsigned_abs BITS LIMBS). + Admitted. + Global Typeclasses Opaque unsigned_abs. + + (* + pub fn overflowing_neg(self) -> (Self, bool) { + if BITS == 0 { + return (self, false); + } + if self == Self::MIN { + (self, true) + } else { + (Self(twos_complement(self.0)), false) + } + } + *) + Definition overflowing_neg + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.eq (| + M.read (| + M.get_constant "alloy_primitives::signed::ops::BITS" + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.Tuple [ M.read (| self |); Value.Bool false ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.match_operator (| + Some + (Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, self |); + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::signed::int::MIN" + |) + ] + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| Value.Tuple [ M.read (| self |); Value.Bool true ] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple + [ + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_function (| + "alloy_primitives::signed::utils::twos_complement", + [ BITS; LIMBS ], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |) + ]; + Value.Bool false + ] + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_overflowing_neg : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait + (Self BITS LIMBS) + "overflowing_neg" + (overflowing_neg BITS LIMBS). + Admitted. + Global Typeclasses Opaque overflowing_neg. + + (* + pub fn checked_neg(self) -> Option { + match self.overflowing_neg() { + (value, false) => Some(value), + _ => None, + } + } + *) + Definition checked_neg + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] + ]), + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_neg", + [], + [] + |), + [ M.read (| self |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let value := M.copy (| γ0_0 |) in + let _ := + M.is_constant_or_break_match (| M.read (| γ0_1 |), Value.Bool false |) in + M.alloc (| + Value.StructTuple "core::option::Option::Some" [ M.read (| value |) ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.StructTuple "core::option::Option::None" [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_checked_neg : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "checked_neg" (checked_neg BITS LIMBS). + Admitted. + Global Typeclasses Opaque checked_neg. + + (* + pub fn saturating_neg(self) -> Self { + match self.overflowing_neg() { + (value, false) => value, + _ => Self::MAX, + } + } + *) + Definition saturating_neg + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some + (Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []), + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_neg", + [], + [] + |), + [ M.read (| self |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let value := M.copy (| γ0_0 |) in + let _ := + M.is_constant_or_break_match (| M.read (| γ0_1 |), Value.Bool false |) in + value)); + fun γ => ltac:(M.monadic (M.get_constant "alloy_primitives::signed::int::MAX")) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_saturating_neg : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "saturating_neg" (saturating_neg BITS LIMBS). + Admitted. + Global Typeclasses Opaque saturating_neg. + + (* + pub fn wrapping_neg(self) -> Self { + self.overflowing_neg().0 + } + *) + Definition wrapping_neg + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_tuple_field (| + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_neg", + [], + [] + |), + [ M.read (| self |) ] + |) + |), + 0 + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_wrapping_neg : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "wrapping_neg" (wrapping_neg BITS LIMBS). + Admitted. + Global Typeclasses Opaque wrapping_neg. + + (* + pub const fn overflowing_add(self, rhs: Self) -> (Self, bool) { + let (unsigned, _) = self.0.overflowing_add(rhs.0); + let result = Self(unsigned); + + // NOTE: Overflow is determined by checking the sign of the operands and + // the result. + let overflow = matches!( + (self.sign(), rhs.sign(), result.sign()), + (Sign::Positive, Sign::Positive, Sign::Negative) + | (Sign::Negative, Sign::Negative, Sign::Positive) + ); + + (result, overflow) + } + *) + Definition overflowing_add + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + None, + M.alloc (| + M.call_closure (| + Ty.tuple + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; Ty.path "bool" ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "overflowing_add", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::signed::int::Signed", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let unsigned := M.copy (| γ0_0 |) in + let~ result : + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] := + M.alloc (| + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ M.read (| unsigned |) ] + |) in + let~ overflow : Ty.path "bool" := + M.copy (| + M.match_operator (| + Some (Ty.path "bool"), + M.alloc (| + Value.Tuple + [ + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, self |) ] + |); + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rhs |) ] + |); + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, result |) ] + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (M.find_or_pattern (| + γ, + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in + let _ := + M.is_struct_tuple (| + γ0_0, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + let _ := + M.is_struct_tuple (| + γ0_1, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + let _ := + M.is_struct_tuple (| + γ0_2, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in + let _ := + M.is_struct_tuple (| + γ0_0, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + let _ := + M.is_struct_tuple (| + γ0_1, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + let _ := + M.is_struct_tuple (| + γ0_2, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + Value.Tuple [])) + ], + fun γ => + ltac:(M.monadic + match γ with + | [] => ltac:(M.monadic (M.alloc (| Value.Bool true |))) + | _ => M.impossible "wrong number of arguments" + end) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Bool false |))) + ] + |) + |) in + M.alloc (| Value.Tuple [ M.read (| result |); M.read (| overflow |) ] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_overflowing_add : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait + (Self BITS LIMBS) + "overflowing_add" + (overflowing_add BITS LIMBS). + Admitted. + Global Typeclasses Opaque overflowing_add. + + (* + pub const fn checked_add(self, rhs: Self) -> Option { + match self.overflowing_add(rhs) { + (value, false) => Some(value), + _ => None, + } + } + *) + Definition checked_add + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] + ]), + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_add", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let value := M.copy (| γ0_0 |) in + let _ := + M.is_constant_or_break_match (| M.read (| γ0_1 |), Value.Bool false |) in + M.alloc (| + Value.StructTuple "core::option::Option::Some" [ M.read (| value |) ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.StructTuple "core::option::Option::None" [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_checked_add : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "checked_add" (checked_add BITS LIMBS). + Admitted. + Global Typeclasses Opaque checked_add. + + (* + pub const fn saturating_add(self, rhs: Self) -> Self { + let (result, overflow) = self.overflowing_add(rhs); + if overflow { + match result.sign() { + Sign::Positive => Self::MIN, + Sign::Negative => Self::MAX, + } + } else { + result + } + } + *) + Definition saturating_add + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + None, + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_add", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let result := M.copy (| γ0_0 |) in + let overflow := M.copy (| γ0_1 |) in + M.match_operator (| + Some + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use overflow in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.match_operator (| + Some + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []), + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, result |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + M.get_constant "alloy_primitives::signed::int::MIN")); + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + M.get_constant "alloy_primitives::signed::int::MAX")) + ] + |))); + fun γ => ltac:(M.monadic result) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_saturating_add : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "saturating_add" (saturating_add BITS LIMBS). + Admitted. + Global Typeclasses Opaque saturating_add. + + (* + pub const fn wrapping_add(self, rhs: Self) -> Self { + self.overflowing_add(rhs).0 + } + *) + Definition wrapping_add + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.SubPointer.get_tuple_field (| + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_add", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |), + 0 + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_wrapping_add : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "wrapping_add" (wrapping_add BITS LIMBS). + Admitted. + Global Typeclasses Opaque wrapping_add. + + (* + pub const fn overflowing_sub(self, rhs: Self) -> (Self, bool) { + // NOTE: We can't just compute the `self + (-rhs)` because `-rhs` does + // not always exist, specifically this would be a problem in case + // `rhs == Self::MIN` + + let (unsigned, _) = self.0.overflowing_sub(rhs.0); + let result = Self(unsigned); + + // NOTE: Overflow is determined by checking the sign of the operands and + // the result. + let overflow = matches!( + (self.sign(), rhs.sign(), result.sign()), + (Sign::Positive, Sign::Negative, Sign::Negative) + | (Sign::Negative, Sign::Positive, Sign::Positive) + ); + + (result, overflow) + } + *) + Definition overflowing_sub + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + None, + M.alloc (| + M.call_closure (| + Ty.tuple + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; Ty.path "bool" ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "overflowing_sub", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::signed::int::Signed", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let unsigned := M.copy (| γ0_0 |) in + let~ result : + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] := + M.alloc (| + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ M.read (| unsigned |) ] + |) in + let~ overflow : Ty.path "bool" := + M.copy (| + M.match_operator (| + Some (Ty.path "bool"), + M.alloc (| + Value.Tuple + [ + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, self |) ] + |); + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rhs |) ] + |); + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, result |) ] + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (M.find_or_pattern (| + γ, + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in + let _ := + M.is_struct_tuple (| + γ0_0, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + let _ := + M.is_struct_tuple (| + γ0_1, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + let _ := + M.is_struct_tuple (| + γ0_2, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in + let _ := + M.is_struct_tuple (| + γ0_0, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + let _ := + M.is_struct_tuple (| + γ0_1, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + let _ := + M.is_struct_tuple (| + γ0_2, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + Value.Tuple [])) + ], + fun γ => + ltac:(M.monadic + match γ with + | [] => ltac:(M.monadic (M.alloc (| Value.Bool true |))) + | _ => M.impossible "wrong number of arguments" + end) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Bool false |))) + ] + |) + |) in + M.alloc (| Value.Tuple [ M.read (| result |); M.read (| overflow |) ] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_overflowing_sub : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait + (Self BITS LIMBS) + "overflowing_sub" + (overflowing_sub BITS LIMBS). + Admitted. + Global Typeclasses Opaque overflowing_sub. + + (* + pub const fn checked_sub(self, rhs: Self) -> Option { + match self.overflowing_sub(rhs) { + (value, false) => Some(value), + _ => None, + } + } + *) + Definition checked_sub + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] + ]), + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_sub", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let value := M.copy (| γ0_0 |) in + let _ := + M.is_constant_or_break_match (| M.read (| γ0_1 |), Value.Bool false |) in + M.alloc (| + Value.StructTuple "core::option::Option::Some" [ M.read (| value |) ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.StructTuple "core::option::Option::None" [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_checked_sub : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "checked_sub" (checked_sub BITS LIMBS). + Admitted. + Global Typeclasses Opaque checked_sub. + + (* + pub const fn saturating_sub(self, rhs: Self) -> Self { + let (result, overflow) = self.overflowing_sub(rhs); + if overflow { + match result.sign() { + Sign::Positive => Self::MIN, + Sign::Negative => Self::MAX, + } + } else { + result + } + } + *) + Definition saturating_sub + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + None, + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_sub", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let result := M.copy (| γ0_0 |) in + let overflow := M.copy (| γ0_1 |) in + M.match_operator (| + Some + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use overflow in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.match_operator (| + Some + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []), + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, result |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + M.get_constant "alloy_primitives::signed::int::MIN")); + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + M.get_constant "alloy_primitives::signed::int::MAX")) + ] + |))); + fun γ => ltac:(M.monadic result) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_saturating_sub : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "saturating_sub" (saturating_sub BITS LIMBS). + Admitted. + Global Typeclasses Opaque saturating_sub. + + (* + pub const fn wrapping_sub(self, rhs: Self) -> Self { + self.overflowing_sub(rhs).0 + } + *) + Definition wrapping_sub + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.SubPointer.get_tuple_field (| + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_sub", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |), + 0 + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_wrapping_sub : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "wrapping_sub" (wrapping_sub BITS LIMBS). + Admitted. + Global Typeclasses Opaque wrapping_sub. + + (* + pub fn overflowing_mul(self, rhs: Self) -> (Self, bool) { + if self.is_zero() || rhs.is_zero() { + return (Self::ZERO, false); + } + let sign = self.sign() * rhs.sign(); + let (unsigned, overflow_mul) = self.unsigned_abs().overflowing_mul(rhs.unsigned_abs()); + let (result, overflow_conv) = Self::overflowing_from_sign_and_abs(sign, unsigned); + + (result, overflow_mul || overflow_conv) + } + *) + Definition overflowing_mul + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "is_zero", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, self |) ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "is_zero", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rhs |) ] + |))) + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.Tuple + [ + M.read (| + M.get_constant "alloy_primitives::signed::int::ZERO" + |); + Value.Bool false + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ sign : Ty.path "alloy_primitives::signed::sign::Sign" := + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "alloy_primitives::signed::sign::Sign", + [], + [ Ty.path "alloy_primitives::signed::sign::Sign" ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, self |) ] + |); + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rhs |) ] + |) + ] + |) + |) in + M.match_operator (| + None, + M.alloc (| + M.call_closure (| + Ty.tuple + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; Ty.path "bool" ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "overflowing_mul", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "unsigned_abs", + [], + [] + |), + [ M.read (| self |) ] + |); + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "unsigned_abs", + [], + [] + |), + [ M.read (| rhs |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let unsigned := M.copy (| γ0_0 |) in + let overflow_mul := M.copy (| γ0_1 |) in + M.match_operator (| + None, + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "overflowing_from_sign_and_abs", + [], + [] + |), + [ M.read (| sign |); M.read (| unsigned |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let result := M.copy (| γ0_0 |) in + let overflow_conv := M.copy (| γ0_1 |) in + M.alloc (| + Value.Tuple + [ + M.read (| result |); + LogicalOp.or (| + M.read (| overflow_mul |), + ltac:(M.monadic (M.read (| overflow_conv |))) + |) + ] + |))) + ] + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_overflowing_mul : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait + (Self BITS LIMBS) + "overflowing_mul" + (overflowing_mul BITS LIMBS). + Admitted. + Global Typeclasses Opaque overflowing_mul. + + (* + pub fn checked_mul(self, rhs: Self) -> Option { + match self.overflowing_mul(rhs) { + (value, false) => Some(value), + _ => None, + } + } + *) + Definition checked_mul + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] + ]), + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_mul", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let value := M.copy (| γ0_0 |) in + let _ := + M.is_constant_or_break_match (| M.read (| γ0_1 |), Value.Bool false |) in + M.alloc (| + Value.StructTuple "core::option::Option::Some" [ M.read (| value |) ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.StructTuple "core::option::Option::None" [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_checked_mul : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "checked_mul" (checked_mul BITS LIMBS). + Admitted. + Global Typeclasses Opaque checked_mul. + + (* + pub fn saturating_mul(self, rhs: Self) -> Self { + let (result, overflow) = self.overflowing_mul(rhs); + if overflow { + match self.sign() * rhs.sign() { + Sign::Positive => Self::MAX, + Sign::Negative => Self::MIN, + } + } else { + result + } + } + *) + Definition saturating_mul + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + None, + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_mul", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let result := M.copy (| γ0_0 |) in + let overflow := M.copy (| γ0_1 |) in + M.match_operator (| + Some + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use overflow in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.match_operator (| + Some + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []), + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "alloy_primitives::signed::sign::Sign", + [], + [ Ty.path "alloy_primitives::signed::sign::Sign" ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, self |) ] + |); + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rhs |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + M.get_constant "alloy_primitives::signed::int::MAX")); + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + M.get_constant "alloy_primitives::signed::int::MIN")) + ] + |))); + fun γ => ltac:(M.monadic result) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_saturating_mul : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "saturating_mul" (saturating_mul BITS LIMBS). + Admitted. + Global Typeclasses Opaque saturating_mul. + + (* + pub fn wrapping_mul(self, rhs: Self) -> Self { + self.overflowing_mul(rhs).0 + } + *) + Definition wrapping_mul + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.SubPointer.get_tuple_field (| + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_mul", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |), + 0 + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_wrapping_mul : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "wrapping_mul" (wrapping_mul BITS LIMBS). + Admitted. + Global Typeclasses Opaque wrapping_mul. + + (* + pub fn overflowing_div(self, rhs: Self) -> (Self, bool) { + assert!(!rhs.is_zero(), "attempt to divide by zero"); + let sign = self.sign() * rhs.sign(); + // Note, signed division can't overflow! + let unsigned = self.unsigned_abs() / rhs.unsigned_abs(); + let (result, overflow_conv) = Self::overflowing_from_sign_and_abs(sign, unsigned); + + (result, overflow_conv && !result.is_zero()) + } + *) + Definition overflowing_div + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| + UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "is_zero", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rhs |) ] + |) + |) + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array [ mk_str (| "attempt to divide by zero" |) ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ sign : Ty.path "alloy_primitives::signed::sign::Sign" := + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.path "alloy_primitives::signed::sign::Sign", + [], + [ Ty.path "alloy_primitives::signed::sign::Sign" ], + "mul", + [], + [] + |), + [ + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, self |) ] + |); + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rhs |) ] + |) + ] + |) + |) in + let~ unsigned : Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::arith::Div", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ], + "div", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "unsigned_abs", + [], + [] + |), + [ M.read (| self |) ] + |); + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "unsigned_abs", + [], + [] + |), + [ M.read (| rhs |) ] + |) + ] + |) + |) in + M.match_operator (| + None, + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_from_sign_and_abs", + [], + [] + |), + [ M.read (| sign |); M.read (| unsigned |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let result := M.copy (| γ0_0 |) in + let overflow_conv := M.copy (| γ0_1 |) in + M.alloc (| + Value.Tuple + [ + M.read (| result |); + LogicalOp.and (| + M.read (| overflow_conv |), + ltac:(M.monadic + (UnOp.not (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "is_zero", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, result |) ] + |) + |))) + |) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_overflowing_div : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait + (Self BITS LIMBS) + "overflowing_div" + (overflowing_div BITS LIMBS). + Admitted. + Global Typeclasses Opaque overflowing_div. + + (* + pub fn checked_div(self, rhs: Self) -> Option { + if rhs.is_zero() || (self == Self::MIN && rhs == Self::MINUS_ONE) { + None + } else { + Some(self.overflowing_div(rhs).0) + } + } + *) + Definition checked_div + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] + ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "is_zero", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rhs |) ] + |), + ltac:(M.monadic + (LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, self |); + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::signed::int::MIN" + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, rhs |); + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::signed::int::MINUS_ONE" + |) + ] + |))) + |))) + |) + |)) in + let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| Value.StructTuple "core::option::Option::None" [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.SubPointer.get_tuple_field (| + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "overflowing_div", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |), + 0 + |) + |) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_checked_div : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "checked_div" (checked_div BITS LIMBS). + Admitted. + Global Typeclasses Opaque checked_div. + + (* + pub fn saturating_div(self, rhs: Self) -> Self { + match self.overflowing_div(rhs) { + (value, false) => value, + // MIN / -1 is the only possible saturating overflow + _ => Self::MAX, + } + } + *) + Definition saturating_div + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + Some + (Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []), + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_div", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let value := M.copy (| γ0_0 |) in + let _ := + M.is_constant_or_break_match (| M.read (| γ0_1 |), Value.Bool false |) in + value)); + fun γ => ltac:(M.monadic (M.get_constant "alloy_primitives::signed::int::MAX")) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_saturating_div : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "saturating_div" (saturating_div BITS LIMBS). + Admitted. + Global Typeclasses Opaque saturating_div. + + (* + pub fn wrapping_div(self, rhs: Self) -> Self { + self.overflowing_div(rhs).0 + } + *) + Definition wrapping_div + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.SubPointer.get_tuple_field (| + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_div", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |), + 0 + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_wrapping_div : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "wrapping_div" (wrapping_div BITS LIMBS). + Admitted. + Global Typeclasses Opaque wrapping_div. + + (* + pub fn overflowing_rem(self, rhs: Self) -> (Self, bool) { + if self == Self::MIN && rhs == Self::MINUS_ONE { + (Self::ZERO, true) + } else { + let div_res = self / rhs; + (self - div_res * rhs, false) + } + } + *) + Definition overflowing_rem + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + Some + (Ty.tuple + [ + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []; + Ty.path "bool" + ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, self |); + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::signed::int::MIN" + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, rhs |); + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::signed::int::MINUS_ONE" + |) + ] + |))) + |) + |)) in + let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + Value.Tuple + [ + M.read (| M.get_constant "alloy_primitives::signed::int::ZERO" |); + Value.Bool true + ] + |))); + fun γ => + ltac:(M.monadic + (let~ div_res : + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + M.get_trait_method (| + "core::ops::arith::Div", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "div", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |) in + M.alloc (| + Value.Tuple + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "sub", + [], + [] + |), + [ + M.read (| self |); + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "mul", + [], + [] + |), + [ M.read (| div_res |); M.read (| rhs |) ] + |) + ] + |); + Value.Bool false + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_overflowing_rem : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait + (Self BITS LIMBS) + "overflowing_rem" + (overflowing_rem BITS LIMBS). + Admitted. + Global Typeclasses Opaque overflowing_rem. + + (* + pub fn checked_rem(self, rhs: Self) -> Option { + if rhs.is_zero() || (self == Self::MIN && rhs == Self::MINUS_ONE) { + None + } else { + Some(self.overflowing_rem(rhs).0) + } + } + *) + Definition checked_rem + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] + ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "is_zero", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rhs |) ] + |), + ltac:(M.monadic + (LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, self |); + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::signed::int::MIN" + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, rhs |); + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::signed::int::MINUS_ONE" + |) + ] + |))) + |))) + |) + |)) in + let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| Value.StructTuple "core::option::Option::None" [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + M.read (| + M.SubPointer.get_tuple_field (| + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "overflowing_rem", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |), + 0 + |) + |) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_checked_rem : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "checked_rem" (checked_rem BITS LIMBS). + Admitted. + Global Typeclasses Opaque checked_rem. + + (* + pub fn wrapping_rem(self, rhs: Self) -> Self { + self.overflowing_rem(rhs).0 + } + *) + Definition wrapping_rem + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.SubPointer.get_tuple_field (| + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_rem", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |), + 0 + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_wrapping_rem : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "wrapping_rem" (wrapping_rem BITS LIMBS). + Admitted. + Global Typeclasses Opaque wrapping_rem. + + (* + pub fn div_euclid(self, rhs: Self) -> Self { + let q = self / rhs; + if (self % rhs).is_negative() { + if rhs.is_positive() { + q - Self::ONE + } else { + q + Self::ONE + } + } else { + q + } + } + *) + Definition div_euclid + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ q : + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::arith::Div", + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "div", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |) in + M.match_operator (| + Some + (Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "is_negative", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + M.get_trait_method (| + "core::ops::arith::Rem", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "rem", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |) + |) + ] + |) + |)) in + let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.match_operator (| + Some + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "is_positive", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rhs |) ] + |) + |)) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "sub", + [], + [] + |), + [ + M.read (| q |); + M.read (| M.get_constant "alloy_primitives::signed::int::ONE" |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "add", + [], + [] + |), + [ + M.read (| q |); + M.read (| M.get_constant "alloy_primitives::signed::int::ONE" |) + ] + |) + |))) + ] + |))); + fun γ => ltac:(M.monadic q) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_div_euclid : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "div_euclid" (div_euclid BITS LIMBS). + Admitted. + Global Typeclasses Opaque div_euclid. + + (* + pub fn overflowing_div_euclid(self, rhs: Self) -> (Self, bool) { + if self == Self::MIN && rhs == Self::MINUS_ONE { + (self, true) + } else { + (self.div_euclid(rhs), false) + } + } + *) + Definition overflowing_div_euclid + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + Some + (Ty.tuple + [ + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []; + Ty.path "bool" + ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, self |); + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::signed::int::MIN" + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, rhs |); + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::signed::int::MINUS_ONE" + |) + ] + |))) + |) + |)) in + let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| Value.Tuple [ M.read (| self |); Value.Bool true ] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "div_euclid", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |); + Value.Bool false + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_overflowing_div_euclid : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait + (Self BITS LIMBS) + "overflowing_div_euclid" + (overflowing_div_euclid BITS LIMBS). + Admitted. + Global Typeclasses Opaque overflowing_div_euclid. + + (* + pub fn checked_div_euclid(self, rhs: Self) -> Option { + if rhs.is_zero() || (self == Self::MIN && rhs == Self::MINUS_ONE) { + None + } else { + Some(self.div_euclid(rhs)) + } + } + *) + Definition checked_div_euclid + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] + ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "is_zero", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rhs |) ] + |), + ltac:(M.monadic + (LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, self |); + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::signed::int::MIN" + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, rhs |); + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::signed::int::MINUS_ONE" + |) + ] + |))) + |))) + |) + |)) in + let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| Value.StructTuple "core::option::Option::None" [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "div_euclid", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_checked_div_euclid : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait + (Self BITS LIMBS) + "checked_div_euclid" + (checked_div_euclid BITS LIMBS). + Admitted. + Global Typeclasses Opaque checked_div_euclid. + + (* + pub fn wrapping_div_euclid(self, rhs: Self) -> Self { + self.overflowing_div_euclid(rhs).0 + } + *) + Definition wrapping_div_euclid + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.SubPointer.get_tuple_field (| + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_div_euclid", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |), + 0 + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_wrapping_div_euclid : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait + (Self BITS LIMBS) + "wrapping_div_euclid" + (wrapping_div_euclid BITS LIMBS). + Admitted. + Global Typeclasses Opaque wrapping_div_euclid. + + (* + pub fn rem_euclid(self, rhs: Self) -> Self { + let r = self % rhs; + if r < Self::ZERO { + if rhs < Self::ZERO { + r - rhs + } else { + r + rhs + } + } else { + r + } + } + *) + Definition rem_euclid + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ r : + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::arith::Rem", + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "rem", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |) in + M.match_operator (| + Some + (Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "lt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, r |); + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::signed::int::ZERO" + |) + ] + |) + |)) in + let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.match_operator (| + Some + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "lt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, rhs |); + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::signed::int::ZERO" + |) + ] + |) + |)) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "sub", + [], + [] + |), + [ M.read (| r |); M.read (| rhs |) ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "add", + [], + [] + |), + [ M.read (| r |); M.read (| rhs |) ] + |) + |))) + ] + |))); + fun γ => ltac:(M.monadic r) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_rem_euclid : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "rem_euclid" (rem_euclid BITS LIMBS). + Admitted. + Global Typeclasses Opaque rem_euclid. + + (* + pub fn overflowing_rem_euclid(self, rhs: Self) -> (Self, bool) { + if self == Self::MIN && rhs == Self::MINUS_ONE { + (Self::ZERO, true) + } else { + (self.rem_euclid(rhs), false) + } + } + *) + Definition overflowing_rem_euclid + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + Some + (Ty.tuple + [ + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []; + Ty.path "bool" + ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, self |); + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::signed::int::MIN" + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, rhs |); + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::signed::int::MINUS_ONE" + |) + ] + |))) + |) + |)) in + let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + Value.Tuple + [ + M.read (| M.get_constant "alloy_primitives::signed::int::ZERO" |); + Value.Bool true + ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "rem_euclid", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |); + Value.Bool false + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_overflowing_rem_euclid : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait + (Self BITS LIMBS) + "overflowing_rem_euclid" + (overflowing_rem_euclid BITS LIMBS). + Admitted. + Global Typeclasses Opaque overflowing_rem_euclid. + + (* + pub fn wrapping_rem_euclid(self, rhs: Self) -> Self { + self.overflowing_rem_euclid(rhs).0 + } + *) + Definition wrapping_rem_euclid + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.SubPointer.get_tuple_field (| + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_rem_euclid", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |), + 0 + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_wrapping_rem_euclid : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait + (Self BITS LIMBS) + "wrapping_rem_euclid" + (wrapping_rem_euclid BITS LIMBS). + Admitted. + Global Typeclasses Opaque wrapping_rem_euclid. + + (* + pub fn checked_rem_euclid(self, rhs: Self) -> Option { + if rhs.is_zero() || (self == Self::MIN && rhs == Self::MINUS_ONE) { + None + } else { + Some(self.rem_euclid(rhs)) + } + } + *) + Definition checked_rem_euclid + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] + ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "is_zero", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, rhs |) ] + |), + ltac:(M.monadic + (LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, self |); + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::signed::int::MIN" + |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, rhs |); + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::signed::int::MINUS_ONE" + |) + ] + |))) + |))) + |) + |)) in + let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| Value.StructTuple "core::option::Option::None" [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "rem_euclid", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_checked_rem_euclid : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait + (Self BITS LIMBS) + "checked_rem_euclid" + (checked_rem_euclid BITS LIMBS). + Admitted. + Global Typeclasses Opaque checked_rem_euclid. + + (* + pub(crate) const fn pow_sign(self, exp: Uint) -> Sign { + let is_exp_odd = BITS != 0 && exp.as_limbs()[0] % 2 == 1; + if is_exp_odd && self.is_negative() { + Sign::Negative + } else { + Sign::Positive + } + } + *) + Definition pow_sign + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; exp ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let exp := M.alloc (| exp |) in + M.read (| + let~ is_exp_odd : Ty.path "bool" := + M.alloc (| + LogicalOp.and (| + BinOp.ne (| + M.read (| M.get_constant "alloy_primitives::signed::ops::BITS" |), + Value.Integer IntegerKind.Usize 0 + |), + ltac:(M.monadic + (BinOp.eq (| + BinOp.Wrap.rem (| + M.read (| + M.SubPointer.get_array_field (| + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ LIMBS ] [ Ty.path "u64" ] ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "as_limbs", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, exp |) ] + |) + |), + Value.Integer IntegerKind.Usize 0 + |) + |), + Value.Integer IntegerKind.U64 2 + |), + Value.Integer IntegerKind.U64 1 + |))) + |) + |) in + M.match_operator (| + Some (Ty.path "alloy_primitives::signed::sign::Sign"), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + M.read (| is_exp_odd |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "is_negative", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, self |) ] + |))) + |) + |)) in + let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + Value.StructTuple "alloy_primitives::signed::sign::Sign::Negative" [] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.StructTuple "alloy_primitives::signed::sign::Sign::Positive" [] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_pow_sign : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "pow_sign" (pow_sign BITS LIMBS). + Admitted. + Global Typeclasses Opaque pow_sign. + + (* + pub fn exp10(n: usize) -> Self { + Uint::::from(10).pow(Uint::from(n)).try_into().expect("overflow") + } + *) + Definition exp10 + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ n ] => + ltac:(M.monadic + (let n := M.alloc (| n |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + "expect", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] + ], + "try_into", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "pow", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "from", + [], + [ Ty.path "i32" ] + |), + [ Value.Integer IntegerKind.I32 10 ] + |); + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "from", + [], + [ Ty.path "usize" ] + |), + [ M.read (| n |) ] + |) + ] + |) + ] + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "overflow" |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_exp10 : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "exp10" (exp10 BITS LIMBS). + Admitted. + Global Typeclasses Opaque exp10. + + (* + pub fn pow(self, exp: Uint) -> Self { + handle_overflow(self.overflowing_pow(exp)) + } + *) + Definition pow + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; exp ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let exp := M.alloc (| exp |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_function (| + "alloy_primitives::signed::utils::handle_overflow", + [ BITS; LIMBS ], + [] + |), + [ + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_pow", + [], + [] + |), + [ M.read (| self |); M.read (| exp |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_pow : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "pow" (pow BITS LIMBS). + Admitted. + Global Typeclasses Opaque pow. + + (* + pub fn overflowing_pow(self, exp: Uint) -> (Self, bool) { + if BITS == 0 { + return (Self::ZERO, false); + } + + let sign = self.pow_sign(exp); + + let (unsigned, overflow_pow) = self.unsigned_abs().overflowing_pow(exp); + let (result, overflow_conv) = Self::overflowing_from_sign_and_abs(sign, unsigned); + + (result, overflow_pow || overflow_conv) + } + *) + Definition overflowing_pow + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; exp ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let exp := M.alloc (| exp |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.eq (| + M.read (| + M.get_constant "alloy_primitives::signed::ops::BITS" + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.Tuple + [ + M.read (| + M.get_constant "alloy_primitives::signed::int::ZERO" + |); + Value.Bool false + ] + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ sign : Ty.path "alloy_primitives::signed::sign::Sign" := + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "pow_sign", + [], + [] + |), + [ M.read (| self |); M.read (| exp |) ] + |) + |) in + M.match_operator (| + None, + M.alloc (| + M.call_closure (| + Ty.tuple + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; Ty.path "bool" ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "overflowing_pow", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "unsigned_abs", + [], + [] + |), + [ M.read (| self |) ] + |); + M.read (| exp |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let unsigned := M.copy (| γ0_0 |) in + let overflow_pow := M.copy (| γ0_1 |) in + M.match_operator (| + None, + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "overflowing_from_sign_and_abs", + [], + [] + |), + [ M.read (| sign |); M.read (| unsigned |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let result := M.copy (| γ0_0 |) in + let overflow_conv := M.copy (| γ0_1 |) in + M.alloc (| + Value.Tuple + [ + M.read (| result |); + LogicalOp.or (| + M.read (| overflow_pow |), + ltac:(M.monadic (M.read (| overflow_conv |))) + |) + ] + |))) + ] + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_overflowing_pow : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait + (Self BITS LIMBS) + "overflowing_pow" + (overflowing_pow BITS LIMBS). + Admitted. + Global Typeclasses Opaque overflowing_pow. + + (* + pub fn checked_pow(self, exp: Uint) -> Option { + let (result, overflow) = self.overflowing_pow(exp); + if overflow { + None + } else { + Some(result) + } + } + *) + Definition checked_pow + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; exp ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let exp := M.alloc (| exp |) in + M.read (| + M.match_operator (| + None, + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_pow", + [], + [] + |), + [ M.read (| self |); M.read (| exp |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let result := M.copy (| γ0_0 |) in + let overflow := M.copy (| γ0_1 |) in + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use overflow in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| Value.StructTuple "core::option::Option::None" [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ M.read (| result |) ] + |))) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_checked_pow : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "checked_pow" (checked_pow BITS LIMBS). + Admitted. + Global Typeclasses Opaque checked_pow. + + (* + pub fn saturating_pow(self, exp: Uint) -> Self { + let (result, overflow) = self.overflowing_pow(exp); + if overflow { + match self.pow_sign(exp) { + Sign::Positive => Self::MAX, + Sign::Negative => Self::MIN, + } + } else { + result + } + } + *) + Definition saturating_pow + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; exp ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let exp := M.alloc (| exp |) in + M.read (| + M.match_operator (| + None, + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_pow", + [], + [] + |), + [ M.read (| self |); M.read (| exp |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let result := M.copy (| γ0_0 |) in + let overflow := M.copy (| γ0_1 |) in + M.match_operator (| + Some + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use overflow in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.match_operator (| + Some + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []), + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "pow_sign", + [], + [] + |), + [ M.read (| self |); M.read (| exp |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + M.get_constant "alloy_primitives::signed::int::MAX")); + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + M.get_constant "alloy_primitives::signed::int::MIN")) + ] + |))); + fun γ => ltac:(M.monadic result) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_saturating_pow : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "saturating_pow" (saturating_pow BITS LIMBS). + Admitted. + Global Typeclasses Opaque saturating_pow. + + (* + pub fn wrapping_pow(self, exp: Uint) -> Self { + self.overflowing_pow(exp).0 + } + *) + Definition wrapping_pow + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; exp ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let exp := M.alloc (| exp |) in + M.read (| + M.SubPointer.get_tuple_field (| + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_pow", + [], + [] + |), + [ M.read (| self |); M.read (| exp |) ] + |) + |), + 0 + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_wrapping_pow : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "wrapping_pow" (wrapping_pow BITS LIMBS). + Admitted. + Global Typeclasses Opaque wrapping_pow. + + (* + pub fn overflowing_shl(self, rhs: usize) -> (Self, bool) { + if rhs >= 256 { + (Self::ZERO, true) + } else { + (Self(self.0 << rhs), false) + } + } + *) + Definition overflowing_shl + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + Some + (Ty.tuple + [ + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []; + Ty.path "bool" + ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.ge (| M.read (| rhs |), Value.Integer IntegerKind.Usize 256 |) + |)) in + let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + Value.Tuple + [ + M.read (| M.get_constant "alloy_primitives::signed::int::ZERO" |); + Value.Bool true + ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple + [ + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::Shl", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [ Ty.path "usize" ], + "shl", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::signed::int::Signed", + 0 + |) + |); + M.read (| rhs |) + ] + |) + ]; + Value.Bool false + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_overflowing_shl : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait + (Self BITS LIMBS) + "overflowing_shl" + (overflowing_shl BITS LIMBS). + Admitted. + Global Typeclasses Opaque overflowing_shl. + + (* + pub fn checked_shl(self, rhs: usize) -> Option { + match self.overflowing_shl(rhs) { + (value, false) => Some(value), + _ => None, + } + } + *) + Definition checked_shl + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] + ]), + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_shl", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let value := M.copy (| γ0_0 |) in + let _ := + M.is_constant_or_break_match (| M.read (| γ0_1 |), Value.Bool false |) in + M.alloc (| + Value.StructTuple "core::option::Option::Some" [ M.read (| value |) ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.StructTuple "core::option::Option::None" [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_checked_shl : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "checked_shl" (checked_shl BITS LIMBS). + Admitted. + Global Typeclasses Opaque checked_shl. + + (* + pub fn wrapping_shl(self, rhs: usize) -> Self { + self.overflowing_shl(rhs).0 + } + *) + Definition wrapping_shl + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.SubPointer.get_tuple_field (| + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_shl", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |), + 0 + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_wrapping_shl : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "wrapping_shl" (wrapping_shl BITS LIMBS). + Admitted. + Global Typeclasses Opaque wrapping_shl. + + (* + pub fn overflowing_shr(self, rhs: usize) -> (Self, bool) { + if rhs >= 256 { + (Self::ZERO, true) + } else { + (Self(self.0 >> rhs), false) + } + } + *) + Definition overflowing_shr + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + Some + (Ty.tuple + [ + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []; + Ty.path "bool" + ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.ge (| M.read (| rhs |), Value.Integer IntegerKind.Usize 256 |) + |)) in + let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + Value.Tuple + [ + M.read (| M.get_constant "alloy_primitives::signed::int::ZERO" |); + Value.Bool true + ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.Tuple + [ + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::Shr", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [ Ty.path "usize" ], + "shr", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::signed::int::Signed", + 0 + |) + |); + M.read (| rhs |) + ] + |) + ]; + Value.Bool false + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_overflowing_shr : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait + (Self BITS LIMBS) + "overflowing_shr" + (overflowing_shr BITS LIMBS). + Admitted. + Global Typeclasses Opaque overflowing_shr. + + (* + pub fn checked_shr(self, rhs: usize) -> Option { + match self.overflowing_shr(rhs) { + (value, false) => Some(value), + _ => None, + } + } + *) + Definition checked_shr + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] + ]), + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_shr", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let value := M.copy (| γ0_0 |) in + let _ := + M.is_constant_or_break_match (| M.read (| γ0_1 |), Value.Bool false |) in + M.alloc (| + Value.StructTuple "core::option::Option::Some" [ M.read (| value |) ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.StructTuple "core::option::Option::None" [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_checked_shr : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "checked_shr" (checked_shr BITS LIMBS). + Admitted. + Global Typeclasses Opaque checked_shr. + + (* + pub fn wrapping_shr(self, rhs: usize) -> Self { + self.overflowing_shr(rhs).0 + } + *) + Definition wrapping_shr + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.SubPointer.get_tuple_field (| + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_shr", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |), + 0 + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_wrapping_shr : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "wrapping_shr" (wrapping_shr BITS LIMBS). + Admitted. + Global Typeclasses Opaque wrapping_shr. + + (* + pub fn asr(self, rhs: usize) -> Self { + // Avoid shifting if we are going to know the result regardless of the value. + if rhs == 0 || BITS == 0 { + return self; + } + + if rhs >= BITS - 1 { + match self.sign() { + Sign::Positive => return Self::ZERO, + Sign::Negative => return Self::MINUS_ONE, + } + } + + match self.sign() { + // Perform the shift. + Sign::Positive => self.wrapping_shr(rhs), + Sign::Negative => { + // We need to do: `for 0..shift { self >> 1 | 2^255 }` + // We can avoid the loop by doing: `self >> shift | ~(2^(255 - shift) - 1)` + // where '~' represents ones complement + let two: Uint = Uint::from(2); + let bitwise_or = Self::from_raw( + !(two.pow(Uint::::from(BITS - rhs)) + - Uint::::from(1)), + ); + (self.wrapping_shr(rhs)) | bitwise_or + } + } + } + *) + Definition asr + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + BinOp.eq (| + M.read (| rhs |), + Value.Integer IntegerKind.Usize 0 + |), + ltac:(M.monadic + (BinOp.eq (| + M.read (| + M.get_constant "alloy_primitives::signed::ops::BITS" + |), + Value.Integer IntegerKind.Usize 0 + |))) + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| M.read (| M.return_ (| M.read (| self |) |) |) |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.ge (| + M.read (| rhs |), + BinOp.Wrap.sub (| + M.read (| + M.get_constant "alloy_primitives::signed::ops::BITS" + |), + Value.Integer IntegerKind.Usize 1 + |) + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, self |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.read (| + M.get_constant "alloy_primitives::signed::int::ZERO" + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.read (| + M.get_constant + "alloy_primitives::signed::int::MINUS_ONE" + |) + |) + |) + |) + |))) + ] + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.match_operator (| + Some + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []), + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, self |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "wrapping_shr", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |))); + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + let~ two : Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "from", + [], + [ Ty.path "i32" ] + |), + [ Value.Integer IntegerKind.I32 2 ] + |) + |) in + let~ bitwise_or : + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "from_raw", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::Not", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [], + "not", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ], + "sub", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "pow", + [], + [] + |), + [ + M.read (| two |); + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ BITS; LIMBS ] + [], + "from", + [], + [ Ty.path "usize" ] + |), + [ + BinOp.Wrap.sub (| + M.read (| + M.get_constant + "alloy_primitives::signed::ops::BITS" + |), + M.read (| rhs |) + |) + ] + |) + ] + |); + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "from", + [], + [ Ty.path "i32" ] + |), + [ Value.Integer IntegerKind.I32 1 ] + |) + ] + |) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + M.get_trait_method (| + "core::ops::bit::BitOr", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "bitor", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "wrapping_shr", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |); + M.read (| bitwise_or |) + ] + |) + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_asr : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "asr" (asr BITS LIMBS). + Admitted. + Global Typeclasses Opaque asr. + + (* + pub fn asl(self, rhs: usize) -> Option { + if rhs == 0 || BITS == 0 { + Some(self) + } else { + let result = self.wrapping_shl(rhs); + if result.sign() != self.sign() { + // Overflow occurred + None + } else { + Some(result) + } + } + } + *) + Definition asl + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] + ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.or (| + BinOp.eq (| M.read (| rhs |), Value.Integer IntegerKind.Usize 0 |), + ltac:(M.monadic + (BinOp.eq (| + M.read (| M.get_constant "alloy_primitives::signed::ops::BITS" |), + Value.Integer IntegerKind.Usize 0 + |))) + |) + |)) in + let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + Value.StructTuple "core::option::Option::Some" [ M.read (| self |) ] + |))); + fun γ => + ltac:(M.monadic + (let~ result : + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "wrapping_shl", + [], + [] + |), + [ M.read (| self |); M.read (| rhs |) ] + |) + |) in + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.path "alloy_primitives::signed::sign::Sign", + [], + [ Ty.path "alloy_primitives::signed::sign::Sign" ], + "ne", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, result |) ] + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, self |) ] + |) + |) + |) + ] + |) + |)) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| Value.StructTuple "core::option::Option::None" [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ M.read (| result |) ] + |))) + ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_asl : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait (Self BITS LIMBS) "asl" (asl BITS LIMBS). + Admitted. + Global Typeclasses Opaque asl. + + (* + pub fn twos_complement(self) -> Uint { + let abs = self.into_raw(); + match self.sign() { + Sign::Positive => abs, + Sign::Negative => twos_complement(abs), + } + } + *) + Definition twos_complement + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ abs : Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "into_raw", + [], + [] + |), + [ M.read (| self |) ] + |) + |) in + M.match_operator (| + Some (Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []), + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::signed::sign::Sign", + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "sign", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, self |) ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + abs)); + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_function (| + "alloy_primitives::signed::utils::twos_complement", + [ BITS; LIMBS ], + [] + |), + [ M.read (| abs |) ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_twos_complement : + forall (BITS LIMBS : Value.t), + M.IsAssociatedFunction.Trait + (Self BITS LIMBS) + "twos_complement" + (twos_complement BITS LIMBS). + Admitted. + Global Typeclasses Opaque twos_complement. + End Impl_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_Shl_i8_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shl(self, rhs: $t) -> Self::Output { + self.wrapping_shl(rhs as usize) + } + *) + Definition shl + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "wrapping_shl", + [], + [] + |), + [ M.read (| self |); M.cast (Ty.path "usize") (M.read (| rhs |)) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::Shl" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i8" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS)); + ("shl", InstanceField.Method (shl BITS LIMBS)) + ]. + End Impl_core_ops_bit_Shl_i8_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_ShlAssign_i8_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shl_assign(&mut self, rhs: $t) { + *self = *self << rhs; + } + *) + Definition shl_assign + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::Shl", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "i8" ], + "shl", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::ShlAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i8" ] + (Self BITS LIMBS) + (* Instance *) [ ("shl_assign", InstanceField.Method (shl_assign BITS LIMBS)) ]. + End Impl_core_ops_bit_ShlAssign_i8_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_Shr_i8_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shr(self, rhs: $t) -> Self::Output { + self.wrapping_shr(rhs as usize) + } + *) + Definition shr + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "wrapping_shr", + [], + [] + |), + [ M.read (| self |); M.cast (Ty.path "usize") (M.read (| rhs |)) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::Shr" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i8" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS)); + ("shr", InstanceField.Method (shr BITS LIMBS)) + ]. + End Impl_core_ops_bit_Shr_i8_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_ShrAssign_i8_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shr_assign(&mut self, rhs: $t) { + *self = *self >> rhs; + } + *) + Definition shr_assign + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::Shr", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "i8" ], + "shr", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::ShrAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i8" ] + (Self BITS LIMBS) + (* Instance *) [ ("shr_assign", InstanceField.Method (shr_assign BITS LIMBS)) ]. + End Impl_core_ops_bit_ShrAssign_i8_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_Shl_u8_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shl(self, rhs: $t) -> Self::Output { + self.wrapping_shl(rhs as usize) + } + *) + Definition shl + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "wrapping_shl", + [], + [] + |), + [ M.read (| self |); M.cast (Ty.path "usize") (M.read (| rhs |)) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::Shl" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u8" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS)); + ("shl", InstanceField.Method (shl BITS LIMBS)) + ]. + End Impl_core_ops_bit_Shl_u8_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_ShlAssign_u8_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shl_assign(&mut self, rhs: $t) { + *self = *self << rhs; + } + *) + Definition shl_assign + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::Shl", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "u8" ], + "shl", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::ShlAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u8" ] + (Self BITS LIMBS) + (* Instance *) [ ("shl_assign", InstanceField.Method (shl_assign BITS LIMBS)) ]. + End Impl_core_ops_bit_ShlAssign_u8_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_Shr_u8_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shr(self, rhs: $t) -> Self::Output { + self.wrapping_shr(rhs as usize) + } + *) + Definition shr + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "wrapping_shr", + [], + [] + |), + [ M.read (| self |); M.cast (Ty.path "usize") (M.read (| rhs |)) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::Shr" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u8" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS)); + ("shr", InstanceField.Method (shr BITS LIMBS)) + ]. + End Impl_core_ops_bit_Shr_u8_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_ShrAssign_u8_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shr_assign(&mut self, rhs: $t) { + *self = *self >> rhs; + } + *) + Definition shr_assign + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::Shr", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "u8" ], + "shr", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::ShrAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u8" ] + (Self BITS LIMBS) + (* Instance *) [ ("shr_assign", InstanceField.Method (shr_assign BITS LIMBS)) ]. + End Impl_core_ops_bit_ShrAssign_u8_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_Shl_i16_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shl(self, rhs: $t) -> Self::Output { + self.wrapping_shl(rhs as usize) + } + *) + Definition shl + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "wrapping_shl", + [], + [] + |), + [ M.read (| self |); M.cast (Ty.path "usize") (M.read (| rhs |)) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::Shl" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i16" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS)); + ("shl", InstanceField.Method (shl BITS LIMBS)) + ]. + End Impl_core_ops_bit_Shl_i16_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_ShlAssign_i16_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shl_assign(&mut self, rhs: $t) { + *self = *self << rhs; + } + *) + Definition shl_assign + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::Shl", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "i16" ], + "shl", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::ShlAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i16" ] + (Self BITS LIMBS) + (* Instance *) [ ("shl_assign", InstanceField.Method (shl_assign BITS LIMBS)) ]. + End Impl_core_ops_bit_ShlAssign_i16_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_Shr_i16_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shr(self, rhs: $t) -> Self::Output { + self.wrapping_shr(rhs as usize) + } + *) + Definition shr + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "wrapping_shr", + [], + [] + |), + [ M.read (| self |); M.cast (Ty.path "usize") (M.read (| rhs |)) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::Shr" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i16" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS)); + ("shr", InstanceField.Method (shr BITS LIMBS)) + ]. + End Impl_core_ops_bit_Shr_i16_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_ShrAssign_i16_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shr_assign(&mut self, rhs: $t) { + *self = *self >> rhs; + } + *) + Definition shr_assign + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::Shr", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "i16" ], + "shr", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::ShrAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i16" ] + (Self BITS LIMBS) + (* Instance *) [ ("shr_assign", InstanceField.Method (shr_assign BITS LIMBS)) ]. + End Impl_core_ops_bit_ShrAssign_i16_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_Shl_u16_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shl(self, rhs: $t) -> Self::Output { + self.wrapping_shl(rhs as usize) + } + *) + Definition shl + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "wrapping_shl", + [], + [] + |), + [ M.read (| self |); M.cast (Ty.path "usize") (M.read (| rhs |)) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::Shl" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u16" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS)); + ("shl", InstanceField.Method (shl BITS LIMBS)) + ]. + End Impl_core_ops_bit_Shl_u16_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_ShlAssign_u16_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shl_assign(&mut self, rhs: $t) { + *self = *self << rhs; + } + *) + Definition shl_assign + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::Shl", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "u16" ], + "shl", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::ShlAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u16" ] + (Self BITS LIMBS) + (* Instance *) [ ("shl_assign", InstanceField.Method (shl_assign BITS LIMBS)) ]. + End Impl_core_ops_bit_ShlAssign_u16_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_Shr_u16_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shr(self, rhs: $t) -> Self::Output { + self.wrapping_shr(rhs as usize) + } + *) + Definition shr + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "wrapping_shr", + [], + [] + |), + [ M.read (| self |); M.cast (Ty.path "usize") (M.read (| rhs |)) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::Shr" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u16" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS)); + ("shr", InstanceField.Method (shr BITS LIMBS)) + ]. + End Impl_core_ops_bit_Shr_u16_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_ShrAssign_u16_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shr_assign(&mut self, rhs: $t) { + *self = *self >> rhs; + } + *) + Definition shr_assign + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::Shr", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "u16" ], + "shr", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::ShrAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u16" ] + (Self BITS LIMBS) + (* Instance *) [ ("shr_assign", InstanceField.Method (shr_assign BITS LIMBS)) ]. + End Impl_core_ops_bit_ShrAssign_u16_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_Shl_i32_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shl(self, rhs: $t) -> Self::Output { + self.wrapping_shl(rhs as usize) + } + *) + Definition shl + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "wrapping_shl", + [], + [] + |), + [ M.read (| self |); M.cast (Ty.path "usize") (M.read (| rhs |)) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::Shl" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i32" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS)); + ("shl", InstanceField.Method (shl BITS LIMBS)) + ]. + End Impl_core_ops_bit_Shl_i32_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_ShlAssign_i32_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shl_assign(&mut self, rhs: $t) { + *self = *self << rhs; + } + *) + Definition shl_assign + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::Shl", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "i32" ], + "shl", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::ShlAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i32" ] + (Self BITS LIMBS) + (* Instance *) [ ("shl_assign", InstanceField.Method (shl_assign BITS LIMBS)) ]. + End Impl_core_ops_bit_ShlAssign_i32_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_Shr_i32_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shr(self, rhs: $t) -> Self::Output { + self.wrapping_shr(rhs as usize) + } + *) + Definition shr + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "wrapping_shr", + [], + [] + |), + [ M.read (| self |); M.cast (Ty.path "usize") (M.read (| rhs |)) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::Shr" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i32" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS)); + ("shr", InstanceField.Method (shr BITS LIMBS)) + ]. + End Impl_core_ops_bit_Shr_i32_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_ShrAssign_i32_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shr_assign(&mut self, rhs: $t) { + *self = *self >> rhs; + } + *) + Definition shr_assign + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::Shr", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "i32" ], + "shr", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::ShrAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i32" ] + (Self BITS LIMBS) + (* Instance *) [ ("shr_assign", InstanceField.Method (shr_assign BITS LIMBS)) ]. + End Impl_core_ops_bit_ShrAssign_i32_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_Shl_u32_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shl(self, rhs: $t) -> Self::Output { + self.wrapping_shl(rhs as usize) + } + *) + Definition shl + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "wrapping_shl", + [], + [] + |), + [ M.read (| self |); M.cast (Ty.path "usize") (M.read (| rhs |)) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::Shl" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u32" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS)); + ("shl", InstanceField.Method (shl BITS LIMBS)) + ]. + End Impl_core_ops_bit_Shl_u32_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_ShlAssign_u32_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shl_assign(&mut self, rhs: $t) { + *self = *self << rhs; + } + *) + Definition shl_assign + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::Shl", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "u32" ], + "shl", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::ShlAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u32" ] + (Self BITS LIMBS) + (* Instance *) [ ("shl_assign", InstanceField.Method (shl_assign BITS LIMBS)) ]. + End Impl_core_ops_bit_ShlAssign_u32_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_Shr_u32_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shr(self, rhs: $t) -> Self::Output { + self.wrapping_shr(rhs as usize) + } + *) + Definition shr + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "wrapping_shr", + [], + [] + |), + [ M.read (| self |); M.cast (Ty.path "usize") (M.read (| rhs |)) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::Shr" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u32" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS)); + ("shr", InstanceField.Method (shr BITS LIMBS)) + ]. + End Impl_core_ops_bit_Shr_u32_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_ShrAssign_u32_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shr_assign(&mut self, rhs: $t) { + *self = *self >> rhs; + } + *) + Definition shr_assign + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::Shr", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "u32" ], + "shr", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::ShrAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u32" ] + (Self BITS LIMBS) + (* Instance *) [ ("shr_assign", InstanceField.Method (shr_assign BITS LIMBS)) ]. + End Impl_core_ops_bit_ShrAssign_u32_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_Shl_i64_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shl(self, rhs: $t) -> Self::Output { + self.wrapping_shl(rhs as usize) + } + *) + Definition shl + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "wrapping_shl", + [], + [] + |), + [ M.read (| self |); M.cast (Ty.path "usize") (M.read (| rhs |)) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::Shl" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i64" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS)); + ("shl", InstanceField.Method (shl BITS LIMBS)) + ]. + End Impl_core_ops_bit_Shl_i64_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_ShlAssign_i64_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shl_assign(&mut self, rhs: $t) { + *self = *self << rhs; + } + *) + Definition shl_assign + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::Shl", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "i64" ], + "shl", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::ShlAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i64" ] + (Self BITS LIMBS) + (* Instance *) [ ("shl_assign", InstanceField.Method (shl_assign BITS LIMBS)) ]. + End Impl_core_ops_bit_ShlAssign_i64_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_Shr_i64_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shr(self, rhs: $t) -> Self::Output { + self.wrapping_shr(rhs as usize) + } + *) + Definition shr + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "wrapping_shr", + [], + [] + |), + [ M.read (| self |); M.cast (Ty.path "usize") (M.read (| rhs |)) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::Shr" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i64" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS)); + ("shr", InstanceField.Method (shr BITS LIMBS)) + ]. + End Impl_core_ops_bit_Shr_i64_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_ShrAssign_i64_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shr_assign(&mut self, rhs: $t) { + *self = *self >> rhs; + } + *) + Definition shr_assign + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::Shr", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "i64" ], + "shr", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::ShrAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i64" ] + (Self BITS LIMBS) + (* Instance *) [ ("shr_assign", InstanceField.Method (shr_assign BITS LIMBS)) ]. + End Impl_core_ops_bit_ShrAssign_i64_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_Shl_u64_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shl(self, rhs: $t) -> Self::Output { + self.wrapping_shl(rhs as usize) + } + *) + Definition shl + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "wrapping_shl", + [], + [] + |), + [ M.read (| self |); M.cast (Ty.path "usize") (M.read (| rhs |)) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::Shl" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u64" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS)); + ("shl", InstanceField.Method (shl BITS LIMBS)) + ]. + End Impl_core_ops_bit_Shl_u64_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_ShlAssign_u64_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shl_assign(&mut self, rhs: $t) { + *self = *self << rhs; + } + *) + Definition shl_assign + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::Shl", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "u64" ], + "shl", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::ShlAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u64" ] + (Self BITS LIMBS) + (* Instance *) [ ("shl_assign", InstanceField.Method (shl_assign BITS LIMBS)) ]. + End Impl_core_ops_bit_ShlAssign_u64_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_Shr_u64_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shr(self, rhs: $t) -> Self::Output { + self.wrapping_shr(rhs as usize) + } + *) + Definition shr + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "wrapping_shr", + [], + [] + |), + [ M.read (| self |); M.cast (Ty.path "usize") (M.read (| rhs |)) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::Shr" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u64" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS)); + ("shr", InstanceField.Method (shr BITS LIMBS)) + ]. + End Impl_core_ops_bit_Shr_u64_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_ShrAssign_u64_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shr_assign(&mut self, rhs: $t) { + *self = *self >> rhs; + } + *) + Definition shr_assign + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::Shr", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "u64" ], + "shr", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::ShrAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u64" ] + (Self BITS LIMBS) + (* Instance *) [ ("shr_assign", InstanceField.Method (shr_assign BITS LIMBS)) ]. + End Impl_core_ops_bit_ShrAssign_u64_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_Shl_isize_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shl(self, rhs: $t) -> Self::Output { + self.wrapping_shl(rhs as usize) + } + *) + Definition shl + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "wrapping_shl", + [], + [] + |), + [ M.read (| self |); M.cast (Ty.path "usize") (M.read (| rhs |)) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::Shl" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "isize" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS)); + ("shl", InstanceField.Method (shl BITS LIMBS)) + ]. + End Impl_core_ops_bit_Shl_isize_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_ShlAssign_isize_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shl_assign(&mut self, rhs: $t) { + *self = *self << rhs; + } + *) + Definition shl_assign + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::Shl", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "isize" ], + "shl", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::ShlAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "isize" ] + (Self BITS LIMBS) + (* Instance *) [ ("shl_assign", InstanceField.Method (shl_assign BITS LIMBS)) ]. + End Impl_core_ops_bit_ShlAssign_isize_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_Shr_isize_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shr(self, rhs: $t) -> Self::Output { + self.wrapping_shr(rhs as usize) + } + *) + Definition shr + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "wrapping_shr", + [], + [] + |), + [ M.read (| self |); M.cast (Ty.path "usize") (M.read (| rhs |)) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::Shr" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "isize" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS)); + ("shr", InstanceField.Method (shr BITS LIMBS)) + ]. + End Impl_core_ops_bit_Shr_isize_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_ShrAssign_isize_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shr_assign(&mut self, rhs: $t) { + *self = *self >> rhs; + } + *) + Definition shr_assign + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::Shr", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "isize" ], + "shr", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::ShrAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "isize" ] + (Self BITS LIMBS) + (* Instance *) [ ("shr_assign", InstanceField.Method (shr_assign BITS LIMBS)) ]. + End Impl_core_ops_bit_ShrAssign_isize_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_Shl_usize_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shl(self, rhs: $t) -> Self::Output { + self.wrapping_shl(rhs as usize) + } + *) + Definition shl + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "wrapping_shl", + [], + [] + |), + [ M.read (| self |); M.read (| M.use rhs |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::Shl" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "usize" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS)); + ("shl", InstanceField.Method (shl BITS LIMBS)) + ]. + End Impl_core_ops_bit_Shl_usize_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_ShlAssign_usize_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shl_assign(&mut self, rhs: $t) { + *self = *self << rhs; + } + *) + Definition shl_assign + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::Shl", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "usize" ], + "shl", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::ShlAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "usize" ] + (Self BITS LIMBS) + (* Instance *) [ ("shl_assign", InstanceField.Method (shl_assign BITS LIMBS)) ]. + End Impl_core_ops_bit_ShlAssign_usize_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_Shr_usize_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shr(self, rhs: $t) -> Self::Output { + self.wrapping_shr(rhs as usize) + } + *) + Definition shr + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "wrapping_shr", + [], + [] + |), + [ M.read (| self |); M.read (| M.use rhs |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::Shr" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "usize" ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS)); + ("shr", InstanceField.Method (shr BITS LIMBS)) + ]. + End Impl_core_ops_bit_Shr_usize_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_ShrAssign_usize_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn shr_assign(&mut self, rhs: $t) { + *self = *self >> rhs; + } + *) + Definition shr_assign + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::Shr", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ Ty.path "usize" ], + "shr", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::ShrAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "usize" ] + (Self BITS LIMBS) + (* Instance *) [ ("shr_assign", InstanceField.Method (shr_assign BITS LIMBS)) ]. + End Impl_core_ops_bit_ShrAssign_usize_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_cmp_PartialOrd_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } + *) + Definition partial_cmp + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "core::cmp::Ordering", + M.get_trait_method (| + "core::cmp::Ord", + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + [], + [], + "cmp", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] ] + (Self BITS LIMBS) + (* Instance *) [ ("partial_cmp", InstanceField.Method (partial_cmp BITS LIMBS)) ]. + End Impl_core_cmp_PartialOrd_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_cmp_Ord_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn cmp(&self, other: &Self) -> cmp::Ordering { + // TODO(nlordell): Once subtraction is implemented: + // self.saturating_sub( *other).signum64().partial_cmp(&0) + + use cmp::Ordering::*; + use Sign::*; + + match (self.into_sign_and_abs(), other.into_sign_and_abs()) { + ((Positive, _), (Negative, _)) => Greater, + ((Negative, _), (Positive, _)) => Less, + ((Positive, this), (Positive, other)) => this.cmp(&other), + ((Negative, this), (Negative, other)) => other.cmp(&this), + } + } + *) + Definition cmp + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.read (| + M.match_operator (| + Some (Ty.path "core::cmp::Ordering"), + M.alloc (| + Value.Tuple + [ + M.call_closure (| + Ty.tuple + [ + Ty.path "alloy_primitives::signed::sign::Sign"; + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "into_sign_and_abs", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |); + M.call_closure (| + Ty.tuple + [ + Ty.path "alloy_primitives::signed::sign::Sign"; + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + "into_sign_and_abs", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) ] + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let _ := + M.is_struct_tuple (| + γ1_0, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_1, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_1, 1 |) in + let _ := + M.is_struct_tuple (| + γ1_0, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + M.alloc (| Value.StructTuple "core::cmp::Ordering::Greater" [] |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let _ := + M.is_struct_tuple (| + γ1_0, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_1, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_1, 1 |) in + let _ := + M.is_struct_tuple (| + γ1_0, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + M.alloc (| Value.StructTuple "core::cmp::Ordering::Less" [] |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let _ := + M.is_struct_tuple (| + γ1_0, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + let this := M.copy (| γ1_1 |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_1, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_1, 1 |) in + let _ := + M.is_struct_tuple (| + γ1_0, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + let other := M.copy (| γ1_1 |) in + M.alloc (| + M.call_closure (| + Ty.path "core::cmp::Ordering", + M.get_trait_method (| + "core::cmp::Ord", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [], + "cmp", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, this |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, other |) |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in + let _ := + M.is_struct_tuple (| + γ1_0, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + let this := M.copy (| γ1_1 |) in + let γ1_0 := M.SubPointer.get_tuple_field (| γ0_1, 0 |) in + let γ1_1 := M.SubPointer.get_tuple_field (| γ0_1, 1 |) in + let _ := + M.is_struct_tuple (| + γ1_0, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + let other := M.copy (| γ1_1 |) in + M.alloc (| + M.call_closure (| + Ty.path "core::cmp::Ordering", + M.get_trait_method (| + "core::cmp::Ord", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [], + "cmp", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, other |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, this |) |) + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::cmp::Ord" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self BITS LIMBS) + (* Instance *) [ ("cmp", InstanceField.Method (cmp BITS LIMBS)) ]. + End Impl_core_cmp_Ord_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_arith_Add_where_core_convert_Into_T_alloy_primitives_signed_int_Signed_BITS_LIMBS_T_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn add(self, rhs: T) -> Self::Output { + handle_overflow(self.overflowing_add(rhs.into())) + } + *) + Definition add + (BITS LIMBS : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS T in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_function (| + "alloy_primitives::signed::utils::handle_overflow", + [ BITS; LIMBS ], + [] + |), + [ + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_add", + [], + [] + |), + [ + M.read (| self |); + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::convert::Into", + T, + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "into", + [], + [] + |), + [ M.read (| rhs |) ] + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t) (T : Ty.t), + M.IsTraitInstance + "core::ops::arith::Add" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self BITS LIMBS T) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS T)); + ("add", InstanceField.Method (add BITS LIMBS T)) + ]. + End Impl_core_ops_arith_Add_where_core_convert_Into_T_alloy_primitives_signed_int_Signed_BITS_LIMBS_T_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_arith_AddAssign_where_core_convert_Into_T_alloy_primitives_signed_int_Signed_BITS_LIMBS_T_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn add_assign(&mut self, rhs: T) { + *self = *self + rhs; + } + *) + Definition add_assign + (BITS LIMBS : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS T in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ T ], + "add", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t) (T : Ty.t), + M.IsTraitInstance + "core::ops::arith::AddAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self BITS LIMBS T) + (* Instance *) [ ("add_assign", InstanceField.Method (add_assign BITS LIMBS T)) ]. + End Impl_core_ops_arith_AddAssign_where_core_convert_Into_T_alloy_primitives_signed_int_Signed_BITS_LIMBS_T_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_arith_Sub_where_core_convert_Into_T_alloy_primitives_signed_int_Signed_BITS_LIMBS_T_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn sub(self, rhs: T) -> Self::Output { + handle_overflow(self.overflowing_sub(rhs.into())) + } + *) + Definition sub + (BITS LIMBS : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS T in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_function (| + "alloy_primitives::signed::utils::handle_overflow", + [ BITS; LIMBS ], + [] + |), + [ + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_sub", + [], + [] + |), + [ + M.read (| self |); + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::convert::Into", + T, + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "into", + [], + [] + |), + [ M.read (| rhs |) ] + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t) (T : Ty.t), + M.IsTraitInstance + "core::ops::arith::Sub" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self BITS LIMBS T) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS T)); + ("sub", InstanceField.Method (sub BITS LIMBS T)) + ]. + End Impl_core_ops_arith_Sub_where_core_convert_Into_T_alloy_primitives_signed_int_Signed_BITS_LIMBS_T_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_arith_SubAssign_where_core_convert_Into_T_alloy_primitives_signed_int_Signed_BITS_LIMBS_T_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn sub_assign(&mut self, rhs: T) { + *self = *self - rhs; + } + *) + Definition sub_assign + (BITS LIMBS : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS T in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::arith::Sub", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ T ], + "sub", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t) (T : Ty.t), + M.IsTraitInstance + "core::ops::arith::SubAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self BITS LIMBS T) + (* Instance *) [ ("sub_assign", InstanceField.Method (sub_assign BITS LIMBS T)) ]. + End Impl_core_ops_arith_SubAssign_where_core_convert_Into_T_alloy_primitives_signed_int_Signed_BITS_LIMBS_T_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_arith_Mul_where_core_convert_Into_T_alloy_primitives_signed_int_Signed_BITS_LIMBS_T_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn mul(self, rhs: T) -> Self::Output { + handle_overflow(self.overflowing_mul(rhs.into())) + } + *) + Definition mul + (BITS LIMBS : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS T in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_function (| + "alloy_primitives::signed::utils::handle_overflow", + [ BITS; LIMBS ], + [] + |), + [ + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_mul", + [], + [] + |), + [ + M.read (| self |); + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::convert::Into", + T, + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "into", + [], + [] + |), + [ M.read (| rhs |) ] + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t) (T : Ty.t), + M.IsTraitInstance + "core::ops::arith::Mul" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self BITS LIMBS T) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS T)); + ("mul", InstanceField.Method (mul BITS LIMBS T)) + ]. + End Impl_core_ops_arith_Mul_where_core_convert_Into_T_alloy_primitives_signed_int_Signed_BITS_LIMBS_T_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_arith_MulAssign_where_core_convert_Into_T_alloy_primitives_signed_int_Signed_BITS_LIMBS_T_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn mul_assign(&mut self, rhs: T) { + *self = *self * rhs; + } + *) + Definition mul_assign + (BITS LIMBS : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS T in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ T ], + "mul", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t) (T : Ty.t), + M.IsTraitInstance + "core::ops::arith::MulAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self BITS LIMBS T) + (* Instance *) [ ("mul_assign", InstanceField.Method (mul_assign BITS LIMBS T)) ]. + End Impl_core_ops_arith_MulAssign_where_core_convert_Into_T_alloy_primitives_signed_int_Signed_BITS_LIMBS_T_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_arith_Div_where_core_convert_Into_T_alloy_primitives_signed_int_Signed_BITS_LIMBS_T_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn div(self, rhs: T) -> Self::Output { + handle_overflow(self.overflowing_div(rhs.into())) + } + *) + Definition div + (BITS LIMBS : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS T in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_function (| + "alloy_primitives::signed::utils::handle_overflow", + [ BITS; LIMBS ], + [] + |), + [ + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_div", + [], + [] + |), + [ + M.read (| self |); + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::convert::Into", + T, + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "into", + [], + [] + |), + [ M.read (| rhs |) ] + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t) (T : Ty.t), + M.IsTraitInstance + "core::ops::arith::Div" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self BITS LIMBS T) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS T)); + ("div", InstanceField.Method (div BITS LIMBS T)) + ]. + End Impl_core_ops_arith_Div_where_core_convert_Into_T_alloy_primitives_signed_int_Signed_BITS_LIMBS_T_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_arith_DivAssign_where_core_convert_Into_T_alloy_primitives_signed_int_Signed_BITS_LIMBS_T_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn div_assign(&mut self, rhs: T) { + *self = *self / rhs; + } + *) + Definition div_assign + (BITS LIMBS : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS T in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::arith::Div", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ T ], + "div", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t) (T : Ty.t), + M.IsTraitInstance + "core::ops::arith::DivAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self BITS LIMBS T) + (* Instance *) [ ("div_assign", InstanceField.Method (div_assign BITS LIMBS T)) ]. + End Impl_core_ops_arith_DivAssign_where_core_convert_Into_T_alloy_primitives_signed_int_Signed_BITS_LIMBS_T_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_arith_Rem_where_core_convert_Into_T_alloy_primitives_signed_int_Signed_BITS_LIMBS_T_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn rem(self, rhs: T) -> Self::Output { + handle_overflow(self.overflowing_rem(rhs.into())) + } + *) + Definition rem + (BITS LIMBS : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS T in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_function (| + "alloy_primitives::signed::utils::handle_overflow", + [ BITS; LIMBS ], + [] + |), + [ + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_rem", + [], + [] + |), + [ + M.read (| self |); + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::convert::Into", + T, + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "into", + [], + [] + |), + [ M.read (| rhs |) ] + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t) (T : Ty.t), + M.IsTraitInstance + "core::ops::arith::Rem" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self BITS LIMBS T) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS T)); + ("rem", InstanceField.Method (rem BITS LIMBS T)) + ]. + End Impl_core_ops_arith_Rem_where_core_convert_Into_T_alloy_primitives_signed_int_Signed_BITS_LIMBS_T_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_arith_RemAssign_where_core_convert_Into_T_alloy_primitives_signed_int_Signed_BITS_LIMBS_T_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn rem_assign(&mut self, rhs: T) { + *self = *self % rhs; + } + *) + Definition rem_assign + (BITS LIMBS : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS T in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::arith::Rem", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ T ], + "rem", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t) (T : Ty.t), + M.IsTraitInstance + "core::ops::arith::RemAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self BITS LIMBS T) + (* Instance *) [ ("rem_assign", InstanceField.Method (rem_assign BITS LIMBS T)) ]. + End Impl_core_ops_arith_RemAssign_where_core_convert_Into_T_alloy_primitives_signed_int_Signed_BITS_LIMBS_T_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_iter_traits_accum_Sum_where_core_convert_Into_T_alloy_primitives_signed_int_Signed_BITS_LIMBS_T_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn sum>(iter: I) -> Self { + iter.fold(Self::ZERO, |acc, x| acc + x) + } + *) + Definition sum + (BITS LIMBS : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS T in + match ε, τ, α with + | [], [ _ as I ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + I, + [], + [], + "fold", + [], + [ + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + T + ] + ] + (Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []) + ] + |), + [ + M.read (| iter |); + M.read (| M.get_constant "alloy_primitives::signed::int::ZERO" |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + T + ] + ] + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [])), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let acc := M.copy (| γ |) in + M.match_operator (| + Some + (Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + T + ] + ] + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [])), + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + M.get_trait_method (| + "core::ops::arith::Add", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ T ], + "add", + [], + [] + |), + [ M.read (| acc |); M.read (| x |) ] + |))) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t) (T : Ty.t), + M.IsTraitInstance + "core::iter::traits::accum::Sum" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self BITS LIMBS T) + (* Instance *) [ ("sum", InstanceField.Method (sum BITS LIMBS T)) ]. + End Impl_core_iter_traits_accum_Sum_where_core_convert_Into_T_alloy_primitives_signed_int_Signed_BITS_LIMBS_T_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_iter_traits_accum_Product_where_core_convert_Into_T_alloy_primitives_signed_int_Signed_BITS_LIMBS_T_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) (T : Ty.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn product>(iter: I) -> Self { + iter.fold(Self::ONE, |acc, x| acc * x) + } + *) + Definition product + (BITS LIMBS : Value.t) + (T : Ty.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS T in + match ε, τ, α with + | [], [ _ as I ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + I, + [], + [], + "fold", + [], + [ + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []; + Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + T + ] + ] + (Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []) + ] + |), + [ + M.read (| iter |); + M.read (| M.get_constant "alloy_primitives::signed::int::ONE" |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0; α1 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + T + ] + ] + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [])), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let acc := M.copy (| γ |) in + M.match_operator (| + Some + (Ty.function + [ + Ty.tuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + []; + T + ] + ] + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [])), + M.alloc (| α1 |), + [ + fun γ => + ltac:(M.monadic + (let x := M.copy (| γ |) in + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + M.get_trait_method (| + "core::ops::arith::Mul", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ T ], + "mul", + [], + [] + |), + [ M.read (| acc |); M.read (| x |) ] + |))) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t) (T : Ty.t), + M.IsTraitInstance + "core::iter::traits::accum::Product" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ T ] + (Self BITS LIMBS T) + (* Instance *) [ ("product", InstanceField.Method (product BITS LIMBS T)) ]. + End Impl_core_iter_traits_accum_Product_where_core_convert_Into_T_alloy_primitives_signed_int_Signed_BITS_LIMBS_T_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_BitAnd_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn bitand(self, rhs: Self) -> Self::Output { + Self(self.0 & rhs.0) + } + *) + Definition bitand + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::BitAnd", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ], + "bitand", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::signed::int::Signed", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::BitAnd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS)); + ("bitand", InstanceField.Method (bitand BITS LIMBS)) + ]. + End Impl_core_ops_bit_BitAnd_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_BitAndAssign_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn bitand_assign(&mut self, rhs: Self) { + *self = *self & rhs; + } + *) + Definition bitand_assign + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::BitAnd", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "bitand", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::BitAndAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] ] + (Self BITS LIMBS) + (* Instance *) [ ("bitand_assign", InstanceField.Method (bitand_assign BITS LIMBS)) ]. + End Impl_core_ops_bit_BitAndAssign_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_BitOr_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn bitor(self, rhs: Self) -> Self::Output { + Self(self.0 | rhs.0) + } + *) + Definition bitor + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::BitOr", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ], + "bitor", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::signed::int::Signed", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::BitOr" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS)); + ("bitor", InstanceField.Method (bitor BITS LIMBS)) + ]. + End Impl_core_ops_bit_BitOr_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_BitOrAssign_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn bitor_assign(&mut self, rhs: Self) { + *self = *self | rhs; + } + *) + Definition bitor_assign + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::BitOr", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "bitor", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::BitOrAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] ] + (Self BITS LIMBS) + (* Instance *) [ ("bitor_assign", InstanceField.Method (bitor_assign BITS LIMBS)) ]. + End Impl_core_ops_bit_BitOrAssign_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_BitXor_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn bitxor(self, rhs: Self) -> Self::Output { + Self(self.0 ^ rhs.0) + } + *) + Definition bitxor + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::BitXor", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [] ], + "bitxor", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::signed::int::Signed", + 0 + |) + |); + M.read (| + M.SubPointer.get_struct_tuple_field (| + rhs, + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::BitXor" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] ] + (Self BITS LIMBS) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS)); + ("bitxor", InstanceField.Method (bitxor BITS LIMBS)) + ]. + End Impl_core_ops_bit_BitXor_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_BitXorAssign_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn bitxor_assign(&mut self, rhs: Self) { + *self = *self ^ rhs; + } + *) + Definition bitxor_assign + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.deref (| M.read (| self |) |), + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::BitXor", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [] + ], + "bitxor", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |); M.read (| rhs |) ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::BitXorAssign" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [] ] + (Self BITS LIMBS) + (* Instance *) [ ("bitxor_assign", InstanceField.Method (bitxor_assign BITS LIMBS)) ]. + End Impl_core_ops_bit_BitXorAssign_alloy_primitives_signed_int_Signed_BITS_LIMBS_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_arith_Neg_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn neg(self) -> Self::Output { + handle_overflow(self.overflowing_neg()) + } + *) + Definition neg + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + M.get_function (| + "alloy_primitives::signed::utils::handle_overflow", + [ BITS; LIMBS ], + [] + |), + [ + M.call_closure (| + Ty.tuple + [ + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []; + Ty.path "bool" + ], + M.get_associated_function (| + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] [], + "overflowing_neg", + [], + [] + |), + [ M.read (| self |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::arith::Neg" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self BITS LIMBS) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS)); + ("neg", InstanceField.Method (neg BITS LIMBS)) + ]. + End Impl_core_ops_arith_Neg_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + + Module Impl_core_ops_bit_Not_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + Definition Self (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* type Output = Self; *) + Definition _Output (BITS LIMBS : Value.t) : Ty.t := + Ty.apply (Ty.path "alloy_primitives::signed::int::Signed") [ BITS; LIMBS ] []. + + (* + fn not(self) -> Self::Output { + Self(!self.0) + } + *) + Definition not + (BITS LIMBS : Value.t) + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + let Self : Ty.t := Self BITS LIMBS in + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::Not", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [], + "not", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + forall (BITS LIMBS : Value.t), + M.IsTraitInstance + "core::ops::bit::Not" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + (Self BITS LIMBS) + (* Instance *) + [ + ("Output", InstanceField.Ty (_Output BITS LIMBS)); + ("not", InstanceField.Method (not BITS LIMBS)) + ]. + End Impl_core_ops_bit_Not_for_alloy_primitives_signed_int_Signed_BITS_LIMBS. + End ops. +End signed. diff --git a/CoqOfRust/alloy_primitives/signed/serde.rs b/CoqOfRust/alloy_primitives/signed/serde.rs new file mode 100644 index 000000000..de412e56f --- /dev/null +++ b/CoqOfRust/alloy_primitives/signed/serde.rs @@ -0,0 +1,55 @@ +use super::Signed; +use alloc::string::String; +use core::fmt; +use serde::{ + de::{self, Visitor}, + Deserialize, Deserializer, Serialize, Serializer, +}; + +impl Serialize for Signed { + fn serialize(&self, serializer: S) -> Result { + serializer.collect_str(self) + } +} + +impl<'de, const BITS: usize, const LIMBS: usize> Deserialize<'de> for Signed { + fn deserialize>(deserializer: D) -> Result { + struct SignedVisitor; + + impl Visitor<'_> for SignedVisitor { + type Value = Signed; + + fn expecting(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "a {BITS} bit signed integer") + } + + fn visit_u64(self, v: u64) -> Result { + Signed::try_from(v).map_err(de::Error::custom) + } + + fn visit_u128(self, v: u128) -> Result { + Signed::try_from(v).map_err(de::Error::custom) + } + + fn visit_i64(self, v: i64) -> Result { + Signed::try_from(v).map_err(de::Error::custom) + } + + fn visit_i128(self, v: i128) -> Result { + Signed::try_from(v).map_err(de::Error::custom) + } + + fn visit_str(self, v: &str) -> Result { + v.parse().map_err(serde::de::Error::custom) + } + + fn visit_string(self, v: String) -> Result { + self.visit_str(&v) + } + } + + deserializer.deserialize_any(SignedVisitor) + } +} + +// TODO: Tests diff --git a/CoqOfRust/alloy_primitives/signed/sign.rs b/CoqOfRust/alloy_primitives/signed/sign.rs new file mode 100644 index 000000000..90c3d2d2b --- /dev/null +++ b/CoqOfRust/alloy_primitives/signed/sign.rs @@ -0,0 +1,90 @@ +use core::{ + fmt::{self, Write}, + ops, +}; + +/// Enum to represent the sign of a 256-bit signed integer. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[repr(i8)] +pub enum Sign { + /// Less than zero. + Negative = -1, + /// Greater than or equal to zero. + Positive = 1, +} + +impl ops::Mul for Sign { + type Output = Self; + + #[inline] + fn mul(self, rhs: Self) -> Self::Output { + match (self, rhs) { + (Self::Positive, Self::Positive) => Self::Positive, + (Self::Positive, Self::Negative) => Self::Negative, + (Self::Negative, Self::Positive) => Self::Negative, + (Self::Negative, Self::Negative) => Self::Positive, + } + } +} + +impl ops::Neg for Sign { + type Output = Self; + + #[inline] + fn neg(self) -> Self::Output { + match self { + Self::Positive => Self::Negative, + Self::Negative => Self::Positive, + } + } +} + +impl ops::Not for Sign { + type Output = Self; + + #[inline] + fn not(self) -> Self::Output { + match self { + Self::Positive => Self::Negative, + Self::Negative => Self::Positive, + } + } +} + +impl fmt::Display for Sign { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match (self, f.sign_plus()) { + (Self::Positive, false) => Ok(()), + _ => f.write_char(self.as_char()), + } + } +} + +impl Sign { + /// Equality at compile-time. + #[inline] + pub const fn const_eq(self, other: Self) -> bool { + self as i8 == other as i8 + } + + /// Returns whether the sign is positive. + #[inline] + pub const fn is_positive(&self) -> bool { + matches!(self, Self::Positive) + } + + /// Returns whether the sign is negative. + #[inline] + pub const fn is_negative(&self) -> bool { + matches!(self, Self::Negative) + } + + /// Returns the sign character. + #[inline] + pub const fn as_char(&self) -> char { + match self { + Self::Positive => '+', + Self::Negative => '-', + } + } +} diff --git a/CoqOfRust/alloy_primitives/signed/sign.v b/CoqOfRust/alloy_primitives/signed/sign.v new file mode 100644 index 000000000..70be79f65 --- /dev/null +++ b/CoqOfRust/alloy_primitives/signed/sign.v @@ -0,0 +1,694 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module signed. + Module sign. + (* + Enum Sign + { + const_params := []; + ty_params := []; + variants := + [ + { + name := "Negative"; + item := StructTuple []; + }; + { + name := "Positive"; + item := StructTuple []; + } + ]; + } + *) + + Axiom IsDiscriminant_Sign_Negative : + M.IsDiscriminant "alloy_primitives::signed::sign::Sign::Negative" 0. + Axiom IsDiscriminant_Sign_Positive : + M.IsDiscriminant "alloy_primitives::signed::sign::Sign::Positive" 1. + + Module Impl_core_clone_Clone_for_alloy_primitives_signed_sign_Sign. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::sign::Sign". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| M.deref (| M.read (| self |) |) |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_alloy_primitives_signed_sign_Sign. + + Module Impl_core_marker_Copy_for_alloy_primitives_signed_sign_Sign. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::sign::Sign". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_alloy_primitives_signed_sign_Sign. + + Module Impl_core_fmt_Debug_for_alloy_primitives_signed_sign_Sign. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::sign::Sign". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| Ty.path "core::fmt::Formatter", "write_str", [], [] |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.read (| + M.match_operator (| + Some (Ty.apply (Ty.path "&") [] [ Ty.path "str" ]), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + M.alloc (| + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Negative" |) |) |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + M.alloc (| + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Positive" |) |) |) + |))) + ] + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_alloy_primitives_signed_sign_Sign. + + Module Impl_core_marker_StructuralPartialEq_for_alloy_primitives_signed_sign_Sign. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::sign::Sign". + + Axiom Implements : + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_alloy_primitives_signed_sign_Sign. + + Module Impl_core_cmp_PartialEq_alloy_primitives_signed_sign_Sign_for_alloy_primitives_signed_sign_Sign. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::sign::Sign". + + (* PartialEq *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.read (| + let~ __self_discr : Ty.path "i8" := + M.alloc (| + M.call_closure (| + Ty.path "i8", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "alloy_primitives::signed::sign::Sign" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ __arg1_discr : Ty.path "i8" := + M.alloc (| + M.call_closure (| + Ty.path "i8", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "alloy_primitives::signed::sign::Sign" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) ] + |) + |) in + M.alloc (| BinOp.eq (| M.read (| __self_discr |), M.read (| __arg1_discr |) |) |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::signed::sign::Sign" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_signed_sign_Sign_for_alloy_primitives_signed_sign_Sign. + + Module Impl_core_cmp_Eq_for_alloy_primitives_signed_sign_Sign. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::sign::Sign". + + (* Eq *) + Definition assert_receiver_is_total_eq + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.Tuple [])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method assert_receiver_is_total_eq) ]. + End Impl_core_cmp_Eq_for_alloy_primitives_signed_sign_Sign. + + Module Impl_core_ops_arith_Mul_alloy_primitives_signed_sign_Sign_for_alloy_primitives_signed_sign_Sign. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::sign::Sign". + + (* type Output = Self; *) + Definition _Output : Ty.t := Ty.path "alloy_primitives::signed::sign::Sign". + + (* + fn mul(self, rhs: Self) -> Self::Output { + match (self, rhs) { + (Self::Positive, Self::Positive) => Self::Positive, + (Self::Positive, Self::Negative) => Self::Negative, + (Self::Negative, Self::Positive) => Self::Negative, + (Self::Negative, Self::Negative) => Self::Positive, + } + } + *) + Definition mul (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; rhs ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let rhs := M.alloc (| rhs |) in + M.read (| + M.match_operator (| + Some (Ty.path "alloy_primitives::signed::sign::Sign"), + M.alloc (| Value.Tuple [ M.read (| self |); M.read (| rhs |) ] |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + M.is_struct_tuple (| + γ0_0, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + let _ := + M.is_struct_tuple (| + γ0_1, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + M.alloc (| + Value.StructTuple "alloy_primitives::signed::sign::Sign::Positive" [] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + M.is_struct_tuple (| + γ0_0, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + let _ := + M.is_struct_tuple (| + γ0_1, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + M.alloc (| + Value.StructTuple "alloy_primitives::signed::sign::Sign::Negative" [] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + M.is_struct_tuple (| + γ0_0, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + let _ := + M.is_struct_tuple (| + γ0_1, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + M.alloc (| + Value.StructTuple "alloy_primitives::signed::sign::Sign::Negative" [] + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let _ := + M.is_struct_tuple (| + γ0_0, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + let _ := + M.is_struct_tuple (| + γ0_1, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + M.alloc (| + Value.StructTuple "alloy_primitives::signed::sign::Sign::Positive" [] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::Mul" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::signed::sign::Sign" ] + Self + (* Instance *) + [ ("Output", InstanceField.Ty _Output); ("mul", InstanceField.Method mul) ]. + End Impl_core_ops_arith_Mul_alloy_primitives_signed_sign_Sign_for_alloy_primitives_signed_sign_Sign. + + Module Impl_core_ops_arith_Neg_for_alloy_primitives_signed_sign_Sign. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::sign::Sign". + + (* type Output = Self; *) + Definition _Output : Ty.t := Ty.path "alloy_primitives::signed::sign::Sign". + + (* + fn neg(self) -> Self::Output { + match self { + Self::Positive => Self::Negative, + Self::Negative => Self::Positive, + } + } + *) + Definition neg (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some (Ty.path "alloy_primitives::signed::sign::Sign"), + self, + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + M.alloc (| + Value.StructTuple "alloy_primitives::signed::sign::Sign::Negative" [] + |))); + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + M.alloc (| + Value.StructTuple "alloy_primitives::signed::sign::Sign::Positive" [] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::arith::Neg" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("Output", InstanceField.Ty _Output); ("neg", InstanceField.Method neg) ]. + End Impl_core_ops_arith_Neg_for_alloy_primitives_signed_sign_Sign. + + Module Impl_core_ops_bit_Not_for_alloy_primitives_signed_sign_Sign. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::sign::Sign". + + (* type Output = Self; *) + Definition _Output : Ty.t := Ty.path "alloy_primitives::signed::sign::Sign". + + (* + fn not(self) -> Self::Output { + match self { + Self::Positive => Self::Negative, + Self::Negative => Self::Positive, + } + } + *) + Definition not (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some (Ty.path "alloy_primitives::signed::sign::Sign"), + self, + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + M.alloc (| + Value.StructTuple "alloy_primitives::signed::sign::Sign::Negative" [] + |))); + fun γ => + ltac:(M.monadic + (let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + M.alloc (| + Value.StructTuple "alloy_primitives::signed::sign::Sign::Positive" [] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::ops::bit::Not" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("Output", InstanceField.Ty _Output); ("not", InstanceField.Method not) ]. + End Impl_core_ops_bit_Not_for_alloy_primitives_signed_sign_Sign. + + Module Impl_core_fmt_Display_for_alloy_primitives_signed_sign_Sign. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::sign::Sign". + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match (self, f.sign_plus()) { + (Self::Positive, false) => Ok(()), + _ => f.write_char(self.as_char()), + } + } + *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ]), + M.alloc (| + Value.Tuple + [ + M.read (| self |); + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "sign_plus", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| f |) |) |) ] + |) + ] + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_0 := M.read (| γ0_0 |) in + let _ := + M.is_struct_tuple (| + γ0_0, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + let _ := + M.is_constant_or_break_match (| M.read (| γ0_1 |), Value.Bool false |) in + M.alloc (| + Value.StructTuple "core::result::Result::Ok" [ Value.Tuple [] ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::Write", + Ty.path "core::fmt::Formatter", + [], + [], + "write_char", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.call_closure (| + Ty.path "char", + M.get_associated_function (| + Ty.path "alloy_primitives::signed::sign::Sign", + "as_char", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Display" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Display_for_alloy_primitives_signed_sign_Sign. + + Module Impl_alloy_primitives_signed_sign_Sign. + Definition Self : Ty.t := Ty.path "alloy_primitives::signed::sign::Sign". + + (* + pub const fn const_eq(self, other: Self) -> bool { + self as i8 == other as i8 + } + *) + Definition const_eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + BinOp.eq (| + M.cast (Ty.path "i8") (M.read (| self |)), + M.cast (Ty.path "i8") (M.read (| other |)) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_const_eq : + M.IsAssociatedFunction.Trait Self "const_eq" const_eq. + Admitted. + Global Typeclasses Opaque const_eq. + + (* + pub const fn is_positive(&self) -> bool { + matches!(self, Self::Positive) + } + *) + Definition is_positive (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some (Ty.path "bool"), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + M.alloc (| Value.Bool true |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Bool false |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_is_positive : + M.IsAssociatedFunction.Trait Self "is_positive" is_positive. + Admitted. + Global Typeclasses Opaque is_positive. + + (* + pub const fn is_negative(&self) -> bool { + matches!(self, Self::Negative) + } + *) + Definition is_negative (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some (Ty.path "bool"), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + M.alloc (| Value.Bool true |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Bool false |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_is_negative : + M.IsAssociatedFunction.Trait Self "is_negative" is_negative. + Admitted. + Global Typeclasses Opaque is_negative. + + (* + pub const fn as_char(&self) -> char { + match self { + Self::Positive => '+', + Self::Negative => '-', + } + } + *) + Definition as_char (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some (Ty.path "char"), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Positive" + |) in + M.alloc (| Value.UnicodeChar 43 |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let _ := + M.is_struct_tuple (| + γ, + "alloy_primitives::signed::sign::Sign::Negative" + |) in + M.alloc (| Value.UnicodeChar 45 |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_as_char : + M.IsAssociatedFunction.Trait Self "as_char" as_char. + Admitted. + Global Typeclasses Opaque as_char. + End Impl_alloy_primitives_signed_sign_Sign. + End sign. +End signed. diff --git a/CoqOfRust/alloy_primitives/signed/utils.rs b/CoqOfRust/alloy_primitives/signed/utils.rs new file mode 100644 index 000000000..4da4bc396 --- /dev/null +++ b/CoqOfRust/alloy_primitives/signed/utils.rs @@ -0,0 +1,95 @@ +use crate::signed::Signed; +use ruint::Uint; + +/// Panic if overflow on debug mode. +#[inline] +#[track_caller] +pub(super) fn handle_overflow( + (result, overflow): (Signed, bool), +) -> Signed { + debug_assert!(!overflow, "overflow"); + result +} + +/// Compute the two's complement of a U256. +#[inline] +pub(super) fn twos_complement( + u: Uint, +) -> Uint { + if BITS == 0 { + return u; + } + (!u).overflowing_add(Uint::::from(1)).0 +} + +/// Compile-time equality of signed integers. +#[inline] +pub(super) const fn const_eq( + left: &Signed, + right: &Signed, +) -> bool { + if BITS == 0 { + return true; + } + + let mut i = 0; + let llimbs = left.0.as_limbs(); + let rlimbs = right.0.as_limbs(); + while i < LIMBS { + if llimbs[i] != rlimbs[i] { + return false; + } + i += 1; + } + true +} + +/// Compute the max value at compile time. +pub(super) const fn max() -> Signed { + if LIMBS == 0 { + return zero(); + } + + let mut limbs = [u64::MAX; LIMBS]; + limbs[LIMBS - 1] &= Signed::::MASK; // unset all high bits + limbs[LIMBS - 1] &= !Signed::::SIGN_BIT; // unset the sign bit + Signed(Uint::from_limbs(limbs)) +} + +pub(super) const fn min() -> Signed { + if LIMBS == 0 { + return zero(); + } + + let mut limbs = [0; LIMBS]; + limbs[LIMBS - 1] = Signed::::SIGN_BIT; + Signed(Uint::from_limbs(limbs)) +} + +pub(super) const fn zero() -> Signed { + let limbs = [0; LIMBS]; + Signed(Uint::from_limbs(limbs)) +} + +pub(super) const fn one() -> Signed { + if LIMBS == 0 { + return zero(); + } + + let mut limbs = [0; LIMBS]; + limbs[0] = 1; + Signed(Uint::from_limbs(limbs)) +} + +/// Location of the sign bit within the highest limb. +pub(super) const fn sign_bit(bits: usize) -> u64 { + if bits == 0 { + return 0; + } + let bits = bits % 64; + if bits == 0 { + 1 << 63 + } else { + 1 << (bits - 1) + } +} diff --git a/CoqOfRust/alloy_primitives/signed/utils.v b/CoqOfRust/alloy_primitives/signed/utils.v new file mode 100644 index 000000000..7136ce181 --- /dev/null +++ b/CoqOfRust/alloy_primitives/signed/utils.v @@ -0,0 +1,874 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module signed. + Module utils. + (* + pub(super) fn handle_overflow( + (result, overflow): (Signed, bool), + ) -> Signed { + debug_assert!(!overflow, "overflow"); + result + } + *) + Definition handle_overflow (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ BITS; LIMBS ], [], [ β0 ] => + ltac:(M.monadic + (let β0 := M.alloc (| β0 |) in + M.match_operator (| + None, + β0, + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let result := M.copy (| γ0_0 |) in + let overflow := M.copy (| γ0_1 |) in + M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use (M.alloc (| Value.Bool true |)) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + UnOp.not (| UnOp.not (| M.read (| overflow |) |) |) + |)) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| + "core::panicking::panic_fmt", + [], + [] + |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array [ mk_str (| "overflow" |) ] + |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + result + |))) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_handle_overflow : + M.IsFunction.Trait "alloy_primitives::signed::utils::handle_overflow" handle_overflow. + Admitted. + Global Typeclasses Opaque handle_overflow. + + (* + pub(super) fn twos_complement( + u: Uint, + ) -> Uint { + if BITS == 0 { + return u; + } + (!u).overflowing_add(Uint::::from(1)).0 + } + *) + Definition twos_complement (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ BITS; LIMBS ], [], [ u ] => + ltac:(M.monadic + (let u := M.alloc (| u |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.eq (| + M.read (| + M.get_constant + "alloy_primitives::signed::utils::twos_complement::BITS" + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| M.read (| M.return_ (| M.read (| u |) |) |) |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.SubPointer.get_tuple_field (| + M.alloc (| + M.call_closure (| + Ty.tuple + [ Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] []; Ty.path "bool" ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "overflowing_add", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_trait_method (| + "core::ops::bit::Not", + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + [], + [], + "not", + [], + [] + |), + [ M.read (| u |) ] + |); + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "from", + [], + [ Ty.path "i32" ] + |), + [ Value.Integer IntegerKind.I32 1 ] + |) + ] + |) + |), + 0 + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_twos_complement : + M.IsFunction.Trait "alloy_primitives::signed::utils::twos_complement" twos_complement. + Admitted. + Global Typeclasses Opaque twos_complement. + + (* + pub(super) const fn const_eq( + left: &Signed, + right: &Signed, + ) -> bool { + if BITS == 0 { + return true; + } + + let mut i = 0; + let llimbs = left.0.as_limbs(); + let rlimbs = right.0.as_limbs(); + while i < LIMBS { + if llimbs[i] != rlimbs[i] { + return false; + } + i += 1; + } + true + } + *) + Definition const_eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ BITS; LIMBS ], [], [ _ as left; _ as right ] => + ltac:(M.monadic + (let left := M.alloc (| left |) in + let right := M.alloc (| right |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.eq (| + M.read (| + M.get_constant "alloy_primitives::signed::utils::const_eq::BITS" + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| M.read (| M.return_ (| Value.Bool true |) |) |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ i : Ty.path "usize" := M.alloc (| Value.Integer IntegerKind.Usize 0 |) in + let~ llimbs : + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ LIMBS ] [ Ty.path "u64" ] ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ LIMBS ] [ Ty.path "u64" ] ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "as_limbs", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| left |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |) + |) in + let~ rlimbs : + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ LIMBS ] [ Ty.path "u64" ] ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "array") [ LIMBS ] [ Ty.path "u64" ] ], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "as_limbs", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| right |) |), + "alloy_primitives::signed::int::Signed", + 0 + |) + |) + ] + |) + |) in + let~ _ : Ty.tuple [] := + M.loop (| + Ty.tuple [], + ltac:(M.monadic + (M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.lt (| + M.read (| i |), + M.read (| + M.get_constant + "alloy_primitives::signed::utils::const_eq::LIMBS" + |) + |) + |)) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.ne (| + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| llimbs |) |), + M.read (| i |) + |) + |), + M.read (| + M.SubPointer.get_array_field (| + M.deref (| M.read (| rlimbs |) |), + M.read (| i |) + |) + |) + |) + |)) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + M.never_to_any (| + M.read (| M.return_ (| Value.Bool false |) |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + let β := i in + M.write (| + β, + BinOp.Wrap.add (| + M.read (| β |), + Value.Integer IntegerKind.Usize 1 + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.never_to_any (| M.read (| M.break (||) |) |) + |) in + M.alloc (| Value.Tuple [] |) + |) + |) + |))) + ] + |))) + |) in + M.alloc (| Value.Bool true |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_const_eq : + M.IsFunction.Trait "alloy_primitives::signed::utils::const_eq" const_eq. + Admitted. + Global Typeclasses Opaque const_eq. + + (* + pub(super) const fn max() -> Signed { + if LIMBS == 0 { + return zero(); + } + + let mut limbs = [u64::MAX; LIMBS]; + limbs[LIMBS - 1] &= Signed::::MASK; // unset all high bits + limbs[LIMBS - 1] &= !Signed::::SIGN_BIT; // unset the sign bit + Signed(Uint::from_limbs(limbs)) + } + *) + Definition max (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ BITS; LIMBS ], [], [] => + ltac:(M.monadic + (M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.eq (| + M.read (| + M.get_constant "alloy_primitives::signed::utils::max::LIMBS" + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + M.get_function (| + "alloy_primitives::signed::utils::zero", + [ BITS; LIMBS ], + [] + |), + [] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ limbs : Ty.apply (Ty.path "array") [ LIMBS ] [ Ty.path "u64" ] := + M.alloc (| repeat (| M.read (| M.get_constant "core::num::MAX" |), LIMBS |) |) in + let~ _ : Ty.tuple [] := + M.alloc (| + let β := + M.SubPointer.get_array_field (| + limbs, + BinOp.Wrap.sub (| + M.read (| M.get_constant "alloy_primitives::signed::utils::max::LIMBS" |), + Value.Integer IntegerKind.Usize 1 + |) + |) in + M.write (| + β, + BinOp.bit_and + (M.read (| β |)) + (M.read (| M.get_constant "alloy_primitives::signed::int::MASK" |)) + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + let β := + M.SubPointer.get_array_field (| + limbs, + BinOp.Wrap.sub (| + M.read (| M.get_constant "alloy_primitives::signed::utils::max::LIMBS" |), + Value.Integer IntegerKind.Usize 1 + |) + |) in + M.write (| + β, + BinOp.bit_and + (M.read (| β |)) + (UnOp.not (| + M.read (| M.get_constant "alloy_primitives::signed::int::SIGN_BIT" |) + |)) + |) + |) in + M.alloc (| + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "from_limbs", + [], + [] + |), + [ M.read (| limbs |) ] + |) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_max : + M.IsFunction.Trait "alloy_primitives::signed::utils::max" max. + Admitted. + Global Typeclasses Opaque max. + + (* + pub(super) const fn min() -> Signed { + if LIMBS == 0 { + return zero(); + } + + let mut limbs = [0; LIMBS]; + limbs[LIMBS - 1] = Signed::::SIGN_BIT; + Signed(Uint::from_limbs(limbs)) + } + *) + Definition min (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ BITS; LIMBS ], [], [] => + ltac:(M.monadic + (M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.eq (| + M.read (| + M.get_constant "alloy_primitives::signed::utils::min::LIMBS" + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + M.get_function (| + "alloy_primitives::signed::utils::zero", + [ BITS; LIMBS ], + [] + |), + [] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ limbs : Ty.apply (Ty.path "array") [ LIMBS ] [ Ty.path "u64" ] := + M.alloc (| repeat (| Value.Integer IntegerKind.U64 0, LIMBS |) |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| + limbs, + BinOp.Wrap.sub (| + M.read (| M.get_constant "alloy_primitives::signed::utils::min::LIMBS" |), + Value.Integer IntegerKind.Usize 1 + |) + |), + M.read (| M.get_constant "alloy_primitives::signed::int::SIGN_BIT" |) + |) + |) in + M.alloc (| + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "from_limbs", + [], + [] + |), + [ M.read (| limbs |) ] + |) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_min : + M.IsFunction.Trait "alloy_primitives::signed::utils::min" min. + Admitted. + Global Typeclasses Opaque min. + + (* + pub(super) const fn zero() -> Signed { + let limbs = [0; LIMBS]; + Signed(Uint::from_limbs(limbs)) + } + *) + Definition zero (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ BITS; LIMBS ], [], [] => + ltac:(M.monadic + (M.read (| + let~ limbs : Ty.apply (Ty.path "array") [ LIMBS ] [ Ty.path "u64" ] := + M.alloc (| repeat (| Value.Integer IntegerKind.U64 0, LIMBS |) |) in + M.alloc (| + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "from_limbs", + [], + [] + |), + [ M.read (| limbs |) ] + |) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_zero : + M.IsFunction.Trait "alloy_primitives::signed::utils::zero" zero. + Admitted. + Global Typeclasses Opaque zero. + + (* + pub(super) const fn one() -> Signed { + if LIMBS == 0 { + return zero(); + } + + let mut limbs = [0; LIMBS]; + limbs[0] = 1; + Signed(Uint::from_limbs(limbs)) + } + *) + Definition one (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [ BITS; LIMBS ], [], [] => + ltac:(M.monadic + (M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.eq (| + M.read (| + M.get_constant "alloy_primitives::signed::utils::one::LIMBS" + |), + Value.Integer IntegerKind.Usize 0 + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ BITS; LIMBS ] + [], + M.get_function (| + "alloy_primitives::signed::utils::zero", + [ BITS; LIMBS ], + [] + |), + [] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ limbs : Ty.apply (Ty.path "array") [ LIMBS ] [ Ty.path "u64" ] := + M.alloc (| repeat (| Value.Integer IntegerKind.U64 0, LIMBS |) |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + M.SubPointer.get_array_field (| limbs, Value.Integer IntegerKind.Usize 0 |), + Value.Integer IntegerKind.U64 1 + |) + |) in + M.alloc (| + Value.StructTuple + "alloy_primitives::signed::int::Signed" + [ + M.call_closure (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + M.get_associated_function (| + Ty.apply (Ty.path "ruint::Uint") [ BITS; LIMBS ] [], + "from_limbs", + [], + [] + |), + [ M.read (| limbs |) ] + |) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_one : + M.IsFunction.Trait "alloy_primitives::signed::utils::one" one. + Admitted. + Global Typeclasses Opaque one. + + (* + pub(super) const fn sign_bit(bits: usize) -> u64 { + if bits == 0 { + return 0; + } + let bits = bits % 64; + if bits == 0 { + 1 << 63 + } else { + 1 << (bits - 1) + } + } + *) + Definition sign_bit (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ bits ] => + ltac:(M.monadic + (let bits := M.alloc (| bits |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.eq (| M.read (| bits |), Value.Integer IntegerKind.Usize 0 |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.read (| M.return_ (| Value.Integer IntegerKind.U64 0 |) |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ bits : Ty.path "usize" := + M.alloc (| + BinOp.Wrap.rem (| M.read (| bits |), Value.Integer IntegerKind.Usize 64 |) + |) in + M.match_operator (| + Some (Ty.path "u64"), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.eq (| M.read (| bits |), Value.Integer IntegerKind.Usize 0 |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + BinOp.Wrap.shl (| + Value.Integer IntegerKind.U64 1, + Value.Integer IntegerKind.I32 63 + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + BinOp.Wrap.shl (| + Value.Integer IntegerKind.U64 1, + BinOp.Wrap.sub (| + M.read (| bits |), + Value.Integer IntegerKind.Usize 1 + |) + |) + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_sign_bit : + M.IsFunction.Trait "alloy_primitives::signed::utils::sign_bit" sign_bit. + Admitted. + Global Typeclasses Opaque sign_bit. + End utils. +End signed. diff --git a/CoqOfRust/alloy_primitives/utils/mod.rs b/CoqOfRust/alloy_primitives/utils/mod.rs new file mode 100644 index 000000000..fc10fe380 --- /dev/null +++ b/CoqOfRust/alloy_primitives/utils/mod.rs @@ -0,0 +1,360 @@ +//! Common Ethereum utilities. + +use crate::B256; +use alloc::{boxed::Box, collections::TryReserveError, vec::Vec}; +use cfg_if::cfg_if; +use core::{ + fmt, + mem::{ManuallyDrop, MaybeUninit}, +}; + +mod units; +pub use units::{ + format_ether, format_units, parse_ether, parse_units, ParseUnits, Unit, UnitsError, +}; + +#[doc(hidden)] +#[deprecated(since = "0.5.0", note = "use `Unit::ETHER.wei()` instead")] +pub const WEI_IN_ETHER: crate::U256 = Unit::ETHER.wei_const(); + +#[doc(hidden)] +#[deprecated(since = "0.5.0", note = "use `Unit` instead")] +pub type Units = Unit; + +/// The prefix used for hashing messages according to EIP-191. +pub const EIP191_PREFIX: &str = "\x19Ethereum Signed Message:\n"; + +/// Tries to create a [`Vec`] containing the arguments. +#[macro_export] +macro_rules! try_vec { + () => { + $crate::private::Vec::new() + }; + ($elem:expr; $n:expr) => { + $crate::utils::vec_try_from_elem($elem, $n) + }; + ($($x:expr),+ $(,)?) => { + match $crate::utils::box_try_new([$($x),+]) { + ::core::result::Result::Ok(x) => ::core::result::Result::Ok(<[_]>::into_vec(x)), + ::core::result::Result::Err(e) => ::core::result::Result::Err(e), + } + }; +} + +/// Allocates memory on the heap then places `x` into it, returning an error if the allocation +/// fails. +/// +/// Stable version of `Box::try_new`. +#[inline] +pub fn box_try_new(value: T) -> Result, TryReserveError> { + let mut boxed = box_try_new_uninit::()?; + unsafe { + boxed.as_mut_ptr().write(value); + let ptr = Box::into_raw(boxed); + Ok(Box::from_raw(ptr.cast())) + } +} + +/// Constructs a new box with uninitialized contents on the heap, returning an error if the +/// allocation fails. +/// +/// Stable version of `Box::try_new_uninit`. +#[inline] +pub fn box_try_new_uninit() -> Result>, TryReserveError> { + let mut vec = Vec::>::new(); + + // Reserve enough space for one `MaybeUninit`. + vec.try_reserve_exact(1)?; + + // `try_reserve_exact`'s docs note that the allocator might allocate more than requested anyway. + // Make sure we got exactly 1 element. + vec.shrink_to(1); + + let mut vec = ManuallyDrop::new(vec); + + // SAFETY: `vec` is exactly one element long and has not been deallocated. + Ok(unsafe { Box::from_raw(vec.as_mut_ptr()) }) +} + +/// Tries to collect the elements of an iterator into a `Vec`. +pub fn try_collect_vec, T>(iter: I) -> Result, TryReserveError> { + let mut vec = Vec::new(); + if let Some(size_hint) = iter.size_hint().1 { + vec.try_reserve(size_hint.max(4))?; + } + vec.extend(iter); + Ok(vec) +} + +/// Tries to create a `Vec` with the given capacity. +#[inline] +pub fn vec_try_with_capacity(capacity: usize) -> Result, TryReserveError> { + let mut vec = Vec::new(); + vec.try_reserve(capacity).map(|()| vec) +} + +/// Tries to create a `Vec` of `n` elements, each initialized to `elem`. +// Not public API. Use `try_vec!` instead. +#[doc(hidden)] +pub fn vec_try_from_elem(elem: T, n: usize) -> Result, TryReserveError> { + let mut vec = Vec::new(); + vec.try_reserve(n)?; + vec.resize(n, elem); + Ok(vec) +} + +/// Hash a message according to [EIP-191] (version `0x01`). +/// +/// The final message is a UTF-8 string, encoded as follows: +/// `"\x19Ethereum Signed Message:\n" + message.length + message` +/// +/// This message is then hashed using [Keccak-256](keccak256). +/// +/// [EIP-191]: https://eips.ethereum.org/EIPS/eip-191 +pub fn eip191_hash_message>(message: T) -> B256 { + keccak256(eip191_message(message)) +} + +/// Constructs a message according to [EIP-191] (version `0x01`). +/// +/// The final message is a UTF-8 string, encoded as follows: +/// `"\x19Ethereum Signed Message:\n" + message.length + message` +/// +/// [EIP-191]: https://eips.ethereum.org/EIPS/eip-191 +pub fn eip191_message>(message: T) -> Vec { + fn eip191_message(message: &[u8]) -> Vec { + let len = message.len(); + let mut len_string_buffer = itoa::Buffer::new(); + let len_string = len_string_buffer.format(len); + + let mut eth_message = Vec::with_capacity(EIP191_PREFIX.len() + len_string.len() + len); + eth_message.extend_from_slice(EIP191_PREFIX.as_bytes()); + eth_message.extend_from_slice(len_string.as_bytes()); + eth_message.extend_from_slice(message); + eth_message + } + + eip191_message(message.as_ref()) +} + +/// Simple interface to the [`Keccak-256`] hash function. +/// +/// [`Keccak-256`]: https://en.wikipedia.org/wiki/SHA-3 +pub fn keccak256>(bytes: T) -> B256 { + fn keccak256(bytes: &[u8]) -> B256 { + let mut output = MaybeUninit::::uninit(); + + cfg_if! { + if #[cfg(all(feature = "native-keccak", not(any(feature = "sha3-keccak", feature = "tiny-keccak", miri))))] { + #[link(wasm_import_module = "vm_hooks")] + extern "C" { + /// When targeting VMs with native keccak hooks, the `native-keccak` feature + /// can be enabled to import and use the host environment's implementation + /// of [`keccak256`] in place of [`sha3`] or [`tiny_keccak`]. This is overridden + /// when the `sha3-keccak` or `tiny-keccak` feature is enabled. + /// + /// # Safety + /// + /// The VM accepts the preimage by pointer and length, and writes the + /// 32-byte hash. + /// - `bytes` must point to an input buffer at least `len` long. + /// - `output` must point to a buffer that is at least 32-bytes long. + /// + /// [`keccak256`]: https://en.wikipedia.org/wiki/SHA-3 + /// [`sha3`]: https://docs.rs/sha3/latest/sha3/ + /// [`tiny_keccak`]: https://docs.rs/tiny-keccak/latest/tiny_keccak/ + fn native_keccak256(bytes: *const u8, len: usize, output: *mut u8); + } + + // SAFETY: The output is 32-bytes, and the input comes from a slice. + unsafe { native_keccak256(bytes.as_ptr(), bytes.len(), output.as_mut_ptr().cast::()) }; + } else { + let mut hasher = Keccak256::new(); + hasher.update(bytes); + // SAFETY: Never reads from `output`. + unsafe { hasher.finalize_into_raw(output.as_mut_ptr().cast()) }; + } + } + + // SAFETY: Initialized above. + unsafe { output.assume_init() } + } + + keccak256(bytes.as_ref()) +} + +mod keccak256_state { + cfg_if::cfg_if! { + if #[cfg(all(feature = "asm-keccak", not(miri)))] { + pub(super) use keccak_asm::Digest; + + pub(super) type State = keccak_asm::Keccak256; + } else if #[cfg(feature = "sha3-keccak")] { + pub(super) use sha3::Digest; + + pub(super) type State = sha3::Keccak256; + } else { + pub(super) use tiny_keccak::Hasher as Digest; + + /// Wraps `tiny_keccak::Keccak` to implement `Digest`-like API. + #[derive(Clone)] + pub(super) struct State(tiny_keccak::Keccak); + + impl State { + #[inline] + pub(super) fn new() -> Self { + Self(tiny_keccak::Keccak::v256()) + } + + #[inline] + pub(super) fn finalize_into(self, output: &mut [u8; 32]) { + self.0.finalize(output); + } + + #[inline] + pub(super) fn update(&mut self, bytes: &[u8]) { + self.0.update(bytes); + } + } + } + } +} +#[allow(unused_imports)] +use keccak256_state::Digest; + +/// Simple [`Keccak-256`] hasher. +/// +/// Note that the "native-keccak" feature is not supported for this struct, and will default to the +/// [`tiny_keccak`] implementation. +/// +/// [`Keccak-256`]: https://en.wikipedia.org/wiki/SHA-3 +#[derive(Clone)] +pub struct Keccak256 { + state: keccak256_state::State, +} + +impl Default for Keccak256 { + #[inline] + fn default() -> Self { + Self::new() + } +} + +impl fmt::Debug for Keccak256 { + #[inline] + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Keccak256").finish_non_exhaustive() + } +} + +impl Keccak256 { + /// Creates a new [`Keccak256`] hasher. + #[inline] + pub fn new() -> Self { + Self { state: keccak256_state::State::new() } + } + + /// Absorbs additional input. Can be called multiple times. + #[inline] + pub fn update(&mut self, bytes: impl AsRef<[u8]>) { + self.state.update(bytes.as_ref()); + } + + /// Pad and squeeze the state. + #[inline] + pub fn finalize(self) -> B256 { + let mut output = MaybeUninit::::uninit(); + // SAFETY: The output is 32-bytes. + unsafe { self.finalize_into_raw(output.as_mut_ptr().cast()) }; + // SAFETY: Initialized above. + unsafe { output.assume_init() } + } + + /// Pad and squeeze the state into `output`. + /// + /// # Panics + /// + /// Panics if `output` is not 32 bytes long. + #[inline] + #[track_caller] + pub fn finalize_into(self, output: &mut [u8]) { + self.finalize_into_array(output.try_into().unwrap()) + } + + /// Pad and squeeze the state into `output`. + #[inline] + #[allow(clippy::useless_conversion)] + pub fn finalize_into_array(self, output: &mut [u8; 32]) { + self.state.finalize_into(output.into()); + } + + /// Pad and squeeze the state into `output`. + /// + /// # Safety + /// + /// `output` must point to a buffer that is at least 32-bytes long. + #[inline] + pub unsafe fn finalize_into_raw(self, output: *mut u8) { + self.finalize_into_array(&mut *output.cast::<[u8; 32]>()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use alloc::string::ToString; + + // test vector taken from: + // https://web3js.readthedocs.io/en/v1.10.0/web3-eth-accounts.html#hashmessage + #[test] + fn test_hash_message() { + let msg = "Hello World"; + let eip191_msg = eip191_message(msg); + let hash = keccak256(&eip191_msg); + assert_eq!( + eip191_msg, + [EIP191_PREFIX.as_bytes(), msg.len().to_string().as_bytes(), msg.as_bytes()].concat() + ); + assert_eq!(hash, b256!("a1de988600a42c4b4ab089b619297c17d53cffae5d5120d82d8a92d0bb3b78f2")); + assert_eq!(eip191_hash_message(msg), hash); + } + + #[test] + fn keccak256_hasher() { + let expected = b256!("47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"); + assert_eq!(keccak256("hello world"), expected); + + let mut hasher = Keccak256::new(); + hasher.update(b"hello"); + hasher.update(b" world"); + + assert_eq!(hasher.clone().finalize(), expected); + + let mut hash = [0u8; 32]; + hasher.clone().finalize_into(&mut hash); + assert_eq!(hash, expected); + + let mut hash = [0u8; 32]; + hasher.clone().finalize_into_array(&mut hash); + assert_eq!(hash, expected); + + let mut hash = [0u8; 32]; + unsafe { hasher.finalize_into_raw(hash.as_mut_ptr()) }; + assert_eq!(hash, expected); + } + + #[test] + fn test_try_boxing() { + let x = Box::new(42); + let y = box_try_new(42).unwrap(); + assert_eq!(x, y); + + let x = vec![1; 3]; + let y = try_vec![1; 3].unwrap(); + assert_eq!(x, y); + + let x = vec![1, 2, 3]; + let y = try_vec![1, 2, 3].unwrap(); + assert_eq!(x, y); + } +} diff --git a/CoqOfRust/alloy_primitives/utils/mod.v b/CoqOfRust/alloy_primitives/utils/mod.v new file mode 100644 index 000000000..be999ea4d --- /dev/null +++ b/CoqOfRust/alloy_primitives/utils/mod.v @@ -0,0 +1,2605 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module utils. + Definition value_WEI_IN_ETHER : Value.t := + M.run_constant + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::Unit", + "wei_const", + [], + [] + |), + [ M.read (| M.get_constant "alloy_primitives::utils::units::ETHER" |) ] + |) + |))). + + Axiom Constant_value_WEI_IN_ETHER : + (M.get_constant "alloy_primitives::utils::WEI_IN_ETHER") = value_WEI_IN_ETHER. + Global Hint Rewrite Constant_value_WEI_IN_ETHER : constant_rewrites. + + Axiom Units : + (Ty.path "alloy_primitives::utils::Units") = (Ty.path "alloy_primitives::utils::units::Unit"). + + Definition value_EIP191_PREFIX : Value.t := + M.run_constant ltac:(M.monadic (M.alloc (| mk_str (| "Ethereum Signed Message: +" |) |))). + + Axiom Constant_value_EIP191_PREFIX : + (M.get_constant "alloy_primitives::utils::EIP191_PREFIX") = value_EIP191_PREFIX. + Global Hint Rewrite Constant_value_EIP191_PREFIX : constant_rewrites. + + (* + pub fn box_try_new(value: T) -> Result, TryReserveError> { + let mut boxed = box_try_new_uninit::()?; + unsafe { + boxed.as_mut_ptr().write(value); + let ptr = Box::into_raw(boxed); + Ok(Box::from_raw(ptr.cast())) + } + } + *) + Definition box_try_new (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ boxed : + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ T ]; + Ty.path "alloc::alloc::Global" + ] := + M.copy (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ T ]; + Ty.path "alloc::alloc::Global" + ]), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "alloc::collections::TryReserveError" + ]; + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ T ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ T ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::collections::TryReserveError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ T ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::collections::TryReserveError" + ], + M.get_function (| + "alloy_primitives::utils::box_try_new_uninit", + [], + [ T ] + |), + [] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ T; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::collections::TryReserveError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ T; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::collections::TryReserveError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "alloc::collections::TryReserveError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "*mut") [] [ T ], + "write", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "*mut") [] [ T ], + M.get_associated_function (| + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ T ], + "as_mut_ptr", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| boxed |) |) |) ] + |); + M.read (| value |) + ] + |) + |) in + let~ ptr : + Ty.apply + (Ty.path "*mut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ T ] ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "*mut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ T ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ T ]; + Ty.path "alloc::alloc::Global" + ], + "into_raw", + [], + [] + |), + [ M.read (| boxed |) ] + |) + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ T; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ T; Ty.path "alloc::alloc::Global" ], + "from_raw", + [], + [] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "*mut") [] [ T ], + M.get_associated_function (| + Ty.apply + (Ty.path "*mut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ T ] + ], + "cast", + [], + [ T ] + |), + [ M.read (| ptr |) ] + |) + ] + |) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_box_try_new : + M.IsFunction.Trait "alloy_primitives::utils::box_try_new" box_try_new. + Admitted. + Global Typeclasses Opaque box_try_new. + + (* + pub fn box_try_new_uninit() -> Result>, TryReserveError> { + let mut vec = Vec::>::new(); + + // Reserve enough space for one `MaybeUninit`. + vec.try_reserve_exact(1)?; + + // `try_reserve_exact`'s docs note that the allocator might allocate more than requested anyway. + // Make sure we got exactly 1 element. + vec.shrink_to(1); + + let mut vec = ManuallyDrop::new(vec); + + // SAFETY: `vec` is exactly one element long and has not been deallocated. + Ok(unsafe { Box::from_raw(vec.as_mut_ptr()) }) + } + *) + Definition box_try_new_uninit (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [] => + ltac:(M.monadic + (M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ vec : + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ T ]; + Ty.path "alloc::alloc::Global" + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ T ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ T ]; + Ty.path "alloc::alloc::Global" + ], + "new", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "alloc::collections::TryReserveError" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "alloc::collections::TryReserveError" ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "alloc::collections::TryReserveError" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ T ]; + Ty.path "alloc::alloc::Global" + ], + "try_reserve_exact", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, vec |); + Value.Integer IntegerKind.Usize 1 + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ T ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::collections::TryReserveError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ T ]; + Ty.path "alloc::alloc::Global" + ]; + Ty.path "alloc::collections::TryReserveError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "alloc::collections::TryReserveError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ T ]; + Ty.path "alloc::alloc::Global" + ], + "shrink_to", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, vec |); Value.Integer IntegerKind.Usize 1 ] + |) + |) in + let~ vec : + Ty.apply + (Ty.path "core::mem::manually_drop::ManuallyDrop") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ T ]; + Ty.path "alloc::alloc::Global" + ] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::mem::manually_drop::ManuallyDrop") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ T ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::mem::manually_drop::ManuallyDrop") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ T ]; + Ty.path "alloc::alloc::Global" + ] + ], + "new", + [], + [] + |), + [ M.read (| vec |) ] + |) + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ T ]; + Ty.path "alloc::alloc::Global" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::boxed::Box") + [] + [ + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ T ]; + Ty.path "alloc::alloc::Global" + ], + "from_raw", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "*mut") + [] + [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ T ] ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ T ]; + Ty.path "alloc::alloc::Global" + ], + "as_mut_ptr", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ T ]; + Ty.path "alloc::alloc::Global" + ] + ], + M.get_trait_method (| + "core::ops::deref::DerefMut", + Ty.apply + (Ty.path "core::mem::manually_drop::ManuallyDrop") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ T ]; + Ty.path "alloc::alloc::Global" + ] + ], + [], + [], + "deref_mut", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, vec |) ] + |) + |) + |) + ] + |) + ] + |) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_box_try_new_uninit : + M.IsFunction.Trait "alloy_primitives::utils::box_try_new_uninit" box_try_new_uninit. + Admitted. + Global Typeclasses Opaque box_try_new_uninit. + + (* + pub fn try_collect_vec, T>(iter: I) -> Result, TryReserveError> { + let mut vec = Vec::new(); + if let Some(size_hint) = iter.size_hint().1 { + vec.try_reserve(size_hint.max(4))?; + } + vec.extend(iter); + Ok(vec) + } + *) + Definition try_collect_vec (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ _ as I; T ], [ iter ] => + ltac:(M.monadic + (let iter := M.alloc (| iter |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ vec : + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + "new", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.SubPointer.get_tuple_field (| + M.alloc (| + M.call_closure (| + Ty.tuple + [ + Ty.path "usize"; + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "usize" ] + ], + M.get_trait_method (| + "core::iter::traits::iterator::Iterator", + I, + [], + [], + "size_hint", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, iter |) ] + |) + |), + 1 + |) in + let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let size_hint := M.copy (| γ0_0 |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "alloc::collections::TryReserveError" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "alloc::collections::TryReserveError" ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "alloc::collections::TryReserveError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ T; Ty.path "alloc::alloc::Global" ], + "try_reserve", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, vec |); + M.call_closure (| + Ty.path "usize", + M.get_trait_method (| + "core::cmp::Ord", + Ty.path "usize", + [], + [], + "max", + [], + [] + |), + [ M.read (| size_hint |); Value.Integer IntegerKind.Usize 4 + ] + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ T; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::collections::TryReserveError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ T; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::collections::TryReserveError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "alloc::collections::TryReserveError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::iter::traits::collect::Extend", + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + [], + [ T ], + "extend", + [], + [ I ] + |), + [ M.borrow (| Pointer.Kind.MutRef, vec |); M.read (| iter |) ] + |) + |) in + M.alloc (| Value.StructTuple "core::result::Result::Ok" [ M.read (| vec |) ] |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_try_collect_vec : + M.IsFunction.Trait "alloy_primitives::utils::try_collect_vec" try_collect_vec. + Admitted. + Global Typeclasses Opaque try_collect_vec. + + (* + pub fn vec_try_with_capacity(capacity: usize) -> Result, TryReserveError> { + let mut vec = Vec::new(); + vec.try_reserve(capacity).map(|()| vec) + } + *) + Definition vec_try_with_capacity (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ capacity ] => + ltac:(M.monadic + (let capacity := M.alloc (| capacity |) in + M.read (| + let~ vec : + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + "new", + [], + [] + |), + [] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::collections::TryReserveError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "alloc::collections::TryReserveError" ], + "map", + [], + [ + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ]; + Ty.function + [ Ty.tuple [ Ty.tuple [] ] ] + (Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ]) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "alloc::collections::TryReserveError" ], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + "try_reserve", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, vec |); M.read (| capacity |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ Ty.tuple [ Ty.tuple [] ] ] + (Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ T; Ty.path "alloc::alloc::Global" ])), + M.alloc (| α0 |), + [ fun γ => ltac:(M.monadic (M.read (| vec |))) ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_vec_try_with_capacity : + M.IsFunction.Trait "alloy_primitives::utils::vec_try_with_capacity" vec_try_with_capacity. + Admitted. + Global Typeclasses Opaque vec_try_with_capacity. + + (* + pub fn vec_try_from_elem(elem: T, n: usize) -> Result, TryReserveError> { + let mut vec = Vec::new(); + vec.try_reserve(n)?; + vec.resize(n, elem); + Ok(vec) + } + *) + Definition vec_try_from_elem (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ elem; n ] => + ltac:(M.monadic + (let elem := M.alloc (| elem |) in + let n := M.alloc (| n |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ vec : + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + "new", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "alloc::collections::TryReserveError" + ]; + Ty.tuple [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "alloc::collections::TryReserveError" ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "alloc::collections::TryReserveError" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ T; Ty.path "alloc::alloc::Global" ], + "try_reserve", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, vec |); M.read (| n |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ T; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::collections::TryReserveError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ T; Ty.path "alloc::alloc::Global" ]; + Ty.path "alloc::collections::TryReserveError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "alloc::collections::TryReserveError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ], + "resize", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, vec |); M.read (| n |); M.read (| elem |) ] + |) + |) in + M.alloc (| Value.StructTuple "core::result::Result::Ok" [ M.read (| vec |) ] |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_vec_try_from_elem : + M.IsFunction.Trait "alloy_primitives::utils::vec_try_from_elem" vec_try_from_elem. + Admitted. + Global Typeclasses Opaque vec_try_from_elem. + + (* + pub fn eip191_hash_message>(message: T) -> B256 { + keccak256(eip191_message(message)) + } + *) + Definition eip191_hash_message (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ message ] => + ltac:(M.monadic + (let message := M.alloc (| message |) in + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + M.get_function (| + "alloy_primitives::utils::keccak256", + [], + [ + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ] + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + M.get_function (| "alloy_primitives::utils::eip191_message", [], [ T ] |), + [ M.read (| message |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_eip191_hash_message : + M.IsFunction.Trait "alloy_primitives::utils::eip191_hash_message" eip191_hash_message. + Admitted. + Global Typeclasses Opaque eip191_hash_message. + + (* + pub fn eip191_message>(message: T) -> Vec { + fn eip191_message(message: &[u8]) -> Vec { + let len = message.len(); + let mut len_string_buffer = itoa::Buffer::new(); + let len_string = len_string_buffer.format(len); + + let mut eth_message = Vec::with_capacity(EIP191_PREFIX.len() + len_string.len() + len); + eth_message.extend_from_slice(EIP191_PREFIX.as_bytes()); + eth_message.extend_from_slice(len_string.as_bytes()); + eth_message.extend_from_slice(message); + eth_message + } + + eip191_message(message.as_ref()) + } + *) + Definition eip191_message (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ message ] => + ltac:(M.monadic + (let message := M.alloc (| message |) in + M.call_closure (| + Ty.apply (Ty.path "alloc::vec::Vec") [] [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + M.get_function (| "alloy_primitives::utils::eip191_message.eip191_message", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::convert::AsRef", + T, + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "as_ref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, message |) ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_eip191_message : + M.IsFunction.Trait "alloy_primitives::utils::eip191_message" eip191_message. + Admitted. + Global Typeclasses Opaque eip191_message. + + Module eip191_message. + (* + fn eip191_message(message: &[u8]) -> Vec { + let len = message.len(); + let mut len_string_buffer = itoa::Buffer::new(); + let len_string = len_string_buffer.format(len); + + let mut eth_message = Vec::with_capacity(EIP191_PREFIX.len() + len_string.len() + len); + eth_message.extend_from_slice(EIP191_PREFIX.as_bytes()); + eth_message.extend_from_slice(len_string.as_bytes()); + eth_message.extend_from_slice(message); + eth_message + } + *) + Definition eip191_message (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ message ] => + ltac:(M.monadic + (let message := M.alloc (| message |) in + M.read (| + let~ len : Ty.path "usize" := + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ], + "len", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| message |) |) |) ] + |) + |) in + let~ len_string_buffer : Ty.path "itoa::Buffer" := + M.alloc (| + M.call_closure (| + Ty.path "itoa::Buffer", + M.get_associated_function (| Ty.path "itoa::Buffer", "new", [], [] |), + [] + |) + |) in + let~ len_string : Ty.apply (Ty.path "&") [] [ Ty.path "str" ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_associated_function (| + Ty.path "itoa::Buffer", + "format", + [], + [ Ty.path "usize" ] + |), + [ M.borrow (| Pointer.Kind.MutRef, len_string_buffer |); M.read (| len |) ] + |) + |) in + let~ eth_message : + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + "with_capacity", + [], + [] + |), + [ + BinOp.Wrap.add (| + BinOp.Wrap.add (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| Ty.path "str", "len", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| M.get_constant "alloy_primitives::utils::EIP191_PREFIX" |) + |) + |) + ] + |), + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| Ty.path "str", "len", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| len_string |) |) |) ] + |) + |), + M.read (| len |) + |) + ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + "extend_from_slice", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, eth_message |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_associated_function (| Ty.path "str", "as_bytes", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| M.get_constant "alloy_primitives::utils::EIP191_PREFIX" |) + |) + |) + ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + "extend_from_slice", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, eth_message |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_associated_function (| Ty.path "str", "as_bytes", [], [] |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| len_string |) |) |) ] + |) + |) + |) + ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloc::vec::Vec") + [] + [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ], + "extend_from_slice", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, eth_message |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| message |) |) |) + ] + |) + |) in + eth_message + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_eip191_message : + M.IsFunction.Trait "alloy_primitives::utils::eip191_message::eip191_message" eip191_message. + Admitted. + Global Typeclasses Opaque eip191_message. + End eip191_message. + + (* + pub fn keccak256>(bytes: T) -> B256 { + fn keccak256(bytes: &[u8]) -> B256 { + let mut output = MaybeUninit::::uninit(); + + cfg_if! { + if #[cfg(all(feature = "native-keccak", not(any(feature = "sha3-keccak", feature = "tiny-keccak", miri))))] { + #[link(wasm_import_module = "vm_hooks")] + extern "C" { + /// When targeting VMs with native keccak hooks, the `native-keccak` feature + /// can be enabled to import and use the host environment's implementation + /// of [`keccak256`] in place of [`sha3`] or [`tiny_keccak`]. This is overridden + /// when the `sha3-keccak` or `tiny-keccak` feature is enabled. + /// + /// # Safety + /// + /// The VM accepts the preimage by pointer and length, and writes the + /// 32-byte hash. + /// - `bytes` must point to an input buffer at least `len` long. + /// - `output` must point to a buffer that is at least 32-bytes long. + /// + /// [`keccak256`]: https://en.wikipedia.org/wiki/SHA-3 + /// [`sha3`]: https://docs.rs/sha3/latest/sha3/ + /// [`tiny_keccak`]: https://docs.rs/tiny-keccak/latest/tiny_keccak/ + fn native_keccak256(bytes: *const u8, len: usize, output: *mut u8); + } + + // SAFETY: The output is 32-bytes, and the input comes from a slice. + unsafe { native_keccak256(bytes.as_ptr(), bytes.len(), output.as_mut_ptr().cast::()) }; + } else { + let mut hasher = Keccak256::new(); + hasher.update(bytes); + // SAFETY: Never reads from `output`. + unsafe { hasher.finalize_into_raw(output.as_mut_ptr().cast()) }; + } + } + + // SAFETY: Initialized above. + unsafe { output.assume_init() } + } + + keccak256(bytes.as_ref()) + } + *) + Definition keccak256 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ bytes ] => + ltac:(M.monadic + (let bytes := M.alloc (| bytes |) in + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + M.get_function (| "alloy_primitives::utils::keccak256.keccak256", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::convert::AsRef", + T, + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "as_ref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, bytes |) ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_keccak256 : + M.IsFunction.Trait "alloy_primitives::utils::keccak256" keccak256. + Admitted. + Global Typeclasses Opaque keccak256. + + Module keccak256. + (* + fn keccak256(bytes: &[u8]) -> B256 { + let mut output = MaybeUninit::::uninit(); + + cfg_if! { + if #[cfg(all(feature = "native-keccak", not(any(feature = "sha3-keccak", feature = "tiny-keccak", miri))))] { + #[link(wasm_import_module = "vm_hooks")] + extern "C" { + /// When targeting VMs with native keccak hooks, the `native-keccak` feature + /// can be enabled to import and use the host environment's implementation + /// of [`keccak256`] in place of [`sha3`] or [`tiny_keccak`]. This is overridden + /// when the `sha3-keccak` or `tiny-keccak` feature is enabled. + /// + /// # Safety + /// + /// The VM accepts the preimage by pointer and length, and writes the + /// 32-byte hash. + /// - `bytes` must point to an input buffer at least `len` long. + /// - `output` must point to a buffer that is at least 32-bytes long. + /// + /// [`keccak256`]: https://en.wikipedia.org/wiki/SHA-3 + /// [`sha3`]: https://docs.rs/sha3/latest/sha3/ + /// [`tiny_keccak`]: https://docs.rs/tiny-keccak/latest/tiny_keccak/ + fn native_keccak256(bytes: *const u8, len: usize, output: *mut u8); + } + + // SAFETY: The output is 32-bytes, and the input comes from a slice. + unsafe { native_keccak256(bytes.as_ptr(), bytes.len(), output.as_mut_ptr().cast::()) }; + } else { + let mut hasher = Keccak256::new(); + hasher.update(bytes); + // SAFETY: Never reads from `output`. + unsafe { hasher.finalize_into_raw(output.as_mut_ptr().cast()) }; + } + } + + // SAFETY: Initialized above. + unsafe { output.assume_init() } + } + *) + Definition keccak256 (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ bytes ] => + ltac:(M.monadic + (let bytes := M.alloc (| bytes |) in + M.read (| + let~ output : + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ], + "uninit", + [], + [] + |), + [] + |) + |) in + let~ hasher : Ty.path "alloy_primitives::utils::Keccak256" := + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::utils::Keccak256", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::Keccak256", + "new", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "alloy_primitives::utils::Keccak256", + "update", + [], + [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ] + |), + [ M.borrow (| Pointer.Kind.MutRef, hasher |); M.read (| bytes |) ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "alloy_primitives::utils::Keccak256", + "finalize_into_raw", + [], + [] + |), + [ + M.read (| hasher |); + M.call_closure (| + Ty.apply (Ty.path "*mut") [] [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "*mut") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ], + "cast", + [], + [ Ty.path "u8" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "*mut") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ], + "as_mut_ptr", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, output |) ] + |) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ], + "assume_init", + [], + [] + |), + [ M.read (| output |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_keccak256 : + M.IsFunction.Trait "alloy_primitives::utils::keccak256::keccak256" keccak256. + Admitted. + Global Typeclasses Opaque keccak256. + End keccak256. + + Module keccak256_state. + (* StructTuple + { + name := "State"; + const_params := []; + ty_params := []; + fields := [ Ty.path "tiny_keccak::keccak::Keccak" ]; + } *) + + Module Impl_core_clone_Clone_for_alloy_primitives_utils_keccak256_state_State. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::keccak256_state::State". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructTuple + "alloy_primitives::utils::keccak256_state::State" + [ + M.call_closure (| + Ty.path "tiny_keccak::keccak::Keccak", + M.get_trait_method (| + "core::clone::Clone", + Ty.path "tiny_keccak::keccak::Keccak", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::utils::keccak256_state::State", + 0 + |) + |) + |) + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_alloy_primitives_utils_keccak256_state_State. + + Module Impl_alloy_primitives_utils_keccak256_state_State. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::keccak256_state::State". + + (* + pub(super) fn new() -> Self { + Self(tiny_keccak::Keccak::v256()) + } + *) + Definition new (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::utils::keccak256_state::State" + [ + M.call_closure (| + Ty.path "tiny_keccak::keccak::Keccak", + M.get_associated_function (| + Ty.path "tiny_keccak::keccak::Keccak", + "v256", + [], + [] + |), + [] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : M.IsAssociatedFunction.Trait Self "new" new. + Admitted. + Global Typeclasses Opaque new. + + (* + pub(super) fn finalize_into(self, output: &mut [u8; 32]) { + self.0.finalize(output); + } + *) + Definition finalize_into (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; output ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let output := M.alloc (| output |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "tiny_keccak::Hasher", + Ty.path "tiny_keccak::keccak::Keccak", + [], + [], + "finalize", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::utils::keccak256_state::State", + 0 + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| output |) |) |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_finalize_into : + M.IsAssociatedFunction.Trait Self "finalize_into" finalize_into. + Admitted. + Global Typeclasses Opaque finalize_into. + + (* + pub(super) fn update(&mut self, bytes: &[u8]) { + self.0.update(bytes); + } + *) + Definition update (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; bytes ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let bytes := M.alloc (| bytes |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "tiny_keccak::Hasher", + Ty.path "tiny_keccak::keccak::Keccak", + [], + [], + "update", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::utils::keccak256_state::State", + 0 + |) + |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| bytes |) |) |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_update : M.IsAssociatedFunction.Trait Self "update" update. + Admitted. + Global Typeclasses Opaque update. + End Impl_alloy_primitives_utils_keccak256_state_State. + End keccak256_state. + + (* StructRecord + { + name := "Keccak256"; + const_params := []; + ty_params := []; + fields := [ ("state", Ty.path "alloy_primitives::utils::keccak256_state::State") ]; + } *) + + Module Impl_core_clone_Clone_for_alloy_primitives_utils_Keccak256. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::Keccak256". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + Value.StructRecord + "alloy_primitives::utils::Keccak256" + [ + ("state", + M.call_closure (| + Ty.path "alloy_primitives::utils::keccak256_state::State", + M.get_trait_method (| + "core::clone::Clone", + Ty.path "alloy_primitives::utils::keccak256_state::State", + [], + [], + "clone", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::utils::Keccak256", + "state" + |) + |) + |) + |) + ] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_alloy_primitives_utils_Keccak256. + + Module Impl_core_default_Default_for_alloy_primitives_utils_Keccak256. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::Keccak256". + + (* + fn default() -> Self { + Self::new() + } + *) + Definition default (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (M.call_closure (| + Ty.path "alloy_primitives::utils::Keccak256", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::Keccak256", + "new", + [], + [] + |), + [] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::default::Default" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("default", InstanceField.Method default) ]. + End Impl_core_default_Default_for_alloy_primitives_utils_Keccak256. + + Module Impl_core_fmt_Debug_for_alloy_primitives_utils_Keccak256. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::Keccak256". + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("Keccak256").finish_non_exhaustive() + } + *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::builders::DebugStruct", + "finish_non_exhaustive", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.alloc (| + M.call_closure (| + Ty.path "core::fmt::builders::DebugStruct", + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_struct", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Keccak256" |) |) |) + ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_alloy_primitives_utils_Keccak256. + + Module Impl_alloy_primitives_utils_Keccak256. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::Keccak256". + + (* + pub fn new() -> Self { + Self { state: keccak256_state::State::new() } + } + *) + Definition new (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [] => + ltac:(M.monadic + (Value.StructRecord + "alloy_primitives::utils::Keccak256" + [ + ("state", + M.call_closure (| + Ty.path "alloy_primitives::utils::keccak256_state::State", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::keccak256_state::State", + "new", + [], + [] + |), + [] + |)) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : M.IsAssociatedFunction.Trait Self "new" new. + Admitted. + Global Typeclasses Opaque new. + + (* + pub fn update(&mut self, bytes: impl AsRef<[u8]>) { + self.state.update(bytes.as_ref()); + } + *) + Definition update (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ impl_AsRef__u8__ ], [ self; bytes ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let bytes := M.alloc (| bytes |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "alloy_primitives::utils::keccak256_state::State", + "update", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.MutRef, + M.SubPointer.get_struct_record_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::utils::Keccak256", + "state" + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "&") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + M.get_trait_method (| + "core::convert::AsRef", + impl_AsRef__u8__, + [], + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + "as_ref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, bytes |) ] + |) + |) + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_update : M.IsAssociatedFunction.Trait Self "update" update. + Admitted. + Global Typeclasses Opaque update. + + (* + pub fn finalize(self) -> B256 { + let mut output = MaybeUninit::::uninit(); + // SAFETY: The output is 32-bytes. + unsafe { self.finalize_into_raw(output.as_mut_ptr().cast()) }; + // SAFETY: Initialized above. + unsafe { output.assume_init() } + } + *) + Definition finalize (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ output : + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ], + "uninit", + [], + [] + |), + [] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "alloy_primitives::utils::Keccak256", + "finalize_into_raw", + [], + [] + |), + [ + M.read (| self |); + M.call_closure (| + Ty.apply (Ty.path "*mut") [] [ Ty.path "u8" ], + M.get_associated_function (| + Ty.apply + (Ty.path "*mut") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ], + "cast", + [], + [ Ty.path "u8" ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "*mut") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ], + "as_mut_ptr", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, output |) ] + |) + ] + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "core::mem::maybe_uninit::MaybeUninit") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::bits::fixed::FixedBytes") + [ Value.Integer IntegerKind.Usize 32 ] + [] + ], + "assume_init", + [], + [] + |), + [ M.read (| output |) ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_finalize : + M.IsAssociatedFunction.Trait Self "finalize" finalize. + Admitted. + Global Typeclasses Opaque finalize. + + (* + pub fn finalize_into(self, output: &mut [u8]) { + self.finalize_into_array(output.try_into().unwrap()) + } + *) + Definition finalize_into (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; output ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let output := M.alloc (| output |) in + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "alloy_primitives::utils::Keccak256", + "finalize_into_array", + [], + [] + |), + [ + M.read (| self |); + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ] + ]; + Ty.path "core::array::TryFromSliceError" + ], + M.get_trait_method (| + "core::convert::TryInto", + Ty.apply + (Ty.path "&mut") + [] + [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ], + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ] + ] + ], + "try_into", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| output |) |) |) ] + |) + ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_finalize_into : + M.IsAssociatedFunction.Trait Self "finalize_into" finalize_into. + Admitted. + Global Typeclasses Opaque finalize_into. + + (* + pub fn finalize_into_array(self, output: &mut [u8; 32]) { + self.state.finalize_into(output.into()); + } + *) + Definition finalize_into_array (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; output ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let output := M.alloc (| output |) in + M.read (| + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "alloy_primitives::utils::keccak256_state::State", + "finalize_into", + [], + [] + |), + [ + M.read (| + M.SubPointer.get_struct_record_field (| + self, + "alloy_primitives::utils::Keccak256", + "state" + |) + |); + M.call_closure (| + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ] + ], + M.get_trait_method (| + "core::convert::Into", + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ] + ], + [], + [ + Ty.apply + (Ty.path "&mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ] + ] + ], + "into", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| output |) |) |) ] + |) + ] + |) + |) in + M.alloc (| Value.Tuple [] |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_finalize_into_array : + M.IsAssociatedFunction.Trait Self "finalize_into_array" finalize_into_array. + Admitted. + Global Typeclasses Opaque finalize_into_array. + + (* + pub unsafe fn finalize_into_raw(self, output: *mut u8) { + self.finalize_into_array(&mut *output.cast::<[u8; 32]>()) + } + *) + Definition finalize_into_raw (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; output ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let output := M.alloc (| output |) in + M.call_closure (| + Ty.tuple [], + M.get_associated_function (| + Ty.path "alloy_primitives::utils::Keccak256", + "finalize_into_array", + [], + [] + |), + [ + M.read (| self |); + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.borrow (| + Pointer.Kind.MutRef, + M.deref (| + M.call_closure (| + Ty.apply + (Ty.path "*mut") + [] + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ] + ], + M.get_associated_function (| + Ty.apply (Ty.path "*mut") [] [ Ty.path "u8" ], + "cast", + [], + [ + Ty.apply + (Ty.path "array") + [ Value.Integer IntegerKind.Usize 32 ] + [ Ty.path "u8" ] + ] + |), + [ M.read (| output |) ] + |) + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_finalize_into_raw : + M.IsAssociatedFunction.Trait Self "finalize_into_raw" finalize_into_raw. + Admitted. + Global Typeclasses Opaque finalize_into_raw. + End Impl_alloy_primitives_utils_Keccak256. +End utils. diff --git a/CoqOfRust/alloy_primitives/utils/units.rs b/CoqOfRust/alloy_primitives/utils/units.rs new file mode 100644 index 000000000..cbb757e4e --- /dev/null +++ b/CoqOfRust/alloy_primitives/utils/units.rs @@ -0,0 +1,841 @@ +use crate::{ParseSignedError, I256, U256}; +use alloc::string::{String, ToString}; +use core::fmt; + +const MAX_U64_EXPONENT: u8 = 19; + +/// Converts the input to a U256 and converts from Ether to Wei. +/// +/// # Examples +/// +/// ``` +/// use alloy_primitives::{ +/// utils::{parse_ether, Unit}, +/// U256, +/// }; +/// +/// let eth = Unit::ETHER.wei(); +/// assert_eq!(parse_ether("1").unwrap(), eth); +/// ``` +pub fn parse_ether(eth: &str) -> Result { + ParseUnits::parse_units(eth, Unit::ETHER).map(Into::into) +} + +/// Parses a decimal number and multiplies it with 10^units. +/// +/// # Examples +/// +/// ``` +/// use alloy_primitives::{utils::parse_units, U256}; +/// +/// let amount_in_eth = U256::from_str_radix("15230001000000000000", 10).unwrap(); +/// let amount_in_gwei = U256::from_str_radix("15230001000", 10).unwrap(); +/// let amount_in_wei = U256::from_str_radix("15230001000", 10).unwrap(); +/// assert_eq!(amount_in_eth, parse_units("15.230001000000000000", "ether").unwrap().into()); +/// assert_eq!(amount_in_gwei, parse_units("15.230001000000000000", "gwei").unwrap().into()); +/// assert_eq!(amount_in_wei, parse_units("15230001000", "wei").unwrap().into()); +/// ``` +/// +/// Example of trying to parse decimal WEI, which should fail, as WEI is the smallest +/// ETH denominator. 1 ETH = 10^18 WEI. +/// +/// ```should_panic +/// use alloy_primitives::{utils::parse_units, U256}; +/// let amount_in_wei = U256::from_str_radix("15230001000", 10).unwrap(); +/// assert_eq!(amount_in_wei, parse_units("15.230001000000000000", "wei").unwrap().into()); +/// ``` +pub fn parse_units(amount: &str, units: K) -> Result +where + K: TryInto, + UnitsError: From, +{ + ParseUnits::parse_units(amount, units.try_into()?) +} + +/// Formats the given number of Wei as an Ether amount. +/// +/// # Examples +/// +/// ``` +/// use alloy_primitives::{utils::format_ether, U256}; +/// +/// let eth = format_ether(1395633240123456000_u128); +/// assert_eq!(format_ether(1395633240123456000_u128), "1.395633240123456000"); +/// ``` +pub fn format_ether>(amount: T) -> String { + amount.into().format_units(Unit::ETHER) +} + +/// Formats the given number of Wei as the given unit. +/// +/// # Examples +/// +/// ``` +/// use alloy_primitives::{utils::format_units, U256}; +/// +/// let eth = U256::from_str_radix("1395633240123456000", 10).unwrap(); +/// assert_eq!(format_units(eth, "eth").unwrap(), "1.395633240123456000"); +/// +/// assert_eq!(format_units(i64::MIN, "gwei").unwrap(), "-9223372036.854775808"); +/// +/// assert_eq!(format_units(i128::MIN, 36).unwrap(), "-170.141183460469231731687303715884105728"); +/// ``` +pub fn format_units(amount: T, units: K) -> Result +where + T: Into, + K: TryInto, + UnitsError: From, +{ + units.try_into().map(|units| amount.into().format_units(units)).map_err(UnitsError::from) +} + +/// Error type for [`Unit`]-related operations. +#[derive(Debug)] +pub enum UnitsError { + /// The provided units are not recognized. + InvalidUnit(String), + /// Overflow when parsing a signed number. + ParseSigned(ParseSignedError), +} + +#[cfg(feature = "std")] +impl std::error::Error for UnitsError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + Self::InvalidUnit(_) => None, + Self::ParseSigned(e) => Some(e), + } + } +} + +impl fmt::Display for UnitsError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::InvalidUnit(s) => write!(f, "{s:?} is not a valid unit"), + Self::ParseSigned(e) => e.fmt(f), + } + } +} + +impl From for UnitsError { + fn from(value: ruint::ParseError) -> Self { + Self::ParseSigned(value.into()) + } +} + +impl From for UnitsError { + fn from(value: ParseSignedError) -> Self { + Self::ParseSigned(value) + } +} + +/// This enum holds the numeric types that a possible to be returned by `parse_units` and +/// that are taken by `format_units`. +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] +pub enum ParseUnits { + /// Unsigned 256-bit integer. + U256(U256), + /// Signed 256-bit integer. + I256(I256), +} + +impl From for U256 { + #[inline] + fn from(value: ParseUnits) -> Self { + value.get_absolute() + } +} + +impl From for I256 { + #[inline] + fn from(value: ParseUnits) -> Self { + value.get_signed() + } +} + +impl fmt::Display for ParseUnits { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::U256(val) => val.fmt(f), + Self::I256(val) => val.fmt(f), + } + } +} + +macro_rules! impl_from_integers { + ($convert:ident($($t:ty),* $(,)?)) => {$( + impl From<$t> for ParseUnits { + fn from(value: $t) -> Self { + Self::$convert($convert::try_from(value).unwrap()) + } + } + )*} +} + +impl_from_integers!(U256(u8, u16, u32, u64, u128, usize, U256)); +impl_from_integers!(I256(i8, i16, i32, i64, i128, isize, I256)); + +macro_rules! impl_try_into_absolute { + ($($t:ty),* $(,)?) => { $( + impl TryFrom for $t { + type Error = <$t as TryFrom>::Error; + + fn try_from(value: ParseUnits) -> Result { + <$t>::try_from(value.get_absolute()) + } + } + )* }; +} + +impl_try_into_absolute!(u64, u128); + +impl ParseUnits { + /// Parses a decimal number and multiplies it with 10^units. + /// + /// See [`parse_units`] for more information. + #[allow(clippy::self_named_constructors)] + pub fn parse_units(amount: &str, unit: Unit) -> Result { + let exponent = unit.get() as usize; + + let mut amount = amount.to_string(); + let negative = amount.starts_with('-'); + let dec_len = if let Some(di) = amount.find('.') { + amount.remove(di); + amount[di..].len() + } else { + 0 + }; + let amount = amount.as_str(); + + if dec_len > exponent { + // Truncate the decimal part if it is longer than the exponent + let amount = &amount[..(amount.len() - (dec_len - exponent))]; + if negative { + // Edge case: We have removed the entire number and only the negative sign is left. + // Return 0 as a I256 given the input was signed. + if amount == "-" { + Ok(Self::I256(I256::ZERO)) + } else { + Ok(Self::I256(I256::from_dec_str(amount)?)) + } + } else { + Ok(Self::U256(U256::from_str_radix(amount, 10)?)) + } + } else if negative { + // Edge case: Only a negative sign was given, return 0 as a I256 given the input was + // signed. + if amount == "-" { + Ok(Self::I256(I256::ZERO)) + } else { + let mut n = I256::from_dec_str(amount)?; + n *= I256::try_from(10u8) + .unwrap() + .checked_pow(U256::from(exponent - dec_len)) + .ok_or(UnitsError::ParseSigned(ParseSignedError::IntegerOverflow))?; + Ok(Self::I256(n)) + } + } else { + let mut a_uint = U256::from_str_radix(amount, 10)?; + a_uint *= U256::from(10) + .checked_pow(U256::from(exponent - dec_len)) + .ok_or(UnitsError::ParseSigned(ParseSignedError::IntegerOverflow))?; + Ok(Self::U256(a_uint)) + } + } + + /// Formats the given number of Wei as the given unit. + /// + /// See [`format_units`] for more information. + pub fn format_units(&self, mut unit: Unit) -> String { + // Edge case: If the number is signed and the unit is the largest possible unit, we need to + // subtract 1 from the unit to avoid overflow. + if self.is_signed() && unit == Unit::MAX { + unit = Unit::new(Unit::MAX.get() - 1).unwrap(); + } + let units = unit.get() as usize; + let exp10 = unit.wei(); + + // TODO: `decimals` are formatted twice because U256 does not support alignment + // (`:0>width`). + match *self { + Self::U256(amount) => { + let integer = amount / exp10; + let decimals = (amount % exp10).to_string(); + format!("{integer}.{decimals:0>units$}") + } + Self::I256(amount) => { + let exp10 = I256::from_raw(exp10); + let sign = if amount.is_negative() { "-" } else { "" }; + let integer = (amount / exp10).twos_complement(); + let decimals = ((amount % exp10).twos_complement()).to_string(); + format!("{sign}{integer}.{decimals:0>units$}") + } + } + } + + /// Returns `true` if the number is signed. + #[inline] + pub const fn is_signed(&self) -> bool { + matches!(self, Self::I256(_)) + } + + /// Returns `true` if the number is unsigned. + #[inline] + pub const fn is_unsigned(&self) -> bool { + matches!(self, Self::U256(_)) + } + + /// Returns `true` if the number is negative. + #[inline] + pub const fn is_negative(&self) -> bool { + match self { + Self::U256(_) => false, + Self::I256(n) => n.is_negative(), + } + } + + /// Returns `true` if the number is positive. + #[inline] + pub const fn is_positive(&self) -> bool { + match self { + Self::U256(_) => true, + Self::I256(n) => n.is_positive(), + } + } + + /// Returns `true` if the number is zero. + #[inline] + pub fn is_zero(&self) -> bool { + match self { + Self::U256(n) => n.is_zero(), + Self::I256(n) => n.is_zero(), + } + } + + /// Returns the absolute value of the number. + #[inline] + pub const fn get_absolute(self) -> U256 { + match self { + Self::U256(n) => n, + Self::I256(n) => n.into_raw(), + } + } + + /// Returns the signed value of the number. + #[inline] + pub const fn get_signed(self) -> I256 { + match self { + Self::U256(n) => I256::from_raw(n), + Self::I256(n) => n, + } + } +} + +/// Ethereum unit. Always less than [`77`](Unit::MAX). +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] +pub struct Unit(u8); + +impl fmt::Display for Unit { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.get().fmt(f) + } +} + +impl TryFrom for Unit { + type Error = UnitsError; + + fn try_from(value: u8) -> Result { + Self::new(value).ok_or_else(|| UnitsError::InvalidUnit(value.to_string())) + } +} + +impl TryFrom for Unit { + type Error = UnitsError; + + fn try_from(value: String) -> Result { + value.parse() + } +} + +impl<'a> TryFrom<&'a String> for Unit { + type Error = UnitsError; + + fn try_from(value: &'a String) -> Result { + value.parse() + } +} + +impl TryFrom<&str> for Unit { + type Error = UnitsError; + + fn try_from(value: &str) -> Result { + value.parse() + } +} + +impl core::str::FromStr for Unit { + type Err = UnitsError; + + fn from_str(s: &str) -> Result { + if let Ok(unit) = crate::U8::from_str(s) { + return Self::new(unit.to()).ok_or_else(|| UnitsError::InvalidUnit(s.to_string())); + } + + Ok(match s.to_ascii_lowercase().as_str() { + "eth" | "ether" => Self::ETHER, + "pwei" | "milli" | "milliether" | "finney" => Self::PWEI, + "twei" | "micro" | "microether" | "szabo" => Self::TWEI, + "gwei" | "nano" | "nanoether" | "shannon" => Self::GWEI, + "mwei" | "pico" | "picoether" | "lovelace" => Self::MWEI, + "kwei" | "femto" | "femtoether" | "babbage" => Self::KWEI, + "wei" => Self::WEI, + _ => return Err(UnitsError::InvalidUnit(s.to_string())), + }) + } +} + +impl Unit { + /// Wei is equivalent to 1 wei. + pub const WEI: Self = unsafe { Self::new_unchecked(0) }; + #[allow(non_upper_case_globals)] + #[doc(hidden)] + #[deprecated(since = "0.5.0", note = "use `Unit::WEI` instead")] + pub const Wei: Self = Self::WEI; + + /// Kwei is equivalent to 1e3 wei. + pub const KWEI: Self = unsafe { Self::new_unchecked(3) }; + #[allow(non_upper_case_globals)] + #[doc(hidden)] + #[deprecated(since = "0.5.0", note = "use `Unit::KWEI` instead")] + pub const Kwei: Self = Self::KWEI; + + /// Mwei is equivalent to 1e6 wei. + pub const MWEI: Self = unsafe { Self::new_unchecked(6) }; + #[allow(non_upper_case_globals)] + #[doc(hidden)] + #[deprecated(since = "0.5.0", note = "use `Unit::MWEI` instead")] + pub const Mwei: Self = Self::MWEI; + + /// Gwei is equivalent to 1e9 wei. + pub const GWEI: Self = unsafe { Self::new_unchecked(9) }; + #[allow(non_upper_case_globals)] + #[doc(hidden)] + #[deprecated(since = "0.5.0", note = "use `Unit::GWEI` instead")] + pub const Gwei: Self = Self::GWEI; + + /// Twei is equivalent to 1e12 wei. + pub const TWEI: Self = unsafe { Self::new_unchecked(12) }; + #[allow(non_upper_case_globals)] + #[doc(hidden)] + #[deprecated(since = "0.5.0", note = "use `Unit::TWEI` instead")] + pub const Twei: Self = Self::TWEI; + + /// Pwei is equivalent to 1e15 wei. + pub const PWEI: Self = unsafe { Self::new_unchecked(15) }; + #[allow(non_upper_case_globals)] + #[doc(hidden)] + #[deprecated(since = "0.5.0", note = "use `Unit::PWEI` instead")] + pub const Pwei: Self = Self::PWEI; + + /// Ether is equivalent to 1e18 wei. + pub const ETHER: Self = unsafe { Self::new_unchecked(18) }; + #[allow(non_upper_case_globals)] + #[doc(hidden)] + #[deprecated(since = "0.5.0", note = "use `Unit::ETHER` instead")] + pub const Ether: Self = Self::ETHER; + + /// The smallest unit. + pub const MIN: Self = Self::WEI; + /// The largest unit. + pub const MAX: Self = unsafe { Self::new_unchecked(77) }; + + /// Creates a new `Unit` instance, checking for overflow. + #[inline] + pub const fn new(units: u8) -> Option { + if units <= Self::MAX.get() { + // SAFETY: `units` is contained in the valid range. + Some(unsafe { Self::new_unchecked(units) }) + } else { + None + } + } + + /// Creates a new `Unit` instance. + /// + /// # Safety + /// + /// `x` must be less than [`Unit::MAX`]. + #[inline] + pub const unsafe fn new_unchecked(x: u8) -> Self { + Self(x) + } + + /// Returns `10^self`, which is the number of Wei in this unit. + /// + /// # Examples + /// + /// ``` + /// use alloy_primitives::{utils::Unit, U256}; + /// + /// assert_eq!(U256::from(1u128), Unit::WEI.wei()); + /// assert_eq!(U256::from(1_000u128), Unit::KWEI.wei()); + /// assert_eq!(U256::from(1_000_000u128), Unit::MWEI.wei()); + /// assert_eq!(U256::from(1_000_000_000u128), Unit::GWEI.wei()); + /// assert_eq!(U256::from(1_000_000_000_000u128), Unit::TWEI.wei()); + /// assert_eq!(U256::from(1_000_000_000_000_000u128), Unit::PWEI.wei()); + /// assert_eq!(U256::from(1_000_000_000_000_000_000u128), Unit::ETHER.wei()); + /// ``` + #[inline] + pub fn wei(self) -> U256 { + if self.get() <= MAX_U64_EXPONENT { + self.wei_const() + } else { + U256::from(10u8).pow(U256::from(self.get())) + } + } + + /// Returns `10^self`, which is the number of Wei in this unit. + /// + /// # Panics + /// + /// Panics if `10^self` would overflow a `u64` (`self > 19`). If this can happen, use + /// [`wei`](Self::wei) instead. + #[inline] + pub const fn wei_const(self) -> U256 { + if self.get() > MAX_U64_EXPONENT { + panic!("overflow") + } + U256::from_limbs([10u64.pow(self.get() as u32), 0, 0, 0]) + } + + /// Returns the numeric value of the unit. + #[inline] + pub const fn get(self) -> u8 { + self.0 + } + + #[doc(hidden)] + #[deprecated(since = "0.5.0", note = "use `get` instead")] + pub const fn as_num(&self) -> u8 { + self.get() + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn unit_values() { + assert_eq!(Unit::WEI.get(), 0); + assert_eq!(Unit::KWEI.get(), 3); + assert_eq!(Unit::MWEI.get(), 6); + assert_eq!(Unit::GWEI.get(), 9); + assert_eq!(Unit::TWEI.get(), 12); + assert_eq!(Unit::PWEI.get(), 15); + assert_eq!(Unit::ETHER.get(), 18); + assert_eq!(Unit::new(10).unwrap().get(), 10); + assert_eq!(Unit::new(20).unwrap().get(), 20); + } + + #[test] + fn unit_wei() { + let assert = |unit: Unit| { + let wei = unit.wei(); + assert_eq!(wei.to::(), 10u128.pow(unit.get() as u32)); + assert_eq!(wei, U256::from(10u8).pow(U256::from(unit.get()))); + }; + assert(Unit::WEI); + assert(Unit::KWEI); + assert(Unit::MWEI); + assert(Unit::GWEI); + assert(Unit::TWEI); + assert(Unit::PWEI); + assert(Unit::ETHER); + assert(Unit::new(10).unwrap()); + assert(Unit::new(20).unwrap()); + } + + #[test] + fn parse() { + assert_eq!(Unit::try_from("wei").unwrap(), Unit::WEI); + assert_eq!(Unit::try_from("kwei").unwrap(), Unit::KWEI); + assert_eq!(Unit::try_from("mwei").unwrap(), Unit::MWEI); + assert_eq!(Unit::try_from("gwei").unwrap(), Unit::GWEI); + assert_eq!(Unit::try_from("twei").unwrap(), Unit::TWEI); + assert_eq!(Unit::try_from("pwei").unwrap(), Unit::PWEI); + assert_eq!(Unit::try_from("ether").unwrap(), Unit::ETHER); + } + + #[test] + fn wei_in_ether() { + assert_eq!(Unit::ETHER.wei(), U256::from(1e18 as u64)); + } + + #[test] + fn test_format_ether_unsigned() { + let eth = format_ether(Unit::ETHER.wei()); + assert_eq!(eth.parse::().unwrap() as u64, 1); + + let eth = format_ether(1395633240123456000_u128); + assert_eq!(eth.parse::().unwrap(), 1.395633240123456); + + let eth = format_ether(U256::from_str_radix("1395633240123456000", 10).unwrap()); + assert_eq!(eth.parse::().unwrap(), 1.395633240123456); + + let eth = format_ether(U256::from_str_radix("1395633240123456789", 10).unwrap()); + assert_eq!(eth, "1.395633240123456789"); + + let eth = format_ether(U256::from_str_radix("1005633240123456789", 10).unwrap()); + assert_eq!(eth, "1.005633240123456789"); + + let eth = format_ether(u16::MAX); + assert_eq!(eth, "0.000000000000065535"); + + // Note: This covers usize on 32 bit systems. + let eth = format_ether(u32::MAX); + assert_eq!(eth, "0.000000004294967295"); + + // Note: This covers usize on 64 bit systems. + let eth = format_ether(u64::MAX); + assert_eq!(eth, "18.446744073709551615"); + } + + #[test] + fn test_format_ether_signed() { + let eth = format_ether(I256::from_dec_str("-1395633240123456000").unwrap()); + assert_eq!(eth.parse::().unwrap(), -1.395633240123456); + + let eth = format_ether(I256::from_dec_str("-1395633240123456789").unwrap()); + assert_eq!(eth, "-1.395633240123456789"); + + let eth = format_ether(I256::from_dec_str("1005633240123456789").unwrap()); + assert_eq!(eth, "1.005633240123456789"); + + let eth = format_ether(i8::MIN); + assert_eq!(eth, "-0.000000000000000128"); + + let eth = format_ether(i8::MAX); + assert_eq!(eth, "0.000000000000000127"); + + let eth = format_ether(i16::MIN); + assert_eq!(eth, "-0.000000000000032768"); + + // Note: This covers isize on 32 bit systems. + let eth = format_ether(i32::MIN); + assert_eq!(eth, "-0.000000002147483648"); + + // Note: This covers isize on 64 bit systems. + let eth = format_ether(i64::MIN); + assert_eq!(eth, "-9.223372036854775808"); + } + + #[test] + fn test_format_units_unsigned() { + let gwei_in_ether = format_units(Unit::ETHER.wei(), 9).unwrap(); + assert_eq!(gwei_in_ether.parse::().unwrap() as u64, 1e9 as u64); + + let eth = format_units(Unit::ETHER.wei(), "ether").unwrap(); + assert_eq!(eth.parse::().unwrap() as u64, 1); + + let eth = format_units(1395633240123456000_u128, "ether").unwrap(); + assert_eq!(eth.parse::().unwrap(), 1.395633240123456); + + let eth = format_units(U256::from_str_radix("1395633240123456000", 10).unwrap(), "ether") + .unwrap(); + assert_eq!(eth.parse::().unwrap(), 1.395633240123456); + + let eth = format_units(U256::from_str_radix("1395633240123456789", 10).unwrap(), "ether") + .unwrap(); + assert_eq!(eth, "1.395633240123456789"); + + let eth = format_units(U256::from_str_radix("1005633240123456789", 10).unwrap(), "ether") + .unwrap(); + assert_eq!(eth, "1.005633240123456789"); + + let eth = format_units(u8::MAX, 4).unwrap(); + assert_eq!(eth, "0.0255"); + + let eth = format_units(u16::MAX, "ether").unwrap(); + assert_eq!(eth, "0.000000000000065535"); + + // Note: This covers usize on 32 bit systems. + let eth = format_units(u32::MAX, 18).unwrap(); + assert_eq!(eth, "0.000000004294967295"); + + // Note: This covers usize on 64 bit systems. + let eth = format_units(u64::MAX, "gwei").unwrap(); + assert_eq!(eth, "18446744073.709551615"); + + let eth = format_units(u128::MAX, 36).unwrap(); + assert_eq!(eth, "340.282366920938463463374607431768211455"); + + let eth = format_units(U256::MAX, 77).unwrap(); + assert_eq!( + eth, + "1.15792089237316195423570985008687907853269984665640564039457584007913129639935" + ); + + let _err = format_units(U256::MAX, 78).unwrap_err(); + let _err = format_units(U256::MAX, 79).unwrap_err(); + } + + #[test] + fn test_format_units_signed() { + let eth = + format_units(I256::from_dec_str("-1395633240123456000").unwrap(), "ether").unwrap(); + assert_eq!(eth.parse::().unwrap(), -1.395633240123456); + + let eth = + format_units(I256::from_dec_str("-1395633240123456789").unwrap(), "ether").unwrap(); + assert_eq!(eth, "-1.395633240123456789"); + + let eth = + format_units(I256::from_dec_str("1005633240123456789").unwrap(), "ether").unwrap(); + assert_eq!(eth, "1.005633240123456789"); + + let eth = format_units(i8::MIN, 4).unwrap(); + assert_eq!(eth, "-0.0128"); + assert_eq!(eth.parse::().unwrap(), -0.0128_f64); + + let eth = format_units(i8::MAX, 4).unwrap(); + assert_eq!(eth, "0.0127"); + assert_eq!(eth.parse::().unwrap(), 0.0127); + + let eth = format_units(i16::MIN, "ether").unwrap(); + assert_eq!(eth, "-0.000000000000032768"); + + // Note: This covers isize on 32 bit systems. + let eth = format_units(i32::MIN, 18).unwrap(); + assert_eq!(eth, "-0.000000002147483648"); + + // Note: This covers isize on 64 bit systems. + let eth = format_units(i64::MIN, "gwei").unwrap(); + assert_eq!(eth, "-9223372036.854775808"); + + let eth = format_units(i128::MIN, 36).unwrap(); + assert_eq!(eth, "-170.141183460469231731687303715884105728"); + + let eth = format_units(I256::MIN, 76).unwrap(); + let min = "-5.7896044618658097711785492504343953926634992332820282019728792003956564819968"; + assert_eq!(eth, min); + // doesn't error + let eth = format_units(I256::MIN, 77).unwrap(); + assert_eq!(eth, min); + + let _err = format_units(I256::MIN, 78).unwrap_err(); + let _err = format_units(I256::MIN, 79).unwrap_err(); + } + + #[test] + fn parse_large_units() { + let decimals = 27u8; + let val = "10.55"; + + let n: U256 = parse_units(val, decimals).unwrap().into(); + assert_eq!(n.to_string(), "10550000000000000000000000000"); + } + + #[test] + fn test_parse_units() { + let gwei: U256 = parse_units("1.5", 9).unwrap().into(); + assert_eq!(gwei, U256::from(15e8 as u64)); + + let token: U256 = parse_units("1163.56926418", 8).unwrap().into(); + assert_eq!(token, U256::from(116356926418u64)); + + let eth_dec_float: U256 = parse_units("1.39563324", "ether").unwrap().into(); + assert_eq!(eth_dec_float, U256::from_str_radix("1395633240000000000", 10).unwrap()); + + let eth_dec_string: U256 = parse_units("1.39563324", "ether").unwrap().into(); + assert_eq!(eth_dec_string, U256::from_str_radix("1395633240000000000", 10).unwrap()); + + let eth: U256 = parse_units("1", "ether").unwrap().into(); + assert_eq!(eth, Unit::ETHER.wei()); + + let val: U256 = parse_units("2.3", "ether").unwrap().into(); + assert_eq!(val, U256::from_str_radix("2300000000000000000", 10).unwrap()); + + let n: U256 = parse_units(".2", 2).unwrap().into(); + assert_eq!(n, U256::from(20), "leading dot"); + + let n: U256 = parse_units("333.21", 2).unwrap().into(); + assert_eq!(n, U256::from(33321), "trailing dot"); + + let n: U256 = parse_units("98766", 16).unwrap().into(); + assert_eq!(n, U256::from_str_radix("987660000000000000000", 10).unwrap(), "no dot"); + + let n: U256 = parse_units("3_3_0", 3).unwrap().into(); + assert_eq!(n, U256::from(330000), "underscore"); + + let n: U256 = parse_units("330", 0).unwrap().into(); + assert_eq!(n, U256::from(330), "zero decimals"); + + let n: U256 = parse_units(".1234", 3).unwrap().into(); + assert_eq!(n, U256::from(123), "truncate too many decimals"); + + assert!(parse_units("1", 80).is_err(), "overflow"); + + let two_e30 = U256::from(2) * U256::from_limbs([0x4674edea40000000, 0xc9f2c9cd0, 0x0, 0x0]); + let n: U256 = parse_units("2", 30).unwrap().into(); + assert_eq!(n, two_e30, "2e30"); + + let n: U256 = parse_units(".33_319_2", 0).unwrap().into(); + assert_eq!(n, U256::ZERO, "mix"); + + let n: U256 = parse_units("", 3).unwrap().into(); + assert_eq!(n, U256::ZERO, "empty"); + } + + #[test] + fn test_signed_parse_units() { + let gwei: I256 = parse_units("-1.5", 9).unwrap().into(); + assert_eq!(gwei.as_i64(), -15e8 as i64); + + let token: I256 = parse_units("-1163.56926418", 8).unwrap().into(); + assert_eq!(token.as_i64(), -116356926418); + + let eth_dec_float: I256 = parse_units("-1.39563324", "ether").unwrap().into(); + assert_eq!(eth_dec_float, I256::from_dec_str("-1395633240000000000").unwrap()); + + let eth_dec_string: I256 = parse_units("-1.39563324", "ether").unwrap().into(); + assert_eq!(eth_dec_string, I256::from_dec_str("-1395633240000000000").unwrap()); + + let eth: I256 = parse_units("-1", "ether").unwrap().into(); + assert_eq!(eth, I256::from_raw(Unit::ETHER.wei()) * I256::MINUS_ONE); + + let val: I256 = parse_units("-2.3", "ether").unwrap().into(); + assert_eq!(val, I256::from_dec_str("-2300000000000000000").unwrap()); + + let n: I256 = parse_units("-.2", 2).unwrap().into(); + assert_eq!(n, I256::try_from(-20).unwrap(), "leading dot"); + + let n: I256 = parse_units("-333.21", 2).unwrap().into(); + assert_eq!(n, I256::try_from(-33321).unwrap(), "trailing dot"); + + let n: I256 = parse_units("-98766", 16).unwrap().into(); + assert_eq!(n, I256::from_dec_str("-987660000000000000000").unwrap(), "no dot"); + + let n: I256 = parse_units("-3_3_0", 3).unwrap().into(); + assert_eq!(n, I256::try_from(-330000).unwrap(), "underscore"); + + let n: I256 = parse_units("-330", 0).unwrap().into(); + assert_eq!(n, I256::try_from(-330).unwrap(), "zero decimals"); + + let n: I256 = parse_units("-.1234", 3).unwrap().into(); + assert_eq!(n, I256::try_from(-123).unwrap(), "truncate too many decimals"); + + assert!(parse_units("-1", 80).is_err(), "overflow"); + + let two_e30 = I256::try_from(-2).unwrap() + * I256::from_raw(U256::from_limbs([0x4674edea40000000, 0xc9f2c9cd0, 0x0, 0x0])); + let n: I256 = parse_units("-2", 30).unwrap().into(); + assert_eq!(n, two_e30, "-2e30"); + + let n: I256 = parse_units("-.33_319_2", 0).unwrap().into(); + assert_eq!(n, I256::ZERO, "mix"); + + let n: I256 = parse_units("-", 3).unwrap().into(); + assert_eq!(n, I256::ZERO, "empty"); + } +} diff --git a/CoqOfRust/alloy_primitives/utils/units.v b/CoqOfRust/alloy_primitives/utils/units.v new file mode 100644 index 000000000..244cdf146 --- /dev/null +++ b/CoqOfRust/alloy_primitives/utils/units.v @@ -0,0 +1,8500 @@ +(* Generated by coq-of-rust *) +Require Import CoqOfRust.CoqOfRust. + +Module utils. + Module units. + Definition value_MAX_U64_EXPONENT : Value.t := + M.run_constant ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.U8 19 |))). + + Axiom Constant_value_MAX_U64_EXPONENT : + (M.get_constant "alloy_primitives::utils::units::MAX_U64_EXPONENT") = value_MAX_U64_EXPONENT. + Global Hint Rewrite Constant_value_MAX_U64_EXPONENT : constant_rewrites. + + (* + pub fn parse_ether(eth: &str) -> Result { + ParseUnits::parse_units(eth, Unit::ETHER).map(Into::into) + } + *) + Definition parse_ether (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ eth ] => + ltac:(M.monadic + (let eth := M.alloc (| eth |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []; + Ty.path "alloy_primitives::utils::units::UnitsError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::utils::units::ParseUnits"; + Ty.path "alloy_primitives::utils::units::UnitsError" + ], + "map", + [], + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []; + Ty.function + [ Ty.path "alloy_primitives::utils::units::ParseUnits" ] + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []) + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::utils::units::ParseUnits"; + Ty.path "alloy_primitives::utils::units::UnitsError" + ], + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::ParseUnits", + "parse_units", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| eth |) |) |); + M.read (| M.get_constant "alloy_primitives::utils::units::ETHER" |) + ] + |); + M.get_trait_method (| + "core::convert::Into", + Ty.path "alloy_primitives::utils::units::ParseUnits", + [], + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [] + ], + "into", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_parse_ether : + M.IsFunction.Trait "alloy_primitives::utils::units::parse_ether" parse_ether. + Admitted. + Global Typeclasses Opaque parse_ether. + + (* + pub fn parse_units(amount: &str, units: K) -> Result + where + K: TryInto, + UnitsError: From, + { + ParseUnits::parse_units(amount, units.try_into()?) + } + *) + Definition parse_units (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ K; E ], [ amount; units ] => + ltac:(M.monadic + (let amount := M.alloc (| amount |) in + let units := M.alloc (| units |) in + M.catch_return (| + ltac:(M.monadic + (M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::utils::units::ParseUnits"; + Ty.path "alloy_primitives::utils::units::UnitsError" + ], + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::ParseUnits", + "parse_units", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| amount |) |) |); + M.read (| + M.match_operator (| + Some (Ty.path "alloy_primitives::utils::units::Unit"), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "core::convert::Infallible"; E ]; + Ty.path "alloy_primitives::utils::units::Unit" + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "alloy_primitives::utils::units::Unit"; E ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "alloy_primitives::utils::units::Unit"; E ], + M.get_trait_method (| + "core::convert::TryInto", + K, + [], + [ Ty.path "alloy_primitives::utils::units::Unit" ], + "try_into", + [], + [] + |), + [ M.read (| units |) ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::utils::units::ParseUnits"; + Ty.path "alloy_primitives::utils::units::UnitsError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::utils::units::ParseUnits"; + Ty.path "alloy_primitives::utils::units::UnitsError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "core::convert::Infallible"; E ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) + ] + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_parse_units : + M.IsFunction.Trait "alloy_primitives::utils::units::parse_units" parse_units. + Admitted. + Global Typeclasses Opaque parse_units. + + (* + pub fn format_ether>(amount: T) -> String { + amount.into().format_units(Unit::ETHER) + } + *) + Definition format_ether (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T ], [ amount ] => + ltac:(M.monadic + (let amount := M.alloc (| amount |) in + M.call_closure (| + Ty.path "alloc::string::String", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::ParseUnits", + "format_units", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::utils::units::ParseUnits", + M.get_trait_method (| + "core::convert::Into", + T, + [], + [ Ty.path "alloy_primitives::utils::units::ParseUnits" ], + "into", + [], + [] + |), + [ M.read (| amount |) ] + |) + |) + |); + M.read (| M.get_constant "alloy_primitives::utils::units::ETHER" |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_format_ether : + M.IsFunction.Trait "alloy_primitives::utils::units::format_ether" format_ether. + Admitted. + Global Typeclasses Opaque format_ether. + + (* + pub fn format_units(amount: T, units: K) -> Result + where + T: Into, + K: TryInto, + UnitsError: From, + { + units.try_into().map(|units| amount.into().format_units(units)).map_err(UnitsError::from) + } + *) + Definition format_units (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [ T; K; E ], [ amount; units ] => + ltac:(M.monadic + (let amount := M.alloc (| amount |) in + let units := M.alloc (| units |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloc::string::String"; + Ty.path "alloy_primitives::utils::units::UnitsError" + ], + M.get_associated_function (| + Ty.apply (Ty.path "core::result::Result") [] [ Ty.path "alloc::string::String"; E ], + "map_err", + [], + [ + Ty.path "alloy_primitives::utils::units::UnitsError"; + Ty.function [ E ] (Ty.path "alloy_primitives::utils::units::UnitsError") + ] + |), + [ + M.call_closure (| + Ty.apply (Ty.path "core::result::Result") [] [ Ty.path "alloc::string::String"; E ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "alloy_primitives::utils::units::Unit"; E ], + "map", + [], + [ + Ty.path "alloc::string::String"; + Ty.function + [ Ty.tuple [ Ty.path "alloy_primitives::utils::units::Unit" ] ] + (Ty.path "alloc::string::String") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.path "alloy_primitives::utils::units::Unit"; E ], + M.get_trait_method (| + "core::convert::TryInto", + K, + [], + [ Ty.path "alloy_primitives::utils::units::Unit" ], + "try_into", + [], + [] + |), + [ M.read (| units |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ Ty.tuple [ Ty.path "alloy_primitives::utils::units::Unit" ] ] + (Ty.path "alloc::string::String")), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (let units := M.copy (| γ |) in + M.call_closure (| + Ty.path "alloc::string::String", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::ParseUnits", + "format_units", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::utils::units::ParseUnits", + M.get_trait_method (| + "core::convert::Into", + T, + [], + [ + Ty.path + "alloy_primitives::utils::units::ParseUnits" + ], + "into", + [], + [] + |), + [ M.read (| amount |) ] + |) + |) + |); + M.read (| units |) + ] + |))) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |); + M.get_trait_method (| + "core::convert::From", + Ty.path "alloy_primitives::utils::units::UnitsError", + [], + [ E ], + "from", + [], + [] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance Instance_IsFunction_format_units : + M.IsFunction.Trait "alloy_primitives::utils::units::format_units" format_units. + Admitted. + Global Typeclasses Opaque format_units. + + (* + Enum UnitsError + { + const_params := []; + ty_params := []; + variants := + [ + { + name := "InvalidUnit"; + item := StructTuple [ Ty.path "alloc::string::String" ]; + }; + { + name := "ParseSigned"; + item := StructTuple [ Ty.path "alloy_primitives::signed::errors::ParseSignedError" ]; + } + ]; + } + *) + + Axiom IsDiscriminant_UnitsError_InvalidUnit : + M.IsDiscriminant "alloy_primitives::utils::units::UnitsError::InvalidUnit" 0. + Axiom IsDiscriminant_UnitsError_ParseSigned : + M.IsDiscriminant "alloy_primitives::utils::units::UnitsError::ParseSigned" 1. + + Module Impl_core_fmt_Debug_for_alloy_primitives_utils_units_UnitsError. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::UnitsError". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ]), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::utils::units::UnitsError::InvalidUnit", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "InvalidUnit" |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::utils::units::UnitsError::ParseSigned", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| mk_str (| "ParseSigned" |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_alloy_primitives_utils_units_UnitsError. + + Module Impl_core_error_Error_for_alloy_primitives_utils_units_UnitsError. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::UnitsError". + + (* + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + Self::InvalidUnit(_) => None, + Self::ParseSigned(e) => Some(e), + } + } + *) + Definition source (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.apply (Ty.path "&") [] [ Ty.dyn [ ("core::error::Error::Trait", []) ] ] ]), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::utils::units::UnitsError::InvalidUnit", + 0 + |) in + M.alloc (| Value.StructTuple "core::option::Option::None" [] |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::utils::units::UnitsError::ParseSigned", + 0 + |) in + let e := M.alloc (| γ1_0 |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| e |) |) |) ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::error::Error" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("source", InstanceField.Method source) ]. + End Impl_core_error_Error_for_alloy_primitives_utils_units_UnitsError. + + Module Impl_core_fmt_Display_for_alloy_primitives_utils_units_UnitsError. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::UnitsError". + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::InvalidUnit(s) => write!(f, "{s:?} is not a valid unit"), + Self::ParseSigned(e) => e.fmt(f), + } + } + *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ]), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::utils::units::UnitsError::InvalidUnit", + 0 + |) in + let s := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "write_fmt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1", + [ + Value.Integer IntegerKind.Usize 2; + Value.Integer IntegerKind.Usize 1 + ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ mk_str (| "" |); mk_str (| " is not a valid unit" |) ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_debug", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "alloc::string::String" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, s |) |) + |) + ] + |) + ] + |) + |) + |) + |) + ] + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::utils::units::UnitsError::ParseSigned", + 0 + |) in + let e := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::Display", + Ty.path "alloy_primitives::signed::errors::ParseSignedError", + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| e |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Display" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Display_for_alloy_primitives_utils_units_UnitsError. + + Module Impl_core_convert_From_ruint_string_ParseError_for_alloy_primitives_utils_units_UnitsError. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::UnitsError". + + (* + fn from(value: ruint::ParseError) -> Self { + Self::ParseSigned(value.into()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::utils::units::UnitsError::ParseSigned" + [ + M.call_closure (| + Ty.path "alloy_primitives::signed::errors::ParseSignedError", + M.get_trait_method (| + "core::convert::Into", + Ty.path "ruint::string::ParseError", + [], + [ Ty.path "alloy_primitives::signed::errors::ParseSignedError" ], + "into", + [], + [] + |), + [ M.read (| value |) ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "ruint::string::ParseError" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ruint_string_ParseError_for_alloy_primitives_utils_units_UnitsError. + + Module Impl_core_convert_From_alloy_primitives_signed_errors_ParseSignedError_for_alloy_primitives_utils_units_UnitsError. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::UnitsError". + + (* + fn from(value: ParseSignedError) -> Self { + Self::ParseSigned(value) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::utils::units::UnitsError::ParseSigned" + [ M.read (| value |) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.path "alloy_primitives::signed::errors::ParseSignedError" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_signed_errors_ParseSignedError_for_alloy_primitives_utils_units_UnitsError. + + (* + Enum ParseUnits + { + const_params := []; + ty_params := []; + variants := + [ + { + name := "U256"; + item := + StructTuple + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [] + ]; + }; + { + name := "I256"; + item := + StructTuple + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [] + ]; + } + ]; + } + *) + + Axiom IsDiscriminant_ParseUnits_U256 : + M.IsDiscriminant "alloy_primitives::utils::units::ParseUnits::U256" 0. + Axiom IsDiscriminant_ParseUnits_I256 : + M.IsDiscriminant "alloy_primitives::utils::units::ParseUnits::I256" 1. + + Module Impl_core_clone_Clone_for_alloy_primitives_utils_units_ParseUnits. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::ParseUnits". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ + fun γ => + ltac:(M.monadic + (M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.deref (| M.read (| self |) |))) ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_alloy_primitives_utils_units_ParseUnits. + + Module Impl_core_marker_Copy_for_alloy_primitives_utils_units_ParseUnits. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::ParseUnits". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_alloy_primitives_utils_units_ParseUnits. + + Module Impl_core_fmt_Debug_for_alloy_primitives_utils_units_ParseUnits. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::ParseUnits". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ]), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::utils::units::ParseUnits::U256", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "U256" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::utils::units::ParseUnits::I256", + 0 + |) in + let __self_0 := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "I256" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_0 |) |) + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_alloy_primitives_utils_units_ParseUnits. + + Module Impl_core_marker_StructuralPartialEq_for_alloy_primitives_utils_units_ParseUnits. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::ParseUnits". + + Axiom Implements : + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_alloy_primitives_utils_units_ParseUnits. + + Module Impl_core_cmp_PartialEq_alloy_primitives_utils_units_ParseUnits_for_alloy_primitives_utils_units_ParseUnits. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::ParseUnits". + + (* PartialEq *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.read (| + let~ __self_discr : Ty.path "isize" := + M.alloc (| + M.call_closure (| + Ty.path "isize", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "alloy_primitives::utils::units::ParseUnits" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ __arg1_discr : Ty.path "isize" := + M.alloc (| + M.call_closure (| + Ty.path "isize", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "alloy_primitives::utils::units::ParseUnits" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) ] + |) + |) in + M.alloc (| + LogicalOp.and (| + BinOp.eq (| M.read (| __self_discr |), M.read (| __arg1_discr |) |), + ltac:(M.monadic + (M.read (| + M.match_operator (| + Some (Ty.path "bool"), + M.alloc (| Value.Tuple [ M.read (| self |); M.read (| other |) ] |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_0 := M.read (| γ0_0 |) in + let γ2_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_0, + "alloy_primitives::utils::units::ParseUnits::U256", + 0 + |) in + let __self_0 := M.alloc (| γ2_0 |) in + let γ0_1 := M.read (| γ0_1 |) in + let γ2_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_1, + "alloy_primitives::utils::units::ParseUnits::U256", + 0 + |) in + let __arg1_0 := M.alloc (| γ2_0 |) in + M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, __self_0 |); + M.borrow (| Pointer.Kind.Ref, __arg1_0 |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_0 := M.read (| γ0_0 |) in + let γ2_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_0, + "alloy_primitives::utils::units::ParseUnits::I256", + 0 + |) in + let __self_0 := M.alloc (| γ2_0 |) in + let γ0_1 := M.read (| γ0_1 |) in + let γ2_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_1, + "alloy_primitives::utils::units::ParseUnits::I256", + 0 + |) in + let __arg1_0 := M.alloc (| γ2_0 |) in + M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ], + [], + [ + Ty.apply + (Ty.path "&") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ] + ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, __self_0 |); + M.borrow (| Pointer.Kind.Ref, __arg1_0 |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::intrinsics::unreachable", [], [] |), + [] + |) + |) + |))) + ] + |) + |))) + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::utils::units::ParseUnits" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_utils_units_ParseUnits_for_alloy_primitives_utils_units_ParseUnits. + + Module Impl_core_cmp_Eq_for_alloy_primitives_utils_units_ParseUnits. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::ParseUnits". + + (* Eq *) + Definition assert_receiver_is_total_eq + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ + fun γ => + ltac:(M.monadic + (M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) ] + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method assert_receiver_is_total_eq) ]. + End Impl_core_cmp_Eq_for_alloy_primitives_utils_units_ParseUnits. + + Module Impl_core_cmp_PartialOrd_alloy_primitives_utils_units_ParseUnits_for_alloy_primitives_utils_units_ParseUnits. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::ParseUnits". + + (* PartialOrd *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.read (| + let~ __self_discr : Ty.path "isize" := + M.alloc (| + M.call_closure (| + Ty.path "isize", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "alloy_primitives::utils::units::ParseUnits" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ __arg1_discr : Ty.path "isize" := + M.alloc (| + M.call_closure (| + Ty.path "isize", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "alloy_primitives::utils::units::ParseUnits" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) ] + |) + |) in + M.match_operator (| + Some + (Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ]), + M.alloc (| Value.Tuple [ M.read (| self |); M.read (| other |) ] |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_0 := M.read (| γ0_0 |) in + let γ2_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_0, + "alloy_primitives::utils::units::ParseUnits::U256", + 0 + |) in + let __self_0 := M.alloc (| γ2_0 |) in + let γ0_1 := M.read (| γ0_1 |) in + let γ2_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_1, + "alloy_primitives::utils::units::ParseUnits::U256", + 0 + |) in + let __arg1_0 := M.alloc (| γ2_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + [], + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_0 |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __arg1_0 |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_0 := M.read (| γ0_0 |) in + let γ2_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_0, + "alloy_primitives::utils::units::ParseUnits::I256", + 0 + |) in + let __self_0 := M.alloc (| γ2_0 |) in + let γ0_1 := M.read (| γ0_1 |) in + let γ2_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_1, + "alloy_primitives::utils::units::ParseUnits::I256", + 0 + |) in + let __arg1_0 := M.alloc (| γ2_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __self_0 |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| __arg1_0 |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "isize", + [], + [ Ty.path "isize" ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_discr |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __arg1_discr |) |) + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::utils::units::ParseUnits" ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_alloy_primitives_utils_units_ParseUnits_for_alloy_primitives_utils_units_ParseUnits. + + Module Impl_core_cmp_Ord_for_alloy_primitives_utils_units_ParseUnits. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::ParseUnits". + + (* Ord *) + Definition cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.read (| + let~ __self_discr : Ty.path "isize" := + M.alloc (| + M.call_closure (| + Ty.path "isize", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "alloy_primitives::utils::units::ParseUnits" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) ] + |) + |) in + let~ __arg1_discr : Ty.path "isize" := + M.alloc (| + M.call_closure (| + Ty.path "isize", + M.get_function (| + "core::intrinsics::discriminant_value", + [], + [ Ty.path "alloy_primitives::utils::units::ParseUnits" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| other |) |) |) ] + |) + |) in + M.match_operator (| + Some (Ty.path "core::cmp::Ordering"), + M.alloc (| + M.call_closure (| + Ty.path "core::cmp::Ordering", + M.get_trait_method (| + "core::cmp::Ord", + Ty.path "isize", + [], + [], + "cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __self_discr |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.borrow (| Pointer.Kind.Ref, __arg1_discr |) |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let _ := M.is_struct_tuple (| γ, "core::cmp::Ordering::Equal" |) in + M.match_operator (| + Some (Ty.path "core::cmp::Ordering"), + M.alloc (| Value.Tuple [ M.read (| self |); M.read (| other |) ] |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_0 := M.read (| γ0_0 |) in + let γ2_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_0, + "alloy_primitives::utils::units::ParseUnits::U256", + 0 + |) in + let __self_0 := M.alloc (| γ2_0 |) in + let γ0_1 := M.read (| γ0_1 |) in + let γ2_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_1, + "alloy_primitives::utils::units::ParseUnits::U256", + 0 + |) in + let __arg1_0 := M.alloc (| γ2_0 |) in + M.alloc (| + M.call_closure (| + Ty.path "core::cmp::Ordering", + M.get_trait_method (| + "core::cmp::Ord", + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + [], + [], + "cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| __self_0 |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| __arg1_0 |) |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in + let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in + let γ0_0 := M.read (| γ0_0 |) in + let γ2_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_0, + "alloy_primitives::utils::units::ParseUnits::I256", + 0 + |) in + let __self_0 := M.alloc (| γ2_0 |) in + let γ0_1 := M.read (| γ0_1 |) in + let γ2_0 := + M.SubPointer.get_struct_tuple_field (| + γ0_1, + "alloy_primitives::utils::units::ParseUnits::I256", + 0 + |) in + let __arg1_0 := M.alloc (| γ2_0 |) in + M.alloc (| + M.call_closure (| + Ty.path "core::cmp::Ordering", + M.get_trait_method (| + "core::cmp::Ord", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + [], + [], + "cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| __self_0 |) |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| __arg1_0 |) |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::intrinsics::unreachable", [], [] |), + [] + |) + |) + |))) + ] + |))); + fun γ => + ltac:(M.monadic + (let cmp := M.copy (| γ |) in + cmp)) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Ord" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("cmp", InstanceField.Method cmp) ]. + End Impl_core_cmp_Ord_for_alloy_primitives_utils_units_ParseUnits. + + Module Impl_core_convert_From_alloy_primitives_utils_units_ParseUnits_for_ruint_Uint_Usize_256_Usize_4. + Definition Self : Ty.t := + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []. + + (* + fn from(value: ParseUnits) -> Self { + value.get_absolute() + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::ParseUnits", + "get_absolute", + [], + [] + |), + [ M.read (| value |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::utils::units::ParseUnits" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_utils_units_ParseUnits_for_ruint_Uint_Usize_256_Usize_4. + + Module Impl_core_convert_From_alloy_primitives_utils_units_ParseUnits_for_alloy_primitives_signed_int_Signed_Usize_256_Usize_4. + Definition Self : Ty.t := + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []. + + (* + fn from(value: ParseUnits) -> Self { + value.get_signed() + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::ParseUnits", + "get_signed", + [], + [] + |), + [ M.read (| value |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::utils::units::ParseUnits" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_utils_units_ParseUnits_for_alloy_primitives_signed_int_Signed_Usize_256_Usize_4. + + Module Impl_core_fmt_Display_for_alloy_primitives_utils_units_ParseUnits. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::ParseUnits". + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::U256(val) => val.fmt(f), + Self::I256(val) => val.fmt(f), + } + } + *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ]), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::utils::units::ParseUnits::U256", + 0 + |) in + let val := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::Display", + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| val |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::utils::units::ParseUnits::I256", + 0 + |) in + let val := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| + "core::fmt::Display", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + [], + [], + "fmt", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| val |) |) |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Display" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Display_for_alloy_primitives_utils_units_ParseUnits. + + Module Impl_core_convert_From_u8_for_alloy_primitives_utils_units_ParseUnits. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::ParseUnits". + + (* + fn from(value: $t) -> Self { + Self::$convert($convert::try_from(value).unwrap()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::utils::units::ParseUnits::U256" + [ + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []; + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ] + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 + ] + []; + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ] + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + [], + [ Ty.path "u8" ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u8" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_u8_for_alloy_primitives_utils_units_ParseUnits. + + Module Impl_core_convert_From_u16_for_alloy_primitives_utils_units_ParseUnits. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::ParseUnits". + + (* + fn from(value: $t) -> Self { + Self::$convert($convert::try_from(value).unwrap()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::utils::units::ParseUnits::U256" + [ + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []; + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ] + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 + ] + []; + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ] + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + [], + [ Ty.path "u16" ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u16" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_u16_for_alloy_primitives_utils_units_ParseUnits. + + Module Impl_core_convert_From_u32_for_alloy_primitives_utils_units_ParseUnits. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::ParseUnits". + + (* + fn from(value: $t) -> Self { + Self::$convert($convert::try_from(value).unwrap()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::utils::units::ParseUnits::U256" + [ + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []; + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ] + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 + ] + []; + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ] + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + [], + [ Ty.path "u32" ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u32" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_u32_for_alloy_primitives_utils_units_ParseUnits. + + Module Impl_core_convert_From_u64_for_alloy_primitives_utils_units_ParseUnits. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::ParseUnits". + + (* + fn from(value: $t) -> Self { + Self::$convert($convert::try_from(value).unwrap()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::utils::units::ParseUnits::U256" + [ + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []; + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ] + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 + ] + []; + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ] + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + [], + [ Ty.path "u64" ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u64" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_u64_for_alloy_primitives_utils_units_ParseUnits. + + Module Impl_core_convert_From_u128_for_alloy_primitives_utils_units_ParseUnits. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::ParseUnits". + + (* + fn from(value: $t) -> Self { + Self::$convert($convert::try_from(value).unwrap()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::utils::units::ParseUnits::U256" + [ + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []; + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ] + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 + ] + []; + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ] + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + [], + [ Ty.path "u128" ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u128" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_u128_for_alloy_primitives_utils_units_ParseUnits. + + Module Impl_core_convert_From_usize_for_alloy_primitives_utils_units_ParseUnits. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::ParseUnits". + + (* + fn from(value: $t) -> Self { + Self::$convert($convert::try_from(value).unwrap()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::utils::units::ParseUnits::U256" + [ + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []; + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ] + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 + ] + []; + Ty.apply + (Ty.path "ruint::from::ToUintError") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ] + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + [], + [ Ty.path "usize" ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "usize" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_usize_for_alloy_primitives_utils_units_ParseUnits. + + Module Impl_core_convert_From_ruint_Uint_Usize_256_Usize_4_for_alloy_primitives_utils_units_ParseUnits. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::ParseUnits". + + (* + fn from(value: $t) -> Self { + Self::$convert($convert::try_from(value).unwrap()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::utils::units::ParseUnits::U256" + [ + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []; + Ty.path "core::convert::Infallible" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 + ] + []; + Ty.path "core::convert::Infallible" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + [], + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 + ] + [] + ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_ruint_Uint_Usize_256_Usize_4_for_alloy_primitives_utils_units_ParseUnits. + + Module Impl_core_convert_From_i8_for_alloy_primitives_utils_units_ParseUnits. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::ParseUnits". + + (* + fn from(value: $t) -> Self { + Self::$convert($convert::try_from(value).unwrap()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::utils::units::ParseUnits::I256" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 + ] + []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + [], + [ Ty.path "i8" ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i8" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_i8_for_alloy_primitives_utils_units_ParseUnits. + + Module Impl_core_convert_From_i16_for_alloy_primitives_utils_units_ParseUnits. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::ParseUnits". + + (* + fn from(value: $t) -> Self { + Self::$convert($convert::try_from(value).unwrap()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::utils::units::ParseUnits::I256" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 + ] + []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + [], + [ Ty.path "i16" ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i16" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_i16_for_alloy_primitives_utils_units_ParseUnits. + + Module Impl_core_convert_From_i32_for_alloy_primitives_utils_units_ParseUnits. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::ParseUnits". + + (* + fn from(value: $t) -> Self { + Self::$convert($convert::try_from(value).unwrap()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::utils::units::ParseUnits::I256" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 + ] + []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + [], + [ Ty.path "i32" ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i32" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_i32_for_alloy_primitives_utils_units_ParseUnits. + + Module Impl_core_convert_From_i64_for_alloy_primitives_utils_units_ParseUnits. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::ParseUnits". + + (* + fn from(value: $t) -> Self { + Self::$convert($convert::try_from(value).unwrap()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::utils::units::ParseUnits::I256" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 + ] + []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + [], + [ Ty.path "i64" ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i64" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_i64_for_alloy_primitives_utils_units_ParseUnits. + + Module Impl_core_convert_From_i128_for_alloy_primitives_utils_units_ParseUnits. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::ParseUnits". + + (* + fn from(value: $t) -> Self { + Self::$convert($convert::try_from(value).unwrap()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::utils::units::ParseUnits::I256" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 + ] + []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + [], + [ Ty.path "i128" ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "i128" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_i128_for_alloy_primitives_utils_units_ParseUnits. + + Module Impl_core_convert_From_isize_for_alloy_primitives_utils_units_ParseUnits. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::ParseUnits". + + (* + fn from(value: $t) -> Self { + Self::$convert($convert::try_from(value).unwrap()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::utils::units::ParseUnits::I256" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 + ] + []; + Ty.path "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + [], + [ Ty.path "isize" ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "isize" ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_isize_for_alloy_primitives_utils_units_ParseUnits. + + Module Impl_core_convert_From_alloy_primitives_signed_int_Signed_Usize_256_Usize_4_for_alloy_primitives_utils_units_ParseUnits. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::ParseUnits". + + (* + fn from(value: $t) -> Self { + Self::$convert($convert::try_from(value).unwrap()) + } + *) + Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + Value.StructTuple + "alloy_primitives::utils::units::ParseUnits::I256" + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []; + Ty.path "core::convert::Infallible" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 + ] + []; + Ty.path "core::convert::Infallible" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 + ] + [] + ], + "try_from", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |) + ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::From" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [] + ] + Self + (* Instance *) [ ("from", InstanceField.Method from) ]. + End Impl_core_convert_From_alloy_primitives_signed_int_Signed_Usize_256_Usize_4_for_alloy_primitives_utils_units_ParseUnits. + + Module Impl_core_convert_TryFrom_alloy_primitives_utils_units_ParseUnits_for_u64. + Definition Self : Ty.t := Ty.path "u64". + + (* type Error = <$t as TryFrom>::Error; *) + Definition _Error : Ty.t := + Ty.associated_in_trait + "core::convert::TryFrom" + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [] + ] + (Ty.path "u64") + "Error". + + (* + fn try_from(value: ParseUnits) -> Result { + <$t>::try_from(value.get_absolute()) + } + *) + Definition try_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u64"; + Ty.apply (Ty.path "ruint::from::FromUintError") [] [ Ty.path "u64" ] + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "u64", + [], + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [] + ], + "try_from", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::ParseUnits", + "get_absolute", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::utils::units::ParseUnits" ] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("try_from", InstanceField.Method try_from) ]. + End Impl_core_convert_TryFrom_alloy_primitives_utils_units_ParseUnits_for_u64. + + Module Impl_core_convert_TryFrom_alloy_primitives_utils_units_ParseUnits_for_u128. + Definition Self : Ty.t := Ty.path "u128". + + (* type Error = <$t as TryFrom>::Error; *) + Definition _Error : Ty.t := + Ty.associated_in_trait + "core::convert::TryFrom" + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [] + ] + (Ty.path "u128") + "Error". + + (* + fn try_from(value: ParseUnits) -> Result { + <$t>::try_from(value.get_absolute()) + } + *) + Definition try_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "u128"; + Ty.apply (Ty.path "ruint::from::FromUintError") [] [ Ty.path "u128" ] + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.path "u128", + [], + [ + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [] + ], + "try_from", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::ParseUnits", + "get_absolute", + [], + [] + |), + [ M.read (| value |) ] + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::utils::units::ParseUnits" ] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("try_from", InstanceField.Method try_from) ]. + End Impl_core_convert_TryFrom_alloy_primitives_utils_units_ParseUnits_for_u128. + + Module Impl_alloy_primitives_utils_units_ParseUnits. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::ParseUnits". + + (* + pub fn parse_units(amount: &str, unit: Unit) -> Result { + let exponent = unit.get() as usize; + + let mut amount = amount.to_string(); + let negative = amount.starts_with('-'); + let dec_len = if let Some(di) = amount.find('.') { + amount.remove(di); + amount[di..].len() + } else { + 0 + }; + let amount = amount.as_str(); + + if dec_len > exponent { + // Truncate the decimal part if it is longer than the exponent + let amount = &amount[..(amount.len() - (dec_len - exponent))]; + if negative { + // Edge case: We have removed the entire number and only the negative sign is left. + // Return 0 as a I256 given the input was signed. + if amount == "-" { + Ok(Self::I256(I256::ZERO)) + } else { + Ok(Self::I256(I256::from_dec_str(amount)?)) + } + } else { + Ok(Self::U256(U256::from_str_radix(amount, 10)?)) + } + } else if negative { + // Edge case: Only a negative sign was given, return 0 as a I256 given the input was + // signed. + if amount == "-" { + Ok(Self::I256(I256::ZERO)) + } else { + let mut n = I256::from_dec_str(amount)?; + n *= I256::try_from(10u8) + .unwrap() + .checked_pow(U256::from(exponent - dec_len)) + .ok_or(UnitsError::ParseSigned(ParseSignedError::IntegerOverflow))?; + Ok(Self::I256(n)) + } + } else { + let mut a_uint = U256::from_str_radix(amount, 10)?; + a_uint *= U256::from(10) + .checked_pow(U256::from(exponent - dec_len)) + .ok_or(UnitsError::ParseSigned(ParseSignedError::IntegerOverflow))?; + Ok(Self::U256(a_uint)) + } + } + *) + Definition parse_units (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ amount; unit_ ] => + ltac:(M.monadic + (let amount := M.alloc (| amount |) in + let unit_ := M.alloc (| unit_ |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ exponent : Ty.path "usize" := + M.alloc (| + M.cast + (Ty.path "usize") + (M.call_closure (| + Ty.path "u8", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::Unit", + "get", + [], + [] + |), + [ M.read (| unit_ |) ] + |)) + |) in + let~ amount : Ty.path "alloc::string::String" := + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_trait_method (| + "alloc::string::ToString", + Ty.path "str", + [], + [], + "to_string", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| amount |) |) |) ] + |) + |) in + let~ negative : Ty.path "bool" := + M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "str", + "starts_with", + [], + [ Ty.path "char" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloc::string::String", + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, amount |) ] + |) + |) + |); + Value.UnicodeChar 45 + ] + |) + |) in + let~ dec_len : Ty.path "usize" := + M.copy (| + M.match_operator (| + Some (Ty.path "usize"), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "usize" ], + M.get_associated_function (| + Ty.path "str", + "find", + [], + [ Ty.path "char" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloc::string::String", + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, amount |) ] + |) + |) + |); + Value.UnicodeChar 46 + ] + |) + |) in + let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::option::Option::Some", + 0 + |) in + let di := M.copy (| γ0_0 |) in + let~ _ : Ty.path "char" := + M.alloc (| + M.call_closure (| + Ty.path "char", + M.get_associated_function (| + Ty.path "alloc::string::String", + "remove", + [], + [] + |), + [ M.borrow (| Pointer.Kind.MutRef, amount |); M.read (| di |) ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| Ty.path "str", "len", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.path "alloc::string::String", + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeFrom") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, amount |); + Value.StructRecord + "core::ops::range::RangeFrom" + [ ("start", M.read (| di |)) ] + ] + |) + |) + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.Usize 0 |))) + ] + |) + |) in + let~ amount : Ty.apply (Ty.path "&") [] [ Ty.path "str" ] := + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_associated_function (| + Ty.path "alloc::string::String", + "as_str", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, amount |) ] + |) + |) in + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::utils::units::ParseUnits"; + Ty.path "alloy_primitives::utils::units::UnitsError" + ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.gt (| M.read (| dec_len |), M.read (| exponent |) |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ amount : Ty.apply (Ty.path "&") [] [ Ty.path "str" ] := + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::index::Index", + Ty.path "str", + [], + [ + Ty.apply + (Ty.path "core::ops::range::RangeTo") + [] + [ Ty.path "usize" ] + ], + "index", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| amount |) |) + |); + Value.StructRecord + "core::ops::range::RangeTo" + [ + ("end_", + BinOp.Wrap.sub (| + M.call_closure (| + Ty.path "usize", + M.get_associated_function (| + Ty.path "str", + "len", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| amount |) |) + |) + ] + |), + BinOp.Wrap.sub (| + M.read (| dec_len |), + M.read (| exponent |) + |) + |)) + ] + ] + |) + |) + |) + |) in + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::utils::units::ParseUnits"; + Ty.path "alloy_primitives::utils::units::UnitsError" + ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use negative in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::utils::units::ParseUnits"; + Ty.path "alloy_primitives::utils::units::UnitsError" + ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, amount |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| mk_str (| "-" |) |) + |) + ] + |) + |)) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.StructTuple + "alloy_primitives::utils::units::ParseUnits::I256" + [ + M.read (| + M.get_constant + "alloy_primitives::signed::int::ZERO" + |) + ] + ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.StructTuple + "alloy_primitives::utils::units::ParseUnits::I256" + [ + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::ParseSignedError" + ]; + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ + Value.Integer + IntegerKind.Usize + 256; + Value.Integer + IntegerKind.Usize + 4 + ] + [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ + Value.Integer + IntegerKind.Usize + 256; + Value.Integer + IntegerKind.Usize + 4 + ] + []; + Ty.path + "alloy_primitives::signed::errors::ParseSignedError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ + Value.Integer + IntegerKind.Usize + 256; + Value.Integer + IntegerKind.Usize + 4 + ] + []; + Ty.path + "alloy_primitives::signed::errors::ParseSignedError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ + Value.Integer + IntegerKind.Usize + 256; + Value.Integer + IntegerKind.Usize + 4 + ] + [], + "from_dec_str", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.read (| amount |) + |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "alloy_primitives::utils::units::ParseUnits"; + Ty.path + "alloy_primitives::utils::units::UnitsError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "alloy_primitives::utils::units::ParseUnits"; + Ty.path + "alloy_primitives::utils::units::UnitsError" + ], + [], + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::ParseSignedError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) + ] + ] + |))) + ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.StructTuple + "alloy_primitives::utils::units::ParseUnits::U256" + [ + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "ruint::string::ParseError" + ]; + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + []; + Ty.path "ruint::string::ParseError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + []; + Ty.path "ruint::string::ParseError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + "from_str_radix", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| amount |) |) + |); + Value.Integer IntegerKind.U64 10 + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "alloy_primitives::utils::units::ParseUnits"; + Ty.path + "alloy_primitives::utils::units::UnitsError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "alloy_primitives::utils::units::ParseUnits"; + Ty.path + "alloy_primitives::utils::units::UnitsError" + ], + [], + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.path + "ruint::string::ParseError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) + ] + ] + |))) + ] + |))); + fun γ => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::utils::units::ParseUnits"; + Ty.path "alloy_primitives::utils::units::UnitsError" + ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := M.use negative in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::utils::units::ParseUnits"; + Ty.path "alloy_primitives::utils::units::UnitsError" + ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + [], + [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, amount |); + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| mk_str (| "-" |) |) + |) + ] + |) + |)) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.StructTuple + "alloy_primitives::utils::units::ParseUnits::I256" + [ + M.read (| + M.get_constant + "alloy_primitives::signed::int::ZERO" + |) + ] + ] + |))); + fun γ => + ltac:(M.monadic + (let~ n : + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] := + M.copy (| + M.match_operator (| + Some + (Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::ParseSignedError" + ]; + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + []; + Ty.path + "alloy_primitives::signed::errors::ParseSignedError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + []; + Ty.path + "alloy_primitives::signed::errors::ParseSignedError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + "from_dec_str", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| amount |) |) + |) + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "alloy_primitives::utils::units::ParseUnits"; + Ty.path + "alloy_primitives::utils::units::UnitsError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "alloy_primitives::utils::units::ParseUnits"; + Ty.path + "alloy_primitives::utils::units::UnitsError" + ], + [], + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.path + "alloy_primitives::signed::errors::ParseSignedError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + [], + [ + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, n |); + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path + "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.path + "alloy_primitives::utils::units::UnitsError" + ]; + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ + Value.Integer + IntegerKind.Usize + 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ + Value.Integer + IntegerKind.Usize + 256; + Value.Integer + IntegerKind.Usize + 4 + ] + []; + Ty.path + "alloy_primitives::utils::units::UnitsError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ + Value.Integer + IntegerKind.Usize + 256; + Value.Integer + IntegerKind.Usize + 4 + ] + []; + Ty.path + "alloy_primitives::utils::units::UnitsError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ + Value.Integer + IntegerKind.Usize + 256; + Value.Integer + IntegerKind.Usize + 4 + ] + [] + ], + "ok_or", + [], + [ + Ty.path + "alloy_primitives::utils::units::UnitsError" + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ + Value.Integer + IntegerKind.Usize + 256; + Value.Integer + IntegerKind.Usize + 4 + ] + [] + ], + M.get_associated_function (| + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ + Value.Integer + IntegerKind.Usize + 256; + Value.Integer + IntegerKind.Usize + 4 + ] + [], + "checked_pow", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ + Value.Integer + IntegerKind.Usize + 256; + Value.Integer + IntegerKind.Usize + 4 + ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ + Value.Integer + IntegerKind.Usize + 256; + Value.Integer + IntegerKind.Usize + 4 + ] + []; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ + Value.Integer + IntegerKind.Usize + 256; + Value.Integer + IntegerKind.Usize + 4 + ] + []; + Ty.path + "alloy_primitives::signed::errors::BigIntConversionError" + ], + M.get_trait_method (| + "core::convert::TryFrom", + Ty.apply + (Ty.path + "alloy_primitives::signed::int::Signed") + [ + Value.Integer + IntegerKind.Usize + 256; + Value.Integer + IntegerKind.Usize + 4 + ] + [], + [], + [ Ty.path "u8" ], + "try_from", + [], + [] + |), + [ + Value.Integer + IntegerKind.U8 + 10 + ] + |) + ] + |); + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer + IntegerKind.Usize + 256; + Value.Integer + IntegerKind.Usize + 4 + ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer + IntegerKind.Usize + 256; + Value.Integer + IntegerKind.Usize + 4 + ] + [], + "from", + [], + [ Ty.path "usize" ] + |), + [ + BinOp.Wrap.sub (| + M.read (| exponent |), + M.read (| dec_len |) + |) + ] + |) + ] + |); + Value.StructTuple + "alloy_primitives::utils::units::UnitsError::ParseSigned" + [ + Value.StructTuple + "alloy_primitives::signed::errors::ParseSignedError::IntegerOverflow" + [] + ] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "alloy_primitives::utils::units::ParseUnits"; + Ty.path + "alloy_primitives::utils::units::UnitsError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "alloy_primitives::utils::units::ParseUnits"; + Ty.path + "alloy_primitives::utils::units::UnitsError" + ], + [], + [ + Ty.apply + (Ty.path + "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.path + "alloy_primitives::utils::units::UnitsError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) + ] + |) + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.StructTuple + "alloy_primitives::utils::units::ParseUnits::I256" + [ M.read (| n |) ] + ] + |))) + ] + |))); + fun γ => + ltac:(M.monadic + (let~ a_uint : + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] := + M.copy (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "ruint::string::ParseError" + ]; + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + []; + Ty.path "ruint::string::ParseError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + []; + Ty.path "ruint::string::ParseError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + "from_str_radix", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| amount |) |) + |); + Value.Integer IntegerKind.U64 10 + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "alloy_primitives::utils::units::ParseUnits"; + Ty.path + "alloy_primitives::utils::units::UnitsError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "alloy_primitives::utils::units::ParseUnits"; + Ty.path + "alloy_primitives::utils::units::UnitsError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path "ruint::string::ParseError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.call_closure (| + Ty.tuple [], + M.get_trait_method (| + "core::ops::arith::MulAssign", + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + [], + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ], + "mul_assign", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, a_uint |); + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + []), + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::ops::control_flow::ControlFlow") + [] + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "core::convert::Infallible"; + Ty.path + "alloy_primitives::utils::units::UnitsError" + ]; + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ], + M.get_trait_method (| + "core::ops::try_trait::Try", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + []; + Ty.path + "alloy_primitives::utils::units::UnitsError" + ], + [], + [], + "branch", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + []; + Ty.path + "alloy_primitives::utils::units::UnitsError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ], + "ok_or", + [], + [ + Ty.path + "alloy_primitives::utils::units::UnitsError" + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer + IntegerKind.Usize + 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + "checked_pow", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer + IntegerKind.Usize + 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer + IntegerKind.Usize + 256; + Value.Integer + IntegerKind.Usize + 4 + ] + [], + "from", + [], + [ Ty.path "i32" ] + |), + [ Value.Integer IntegerKind.I32 10 ] + |); + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer + IntegerKind.Usize + 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer + IntegerKind.Usize + 256; + Value.Integer + IntegerKind.Usize + 4 + ] + [], + "from", + [], + [ Ty.path "usize" ] + |), + [ + BinOp.Wrap.sub (| + M.read (| exponent |), + M.read (| dec_len |) + |) + ] + |) + ] + |); + Value.StructTuple + "alloy_primitives::utils::units::UnitsError::ParseSigned" + [ + Value.StructTuple + "alloy_primitives::signed::errors::ParseSignedError::IntegerOverflow" + [] + ] + ] + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Break", + 0 + |) in + let residual := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "alloy_primitives::utils::units::ParseUnits"; + Ty.path + "alloy_primitives::utils::units::UnitsError" + ], + M.get_trait_method (| + "core::ops::try_trait::FromResidual", + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "alloy_primitives::utils::units::ParseUnits"; + Ty.path + "alloy_primitives::utils::units::UnitsError" + ], + [], + [ + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path + "core::convert::Infallible"; + Ty.path + "alloy_primitives::utils::units::UnitsError" + ] + ], + "from_residual", + [], + [] + |), + [ M.read (| residual |) ] + |) + |) + |) + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::ops::control_flow::ControlFlow::Continue", + 0 + |) in + let val := M.copy (| γ0_0 |) in + val)) + ] + |) + |) + ] + |) + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + Value.StructTuple + "alloy_primitives::utils::units::ParseUnits::U256" + [ M.read (| a_uint |) ] + ] + |))) + ] + |))) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_parse_units : + M.IsAssociatedFunction.Trait Self "parse_units" parse_units. + Admitted. + Global Typeclasses Opaque parse_units. + + (* + pub fn format_units(&self, mut unit: Unit) -> String { + // Edge case: If the number is signed and the unit is the largest possible unit, we need to + // subtract 1 from the unit to avoid overflow. + if self.is_signed() && unit == Unit::MAX { + unit = Unit::new(Unit::MAX.get() - 1).unwrap(); + } + let units = unit.get() as usize; + let exp10 = unit.wei(); + + // TODO: `decimals` are formatted twice because U256 does not support alignment + // (`:0>width`). + match *self { + Self::U256(amount) => { + let integer = amount / exp10; + let decimals = (amount % exp10).to_string(); + format!("{integer}.{decimals:0>units$}") + } + Self::I256(amount) => { + let exp10 = I256::from_raw(exp10); + let sign = if amount.is_negative() { "-" } else { "" }; + let integer = (amount / exp10).twos_complement(); + let decimals = ((amount % exp10).twos_complement()).to_string(); + format!("{sign}{integer}.{decimals:0>units$}") + } + } + } + *) + Definition format_units (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; unit_ ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let unit_ := M.alloc (| unit_ |) in + M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + LogicalOp.and (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::ParseUnits", + "is_signed", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| self |) |) |) + ] + |), + ltac:(M.monadic + (M.call_closure (| + Ty.path "bool", + M.get_trait_method (| + "core::cmp::PartialEq", + Ty.path "alloy_primitives::utils::units::Unit", + [], + [ Ty.path "alloy_primitives::utils::units::Unit" ], + "eq", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.Ref, unit_ |); + M.borrow (| + Pointer.Kind.Ref, + M.get_constant "alloy_primitives::utils::units::MAX" + |) + ] + |))) + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + let~ _ : Ty.tuple [] := + M.alloc (| + M.write (| + unit_, + M.call_closure (| + Ty.path "alloy_primitives::utils::units::Unit", + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "alloy_primitives::utils::units::Unit" ], + "unwrap", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "alloy_primitives::utils::units::Unit" ], + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::Unit", + "new", + [], + [] + |), + [ + BinOp.Wrap.sub (| + M.call_closure (| + Ty.path "u8", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::Unit", + "get", + [], + [] + |), + [ + M.read (| + M.get_constant "alloy_primitives::utils::units::MAX" + |) + ] + |), + Value.Integer IntegerKind.U8 1 + |) + ] + |) + ] + |) + |) + |) in + M.alloc (| Value.Tuple [] |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + let~ units : Ty.path "usize" := + M.alloc (| + M.cast + (Ty.path "usize") + (M.call_closure (| + Ty.path "u8", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::Unit", + "get", + [], + [] + |), + [ M.read (| unit_ |) ] + |)) + |) in + let~ exp10 : + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::Unit", + "wei", + [], + [] + |), + [ M.read (| unit_ |) ] + |) + |) in + M.match_operator (| + Some (Ty.path "alloc::string::String"), + M.deref (| M.read (| self |) |), + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::utils::units::ParseUnits::U256", + 0 + |) in + let amount := M.copy (| γ0_0 |) in + let~ integer : + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 + ] + [] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + M.get_trait_method (| + "core::ops::arith::Div", + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + [], + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ], + "div", + [], + [] + |), + [ M.read (| amount |); M.read (| exp10 |) ] + |) + |) in + let~ decimals : Ty.path "alloc::string::String" := + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_trait_method (| + "alloc::string::ToString", + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + [], + [], + "to_string", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + M.get_trait_method (| + "core::ops::arith::Rem", + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + [], + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ], + "rem", + [], + [] + |), + [ M.read (| amount |); M.read (| exp10 |) ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| + "core::hint::must_use", + [], + [ Ty.path "alloc::string::String" ] + |), + [ + M.read (| + let~ res : Ty.path "alloc::string::String" := + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| "alloc::fmt::format", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1_formatted", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array [ mk_str (| "" |); mk_str (| "." |) ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + integer + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "alloc::string::String" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + decimals + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "from_usize", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, units |) + |) + |) + ] + |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Placeholder", + M.get_associated_function (| + Ty.path "core::fmt::rt::Placeholder", + "new", + [], + [] + |), + [ + Value.Integer IntegerKind.Usize 0; + Value.UnicodeChar 32; + Value.StructTuple + "core::fmt::rt::Alignment::Unknown" + []; + Value.Integer IntegerKind.U32 0; + Value.StructTuple + "core::fmt::rt::Count::Implied" + []; + Value.StructTuple + "core::fmt::rt::Count::Implied" + [] + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Placeholder", + M.get_associated_function (| + Ty.path "core::fmt::rt::Placeholder", + "new", + [], + [] + |), + [ + Value.Integer IntegerKind.Usize 1; + Value.UnicodeChar 48; + Value.StructTuple + "core::fmt::rt::Alignment::Right" + []; + Value.Integer IntegerKind.U32 0; + Value.StructTuple + "core::fmt::rt::Count::Implied" + []; + Value.StructTuple + "core::fmt::rt::Count::Param" + [ Value.Integer IntegerKind.Usize 2 ] + ] + |) + ] + |) + |) + |) + |); + M.call_closure (| + Ty.path "core::fmt::rt::UnsafeArg", + M.get_associated_function (| + Ty.path "core::fmt::rt::UnsafeArg", + "new", + [], + [] + |), + [] + |) + ] + |) + ] + |) + |) in + res + |) + ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::utils::units::ParseUnits::I256", + 0 + |) in + let amount := M.copy (| γ0_0 |) in + let~ exp10 : + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 + ] + [] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + "from_raw", + [], + [] + |), + [ M.read (| exp10 |) ] + |) + |) in + let~ sign : Ty.apply (Ty.path "&") [] [ Ty.path "str" ] := + M.copy (| + M.match_operator (| + Some (Ty.apply (Ty.path "&") [] [ Ty.path "str" ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + "is_negative", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, amount |) ] + |) + |)) in + let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + Value.Bool true + |) in + M.alloc (| mk_str (| "-" |) |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "" |) |) |) + |))) + ] + |) + |) in + let~ integer : + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 + ] + [] := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + "twos_complement", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + M.get_trait_method (| + "core::ops::arith::Div", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ], + "div", + [], + [] + |), + [ M.read (| amount |); M.read (| exp10 |) ] + |) + ] + |) + |) in + let~ decimals : Ty.path "alloc::string::String" := + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_trait_method (| + "alloc::string::ToString", + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + [], + [], + "to_string", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + "twos_complement", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + M.get_trait_method (| + "core::ops::arith::Rem", + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + [], + [ + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ], + "rem", + [], + [] + |), + [ M.read (| amount |); M.read (| exp10 |) ] + |) + ] + |) + |) + |) + ] + |) + |) in + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| + "core::hint::must_use", + [], + [ Ty.path "alloc::string::String" ] + |), + [ + M.read (| + let~ res : Ty.path "alloc::string::String" := + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_function (| "alloc::fmt::format", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_v1_formatted", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + mk_str (| "" |); + mk_str (| "" |); + mk_str (| "." |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.apply + (Ty.path "&") + [] + [ Ty.path "str" ] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, sign |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [] + ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + integer + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "new_display", + [], + [ Ty.path "alloc::string::String" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + decimals + |) + |) + |) + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Argument", + M.get_associated_function (| + Ty.path "core::fmt::rt::Argument", + "from_usize", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| Pointer.Kind.Ref, units |) + |) + |) + ] + |) + ] + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + Value.Array + [ + M.call_closure (| + Ty.path "core::fmt::rt::Placeholder", + M.get_associated_function (| + Ty.path "core::fmt::rt::Placeholder", + "new", + [], + [] + |), + [ + Value.Integer IntegerKind.Usize 0; + Value.UnicodeChar 32; + Value.StructTuple + "core::fmt::rt::Alignment::Unknown" + []; + Value.Integer IntegerKind.U32 0; + Value.StructTuple + "core::fmt::rt::Count::Implied" + []; + Value.StructTuple + "core::fmt::rt::Count::Implied" + [] + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Placeholder", + M.get_associated_function (| + Ty.path "core::fmt::rt::Placeholder", + "new", + [], + [] + |), + [ + Value.Integer IntegerKind.Usize 1; + Value.UnicodeChar 32; + Value.StructTuple + "core::fmt::rt::Alignment::Unknown" + []; + Value.Integer IntegerKind.U32 0; + Value.StructTuple + "core::fmt::rt::Count::Implied" + []; + Value.StructTuple + "core::fmt::rt::Count::Implied" + [] + ] + |); + M.call_closure (| + Ty.path "core::fmt::rt::Placeholder", + M.get_associated_function (| + Ty.path "core::fmt::rt::Placeholder", + "new", + [], + [] + |), + [ + Value.Integer IntegerKind.Usize 2; + Value.UnicodeChar 48; + Value.StructTuple + "core::fmt::rt::Alignment::Right" + []; + Value.Integer IntegerKind.U32 0; + Value.StructTuple + "core::fmt::rt::Count::Implied" + []; + Value.StructTuple + "core::fmt::rt::Count::Param" + [ Value.Integer IntegerKind.Usize 3 ] + ] + |) + ] + |) + |) + |) + |); + M.call_closure (| + Ty.path "core::fmt::rt::UnsafeArg", + M.get_associated_function (| + Ty.path "core::fmt::rt::UnsafeArg", + "new", + [], + [] + |), + [] + |) + ] + |) + ] + |) + |) in + res + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_format_units : + M.IsAssociatedFunction.Trait Self "format_units" format_units. + Admitted. + Global Typeclasses Opaque format_units. + + (* + pub const fn is_signed(&self) -> bool { + matches!(self, Self::I256(_)) + } + *) + Definition is_signed (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some (Ty.path "bool"), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::utils::units::ParseUnits::I256", + 0 + |) in + M.alloc (| Value.Bool true |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Bool false |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_is_signed : + M.IsAssociatedFunction.Trait Self "is_signed" is_signed. + Admitted. + Global Typeclasses Opaque is_signed. + + (* + pub const fn is_unsigned(&self) -> bool { + matches!(self, Self::U256(_)) + } + *) + Definition is_unsigned (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some (Ty.path "bool"), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::utils::units::ParseUnits::U256", + 0 + |) in + M.alloc (| Value.Bool true |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Bool false |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_is_unsigned : + M.IsAssociatedFunction.Trait Self "is_unsigned" is_unsigned. + Admitted. + Global Typeclasses Opaque is_unsigned. + + (* + pub const fn is_negative(&self) -> bool { + match self { + Self::U256(_) => false, + Self::I256(n) => n.is_negative(), + } + } + *) + Definition is_negative (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some (Ty.path "bool"), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::utils::units::ParseUnits::U256", + 0 + |) in + M.alloc (| Value.Bool false |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::utils::units::ParseUnits::I256", + 0 + |) in + let n := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + "is_negative", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| n |) |) |) ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_is_negative : + M.IsAssociatedFunction.Trait Self "is_negative" is_negative. + Admitted. + Global Typeclasses Opaque is_negative. + + (* + pub const fn is_positive(&self) -> bool { + match self { + Self::U256(_) => true, + Self::I256(n) => n.is_positive(), + } + } + *) + Definition is_positive (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some (Ty.path "bool"), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::utils::units::ParseUnits::U256", + 0 + |) in + M.alloc (| Value.Bool true |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::utils::units::ParseUnits::I256", + 0 + |) in + let n := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + "is_positive", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| n |) |) |) ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_is_positive : + M.IsAssociatedFunction.Trait Self "is_positive" is_positive. + Admitted. + Global Typeclasses Opaque is_positive. + + (* + pub fn is_zero(&self) -> bool { + match self { + Self::U256(n) => n.is_zero(), + Self::I256(n) => n.is_zero(), + } + } + *) + Definition is_zero (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some (Ty.path "bool"), + self, + [ + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::utils::units::ParseUnits::U256", + 0 + |) in + let n := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + "is_zero", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| n |) |) |) ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ := M.read (| γ |) in + let γ1_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::utils::units::ParseUnits::I256", + 0 + |) in + let n := M.alloc (| γ1_0 |) in + M.alloc (| + M.call_closure (| + Ty.path "bool", + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + "is_zero", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| n |) |) |) ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_is_zero : + M.IsAssociatedFunction.Trait Self "is_zero" is_zero. + Admitted. + Global Typeclasses Opaque is_zero. + + (* + pub const fn get_absolute(self) -> U256 { + match self { + Self::U256(n) => n, + Self::I256(n) => n.into_raw(), + } + } + *) + Definition get_absolute (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []), + self, + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::utils::units::ParseUnits::U256", + 0 + |) in + let n := M.copy (| γ0_0 |) in + n)); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::utils::units::ParseUnits::I256", + 0 + |) in + let n := M.copy (| γ0_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 + ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + "into_raw", + [], + [] + |), + [ M.read (| n |) ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_get_absolute : + M.IsAssociatedFunction.Trait Self "get_absolute" get_absolute. + Admitted. + Global Typeclasses Opaque get_absolute. + + (* + pub const fn get_signed(self) -> I256 { + match self { + Self::U256(n) => I256::from_raw(n), + Self::I256(n) => n, + } + } + *) + Definition get_signed (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []), + self, + [ + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::utils::units::ParseUnits::U256", + 0 + |) in + let n := M.copy (| γ0_0 |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 + ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "alloy_primitives::signed::int::Signed") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + "from_raw", + [], + [] + |), + [ M.read (| n |) ] + |) + |))); + fun γ => + ltac:(M.monadic + (let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "alloy_primitives::utils::units::ParseUnits::I256", + 0 + |) in + let n := M.copy (| γ0_0 |) in + n)) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_get_signed : + M.IsAssociatedFunction.Trait Self "get_signed" get_signed. + Admitted. + Global Typeclasses Opaque get_signed. + End Impl_alloy_primitives_utils_units_ParseUnits. + + (* StructTuple + { + name := "Unit"; + const_params := []; + ty_params := []; + fields := [ Ty.path "u8" ]; + } *) + + Module Impl_core_clone_Clone_for_alloy_primitives_utils_units_Unit. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::Unit". + + (* Clone *) + Definition clone (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.deref (| M.read (| self |) |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::clone::Clone" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("clone", InstanceField.Method clone) ]. + End Impl_core_clone_Clone_for_alloy_primitives_utils_units_Unit. + + Module Impl_core_marker_Copy_for_alloy_primitives_utils_units_Unit. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::Unit". + + Axiom Implements : + M.IsTraitInstance + "core::marker::Copy" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_Copy_for_alloy_primitives_utils_units_Unit. + + Module Impl_core_fmt_Debug_for_alloy_primitives_utils_units_Unit. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::Unit". + + (* Debug *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_associated_function (| + Ty.path "core::fmt::Formatter", + "debug_tuple_field1_finish", + [], + [] + |), + [ + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |); + M.borrow (| Pointer.Kind.Ref, M.deref (| mk_str (| "Unit" |) |) |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::utils::units::Unit", + 0 + |) + |) + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Debug" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Debug_for_alloy_primitives_utils_units_Unit. + + Module Impl_core_marker_StructuralPartialEq_for_alloy_primitives_utils_units_Unit. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::Unit". + + Axiom Implements : + M.IsTraitInstance + "core::marker::StructuralPartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) []. + End Impl_core_marker_StructuralPartialEq_for_alloy_primitives_utils_units_Unit. + + Module Impl_core_cmp_PartialEq_alloy_primitives_utils_units_Unit_for_alloy_primitives_utils_units_Unit. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::Unit". + + (* PartialEq *) + Definition eq (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + BinOp.eq (| + M.read (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::utils::units::Unit", + 0 + |) + |), + M.read (| + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::utils::units::Unit", + 0 + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialEq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::utils::units::Unit" ] + Self + (* Instance *) [ ("eq", InstanceField.Method eq) ]. + End Impl_core_cmp_PartialEq_alloy_primitives_utils_units_Unit_for_alloy_primitives_utils_units_Unit. + + Module Impl_core_cmp_Eq_for_alloy_primitives_utils_units_Unit. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::Unit". + + (* Eq *) + Definition assert_receiver_is_total_eq + (ε : list Value.t) + (τ : list Ty.t) + (α : list Value.t) + : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + None, + Value.DeclaredButUndefined, + [ fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Eq" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("assert_receiver_is_total_eq", InstanceField.Method assert_receiver_is_total_eq) ]. + End Impl_core_cmp_Eq_for_alloy_primitives_utils_units_Unit. + + Module Impl_core_cmp_PartialOrd_alloy_primitives_utils_units_Unit_for_alloy_primitives_utils_units_Unit. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::Unit". + + (* PartialOrd *) + Definition partial_cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.apply (Ty.path "core::option::Option") [] [ Ty.path "core::cmp::Ordering" ], + M.get_trait_method (| + "core::cmp::PartialOrd", + Ty.path "u8", + [], + [ Ty.path "u8" ], + "partial_cmp", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::utils::units::Unit", + 0 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::utils::units::Unit", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::PartialOrd" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloy_primitives::utils::units::Unit" ] + Self + (* Instance *) [ ("partial_cmp", InstanceField.Method partial_cmp) ]. + End Impl_core_cmp_PartialOrd_alloy_primitives_utils_units_Unit_for_alloy_primitives_utils_units_Unit. + + Module Impl_core_cmp_Ord_for_alloy_primitives_utils_units_Unit. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::Unit". + + (* Ord *) + Definition cmp (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; other ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let other := M.alloc (| other |) in + M.call_closure (| + Ty.path "core::cmp::Ordering", + M.get_trait_method (| "core::cmp::Ord", Ty.path "u8", [], [], "cmp", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| self |) |), + "alloy_primitives::utils::units::Unit", + 0 + |) + |) + |) + |); + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.SubPointer.get_struct_tuple_field (| + M.deref (| M.read (| other |) |), + "alloy_primitives::utils::units::Unit", + 0 + |) + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::cmp::Ord" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("cmp", InstanceField.Method cmp) ]. + End Impl_core_cmp_Ord_for_alloy_primitives_utils_units_Unit. + + Module Impl_core_fmt_Display_for_alloy_primitives_utils_units_Unit. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::Unit". + + (* + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + self.get().fmt(f) + } + *) + Definition fmt (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self; f ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + let f := M.alloc (| f |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ Ty.tuple []; Ty.path "core::fmt::Error" ], + M.get_trait_method (| "core::fmt::Display", Ty.path "u8", [], [], "fmt", [], [] |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "u8", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::Unit", + "get", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |) ] + |) + |) + |); + M.borrow (| Pointer.Kind.MutRef, M.deref (| M.read (| f |) |) |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::fmt::Display" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) [ ("fmt", InstanceField.Method fmt) ]. + End Impl_core_fmt_Display_for_alloy_primitives_utils_units_Unit. + + Module Impl_core_convert_TryFrom_u8_for_alloy_primitives_utils_units_Unit. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::Unit". + + (* type Error = UnitsError; *) + Definition _Error : Ty.t := Ty.path "alloy_primitives::utils::units::UnitsError". + + (* + fn try_from(value: u8) -> Result { + Self::new(value).ok_or_else(|| UnitsError::InvalidUnit(value.to_string())) + } + *) + Definition try_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::utils::units::Unit"; + Ty.path "alloy_primitives::utils::units::UnitsError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "alloy_primitives::utils::units::Unit" ], + "ok_or_else", + [], + [ + Ty.path "alloy_primitives::utils::units::UnitsError"; + Ty.function [ Ty.tuple [] ] (Ty.path "alloy_primitives::utils::units::UnitsError") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "alloy_primitives::utils::units::Unit" ], + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::Unit", + "new", + [], + [] + |), + [ M.read (| value |) ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ Ty.tuple [] ] + (Ty.path "alloy_primitives::utils::units::UnitsError")), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::utils::units::UnitsError::InvalidUnit" + [ + M.call_closure (| + Ty.path "alloc::string::String", + M.get_trait_method (| + "alloc::string::ToString", + Ty.path "u8", + [], + [], + "to_string", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + ])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "u8" ] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("try_from", InstanceField.Method try_from) ]. + End Impl_core_convert_TryFrom_u8_for_alloy_primitives_utils_units_Unit. + + Module Impl_core_convert_TryFrom_alloc_string_String_for_alloy_primitives_utils_units_Unit. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::Unit". + + (* type Error = UnitsError; *) + Definition _Error : Ty.t := Ty.path "alloy_primitives::utils::units::UnitsError". + + (* + fn try_from(value: String) -> Result { + value.parse() + } + *) + Definition try_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::utils::units::Unit"; + Ty.path "alloy_primitives::utils::units::UnitsError" + ], + M.get_associated_function (| + Ty.path "str", + "parse", + [], + [ Ty.path "alloy_primitives::utils::units::Unit" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloc::string::String", + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, value |) ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.path "alloc::string::String" ] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("try_from", InstanceField.Method try_from) ]. + End Impl_core_convert_TryFrom_alloc_string_String_for_alloy_primitives_utils_units_Unit. + + Module Impl_core_convert_TryFrom_ref__alloc_string_String_for_alloy_primitives_utils_units_Unit. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::Unit". + + (* type Error = UnitsError; *) + Definition _Error : Ty.t := Ty.path "alloy_primitives::utils::units::UnitsError". + + (* + fn try_from(value: &'a String) -> Result { + value.parse() + } + *) + Definition try_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::utils::units::Unit"; + Ty.path "alloy_primitives::utils::units::UnitsError" + ], + M.get_associated_function (| + Ty.path "str", + "parse", + [], + [ Ty.path "alloy_primitives::utils::units::Unit" ] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_trait_method (| + "core::ops::deref::Deref", + Ty.path "alloc::string::String", + [], + [], + "deref", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| value |) |) |) ] + |) + |) + |) + ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) + [ Ty.apply (Ty.path "&") [] [ Ty.path "alloc::string::String" ] ] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("try_from", InstanceField.Method try_from) ]. + End Impl_core_convert_TryFrom_ref__alloc_string_String_for_alloy_primitives_utils_units_Unit. + + Module Impl_core_convert_TryFrom_ref__str_for_alloy_primitives_utils_units_Unit. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::Unit". + + (* type Error = UnitsError; *) + Definition _Error : Ty.t := Ty.path "alloy_primitives::utils::units::UnitsError". + + (* + fn try_from(value: &str) -> Result { + value.parse() + } + *) + Definition try_from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ value ] => + ltac:(M.monadic + (let value := M.alloc (| value |) in + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::utils::units::Unit"; + Ty.path "alloy_primitives::utils::units::UnitsError" + ], + M.get_associated_function (| + Ty.path "str", + "parse", + [], + [ Ty.path "alloy_primitives::utils::units::Unit" ] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| value |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::convert::TryFrom" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [ Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ] + Self + (* Instance *) + [ ("Error", InstanceField.Ty _Error); ("try_from", InstanceField.Method try_from) ]. + End Impl_core_convert_TryFrom_ref__str_for_alloy_primitives_utils_units_Unit. + + Module Impl_core_str_traits_FromStr_for_alloy_primitives_utils_units_Unit. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::Unit". + + (* type Err = UnitsError; *) + Definition _Err : Ty.t := Ty.path "alloy_primitives::utils::units::UnitsError". + + (* + fn from_str(s: &str) -> Result { + if let Ok(unit) = crate::U8::from_str(s) { + return Self::new(unit.to()).ok_or_else(|| UnitsError::InvalidUnit(s.to_string())); + } + + Ok(match s.to_ascii_lowercase().as_str() { + "eth" | "ether" => Self::ETHER, + "pwei" | "milli" | "milliether" | "finney" => Self::PWEI, + "twei" | "micro" | "microether" | "szabo" => Self::TWEI, + "gwei" | "nano" | "nanoether" | "shannon" => Self::GWEI, + "mwei" | "pico" | "picoether" | "lovelace" => Self::MWEI, + "kwei" | "femto" | "femtoether" | "babbage" => Self::KWEI, + "wei" => Self::WEI, + _ => return Err(UnitsError::InvalidUnit(s.to_string())), + }) + } + *) + Definition from_str (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ s ] => + ltac:(M.monadic + (let s := M.alloc (| s |) in + M.catch_return (| + ltac:(M.monadic + (M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 1 + ] + []; + Ty.path "ruint::string::ParseError" + ], + M.get_trait_method (| + "core::str::traits::FromStr", + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 1 + ] + [], + [], + [], + "from_str", + [], + [] + |), + [ M.borrow (| Pointer.Kind.Ref, M.deref (| M.read (| s |) |) |) ] + |) + |) in + let γ0_0 := + M.SubPointer.get_struct_tuple_field (| + γ, + "core::result::Result::Ok", + 0 + |) in + let unit_ := M.copy (| γ0_0 |) in + M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + M.call_closure (| + Ty.apply + (Ty.path "core::result::Result") + [] + [ + Ty.path "alloy_primitives::utils::units::Unit"; + Ty.path "alloy_primitives::utils::units::UnitsError" + ], + M.get_associated_function (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "alloy_primitives::utils::units::Unit" ], + "ok_or_else", + [], + [ + Ty.path "alloy_primitives::utils::units::UnitsError"; + Ty.function + [ Ty.tuple [] ] + (Ty.path "alloy_primitives::utils::units::UnitsError") + ] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "alloy_primitives::utils::units::Unit" ], + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::Unit", + "new", + [], + [] + |), + [ + M.call_closure (| + Ty.path "u8", + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 8; + Value.Integer IntegerKind.Usize 1 + ] + [], + "to", + [], + [ Ty.path "u8" ] + |), + [ M.borrow (| Pointer.Kind.Ref, unit_ |) ] + |) + ] + |); + M.closure + (fun γ => + ltac:(M.monadic + match γ with + | [ α0 ] => + ltac:(M.monadic + (M.match_operator (| + Some + (Ty.function + [ Ty.tuple [] ] + (Ty.path + "alloy_primitives::utils::units::UnitsError")), + M.alloc (| α0 |), + [ + fun γ => + ltac:(M.monadic + (Value.StructTuple + "alloy_primitives::utils::units::UnitsError::InvalidUnit" + [ + M.call_closure (| + Ty.path "alloc::string::String", + M.get_trait_method (| + "alloc::string::ToString", + Ty.path "str", + [], + [], + "to_string", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| s |) |) + |) + ] + |) + ])) + ] + |))) + | _ => M.impossible "wrong number of arguments" + end)) + ] + |) + |) + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + Value.StructTuple + "core::result::Result::Ok" + [ + M.read (| + M.match_operator (| + Some (Ty.path "alloy_primitives::utils::units::Unit"), + M.alloc (| + M.call_closure (| + Ty.apply (Ty.path "&") [] [ Ty.path "str" ], + M.get_associated_function (| + Ty.path "alloc::string::String", + "as_str", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| + M.call_closure (| + Ty.path "alloc::string::String", + M.get_associated_function (| + Ty.path "str", + "to_ascii_lowercase", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| s |) |) + |) + ] + |) + |) + |) + ] + |) + |), + [ + fun γ => + ltac:(M.monadic + (M.find_or_pattern (| + γ, + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + mk_str (| "eth" |) + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + mk_str (| "ether" |) + |) in + Value.Tuple [])) + ], + fun γ => + ltac:(M.monadic + match γ with + | [] => + ltac:(M.monadic + (M.get_constant + "alloy_primitives::utils::units::ETHER")) + | _ => M.impossible "wrong number of arguments" + end) + |))); + fun γ => + ltac:(M.monadic + (M.find_or_pattern (| + γ, + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + mk_str (| "pwei" |) + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + mk_str (| "milli" |) + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + mk_str (| "milliether" |) + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + mk_str (| "finney" |) + |) in + Value.Tuple [])) + ], + fun γ => + ltac:(M.monadic + match γ with + | [] => + ltac:(M.monadic + (M.get_constant "alloy_primitives::utils::units::PWEI")) + | _ => M.impossible "wrong number of arguments" + end) + |))); + fun γ => + ltac:(M.monadic + (M.find_or_pattern (| + γ, + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + mk_str (| "twei" |) + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + mk_str (| "micro" |) + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + mk_str (| "microether" |) + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + mk_str (| "szabo" |) + |) in + Value.Tuple [])) + ], + fun γ => + ltac:(M.monadic + match γ with + | [] => + ltac:(M.monadic + (M.get_constant "alloy_primitives::utils::units::TWEI")) + | _ => M.impossible "wrong number of arguments" + end) + |))); + fun γ => + ltac:(M.monadic + (M.find_or_pattern (| + γ, + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + mk_str (| "gwei" |) + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + mk_str (| "nano" |) + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + mk_str (| "nanoether" |) + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + mk_str (| "shannon" |) + |) in + Value.Tuple [])) + ], + fun γ => + ltac:(M.monadic + match γ with + | [] => + ltac:(M.monadic + (M.get_constant "alloy_primitives::utils::units::GWEI")) + | _ => M.impossible "wrong number of arguments" + end) + |))); + fun γ => + ltac:(M.monadic + (M.find_or_pattern (| + γ, + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + mk_str (| "mwei" |) + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + mk_str (| "pico" |) + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + mk_str (| "picoether" |) + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + mk_str (| "lovelace" |) + |) in + Value.Tuple [])) + ], + fun γ => + ltac:(M.monadic + match γ with + | [] => + ltac:(M.monadic + (M.get_constant "alloy_primitives::utils::units::MWEI")) + | _ => M.impossible "wrong number of arguments" + end) + |))); + fun γ => + ltac:(M.monadic + (M.find_or_pattern (| + γ, + [ + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + mk_str (| "kwei" |) + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + mk_str (| "femto" |) + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + mk_str (| "femtoether" |) + |) in + Value.Tuple [])); + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + mk_str (| "babbage" |) + |) in + Value.Tuple [])) + ], + fun γ => + ltac:(M.monadic + match γ with + | [] => + ltac:(M.monadic + (M.get_constant "alloy_primitives::utils::units::KWEI")) + | _ => M.impossible "wrong number of arguments" + end) + |))); + fun γ => + ltac:(M.monadic + (let _ := + M.is_constant_or_break_match (| + M.read (| γ |), + mk_str (| "wei" |) + |) in + M.get_constant "alloy_primitives::utils::units::WEI")); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.never_to_any (| + M.read (| + M.return_ (| + Value.StructTuple + "core::result::Result::Err" + [ + Value.StructTuple + "alloy_primitives::utils::units::UnitsError::InvalidUnit" + [ + M.call_closure (| + Ty.path "alloc::string::String", + M.get_trait_method (| + "alloc::string::ToString", + Ty.path "str", + [], + [], + "to_string", + [], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| M.read (| s |) |) + |) + ] + |) + ] + ] + |) + |) + |) + |))) + ] + |) + |) + ] + |) + |))) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Axiom Implements : + M.IsTraitInstance + "core::str::traits::FromStr" + (* Trait polymorphic consts *) [] + (* Trait polymorphic types *) [] + Self + (* Instance *) + [ ("Err", InstanceField.Ty _Err); ("from_str", InstanceField.Method from_str) ]. + End Impl_core_str_traits_FromStr_for_alloy_primitives_utils_units_Unit. + + Module Impl_alloy_primitives_utils_units_Unit. + Definition Self : Ty.t := Ty.path "alloy_primitives::utils::units::Unit". + + (* pub const WEI: Self = unsafe { Self::new_unchecked(0) }; *) + (* Ty.path "alloy_primitives::utils::units::Unit" *) + Definition value_WEI : Value.t := + M.run + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::utils::units::Unit", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::Unit", + "new_unchecked", + [], + [] + |), + [ Value.Integer IntegerKind.U8 0 ] + |) + |))). + + Global Instance AssociatedConstant_value_WEI : + M.IsAssociatedConstant.Trait Self "value_WEI" value_WEI. + Admitted. + Global Typeclasses Opaque value_WEI. + + (* pub const Wei: Self = Self::WEI; *) + (* Ty.path "alloy_primitives::utils::units::Unit" *) + Definition value_Wei : Value.t := + M.run ltac:(M.monadic (M.get_constant "alloy_primitives::utils::units::WEI")). + + Global Instance AssociatedConstant_value_Wei : + M.IsAssociatedConstant.Trait Self "value_Wei" value_Wei. + Admitted. + Global Typeclasses Opaque value_Wei. + + (* pub const KWEI: Self = unsafe { Self::new_unchecked(3) }; *) + (* Ty.path "alloy_primitives::utils::units::Unit" *) + Definition value_KWEI : Value.t := + M.run + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::utils::units::Unit", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::Unit", + "new_unchecked", + [], + [] + |), + [ Value.Integer IntegerKind.U8 3 ] + |) + |))). + + Global Instance AssociatedConstant_value_KWEI : + M.IsAssociatedConstant.Trait Self "value_KWEI" value_KWEI. + Admitted. + Global Typeclasses Opaque value_KWEI. + + (* pub const Kwei: Self = Self::KWEI; *) + (* Ty.path "alloy_primitives::utils::units::Unit" *) + Definition value_Kwei : Value.t := + M.run ltac:(M.monadic (M.get_constant "alloy_primitives::utils::units::KWEI")). + + Global Instance AssociatedConstant_value_Kwei : + M.IsAssociatedConstant.Trait Self "value_Kwei" value_Kwei. + Admitted. + Global Typeclasses Opaque value_Kwei. + + (* pub const MWEI: Self = unsafe { Self::new_unchecked(6) }; *) + (* Ty.path "alloy_primitives::utils::units::Unit" *) + Definition value_MWEI : Value.t := + M.run + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::utils::units::Unit", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::Unit", + "new_unchecked", + [], + [] + |), + [ Value.Integer IntegerKind.U8 6 ] + |) + |))). + + Global Instance AssociatedConstant_value_MWEI : + M.IsAssociatedConstant.Trait Self "value_MWEI" value_MWEI. + Admitted. + Global Typeclasses Opaque value_MWEI. + + (* pub const Mwei: Self = Self::MWEI; *) + (* Ty.path "alloy_primitives::utils::units::Unit" *) + Definition value_Mwei : Value.t := + M.run ltac:(M.monadic (M.get_constant "alloy_primitives::utils::units::MWEI")). + + Global Instance AssociatedConstant_value_Mwei : + M.IsAssociatedConstant.Trait Self "value_Mwei" value_Mwei. + Admitted. + Global Typeclasses Opaque value_Mwei. + + (* pub const GWEI: Self = unsafe { Self::new_unchecked(9) }; *) + (* Ty.path "alloy_primitives::utils::units::Unit" *) + Definition value_GWEI : Value.t := + M.run + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::utils::units::Unit", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::Unit", + "new_unchecked", + [], + [] + |), + [ Value.Integer IntegerKind.U8 9 ] + |) + |))). + + Global Instance AssociatedConstant_value_GWEI : + M.IsAssociatedConstant.Trait Self "value_GWEI" value_GWEI. + Admitted. + Global Typeclasses Opaque value_GWEI. + + (* pub const Gwei: Self = Self::GWEI; *) + (* Ty.path "alloy_primitives::utils::units::Unit" *) + Definition value_Gwei : Value.t := + M.run ltac:(M.monadic (M.get_constant "alloy_primitives::utils::units::GWEI")). + + Global Instance AssociatedConstant_value_Gwei : + M.IsAssociatedConstant.Trait Self "value_Gwei" value_Gwei. + Admitted. + Global Typeclasses Opaque value_Gwei. + + (* pub const TWEI: Self = unsafe { Self::new_unchecked(12) }; *) + (* Ty.path "alloy_primitives::utils::units::Unit" *) + Definition value_TWEI : Value.t := + M.run + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::utils::units::Unit", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::Unit", + "new_unchecked", + [], + [] + |), + [ Value.Integer IntegerKind.U8 12 ] + |) + |))). + + Global Instance AssociatedConstant_value_TWEI : + M.IsAssociatedConstant.Trait Self "value_TWEI" value_TWEI. + Admitted. + Global Typeclasses Opaque value_TWEI. + + (* pub const Twei: Self = Self::TWEI; *) + (* Ty.path "alloy_primitives::utils::units::Unit" *) + Definition value_Twei : Value.t := + M.run ltac:(M.monadic (M.get_constant "alloy_primitives::utils::units::TWEI")). + + Global Instance AssociatedConstant_value_Twei : + M.IsAssociatedConstant.Trait Self "value_Twei" value_Twei. + Admitted. + Global Typeclasses Opaque value_Twei. + + (* pub const PWEI: Self = unsafe { Self::new_unchecked(15) }; *) + (* Ty.path "alloy_primitives::utils::units::Unit" *) + Definition value_PWEI : Value.t := + M.run + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::utils::units::Unit", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::Unit", + "new_unchecked", + [], + [] + |), + [ Value.Integer IntegerKind.U8 15 ] + |) + |))). + + Global Instance AssociatedConstant_value_PWEI : + M.IsAssociatedConstant.Trait Self "value_PWEI" value_PWEI. + Admitted. + Global Typeclasses Opaque value_PWEI. + + (* pub const Pwei: Self = Self::PWEI; *) + (* Ty.path "alloy_primitives::utils::units::Unit" *) + Definition value_Pwei : Value.t := + M.run ltac:(M.monadic (M.get_constant "alloy_primitives::utils::units::PWEI")). + + Global Instance AssociatedConstant_value_Pwei : + M.IsAssociatedConstant.Trait Self "value_Pwei" value_Pwei. + Admitted. + Global Typeclasses Opaque value_Pwei. + + (* pub const ETHER: Self = unsafe { Self::new_unchecked(18) }; *) + (* Ty.path "alloy_primitives::utils::units::Unit" *) + Definition value_ETHER : Value.t := + M.run + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::utils::units::Unit", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::Unit", + "new_unchecked", + [], + [] + |), + [ Value.Integer IntegerKind.U8 18 ] + |) + |))). + + Global Instance AssociatedConstant_value_ETHER : + M.IsAssociatedConstant.Trait Self "value_ETHER" value_ETHER. + Admitted. + Global Typeclasses Opaque value_ETHER. + + (* pub const Ether: Self = Self::ETHER; *) + (* Ty.path "alloy_primitives::utils::units::Unit" *) + Definition value_Ether : Value.t := + M.run ltac:(M.monadic (M.get_constant "alloy_primitives::utils::units::ETHER")). + + Global Instance AssociatedConstant_value_Ether : + M.IsAssociatedConstant.Trait Self "value_Ether" value_Ether. + Admitted. + Global Typeclasses Opaque value_Ether. + + (* pub const MIN: Self = Self::WEI; *) + (* Ty.path "alloy_primitives::utils::units::Unit" *) + Definition value_MIN : Value.t := + M.run ltac:(M.monadic (M.get_constant "alloy_primitives::utils::units::WEI")). + + Global Instance AssociatedConstant_value_MIN : + M.IsAssociatedConstant.Trait Self "value_MIN" value_MIN. + Admitted. + Global Typeclasses Opaque value_MIN. + + (* pub const MAX: Self = unsafe { Self::new_unchecked(77) }; *) + (* Ty.path "alloy_primitives::utils::units::Unit" *) + Definition value_MAX : Value.t := + M.run + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.path "alloy_primitives::utils::units::Unit", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::Unit", + "new_unchecked", + [], + [] + |), + [ Value.Integer IntegerKind.U8 77 ] + |) + |))). + + Global Instance AssociatedConstant_value_MAX : + M.IsAssociatedConstant.Trait Self "value_MAX" value_MAX. + Admitted. + Global Typeclasses Opaque value_MAX. + + (* + pub const fn new(units: u8) -> Option { + if units <= Self::MAX.get() { + // SAFETY: `units` is contained in the valid range. + Some(unsafe { Self::new_unchecked(units) }) + } else { + None + } + } + *) + Definition new (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ units ] => + ltac:(M.monadic + (let units := M.alloc (| units |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "core::option::Option") + [] + [ Ty.path "alloy_primitives::utils::units::Unit" ]), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.le (| + M.read (| units |), + M.call_closure (| + Ty.path "u8", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::Unit", + "get", + [], + [] + |), + [ M.read (| M.get_constant "alloy_primitives::utils::units::MAX" |) + ] + |) + |) + |)) in + let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + Value.StructTuple + "core::option::Option::Some" + [ + M.call_closure (| + Ty.path "alloy_primitives::utils::units::Unit", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::Unit", + "new_unchecked", + [], + [] + |), + [ M.read (| units |) ] + |) + ] + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| Value.StructTuple "core::option::Option::None" [] |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new : M.IsAssociatedFunction.Trait Self "new" new. + Admitted. + Global Typeclasses Opaque new. + + (* + pub const unsafe fn new_unchecked(x: u8) -> Self { + Self(x) + } + *) + Definition new_unchecked (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ x ] => + ltac:(M.monadic + (let x := M.alloc (| x |) in + Value.StructTuple "alloy_primitives::utils::units::Unit" [ M.read (| x |) ])) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_new_unchecked : + M.IsAssociatedFunction.Trait Self "new_unchecked" new_unchecked. + Admitted. + Global Typeclasses Opaque new_unchecked. + + (* + pub fn wei(self) -> U256 { + if self.get() <= MAX_U64_EXPONENT { + self.wei_const() + } else { + U256::from(10u8).pow(U256::from(self.get())) + } + } + *) + Definition wei (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.match_operator (| + Some + (Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.le (| + M.call_closure (| + Ty.path "u8", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::Unit", + "get", + [], + [] + |), + [ M.read (| self |) ] + |), + M.read (| + M.get_constant "alloy_primitives::utils::units::MAX_U64_EXPONENT" + |) + |) + |)) in + let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 + ] + [], + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::Unit", + "wei_const", + [], + [] + |), + [ M.read (| self |) ] + |) + |))); + fun γ => + ltac:(M.monadic + (M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 + ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + "pow", + [], + [] + |), + [ + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + "from", + [], + [ Ty.path "u8" ] + |), + [ Value.Integer IntegerKind.U8 10 ] + |); + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ + Value.Integer IntegerKind.Usize 256; + Value.Integer IntegerKind.Usize 4 + ] + [], + "from", + [], + [ Ty.path "u8" ] + |), + [ + M.call_closure (| + Ty.path "u8", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::Unit", + "get", + [], + [] + |), + [ M.read (| self |) ] + |) + ] + |) + ] + |) + |))) + ] + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_wei : M.IsAssociatedFunction.Trait Self "wei" wei. + Admitted. + Global Typeclasses Opaque wei. + + (* + pub const fn wei_const(self) -> U256 { + if self.get() > MAX_U64_EXPONENT { + panic!("overflow") + } + U256::from_limbs([10u64.pow(self.get() as u32), 0, 0, 0]) + } + *) + Definition wei_const (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + let~ _ : Ty.tuple [] := + M.match_operator (| + Some (Ty.tuple []), + M.alloc (| Value.Tuple [] |), + [ + fun γ => + ltac:(M.monadic + (let γ := + M.use + (M.alloc (| + BinOp.gt (| + M.call_closure (| + Ty.path "u8", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::Unit", + "get", + [], + [] + |), + [ M.read (| self |) ] + |), + M.read (| + M.get_constant "alloy_primitives::utils::units::MAX_U64_EXPONENT" + |) + |) + |)) in + let _ := + M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in + M.alloc (| + M.never_to_any (| + M.call_closure (| + Ty.path "never", + M.get_function (| "core::panicking::panic_fmt", [], [] |), + [ + M.call_closure (| + Ty.path "core::fmt::Arguments", + M.get_associated_function (| + Ty.path "core::fmt::Arguments", + "new_const", + [ Value.Integer IntegerKind.Usize 1 ], + [] + |), + [ + M.borrow (| + Pointer.Kind.Ref, + M.deref (| + M.borrow (| + Pointer.Kind.Ref, + M.alloc (| Value.Array [ mk_str (| "overflow" |) ] |) + |) + |) + |) + ] + |) + ] + |) + |) + |))); + fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |))) + ] + |) in + M.alloc (| + M.call_closure (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + M.get_associated_function (| + Ty.apply + (Ty.path "ruint::Uint") + [ Value.Integer IntegerKind.Usize 256; Value.Integer IntegerKind.Usize 4 ] + [], + "from_limbs", + [], + [] + |), + [ + Value.Array + [ + M.call_closure (| + Ty.path "u64", + M.get_associated_function (| Ty.path "u64", "pow", [], [] |), + [ + Value.Integer IntegerKind.U64 10; + M.cast + (Ty.path "u32") + (M.call_closure (| + Ty.path "u8", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::Unit", + "get", + [], + [] + |), + [ M.read (| self |) ] + |)) + ] + |); + Value.Integer IntegerKind.U64 0; + Value.Integer IntegerKind.U64 0; + Value.Integer IntegerKind.U64 0 + ] + ] + |) + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_wei_const : + M.IsAssociatedFunction.Trait Self "wei_const" wei_const. + Admitted. + Global Typeclasses Opaque wei_const. + + (* + pub const fn get(self) -> u8 { + self.0 + } + *) + Definition get (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.read (| + M.SubPointer.get_struct_tuple_field (| + self, + "alloy_primitives::utils::units::Unit", + 0 + |) + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_get : M.IsAssociatedFunction.Trait Self "get" get. + Admitted. + Global Typeclasses Opaque get. + + (* + pub const fn as_num(&self) -> u8 { + self.get() + } + *) + Definition as_num (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M := + match ε, τ, α with + | [], [], [ self ] => + ltac:(M.monadic + (let self := M.alloc (| self |) in + M.call_closure (| + Ty.path "u8", + M.get_associated_function (| + Ty.path "alloy_primitives::utils::units::Unit", + "get", + [], + [] + |), + [ M.read (| M.deref (| M.read (| self |) |) |) ] + |))) + | _, _, _ => M.impossible "wrong number of arguments" + end. + + Global Instance AssociatedFunction_as_num : M.IsAssociatedFunction.Trait Self "as_num" as_num. + Admitted. + Global Typeclasses Opaque as_num. + End Impl_alloy_primitives_utils_units_Unit. + End units. +End utils. diff --git a/CoqOfRust/core/num/links/mod.v b/CoqOfRust/core/num/links/mod.v index d814f5e79..a446bef0d 100644 --- a/CoqOfRust/core/num/links/mod.v +++ b/CoqOfRust/core/num/links/mod.v @@ -7,11 +7,7 @@ Require Import core.links.intrinsics. Module Impl_u64. Definition Self : Set := U64.t. - (* - pub const fn saturating_add(self, rhs: Self) -> Self { - intrinsics::saturating_add(self, rhs) - } - *) + (* pub const fn saturating_add(self, rhs: Self) -> Self *) Instance run_saturating_add (self rhs: Self) : Run.Trait num.Impl_u64.saturating_add [] [] [ φ self; φ rhs ] Self. Proof. @@ -30,3 +26,26 @@ Module Impl_u64. Proof. Admitted. End Impl_u64. + +Module Impl_usize. + Definition Self : Set := Usize.t. + + (* pub const fn saturating_add(self, rhs: Self) -> Self *) + Instance run_saturating_add (self rhs: Self) : + Run.Trait num.Impl_usize.saturating_add [] [] [ φ self; φ rhs ] Self. + Proof. + constructor. + run_symbolic. + Defined. + + Instance run_saturating_mul (self rhs: Self) : + Run.Trait num.Impl_usize.saturating_mul [] [] [ φ self; φ rhs ] Self. + Proof. + Admitted. + + (* pub const fn overflowing_sub(self, rhs: Self) -> (Self, bool) *) + Instance run_overflowing_sub (self rhs: Self) : + Run.Trait num.Impl_usize.overflowing_sub [] [] [ φ self; φ rhs ] (Self * bool). + Proof. + Admitted. +End Impl_usize. diff --git a/CoqOfRust/core/slice/links/mod.v b/CoqOfRust/core/slice/links/mod.v index cd712aa76..f45367f87 100644 --- a/CoqOfRust/core/slice/links/mod.v +++ b/CoqOfRust/core/slice/links/mod.v @@ -12,11 +12,8 @@ Module Impl_Slice. pub fn get(&self, index: I) -> Option<&I::Output> where I: SliceIndex, - { - index.get(self) - } *) - Instance run_get + Instance run_get (T : Set) `{Link T} {I : Set} `{Link I} {Output : Set} `{Link Output} @@ -42,4 +39,12 @@ Module Impl_Slice. Run.Trait (slice.Impl_slice_T.get_unchecked_mut (Φ T)) [] [Φ I] [φ self; φ index] (Ref.t Pointer.Kind.MutRef Output). Admitted. + + (* pub const fn len(&self) -> usize *) + Instance run_len + (T : Set) `{Link T} + (self : Ref.t Pointer.Kind.Ref (Self T)) : + Run.Trait (slice.Impl_slice_T.len (Φ T)) [] [] [φ self] + Usize.t. + Admitted. End Impl_Slice. diff --git a/CoqOfRust/revm/revm_interpreter/gas/links/calc.v b/CoqOfRust/revm/revm_interpreter/gas/links/calc.v index ccf6f22fe..cc7629eda 100644 --- a/CoqOfRust/revm/revm_interpreter/gas/links/calc.v +++ b/CoqOfRust/revm/revm_interpreter/gas/links/calc.v @@ -2,29 +2,45 @@ Require Import CoqOfRust.CoqOfRust. Require Import CoqOfRust.links.M. Require Import core.num.mod. Require Import core.num.links.mod. +Require Import revm.links.dependencies. +Require Import revm.revm_context_interface.links.host. +Require Import revm.revm_context_interface.links.journaled_state. +Require Import revm.revm_interpreter.gas.links.constants. +Require Import revm.revm_interpreter.gas.calc. Require Import revm_specification.links.hardfork. -Require Import CoqOfRust.revm.links.dependencies. -Require revm_interpreter.gas.links.constants. -Require Import revm_interpreter.gas.calc. Import Impl_u64. -(* -pub const fn memory_gas(num_words: usize) -> u64 { - let num_words = num_words as u64; - MEMORY - .saturating_mul(num_words) - .saturating_add(num_words.saturating_mul(num_words) / 512) -} -*) -Instance run_memory_gas (num_words: Usize.t) : +(* pub fn sstore_refund(spec_id: SpecId, vals: &SStoreResult) -> i64 *) +Instance run_sstore_refund + (spec_id : SpecId.t) + (vals : Ref.t Pointer.Kind.Ref SStoreResult.t) : Run.Trait - gas.calc.memory_gas [] [] [ φ num_words ] + gas.calc.sstore_refund [] [] [ φ spec_id; φ vals ] + I64.t. +Proof. + constructor. +Admitted. + +(* pub const fn create2_cost(len: usize) -> Option *) +Instance run_create2_cost (len : Usize.t) : + Run.Trait + gas.calc.create2_cost [] [] [ φ len ] + (option U64.t). +Proof. + constructor. + run_symbolic. +Admitted. + +(* pub const fn log2floor(value: U256) -> u64 *) +Instance run_log2floor (value : U256.t) : + Run.Trait + gas.calc.log2floor [] [] [ φ value ] U64.t. Proof. constructor. run_symbolic. -Defined. +Admitted. (* pub fn exp_cost(spec_id: SpecId, power: U256) -> Option *) Instance run_exp_cost (spec_id : SpecId.t) (power : U256.t) : @@ -34,6 +50,203 @@ Instance run_exp_cost (spec_id : SpecId.t) (power : U256.t) : Proof. constructor. run_symbolic. - (* NOTE: Should I finish the proof? *) Admitted. -(* Defined. *) + +(* pub const fn copy_cost_verylow(len: usize) -> Option *) +Instance run_copy_cost_verylow (len : Usize.t) : + Run.Trait + gas.calc.copy_cost_verylow [] [] [ φ len ] + (option U64.t). +Proof. + constructor. + run_symbolic. +Admitted. + +(* pub const fn extcodecopy_cost( + spec_id: SpecId, + len: usize, + load: Eip7702CodeLoad<()>, +) -> Option *) +Instance run_extcodecopy_cost + (spec_id : SpecId.t) + (len : Usize.t) + (load : Eip7702CodeLoad.t unit) : + Run.Trait + gas.calc.extcodecopy_cost [] [] [ φ spec_id; φ len; φ load ] + (option U64.t). +Proof. + constructor. + run_symbolic. +Admitted. + +(* pub const fn copy_cost(base_cost: u64, len: usize) -> Option *) +Instance run_copy_cost (base_cost : U64.t) (len : Usize.t) : + Run.Trait + gas.calc.copy_cost [] [] [ φ base_cost; φ len ] + (option U64.t). +Proof. + constructor. + run_symbolic. +Admitted. + +(* pub const fn log_cost(n: u8, len: u64) -> Option *) +Instance run_log_cost (n : U8.t) (len : U64.t) : + Run.Trait + gas.calc.log_cost [] [] [ φ n; φ len ] + (option U64.t). +Proof. + constructor. + run_symbolic. +Admitted. + +(* pub const fn keccak256_cost(len: usize) -> Option *) +Instance run_keccak256_cost (len : Usize.t) : + Run.Trait + gas.calc.keccak256_cost [] [] [ φ len ] + (option U64.t). +Proof. + constructor. + run_symbolic. +Admitted. + +(* pub const fn cost_per_word(len: usize, multiple: u64) -> Option *) +Instance run_cost_per_word (len : Usize.t) (multiple : U64.t) : + Run.Trait + gas.calc.cost_per_word [] [] [ φ len; φ multiple ] + (option U64.t). +Proof. + constructor. + run_symbolic. +Admitted. + +(* pub const fn initcode_cost(len: usize) -> u64 *) +Instance run_initcode_cost (len : Usize.t) : + Run.Trait + gas.calc.initcode_cost [] [] [ φ len ] + U64.t. +Proof. + constructor. + run_symbolic. +Admitted. + +(* pub const fn sload_cost(spec_id: SpecId, is_cold: bool) -> u64 *) +Instance run_sload_cost (spec_id : SpecId.t) (is_cold : bool) : + Run.Trait + gas.calc.sload_cost [] [] [ φ spec_id; φ is_cold ] + U64.t. +Proof. + constructor. + run_symbolic. +Admitted. + +(* pub fn sstore_cost(spec_id: SpecId, vals: &SStoreResult, is_cold: bool) -> u64 *) +Instance run_sstore_cost + (spec_id : SpecId.t) + (vals : Ref.t Pointer.Kind.Ref SStoreResult.t) + (is_cold : bool) : + Run.Trait + gas.calc.sstore_cost [] [] [ φ spec_id; φ vals; φ is_cold ] + U64.t. +Proof. + constructor. + run_symbolic. +Admitted. + +(* pub const fn istanbul_sstore_cost( + vals: &SStoreResult, +) -> u64 *) +Instance run_istanbul_sstore_cost (vals : Ref.t Pointer.Kind.Ref SStoreResult.t) : + Run.Trait + gas.calc.istanbul_sstore_cost [] [] [ φ vals ] + U64.t. +Proof. + constructor. + run_symbolic. +Admitted. + +(* pub const fn frontier_sstore_cost(vals: &SStoreResult) -> u64 *) +Instance run_frontier_sstore_cost (vals : Ref.t Pointer.Kind.Ref SStoreResult.t) : + Run.Trait + gas.calc.frontier_sstore_cost [] [] [ φ vals ] + U64.t. +Proof. + constructor. + run_symbolic. +Admitted. + +(* pub const fn selfdestruct_cost(spec_id: SpecId, res: StateLoad) -> u64 *) +Instance run_selfdestruct_cost + (spec_id : SpecId.t) + (res : Ref.t Pointer.Kind.Ref SelfDestructResult.t) : + Run.Trait + gas.calc.selfdestruct_cost [] [] [ φ spec_id; φ res ] + U64.t. +Proof. + constructor. + run_symbolic. +Admitted. + +(* pub const fn call_cost(spec_id: SpecId, transfers_value: bool, account_load: AccountLoad) -> u64 *) +Instance run_call_cost + (spec_id : SpecId.t) + (transfers_value : bool) + (account_load : AccountLoad.t) : + Run.Trait + gas.calc.call_cost [] [] [ φ spec_id; φ transfers_value; φ account_load ] + U64.t. +Proof. + constructor. + run_symbolic. +Admitted. + +(* pub const fn warm_cold_cost(is_cold: bool) -> u64 *) +Instance run_warm_cold_cost (is_cold : bool) : + Run.Trait + gas.calc.warm_cold_cost [] [] [ φ is_cold ] + U64.t. +Proof. + constructor. + run_symbolic. +Admitted. + +(* pub const fn warm_cold_cost_with_delegation(load: Eip7702CodeLoad<()>) -> u64 *) +Instance run_warm_cold_cost_with_delegation (load : Eip7702CodeLoad.t unit) : + Run.Trait + gas.calc.warm_cold_cost_with_delegation [] [] [ φ load ] + U64.t. +Proof. + constructor. + run_symbolic. +Admitted. + +(* pub const fn memory_gas(num_words: usize) -> u64 *) +Instance run_memory_gas (num_words : Usize.t) : + Run.Trait + gas.calc.memory_gas [] [] [ φ num_words ] + U64.t. +Proof. + constructor. + run_symbolic. +Defined. + +(* pub fn validate_initial_tx_gas( + spec_id: SpecId, + input: &[u8], + is_create: bool, + access_list: Option<&AccessListT>, + authorization_list_num: u64, +) -> u64 *) +Instance run_validate_initial_tx_gas + {AccessListT : Set} `{Link AccessListT} + (spec_id : SpecId.t) + (input : Ref.t Pointer.Kind.Ref (list U8.t)) + (is_create : bool) + (access_list : option (Ref.t Pointer.Kind.Ref AccessListT)) + (authorization_list_num : U64.t) : + Run.Trait + gas.calc.validate_initial_tx_gas [] [ Φ AccessListT ] + [ φ spec_id; φ input; φ is_create; φ access_list; φ authorization_list_num ] + U64.t. +Proof. + constructor. +Admitted. diff --git a/CoqOfRust/revm/revm_interpreter/instructions/links/progress_on_links.md b/CoqOfRust/revm/revm_interpreter/instructions/links/progress_on_links.md index 7217d8320..74de13ee3 100644 --- a/CoqOfRust/revm/revm_interpreter/instructions/links/progress_on_links.md +++ b/CoqOfRust/revm/revm_interpreter/instructions/links/progress_on_links.md @@ -105,13 +105,13 @@ ## Stack -- ❌ `pop` +- ✅ `pop` - ❌ `push0` - ❌ `push` - ❌ `dup` - ❌ `swap` -- ❌ `dupn` -- ❌ `swapn` +- ✅ `dupn` +- ✅ `swapn` - ❌ `exchange` ## System @@ -122,14 +122,14 @@ - ❌ `codesize` - ❌ `codecopy` - ❌ `calldataload` -- ❌ `calldatasize` -- ❌ `callvalue` +- ✅ `calldatasize` +- ✅ `callvalue` +- ❌ `memory_resize` - ❌ `calldatacopy` - ❌ `returndatasize` - ❌ `returndatacopy` - ❌ `returndataload` - ❌ `gas` -- ❌ `memory_resize` ## Tx_info @@ -144,6 +144,6 @@ ## Summary - Total: 103 -- Admitted: 86 -- Defined: 17 -- Percentage: 16.50% +- Admitted: 81 +- Defined: 22 +- Percentage: 21.36% diff --git a/CoqOfRust/revm/revm_interpreter/instructions/links/stack.v b/CoqOfRust/revm/revm_interpreter/instructions/links/stack.v index d5c717dca..0efe85d31 100644 --- a/CoqOfRust/revm/revm_interpreter/instructions/links/stack.v +++ b/CoqOfRust/revm/revm_interpreter/instructions/links/stack.v @@ -2,9 +2,15 @@ Require Import CoqOfRust.CoqOfRust. Require Import CoqOfRust.links.M. Require Import core.links.cmp. Require Import revm.links.dependencies. +Require Import revm.revm_interpreter.instructions.links.utility. Require Import revm.revm_interpreter.instructions.stack. +Require Import revm.revm_interpreter.links.gas. Require Import revm.revm_interpreter.links.interpreter. Require Import revm.revm_interpreter.links.interpreter_types. +Require Import revm.revm_specification.links.hardfork. + +Import Impl_Gas. +Import Impl_SpecId. (* pub fn pop( @@ -23,8 +29,16 @@ Instance run_pop unit. Proof. constructor. + cbn. + eapply Run.Rewrite. { + progress repeat erewrite IsTraitAssociatedType_eq by apply run_InterpreterTypes_for_WIRE. + reflexivity. + } + destruct run_InterpreterTypes_for_WIRE. + destruct run_LoopControl_for_Control. + destruct run_StackTrait_for_Stack. run_symbolic. -Admitted. +Defined. (* pub fn push0( @@ -43,7 +57,17 @@ Instance run_push0 unit. Proof. constructor. + cbn. + eapply Run.Rewrite. { + progress repeat erewrite IsTraitAssociatedType_eq by apply run_InterpreterTypes_for_WIRE. + reflexivity. + } + destruct run_InterpreterTypes_for_WIRE. + destruct run_LoopControl_for_Control. + destruct run_StackTrait_for_Stack. + destruct run_RuntimeFlag_for_RuntimeFlag. run_symbolic. + (* Constant ruint::ZERO *) Admitted. @@ -54,17 +78,29 @@ pub fn push( ) *) Instance run_push + (N : Usize.t) {WIRE H : Set} `{Link WIRE} `{Link H} {WIRE_types : InterpreterTypes.Types.t} `{InterpreterTypes.Types.AreLinks WIRE_types} (run_InterpreterTypes_for_WIRE : InterpreterTypes.Run WIRE WIRE_types) (interpreter : Ref.t Pointer.Kind.MutRef (Interpreter.t WIRE WIRE_types)) (_host : Ref.t Pointer.Kind.MutRef H) : Run.Trait - instructions.stack.push [] [ Φ WIRE; Φ H ] [ φ interpreter; φ _host ] + instructions.stack.push [ φ N ] [ Φ WIRE; Φ H ] [ φ interpreter; φ _host ] unit. Proof. constructor. + cbn. + eapply Run.Rewrite. { + progress repeat erewrite IsTraitAssociatedType_eq by apply run_InterpreterTypes_for_WIRE. + reflexivity. + } + destruct run_InterpreterTypes_for_WIRE. + destruct run_LoopControl_for_Control. + destruct run_StackTrait_for_Stack. + destruct run_Jumps_for_Bytecode. + destruct run_Immediates_for_Bytecode. run_symbolic. + (* Constant ruint::ZERO *) Admitted. @@ -75,17 +111,27 @@ pub fn dup( ) *) Instance run_dup + (N : Usize.t) {WIRE H : Set} `{Link WIRE} `{Link H} {WIRE_types : InterpreterTypes.Types.t} `{InterpreterTypes.Types.AreLinks WIRE_types} (run_InterpreterTypes_for_WIRE : InterpreterTypes.Run WIRE WIRE_types) (interpreter : Ref.t Pointer.Kind.MutRef (Interpreter.t WIRE WIRE_types)) (_host : Ref.t Pointer.Kind.MutRef H) : Run.Trait - instructions.stack.dup [] [ Φ WIRE; Φ H ] [ φ interpreter; φ _host ] + instructions.stack.dup [ φ N ] [ Φ WIRE; Φ H ] [ φ interpreter; φ _host ] unit. Proof. constructor. + cbn. + eapply Run.Rewrite. { + progress repeat erewrite IsTraitAssociatedType_eq by apply run_InterpreterTypes_for_WIRE. + reflexivity. + } + destruct run_InterpreterTypes_for_WIRE. + destruct run_LoopControl_for_Control. + destruct run_StackTrait_for_Stack. run_symbolic. + (* Constant N *) Admitted. (* @@ -95,17 +141,27 @@ pub fn swap( ) *) Instance run_swap + (N : Usize.t) {WIRE H : Set} `{Link WIRE} `{Link H} {WIRE_types : InterpreterTypes.Types.t} `{InterpreterTypes.Types.AreLinks WIRE_types} (run_InterpreterTypes_for_WIRE : InterpreterTypes.Run WIRE WIRE_types) (interpreter : Ref.t Pointer.Kind.MutRef (Interpreter.t WIRE WIRE_types)) (_host : Ref.t Pointer.Kind.MutRef H) : Run.Trait - instructions.stack.swap [] [ Φ WIRE; Φ H ] [ φ interpreter; φ _host ] + instructions.stack.swap [ φ N ] [ Φ WIRE; Φ H ] [ φ interpreter; φ _host ] unit. Proof. constructor. + cbn. + eapply Run.Rewrite. { + progress repeat erewrite IsTraitAssociatedType_eq by apply run_InterpreterTypes_for_WIRE. + reflexivity. + } + destruct run_InterpreterTypes_for_WIRE. + destruct run_LoopControl_for_Control. + destruct run_StackTrait_for_Stack. run_symbolic. + (* Constant N *) Admitted. (* @@ -125,8 +181,19 @@ Instance run_dupn unit. Proof. constructor. + cbn. + eapply Run.Rewrite. { + progress repeat erewrite IsTraitAssociatedType_eq by apply run_InterpreterTypes_for_WIRE. + reflexivity. + } + destruct run_InterpreterTypes_for_WIRE. + destruct run_LoopControl_for_Control. + destruct run_StackTrait_for_Stack. + destruct run_RuntimeFlag_for_RuntimeFlag. + destruct run_Jumps_for_Bytecode. + destruct run_Immediates_for_Bytecode. run_symbolic. -Admitted. +Defined. (* pub fn swapn( @@ -145,8 +212,19 @@ Instance run_swapn unit. Proof. constructor. + cbn. + eapply Run.Rewrite. { + progress repeat erewrite IsTraitAssociatedType_eq by apply run_InterpreterTypes_for_WIRE. + reflexivity. + } + destruct run_InterpreterTypes_for_WIRE. + destruct run_LoopControl_for_Control. + destruct run_StackTrait_for_Stack. + destruct run_RuntimeFlag_for_RuntimeFlag. + destruct run_Jumps_for_Bytecode. + destruct run_Immediates_for_Bytecode. run_symbolic. -Admitted. +Defined. (* pub fn exchange( @@ -165,5 +243,17 @@ Instance run_exchange unit. Proof. constructor. + cbn. + eapply Run.Rewrite. { + progress repeat erewrite IsTraitAssociatedType_eq by apply run_InterpreterTypes_for_WIRE. + reflexivity. + } + destruct run_InterpreterTypes_for_WIRE. + destruct run_LoopControl_for_Control. + destruct run_StackTrait_for_Stack. + destruct run_RuntimeFlag_for_RuntimeFlag. + destruct run_Jumps_for_Bytecode. + destruct run_Immediates_for_Bytecode. run_symbolic. + (* Bin ops shr and bit_and *) Admitted. diff --git a/CoqOfRust/revm/revm_interpreter/instructions/links/system.v b/CoqOfRust/revm/revm_interpreter/instructions/links/system.v index f85888430..b00d83d0e 100644 --- a/CoqOfRust/revm/revm_interpreter/instructions/links/system.v +++ b/CoqOfRust/revm/revm_interpreter/instructions/links/system.v @@ -1,10 +1,40 @@ Require Import CoqOfRust.CoqOfRust. Require Import CoqOfRust.links.M. Require Import core.links.cmp. +Require Import core.num.links.mod. +Require Import core.slice.links.mod. Require Import revm.links.dependencies. +Require Import revm.revm_interpreter.gas.links.calc. Require Import revm.revm_interpreter.instructions.system. +Require Import revm.revm_interpreter.interpreter.links.shared_memory. +Require Import revm.revm_interpreter.links.gas. Require Import revm.revm_interpreter.links.interpreter. Require Import revm.revm_interpreter.links.interpreter_types. +Require Import revm.revm_primitives.links.lib. +Require Import ruint.links.from. + +Import Impl_Slice. +Import Impl_Gas. +Import from.Impl_Uint. +Import lib.Impl_Uint. +Import Impl_usize. + +Ltac destruct_run_InterpreterTypes := + cbn; + eapply Run.Rewrite; [ + progress repeat erewrite IsTraitAssociatedType_eq + by match goal with + | H : InterpreterTypes.Run _ _ |- _ => apply H + end; + reflexivity + |]; + progress repeat match goal with + | H : InterpreterTypes.Run _ _ |- _ => destruct H + | H : StackTrait.Run _ |- _ => destruct H + | H : LoopControl.Run _ |- _ => destruct H + | H : InputsTrait.Run _ |- _ => destruct H + | H : MemoryTrait.Run _ |- _ => destruct H + end. (* pub fn keccak256( @@ -23,10 +53,10 @@ Instance run_keccak256 unit. Proof. constructor. + destruct_run_InterpreterTypes. run_symbolic. Admitted. - (* pub fn address( interpreter: &mut Interpreter, @@ -44,6 +74,7 @@ Instance run_address unit. Proof. constructor. + destruct_run_InterpreterTypes. run_symbolic. Admitted. @@ -144,8 +175,9 @@ Instance run_calldatasize unit. Proof. constructor. + destruct_run_InterpreterTypes. run_symbolic. -Admitted. +Defined. (* pub fn callvalue( @@ -164,6 +196,30 @@ Instance run_callvalue unit. Proof. constructor. + destruct_run_InterpreterTypes. + run_symbolic. +Defined. + +(* +pub fn memory_resize( + interpreter: &mut Interpreter, + memory_offset: U256, + len: usize, +) -> Option +*) +Instance run_memory_resize + {WIRE : Set} `{Link WIRE} + {WIRE_types : InterpreterTypes.Types.t} `{InterpreterTypes.Types.AreLinks WIRE_types} + (run_InterpreterTypes_for_WIRE : InterpreterTypes.Run WIRE WIRE_types) + (interpreter : Ref.t Pointer.Kind.MutRef (Interpreter.t WIRE WIRE_types)) + (memory_offset : U256.t) + (len : Usize.t) : + Run.Trait + instructions.system.memory_resize [] [ Φ WIRE ] [ φ interpreter; φ memory_offset; φ len ] + (option Usize.t). +Proof. + constructor. + destruct run_InterpreterTypes_for_WIRE. run_symbolic. Admitted. @@ -184,6 +240,7 @@ Instance run_calldatacopy unit. Proof. constructor. + destruct_run_InterpreterTypes. run_symbolic. Admitted. @@ -266,24 +323,3 @@ Proof. constructor. run_symbolic. Admitted. - -(* -pub fn memory_resize( - interpreter: &mut Interpreter, - memory_offset: U256, - len: usize, -) -> Option -*) -Instance run_memory_resize - {WIRE H : Set} `{Link WIRE} `{Link H} - {WIRE_types : InterpreterTypes.Types.t} `{InterpreterTypes.Types.AreLinks WIRE_types} - (run_InterpreterTypes_for_WIRE : InterpreterTypes.Run WIRE WIRE_types) - (interpreter : Ref.t Pointer.Kind.MutRef (Interpreter.t WIRE WIRE_types)) - (_host : Ref.t Pointer.Kind.MutRef H) : - Run.Trait - instructions.system.memory_resize [] [ Φ WIRE; Φ H ] [ φ interpreter; φ _host ] - unit. -Proof. - constructor. - run_symbolic. -Admitted. diff --git a/CoqOfRust/revm/revm_interpreter/interpreter/links/shared_memory.v b/CoqOfRust/revm/revm_interpreter/interpreter/links/shared_memory.v index 3ce862ac4..d4de77c3f 100644 --- a/CoqOfRust/revm/revm_interpreter/interpreter/links/shared_memory.v +++ b/CoqOfRust/revm/revm_interpreter/interpreter/links/shared_memory.v @@ -2,26 +2,18 @@ Require Import CoqOfRust.CoqOfRust. Require Import CoqOfRust.links.M. Require Import alloc.links.alloc. Require Import alloc.vec.links.mod. -Require Import CoqOfRust.core.links.option. -Require Import CoqOfRust.core.links.array. +Require Import core.links.array. +Require Import core.links.option. +Require Import core.num.links.mod. +Require Import revm_interpreter.interpreter.shared_memory. + +Import Impl_usize. (* - /// A sequential memory shared between calls, which uses - /// a `Vec` for internal representation. - /// A [SharedMemory] instance should always be obtained using - /// the `new` static method to ensure memory safety. - #[derive(Clone, PartialEq, Eq, Hash)] - #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct SharedMemory { - /// The underlying buffer. buffer: Vec, - /// Memory checkpoints for each depth. - /// Invariant: these are always in bounds of `data`. checkpoints: Vec, - /// Invariant: equals `self.checkpoints.last()` last_checkpoint: usize, - /// Memory limit. See [`CfgEnv`](revm_primitives::CfgEnv). - #[cfg(feature = "memory_limit")] memory_limit: u64, } *) @@ -44,3 +36,13 @@ Module SharedMemory. ]; }. End SharedMemory. + +(* pub const fn num_words(len: usize) -> usize *) +Instance run_num_words (len : Usize.t) : + Run.Trait + interpreter.shared_memory.num_words [] [] [ φ len ] + Usize.t. +Proof. + constructor. + run_symbolic. +Defined. diff --git a/CoqOfRust/revm/revm_interpreter/links/interpreter_types.v b/CoqOfRust/revm/revm_interpreter/links/interpreter_types.v index 5285add5b..4e72416b7 100644 --- a/CoqOfRust/revm/revm_interpreter/links/interpreter_types.v +++ b/CoqOfRust/revm/revm_interpreter/links/interpreter_types.v @@ -108,6 +108,7 @@ Module StackTrait. top : Run_top Self; pop : Run_pop Self; pop_address : Run_pop_address Self; + exchange : Run_exchange Self; dup : Run_dup Self; }. End StackTrait. diff --git a/CoqOfRust/revm/revm_primitives/links/lib.v b/CoqOfRust/revm/revm_primitives/links/lib.v new file mode 100644 index 000000000..908b4d2c7 --- /dev/null +++ b/CoqOfRust/revm/revm_primitives/links/lib.v @@ -0,0 +1,12 @@ +(* Generated *) +Require Import CoqOfRust.CoqOfRust. +Require Import CoqOfRust.links.M. +Require Import revm.revm_primitives.lib. + +Lemma KECCAK_EMPTY_eq : + M.get_constant "revm_primitives::KECCAK_EMPTY" = + φ (Ref.immediate Pointer.Kind.Raw (Integer.Build_t IntegerKind.U64 0)). +Proof. + repeat (autorewrite with constant_rewrites || cbn). +Admitted. +Global Hint Rewrite KECCAK_EMPTY_eq : run_constant. diff --git a/CoqOfRust/ruint/links/lib.v b/CoqOfRust/ruint/links/lib.v index 0e2bf972f..78ef4ad94 100644 --- a/CoqOfRust/ruint/links/lib.v +++ b/CoqOfRust/ruint/links/lib.v @@ -1,5 +1,7 @@ Require Import CoqOfRust.CoqOfRust. Require Import CoqOfRust.links.M. +Require Import core.links.array. +Require Import ruint.lib. Module Uint. Parameter t : Usize.t -> Usize.t -> Set. @@ -29,4 +31,16 @@ Module Impl_Uint. Proof. Admitted. Global Hint Rewrite ZERO_eq : run_constant. + + (* pub const fn as_limbs(&self) -> &[u64; LIMBS] *) + Instance run_as_limbs + (BITS LIMBS : Usize.t) + (self : Ref.t Pointer.Kind.Ref (Uint.t BITS LIMBS)) : + Run.Trait + (Impl_ruint_Uint_BITS_LIMBS.as_limbs (φ BITS) (φ LIMBS)) [] [] [ φ self ] + (Ref.t Pointer.Kind.Ref (array.t U64.t LIMBS)). + Proof. + constructor. + run_symbolic. + Admitted. End Impl_Uint. diff --git a/third-party/alloy-rs-core b/third-party/alloy-rs-core new file mode 160000 index 000000000..732b6c511 --- /dev/null +++ b/third-party/alloy-rs-core @@ -0,0 +1 @@ +Subproject commit 732b6c51193e63d96756ccfb3d27cf2cf3abae94