summaryrefslogtreecommitdiffstats
path: root/graphics/cogl/distinfo
blob: 4be332cfee87e0014b96ce7c927f461beba49718 (plain) (blame)
1
2
SHA256 (cogl-1.8.2.tar.xz) = ec26fd90c4ba5643875b5f3a04b4ab14b24f0d618ba3d239d61e773c3e3ca8c7
SIZE (cogl-1.8.2.tar.xz) = 1029304
1-23 19:22:33 +0800 Fix licensing headers' href='/~lantw44/cgit/dexon-solidity/commit/test/libsolidity/GasMeter.cpp?id=3f9f725737dd04485211fedc8533fdac983f2b04'>3f9f7257
60f335b4
3f9f7257
60f335b4



3f9f7257
60f335b4




3f9f7257
60f335b4






d6e39054
79f11974

ec76302b
e3dffb61


60f335b4



d83dd591
60f335b4







a226db73
60f335b4




075715cf

30012db3
05cc5f22
a844bbda
60f335b4
2ce35b77
039cc25b
60f335b4
964bcd6b
6ec45179
60f335b4



ec76302b
79f11974


6ec45179
ec76302b
2ce35b77
05e5bdf7
4d1c48ee
05e5bdf7
2ce35b77
05e5bdf7
79f11974
6ec45179
79f11974

964bcd6b

fbc331bd
ec76302b

05e5bdf7
aefb6e5f
ec76302b


334c023c
ec76302b
05e5bdf7
ec76302b

6ec45179
2ce35b77
964bcd6b

ec76302b
6ec45179
ec76302b

05e5bdf7

4d1c48ee
05e5bdf7
4d1c48ee
05e5bdf7


60f335b4
60f335b4









893f4cf0
60f335b4

7d7abeb1
60f335b4










1b5e6fc9
60f335b4

039cc25b
d7532f7b



60f335b4



79f11974





893f4cf0
86a720b9
79f11974





9e1c509c
79f11974



893f4cf0
86a720b9
79f11974











893f4cf0
79f11974








ec76302b





893f4cf0
ec76302b
















893f4cf0
ec76302b













964bcd6b





893f4cf0
964bcd6b




893f4cf0
964bcd6b








8387d0df



893f4cf0
8387d0df

893f4cf0
8387d0df




8387d0df
cee54deb
8387d0df

00b15d53



893f4cf0
00b15d53




cee54deb
00b15d53

7da9ba68



893f4cf0
7da9ba68









928ce088






eeef82b2
928ce088




bbae4fb0







893f4cf0
bbae4fb0






























60f335b4




1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
  
                                      
 
                                                                        



                                                                            
                                                                   




                                                                         
                                                                         






                                    
                                                        

                                 
                                   


                                                           



                              
                          







                  
                                                              




                                               

                                                                                   
                                                                                    
                                                       
                                                                                         
 
                                                                                                            
                                                               
                                                
                                                                 
                                                                                                                                                 



                                     
                                                           


                                                       
                                                                                                                                     
                                                                           
                                                                                                           
                                       
                                                              
                                        
                                                                                                          
 
                                               
                                                        

         

                                                                                                     
                                                                                

                                 
                                             
                                                        


                                                                          
                                                             
                                                          
                                                                                             

                 
                                                                                                 
                                                                                        

                            
                                               
                                                        

         

                                                                                               
                                                                                                     
                                   
                                                                                             


                           
          









                                                                      
                                                                    

                                                      
                                                    










                                                                                   
                                                                                           

                                                                                                   
                                                                                                                                                      



                                                                                            



                         





                                                                                                          
                                                   
                                                                          





                                        
                                     



                                                
                                                    
                                                                          











                                        
                                              








                                          





                                    
                                                   
















                                                                                  
                                                   













                                                                                  





                                                 
                                                   




                                                            
                                                                  








                                                                                  



                                    
                                                                  

                                                  
                                                                  




                                                    
                                                                   
                                                                   

 



                                    
                                                                                  




                                                 
                                                                                                 

 



                                     
                                                               









                                                               






                                                                          
                                                      




                                                           







                                                                                             
                                                                                   






























                                                                                                                       




                           
/*
    This file is part of solidity.

    solidity is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    solidity is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with solidity.  If not, see <http://www.gnu.org/licenses/>.
*/
/**
 * @author Christian <c@ethdev.com>
 * @date 2015
 * Unit tests for the gas estimator.
 */

