Git Product home page Git Product logo

Comments (3)

drlecks avatar drlecks commented on August 11, 2024

Hi, thanks for the feedback!

First in EncodeInput, it will always put tuple's content at the end of currently constructed data block using $input->hash. For non-dynamic parameters it should be put in-place as far as i understand the specs so that's the first error which will prevent correctly encoding some tuples.

Check the $round parameter on EncodeInput(). Static types ignore round=2 and attach the encoded value directly on first round, as you say.

In EncodeGroup
$currentDynamicIndex = count($inputs) * self::NUM_ZEROS / 2;
This is probably not correct as well as single tuple can have several non-dynamic fields only, eg. 3 UINTs, so the assumption that first dynamic 32b data block starts at position which is just a number of inputs is not always correct (we need to process all tuples before we know first dynamic block number).

Yes, you are right. One of the latest commits fixes the same issue, but on the "decode" process.

Throught experimentation, we saw that a tuple with only static attribute types behave like a static type itself. So, it's not encoded using a offset index, it just encodes all its parameters in place. I haven't been able to find any docs with info about this "feature"... If you find it, I will be pleased to check it and make sure our code adjusts to the docs.

August is complicated... But I'll update it as soon as possible.

Make sure you are on main branch for most recent changes.

from simple-web3-php.

slawomir-pryczek avatar slawomir-pryczek commented on August 11, 2024

Hey, thanks for the message... for decoding yes seems to work 100% correct. As for first point i think there's an issue with this code (the issue is here only for tuple)

else if ($varType == VariableType::Tuple) {
  $input->hash =  self::EncodeGroup($input->components, $inputData);

  $res =  '';
  if (self::ExistsDynamicParameter($input->components)) {
	$res = self::EncodeInput_UInt($currentDynamicIndex); 
  }
                 
  return $res;

So what i think it does is it'll always put the tuple content as last data in the block ( $input->hash ). If content is dynamic it'll also put an offset in-place.

It should work this way (i think)

$res = self::EncodeGroup($input->components, $inputData);
				
				// if the tuple is dynamic, we return offset and add tuple's data at the end
				if (self::ExistsDynamicParameter($input->components)) {
					$input->hash = $res;
					return self::EncodeInput_UInt($currentDynamicIndex);
				}
				return $res;

So for static it'll return $res in-place, and for dynamic it'll return offset and put data in input->hash to be added in phase 2.

Throught experimentation, we saw that a tuple with only static attribute types behave like a static type itself.

Yes, correct... if all attribs are static the tuple is treated as static type. Attached the structure desc at the bottom...

Will prepare a fix and submit tomorrow i think, need to test it more wanted to make sure it won't break other things but it seems ok, just need to encode/decode more contract parameters, unless there's some test suite...

                (
                    [0] => Array
                        (
                            [internalType] => address[]
                            [name] => path
                            [type] => address[]
                        )

                    [1] => Array
                        (
                            [internalType] => string[]
                            [name] => poolVersion
                            [type] => string[]
                        )

                    [2] => Array
                        (
                            [internalType] => uint256[]
                            [name] => versionLen
                            [type] => uint256[]
                        )

                    [3] => Array
                        (
                            [internalType] => uint24[]
                            [name] => fees
                            [type] => uint24[]
                        )

                    [4] => Array
                        (
                            [components] => Array
                                (
                                    [0] => Array
                                        (
                                            [internalType] => uint256
                                            [name] => amountIn
                                            [type] => uint256
                                        )

                                    [1] => Array
                                        (
                                            [internalType] => uint256
                                            [name] => amountOutMin
                                            [type] => uint256
                                        )

                                    [2] => Array
                                        (
                                            [internalType] => address
                                            [name] => to
                                            [type] => address
                                        )

                                    [3] => Array
                                        (
                                            [internalType] => uint256
                                            [name] => deadline
                                            [type] => uint256
                                        )

                                )

                            [internalType] => struct SmartExchangeRouter.SwapData
                            [name] => data
                            [type] => tuple
                        )

                )```


from simple-web3-php.

slawomir-pryczek avatar slawomir-pryczek commented on August 11, 2024

#39

from simple-web3-php.

Related Issues (20)

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.