Giter Site home page Giter Site logo

alloy-rs / core Goto Github PK

View Code? Open in Web Editor NEW
748.0 748.0 124.0 2.71 MB

High-performance, well-tested & documented core libraries for Ethereum, in Rust

Home Page: https://alloy.rs

License: Apache License 2.0

Rust 93.39% Shell 0.05% C 0.92% Solidity 5.64%
blockchain ethereum evm rust solidity

core's People

Contributors

andyrobert3 avatar bernard-wagner avatar blombern avatar cool-mestorf avatar danipopes avatar emperororokusaki avatar evalir avatar gakonst avatar huyhduong1401 avatar jafar75 avatar klkvr avatar kpp avatar mattsse avatar michprev avatar mouseless-eth avatar niansol avatar onbjerg avatar prestwich avatar quentinv72 avatar rachel-bousfield avatar rkrasiuk avatar rodrigoherrerai avatar rongyi avatar shawnharmsen avatar supernovahs avatar tcoratger avatar will-smith11 avatar wollac avatar yash-atreya avatar zerosnacks avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

core's Issues

Incorrect size expression when expanding arrays containing dynamic types

type_data_size multiples array length by inner_size, which will incorrectly calculate lengths and incorrectly inner_size expressions.

https://github.com/alloy-rs/core/blob/main/crates/sol-macro/src/expand/type.rs#L159-L179

blocker for #85

current behavior:

    struct Foo {
        address[] baz;
    }

    /// Nested struct.
    struct Nested {
        Foo[2] a;
    }

produces code like this:

            0usize
                + 2usize * (0usize + 32usize + 64usize + self.a.baz.len() * (32usize))

correct behavior:

            0usize
                + self.a.iter().map( |element| /* inner size expression for element */ ).sum::<usize>()

2 incorrect things:

  • assumes all array elements of Foo.a are the same size
  • because there's no iteration, it does not index `self.a[0].baz.len()'

both of these would be resolved using an iter in the expansion

[Bug] Cant decode Solidity calls to functions with no arguments

Component

sol! macro

What version of Alloy are you on?

v0.2.0

Operating System

Linux

Describe the bug

I think the problem is related to deposit taking in no arguments.

use alloy_sol_types::{sol, SolCall};

sol! {
    interface WETH {
        function deposit() external payable;
    }
}

fn main() {
    WETH::depositCall::decode(&WETH::depositCall::SELECTOR, true).expect("it should work");
}

Add `Address` to primitives

  • Add address to primitives
    • parsing w/ and w/o checksum
    • hexification w/ and w/o checksum
  • Update ABI crates to use Address instead of B160

[Bug] update type_system.md

Component

No response

What version of Alloy are you on?

No response

Operating System

None

Describe the bug

No response

[Feature] Add a borrowed `JsonAbi`

Component

json-abi

Describe the feature you would like

Add a borrowed version of all json-abi types, which implement ToOwned. Ideally methods are implemented only once, with the owned version implementing Deref towards the borrowed type, but this might not be fully doable.

This might also allow declaring the entire ABI as a const/static by setting the lifetime to 'static.

Additional context

Refs: #136

Pre-publication TODOs

Blockers

  • License review
  • #13
  • Finalize crate names
  • #14
  • Docs review
  • #29
  • port any upstream (reth) rlp changes
  • #30
  • #32
  • depend on main ruint
  • rename crates to final names below

pre-pub actions

  • grab names on crates.io

pub

  • release ethers-rlp to crates.io

Post pub

  • #12
  • ethers-rlp support in official ruint
  • migrate to official ruint (blocks primitives publishing)

Add `ParamKind` to json-abi `{,Event}Param`

currently the type field is unparsed, while ethabi users expect a parsed ParamKind enum. This would also remove the intermediate enum between the {Simple,Complex} structs

Support generating `sol!` from ABI JSON

Needs #72.

  • Add inner attributes to File
    • Parse #[sol(...)] attributes, maybe #![sol(include = "path/to/abi.json")]
  • Parse included JSON string as dynamic JSON ABI
  • Generate a Solidity interface string
  • Parse Solidity interface string into a TokenStream, and call sol

Support Fallback and Receive as special functions in sol-types

          I think this can be done in another PR, since we don't handle any type of function (constructor, fallback...) other than literally `function`

Originally posted by @DaniPopes in #153 (comment)

Similar to the way error & panic are included in the base lib, we should consider including fallback and receive as hard-coded types. This requires special handling, as they have no selector

Consider: should we introduce a borrow abstraction for sol type encodable

          > But we're cloning the data to get the inner tuple, so this is not ideal

I'm gonna think about this a bit more. what do you think of this:

trait SolType {

    type BorrowAbstraction: From<Self::RustType>;

    fn encode<T: Into<Self::BorrowAbstraction>>(t: T)

}

pub enum TupleBorrowAbstraction<'t, 'u, T, U> {
    Owned((T,U)),
    Borrowed(&'t (T, U)),
    MembersBorrowed((&'t T, &'u U))
}

// From impls here

Originally posted by @prestwich in #83 (comment)

[Feature] Convenient way to decode a contract error

Component

sol-type, sol! macro

Describe the feature you would like

Currently we generate a ContractErrors enum, which is fine for custom errors but cannot be used to also decode Solidity panics and reverts.
We should provide some way to easily decode all of the above in one method

Additional context

No response

[Bug] (U)Int tokenization broken for types with odd bit lengths

Component

sol-type

What version of Alloy are you on?

No response

Operating System

macOS (Apple Silicon)

Describe the bug

(de)Tokenization logic does not properly handle ints whose length is different from the rust type's length. causes panic in the copy_from_slice in the macro

    #[test]
    fn tokenizing_int_sizes() {
        Uint::<24>::tokenize(&1u32);

        let word: [u8; 32] = (0..32).collect::<Vec<u8>>().try_into().unwrap();
        let word: WordToken = word.into();

        assert_eq!(Uint::<24>::detokenize(word), 126495);
    }```

Improve `dyn-abi` encoding performance

Benchmark from #57, as of commit 64bf519:

ethabi/encode/single    time:   [82.202 ns 82.358 ns 82.525 ns]                                 
ethabi/encode/struct    time:   [164.10 ns 165.43 ns 166.85 ns]                                 

ethabi/decode/word      time:   [34.678 ns 34.765 ns 34.861 ns]                                
ethabi/decode/dynamic   time:   [78.638 ns 78.759 ns 78.910 ns]                                  

dyn-abi/encode/single   time:   [68.373 ns 68.550 ns 68.741 ns]                                  
dyn-abi/encode/struct   time:   [683.96 ns 684.70 ns 685.52 ns]                                   

dyn-abi/decode/word     time:   [54.141 ns 54.203 ns 54.266 ns]                                
dyn-abi/decode/dynamic  time:   [80.822 ns 80.932 ns 81.053 ns]                                   

sol-types/encode/single time:   [42.843 ns 43.007 ns 43.207 ns]                                     
sol-types/encode/struct time:   [49.110 ns 49.171 ns 49.235 ns]                                    

sol-types/decode/word   time:   [1.3375 ns 1.3389 ns 1.3405 ns]                                   
sol-types/decode/dynamic                                                                             
                        time:   [39.279 ns 39.478 ns 39.721 ns]

Maybe we can skip tokenizing by encoding directly the DynSolValue? Looking at the "struct" bench, ethabi is much more concise because of ethabi::encode(tokens: &[ethabi::Token]), while dyn-abi has to declare all the types, and then also clone the input on each call.

Originally posted by @DaniPopes in #57 (comment)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.