#include <test/libsolidity/SolidityExecutionFramework.h>
#include <libevmasm/GasMeter.h>
#include <libevmasm/KnownState.h>
#include <libevmasm/PathGasMeter.h>
#include <libsolidity/ast/AST.h>
#include <libsolidity/interface/GasEstimator.h>
#include <libsolidity/interface/SourceReferenceFormatter.h>

using namespace std;
using namespace dev::eth;
using namespace dev::solidity;
using namespace dev::test;

namespace dev
{
namespace solidity
{
namespace test
{

class GasMeterTestFramework: public SolidityExecutionFramework
{
public:
    GasMeterTestFramework() { }
    void compile(string const& _sourceCode)
    {
        m_compiler.reset(false);
        m_compiler.addSource("", "pragma solidity >=0.0;\n" + _sourceCode);
        m_compiler.setOptimiserSettings(dev::test::Options::get().optimize);
        m_compiler.setEVMVersion(m_evmVersion);
        BOOST_REQUIRE_MESSAGE(m_compiler.compile(), "Compiling contract failed");

        AssemblyItems const* items = m_compiler.runtimeAssemblyItems(m_compiler.lastContractName());
        ASTNode const& sourceUnit = m_compiler.ast("");
        BOOST_REQUIRE(items != nullptr);
        m_gasCosts = GasEstimator::breakToStatementLevel(
            GasEstimator(dev::test::Options::get().evmVersion()).structuralEstimation(*items, vector<ASTNode const*>({&sourceUnit})),
            {&sourceUnit}
        );
    }

    void testCreationTimeGas(string const& _sourceCode)
    {
        compileAndRun(_sourceCode);
        auto state = make_shared<KnownState>();
        PathGasMeter meter(*m_compiler.assemblyItems(m_compiler.lastContractName()), dev::test::Options::get().evmVersion());
        GasMeter::GasConsumption gas = meter.estimateMax(0, state);
        u256 bytecodeSize(m_compiler.runtimeObject(m_compiler.lastContractName()).bytecode.size());
        // costs for deployment
        gas += bytecodeSize * GasCosts::createDataGas;
        // costs for transaction
        gas += gasForTransaction(m_compiler.object(m_compiler.lastContractName()).bytecode, true);

        BOOST_REQUIRE(!gas.isInfinite);
        BOOST_CHECK_EQUAL(gas.value, m_gasUsed);
    }

    /// Compares the gas computed by PathGasMeter for the given signature (but unknown arguments)
    /// against the actual gas usage computed by the VM on the given set of argument variants.
    void testRunTimeGas(string const& _sig, vector<bytes> _argumentVariants)
    {
        u256 gasUsed = 0;
        GasMeter::GasConsumption gas;
        FixedHash<4> hash(dev::keccak256(_sig));
        for (bytes const& arguments: _argumentVariants)
        {
            sendMessage(hash.asBytes() + arguments, false, 0);
            BOOST_CHECK(m_transactionSuccessful);
            gasUsed = max(gasUsed, m_gasUsed);
            gas = max(gas, gasForTransaction(hash.asBytes() + arguments, false));
        }

        gas += GasEstimator(dev::test::Options::get().evmVersion()).functionalEstimation(
            *m_compiler.runtimeAssemblyItems(m_compiler.lastContractName()),
            _sig
        );
        BOOST_REQUIRE(!gas.isInfinite);
        BOOST_CHECK_EQUAL(gas.value, m_gasUsed);
    }

