Closed LFsWang closed 5 years ago
Required : https://github.com/second-state/lityvm/pull/4
Here is a simple test code
pragma lity ^1.2.6; contract A { function abs() public pure returns(bytes32) { string memory input = "AAAAAAAAAAAAAAAAAAAA"; // A*20 string memory tmp = eni("FUNC", input, input, input, input, input); return keccak256(abi.encodePacked(tmp)); } }
Old codegen will make 5 copy of input to pass eni. New implementation only save the location of the string in memory, it reduced many gas.
Example Code :
pragma lity ^1.2.6; contract A { function main(string memory dat) public returns(string memory) { string memory res = eni("reverse", dat); return res; } }
Old codegen
608060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063769f204d14610046575b600080fd5b34801561005257600080fd5b506100ad600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610128565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100ed5780820151818401526020810190506100d2565b50505050905090810190601f16801561011a5780820d805160018360200d6101000a0d1916815260200191505b509250505060405180910390f35b60608060405160206040519081016040526001905260206040519081016040527f6b00000000000000000000000000000000000000000000000000000000000000905260206040519081016040526001905260206040519081016040527f04000000000000000000000000000000000000000000000000000000000000009052602060405190810160405280600090528460206040519081016040525280604051819003602090039052907f7265766572736500000000000000000000000000000000000000000000000000f59050809150509190505600a165627a7a7230582094b0db605b4bec6d14258ee9131c37860f47689ed56e541acfc87f5d14ab4fd70029
New codegen
608060405260043610610041576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff168063769f204d14610046575b600080fd5b34801561005257600080fd5b506100ad600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610128565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100ed5780820151818401526020810190506100d2565b50505050905090810190601f16801561011a5780820d805160018360200d6101000a0d1916815260200191505b509250505060405180910390f35b60608060405160206040519081016040526001905260206040519081016040527f0400000000000000000000000000000000000000000000000000000000000000905260206040519081016040526001905260206040519081016040527f04000000000000000000000000000000000000000000000000000000000000009052602060405190810160405280600090528480516020019081601f0160209004602002604051908101604052905b6020831015156101fa57805182526020820191506020810190506020830392506101d5565b6001836020036101000a0d801982511681845116808217855250505050505080604051819003602090039052907f7265766572736500000000000000000000000000000000000000000000000000f59050809150509190505600a165627a7a72305820584657f957ff644a1b384e13f0ea6475debc60fc78c189378d047740429db49d0029
Test input :
string pattern : BCDE1234ABCDE1234.... ans so on
BCDE1234ABCDE1234
X1
0x769f204d000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000014100000000000000000000000000000000000000000000000000000000000000
X10
0x769f204d0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000a4142434445313233344100000000000000000000000000000000000000000000
X100
0x769f204d000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000644142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344100000000000000000000000000000000000000000000000000000000
X1000
0x769f204d000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000003e841424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441424344453132333441000000000000000000000000000000000000000000000000
X10000
0x769f204d000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000027104142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344142434445313233344100000000000000000000000000000000
@LFsWang Please refine your commit message like this format "[Component] Your feature/bugfix".
And have you tested this feature with the String Reverse or other examples?
LGTM
Required : https://github.com/second-state/lityvm/pull/4
Change
Examples
Here is a simple test code
Old codegen will make 5 copy of input to pass eni. New implementation only save the location of the string in memory, it reduced many gas.
gas used : ( from start to eni call )
ENI_Reverse Test
Example Code :
Old codegen
New codegen
Test input :
string pattern :
BCDE1234ABCDE1234
.... ans so onX1
X10
X100
X1000
X10000