Skip to main content
Notice removed Draw attention by Ismael
Bounty Ended with Payam Safaei's answer chosen by Ismael
Notice added Draw attention by Ismael
Bounty Started worth 100 reputation by Ismael
added 4 characters in body
Source Link
Emrah
  • 1.7k
  • 2
  • 11
  • 27

I am experimenting the ecmul opcode (inside the EccMul function) where I can multiply the given generator with the given number.

pragma solidity ^0.8.0;

contract TestEccMul {
   
    struct G1Point {
        uint X;
        uint Y;
    }

    struct G2Point {
        uint[2] X;
        uint[2] Y;
    }

    /// @return the generator of G1
    function P1() public pure returns (G1Point memory) {
        return G1Point(1, 2);
    }
    
    /// @return the generator of G2
    function P2() public pure returns (G2Point memory) {
        return G2Point(
            [535000198726010842494463887012728317008839985956991949449597676023059784793,
            50911955057697873758342946860545764866265758828426205386527214348449976128083],

            [34456506622601912613857833514763279459301076221556609925761869949091594580415,
            8211078999328499834214571830542910221251497399640112479758011117184688730247]
        );
        
    }

    function EccMul(uint s) public view returns (G1Point memory r) {
        uint[3] memory input;
        input[0] = P1().X;
        input[1] = P1().Y;
        input[2] = s;

        assembly {
            if iszero (staticcall(gas(), 0x07, input, 0x60, r, 0x40)) {
                revert (0,0)
            }
        }
        return r;
    }
}

The code perfectly works with the given generator (where g1 = (1,2) ); however, EVM reverts when I change the generator to any other coordinates. Why is this the case? Whats the point of this if I can't use other generators then the one defined in EIP-197. Am I missing something?

I am experimenting the ecmul opcode (inside EccMul function) where I can multiply the given generator with the given number.

pragma solidity ^0.8.0;

contract TestEccMul {
   
    struct G1Point {
        uint X;
        uint Y;
    }

    struct G2Point {
        uint[2] X;
        uint[2] Y;
    }

    /// @return the generator of G1
    function P1() public pure returns (G1Point memory) {
        return G1Point(1, 2);
    }
    
    /// @return the generator of G2
    function P2() public pure returns (G2Point memory) {
        return G2Point(
            [535000198726010842494463887012728317008839985956991949449597676023059784793,
            50911955057697873758342946860545764866265758828426205386527214348449976128083],

            [34456506622601912613857833514763279459301076221556609925761869949091594580415,
            8211078999328499834214571830542910221251497399640112479758011117184688730247]
        );
        
    }

    function EccMul(uint s) public view returns (G1Point memory r) {
        uint[3] memory input;
        input[0] = P1().X;
        input[1] = P1().Y;
        input[2] = s;

        assembly {
            if iszero (staticcall(gas(), 0x07, input, 0x60, r, 0x40)) {
                revert (0,0)
            }
        }
        return r;
    }
}

The code perfectly works with the given generator (where g1 = (1,2) ); however, EVM reverts when I change the generator to any other coordinates. Why is this the case? Whats the point of this if I can't use other generators then the one defined in EIP-197. Am I missing something?

I am experimenting the ecmul opcode (inside the EccMul function) where I can multiply the given generator with the given number.

pragma solidity ^0.8.0;

contract TestEccMul {
   
    struct G1Point {
        uint X;
        uint Y;
    }

    struct G2Point {
        uint[2] X;
        uint[2] Y;
    }

    /// @return the generator of G1
    function P1() public pure returns (G1Point memory) {
        return G1Point(1, 2);
    }
    
    /// @return the generator of G2
    function P2() public pure returns (G2Point memory) {
        return G2Point(
            [535000198726010842494463887012728317008839985956991949449597676023059784793,
            50911955057697873758342946860545764866265758828426205386527214348449976128083],

            [34456506622601912613857833514763279459301076221556609925761869949091594580415,
            8211078999328499834214571830542910221251497399640112479758011117184688730247]
        );
        
    }

    function EccMul(uint s) public view returns (G1Point memory r) {
        uint[3] memory input;
        input[0] = P1().X;
        input[1] = P1().Y;
        input[2] = s;

        assembly {
            if iszero (staticcall(gas(), 0x07, input, 0x60, r, 0x40)) {
                revert (0,0)
            }
        }
        return r;
    }
}

The code perfectly works with the given generator (where g1 = (1,2) ); however, EVM reverts when I change the generator to any other coordinates. Why is this the case? Whats the point of this if I can't use other generators then the one defined in EIP-197. Am I missing something?

added 9 characters in body
Source Link
Emrah
  • 1.7k
  • 2
  • 11
  • 27

I am experimenting the ecmul opcode (inside EccMul function) where I can multiply the given generator with the given number.

pragma solidity ^0.8.0;