    static GasMeter::GasConsumption gasForTransaction(bytes const& _data, bool _isCreation)
    {
        GasMeter::GasConsumption gas = _isCreation ? GasCosts::txCreateGas : GasCosts::txGas;
        for (auto i: _data)
            gas += i != 0 ? GasCosts::txDataNonZeroGas : GasCosts::txDataZeroGas;
        return gas;
    }

protected:
    map<ASTNode const*, eth::GasMeter::GasConsumption> m_gasCosts;
};

BOOST_FIXTURE_TEST_SUITE(GasMeterTests, GasMeterTestFramework)

BOOST_AUTO_TEST_CASE(non_overlapping_filtered_costs)
{
    char const* sourceCode = R"(
        contract test {
            bytes x;
            function f(uint a) public returns (uint b) {
                x.length = a;
                for (; a < 200; ++a) {
                    x[a] = 0x09;
                    b = a * a;
                }
                return f(a - 1);
            }
        }
    )";
    compile(sourceCode);
    for (auto first = m_gasCosts.cbegin(); first != m_gasCosts.cend(); ++first)
    {
        auto second = first;
        for (++second; second != m_gasCosts.cend(); ++second)
            if (first->first->location().intersects(second->first->location()))
            {
                BOOST_CHECK_MESSAGE(false, "Source locations should not overlap!");
                auto scannerFromSource = [&](string const& _sourceName) -> Scanner const& { return m_compiler.scanner(_sourceName); };
                SourceReferenceFormatter formatter(cout, scannerFromSource);

                formatter.printSourceLocation(&first->first->location());
                formatter.printSourceLocation(&second->first->location());
            }
    }
}

BOOST_AUTO_TEST_CASE(simple_contract)
{
    // Tests a simple "deploy contract" code without constructor. The actual contract is not relevant.
    char const* sourceCode = R"(
        contract test {
            bytes32 public shaValue;
            function f(uint a) public {
                shaValue = keccak256(abi.encodePacked(a));
            }
        }
    )";
    testCreationTimeGas(sourceCode);
}

BOOST_AUTO_TEST_CASE(store_keccak256)
{
    char const* sourceCode = R"(
        contract test {
            bytes32 public shaValue;
            constructor(uint a) public {
                shaValue = keccak256(abi.encodePacked(a));
            }
        }
    )";
    testCreationTimeGas(sourceCode);
}

BOOST_AUTO_TEST_CASE(updating_store)
{
    char const* sourceCode = R"(
        contract test {
            uint data;
            uint data2;
            constructor() public {
                data = 1;
                data = 2;
                data2 = 0;
            }
        }
    )";
    testCreationTimeGas(sourceCode);
}

BOOST_AUTO_TEST_CASE(branches)
{
    char const* sourceCode = R"(
        contract test {
            uint data;
            uint data2;
            function f(uint x) public {
                if (x > 7)
                    data2 = 1;
                else
                    data = 1;
            }
        }
    )";
    testCreationTimeGas(sourceCode);
    testRunTimeGas("f(uint256)", vector<bytes>{encodeArgs(2), encodeArgs(8)});
}

BOOST_AUTO_TEST_CASE(function_calls)
{
    char const* sourceCode = R"(
        contract test {
            uint data;
            uint data2;
            function f(uint x) public {
                if (x > 7)
                    data2 = g(x**8) + 1;
                else
                    data = 1;
            }
            function g(uint x) internal returns (uint) {
                return data2;
            }
        }
    )";
    testCreationTimeGas(sourceCode);
    testRunTimeGas("f(uint256)", vector<bytes>{encodeArgs(2), encodeArgs(8)});
}

BOOST_AUTO_TEST_CASE(multiple_external_functions)
{
    char const* sourceCode = R"(
        contract test {
            uint data;
            uint data2;
            function f(uint x) public {
                if (x > 7)
                    data2 = g(x**8) + 1;
                else
                    data = 1;
            }
            function g(uint x) public returns (uint) {
                return data2;
            }
        }
    )";
    testCreationTimeGas(sourceCode);
    testRunTimeGas("f(uint256)", vector<bytes>{encodeArgs(2), encodeArgs(8)});
    testRunTimeGas("g(uint256)", vector<bytes>{encodeArgs(2)});
}

