Git Product home page Git Product logo

Comments (2)

sleepfinance avatar sleepfinance commented on September 15, 2024

Ignore my squabbles, I was able to make it work. i will make. pull request after Im done with everything. I noticed you are treating fixed size arrays as variable size array. In the spec the fixed size arrays are treated as Tuples and have no need to prefix the the encoded length. Modifying the Encode Input function to encode a fixed size array as a tuple fixes this problem, look below.

 private static function EncodeInput($input, $inputData, $round, &$currentDynamicIndex)
    {
        $hash = "";

        if ($round == 1) {
            $input_type = is_string($input) ? $input : $input->type;
            $varType = self::GetParameterType($input_type);

            //dynamic
            if (Utils::string_contains($input->type, '[]')) {
                $input->hash =  self::EncodeInput_Array($input, $inputData);
                $res = self::EncodeInput_UInt($currentDynamicIndex);
                return $res;
            } else if (preg_match_all('/\[(\d+)\]/', $input->type, $matches)) {
                $typeStr = str_replace($matches[0], "", $input->type);
                $type = (object)['type' => $typeStr];
                $inferredType = array_fill(0, (int)$matches[1][0], $type);
                $res = self::EncodeGroup($inferredType, $inputData);
                return $res;
            } else if ($varType == VariableType::Tuple) {
                $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;
            } else if ($varType == VariableType::String) {
                $input->hash = self::EncodeInput_String($inputData);
                $res = self::EncodeInput_UInt($currentDynamicIndex);
                return $res;
            } else if ($varType == VariableType::Bytes) {
                $input->hash = self::EncodeInput_Bytes($inputData);
                $res = self::EncodeInput_UInt($currentDynamicIndex);
                return $res;
            }
            //static
            else if ($varType == VariableType::UInt) {
                return self::EncodeInput_UInt($inputData);
            } else if ($varType == VariableType::Int) {
                return self::EncodeInput_Int($inputData);
            } else if ($varType == VariableType::Bool) {
                return self::EncodeInput_Bool($inputData);
            } else if ($varType == VariableType::Address) {
                return self::EncodeInput_Address($inputData);
            } else if ($varType == VariableType::BytesFixed) {
                return self::EncodeInput_BytesFixed($inputData);
            }
        } else if ($round == 2) {
            if (isset($input->hash) and $input->hash != '') {
                return $input->hash;
            }
        }

        return  $hash;
    }
```php

from simple-web3-php.

drlecks avatar drlecks commented on September 15, 2024

Sorry for the delay.

Yes, I was handling static types & static length while decoding, but not on encoding.

I added the same logic to check array mode on Encoding operations.

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.