contract TestEccMul {
   
    struct G1Point {
        uint X;
        uint Y;
    }

    struct G2Point {
        uint[2] X;
        uint[2] Y;
    }

    /// @return the generator of G1
    function P1() public pure returns (G1Point memory) {
        return G1Point(1, 2);
    }
    
    /// @return the generator of G2
    function P2() public pure returns (G2Point memory) {
        return G2Point(
            [535000198726010842494463887012728317008839985956991949449597676023059784793,
            50911955057697873758342946860545764866265758828426205386527214348449976128083],

            [34456506622601912613857833514763279459301076221556609925761869949091594580415,
            8211078999328499834214571830542910221251497399640112479758011117184688730247]
        );
        
    }

    function EccMul(uint s) public view returns (G1Point memory r) {
        uint[3] memory input;
        input[0] = P1().X;
        input[1] = P1().Y;
        input[2] = s;

        assembly {
            if iszero (staticcall(gas(), 0x07, input, 0x60, r, 0x40)) {
                revert (0,0)
            }
        }
        return r;
    }
}

The code perfectly works with the given generator (where g1 = (1,2) ); however, EVM reverts when I change the generator to any other coordinates. Why is this the case? Whats the point of this if I can't use other generators then the one defined in EIP-197. Am I missing something?

I am experimenting the ecmul opcode (inside EccMul) where I can multiply the given generator with the given number.

pragma solidity ^0.8.0;

contract TestEccMul {
   
    struct G1Point {
        uint X;
        uint Y;
    }

    struct G2Point {
        uint[2] X;
        uint[2] Y;
    }

    /// @return the generator of G1
    function P1() public pure returns (G1Point memory) {
        return G1Point(1, 2);
    }
    
    /// @return the generator of G2
    function P2() public pure returns (G2Point memory) {
        return G2Point(
            [535000198726010842494463887012728317008839985956991949449597676023059784793,
            50911955057697873758342946860545764866265758828426205386527214348449976128083],

            [34456506622601912613857833514763279459301076221556609925761869949091594580415,
            8211078999328499834214571830542910221251497399640112479758011117184688730247]
        );
        
    }

    function EccMul(uint s) public view returns (G1Point memory r) {
        uint[3] memory input;
        input[0] = P1().X;
        input[1] = P1().Y;
        input[2] = s;

        assembly {
            if iszero (staticcall(gas(), 0x07, input, 0x60, r, 0x40)) {
                revert (0,0)
            }
        }
        return r;
    }
}

The code perfectly works with the given generator (where g1 = (1,2) ); however, EVM reverts when I change the generator to any other coordinates. Why is this the case? Whats the point of this if I can't use other generators then the one defined in EIP-197. Am I missing something?

I am experimenting the ecmul opcode (inside EccMul function) where I can multiply the given generator with the given number.

pragma solidity ^0.8.0;

contract TestEccMul {
   
    struct G1Point {
        uint X;
        uint Y;
    }

    struct G2Point {
        uint[2] X;
        uint[2] Y;
    }

    /// @return the generator of G1
    function P1() public pure returns (G1Point memory) {
        return G1Point(1, 2);
    }
    
    /// @return the generator of G2
    function P2() public pure returns (G2Point memory) {
        return G2Point(
            [535000198726010842494463887012728317008839985956991949449597676023059784793,
            50911955057697873758342946860545764866265758828426205386527214348449976128083],

            [34456506622601912613857833514763279459301076221556609925761869949091594580415,
            8211078999328499834214571830542910221251497399640112479758011117184688730247]
        );
        
    }

    function EccMul(uint s) public view returns (G1Point memory r) {
        uint[3] memory input;
        input[0] = P1().X;
        input[1] = P1().Y;
        input[2] = s;

        assembly {
            if iszero (staticcall(gas(), 0x07, input, 0x60, r, 0x40)) {
                revert (0,0)
            }
        }
        return r;
    }
}

The code perfectly works with the given generator (where g1 = (1,2) ); however, EVM reverts when I change the generator to any other coordinates. Why is this the case? Whats the point of this if I can't use other generators then the one defined in EIP-197. Am I missing something?

Source Link
Emrah
  • 1.7k
  • 2
  • 11
  • 27

Pre-compiled contract - ecmul

I am experimenting the ecmul opcode (inside EccMul) where I can multiply the given generator with the given number.

pragma solidity ^0.8.0;

contract TestEccMul {
   
    struct G1Point {
        uint X;
        uint Y;
    }

    struct G2Point {
        uint[2] X;
        uint[2] Y;
    }

    /// @return the generator of G1
    function P1() public pure returns (G1Point memory) {
        return G1Point(1, 2);
    }
    
    /// @return the generator of G2
    function P2() public pure returns (G2Point memory) {
        return G2Point(
            [535000198726010842494463887012728317008839985956991949449597676023059784793,
            50911955057697873758342946860545764866265758828426205386527214348449976128083],

            [34456506622601912613857833514763279459301076221556609925761869949091594580415,
            8211078999328499834214571830542910221251497399640112479758011117184688730247]
        );
        
    }

    function EccMul(uint s) public view returns (G1Point memory r) {
        uint[3] memory input;
        input[0] = P1().X;
        input[1] = P1().Y;
        input[2] = s;

        assembly {
            if iszero (staticcall(gas(), 0x07, input, 0x60, r, 0x40)) {
                revert (0,0)
            }
        }
        return r;
    }
}

The code perfectly works with the given generator (where g1 = (1,2) ); however, EVM reverts when I change the generator to any other coordinates. Why is this the case? Whats the point of this if I can't use other generators then the one defined in EIP-197. Am I missing something?