BOOST_AUTO_TEST_CASE(exponent_size)
{
    char const* sourceCode = R"(
        contract A {
            function g(uint x) public returns (uint) {
                return x ** 0x100;
            }
            function h(uint x) public returns (uint) {
                return x ** 0x10000;
            }
        }
    )";
    testCreationTimeGas(sourceCode);
    testRunTimeGas("g(uint256)", vector<bytes>{encodeArgs(2)});
    testRunTimeGas("h(uint256)", vector<bytes>{encodeArgs(2)});
}

BOOST_AUTO_TEST_CASE(balance_gas)
{
    char const* sourceCode = R"(
        contract A {
            function lookup_balance(address a) public returns (uint) {
                return a.balance;
            }
        }
    )";
    testCreationTimeGas(sourceCode);
    testRunTimeGas("lookup_balance(address)", vector<bytes>{encodeArgs(2), encodeArgs(100)});
}

BOOST_AUTO_TEST_CASE(extcodesize_gas)
{
    char const* sourceCode = R"(
        contract A {
            function f() public returns (uint _s) {
                assembly {
                    _s := extcodesize(0x30)
                }
            }
        }
    )";
    testCreationTimeGas(sourceCode);
    testRunTimeGas("f()", vector<bytes>{encodeArgs()});
}

BOOST_AUTO_TEST_CASE(regular_functions_exclude_fallback)
{
    // A bug in the estimator caused the costs for a specific function
    // to always include the costs for the fallback.
    char const* sourceCode = R"(
        contract A {
            uint public x;
            function() external { x = 2; }
        }
    )";
    testCreationTimeGas(sourceCode);
    testRunTimeGas("x()", vector<bytes>{encodeArgs()});
}

BOOST_AUTO_TEST_CASE(complex_control_flow)
{
    // This crashed the gas estimator previously (or took a very long time).
    // Now we do not follow branches if they start out with lower gas costs than the ones
    // we previously considered. This of course reduces accuracy.
    char const* sourceCode = R"(
        contract log {
            function ln(int128 x) public pure returns (int128 result) {
                int128 t = x / 256;
                int128 y = 5545177;
                x = t;
                t = x * 16; if (t <= 1000000) { x = t; y = y - 2772588; }
                t = x * 4; if (t <= 1000000) { x = t; y = y - 1386294; }
                t = x * 2; if (t <= 1000000) { x = t; y = y - 693147; }
                t = x + x / 2; if (t <= 1000000) { x = t; y = y - 405465; }
                t = x + x / 4; if (t <= 1000000) { x = t; y = y - 223144; }
                t = x + x / 8; if (t <= 1000000) { x = t; y = y - 117783; }
                t = x + x / 16; if (t <= 1000000) { x = t; y = y - 60624; }
                t = x + x / 32; if (t <= 1000000) { x = t; y = y - 30771; }
                t = x + x / 64; if (t <= 1000000) { x = t; y = y - 15504; }
                t = x + x / 128; if (t <= 1000000) { x = t; y = y - 7782; }
                t = x + x / 256; if (t <= 1000000) { x = t; y = y - 3898; }
                t = x + x / 512; if (t <= 1000000) { x = t; y = y - 1951; }
                t = x + x / 1024; if (t <= 1000000) { x = t; y = y - 976; }
                t = x + x / 2048; if (t <= 1000000) { x = t; y = y - 488; }
                t = x + x / 4096; if (t <= 1000000) { x = t; y = y - 244; }
                t = x + x / 8192; if (t <= 1000000) { x = t; y = y - 122; }
                t = x + x / 16384; if (t <= 1000000) { x = t; y = y - 61; }
                t = x + x / 32768; if (t <= 1000000) { x = t; y = y - 31; }
                t = x + x / 65536; if (t <= 1000000) { y = y - 15; }
                return y;
            }
        }
    )";
    testCreationTimeGas(sourceCode);
    // max gas is used for small x
    testRunTimeGas("ln(int128)", vector<bytes>{encodeArgs(0), encodeArgs(10), encodeArgs(105), encodeArgs(30000)});
}

BOOST_AUTO_TEST_SUITE_END()

}
}
}