Skip to content

Commit fe34f37

Browse files
committed
tmp
1 parent 56463af commit fe34f37

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+886
-1298
lines changed

docs/tests/AsyncToken.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ contract AsyncTokenSender {
1616
Nil.FORWARD_REMAINING,
1717
0,
1818
tokens,
19-
""
19+
"", 0, 0
2020
);
2121
}
2222
}

docs/tests/FT.sol

+3-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ contract FT is NilTokenBase {
3636
Nil.FORWARD_REMAINING,
3737
0,
3838
ft,
39-
""
39+
"",
40+
0,
41+
0
4042
);
4143
}
4244

nil/client/direct_client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ func (c *DirectClient) SetTokenName(
348348
return common.EmptyHash, err
349349
}
350350

351-
return c.SendExternalTransaction(ctx, data, contractAddr, pk, types.NewFeePackFromGas(100_000))
351+
return c.SendExternalTransaction(ctx, data, contractAddr, pk, types.NewFeePackFromGas(500_000))
352352
}
353353

354354
func (c *DirectClient) ChangeTokenAmount(
@@ -367,7 +367,7 @@ func (c *DirectClient) ChangeTokenAmount(
367367
return common.EmptyHash, err
368368
}
369369

370-
return c.SendExternalTransaction(ctx, data, contractAddr, pk, types.NewFeePackFromGas(100_000))
370+
return c.SendExternalTransaction(ctx, data, contractAddr, pk, types.NewFeePackFromGas(500_000))
371371
}
372372

373373
func (c *DirectClient) DbInitTimestamp(ctx context.Context, ts uint64) error {

nil/client/rpc/client.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ func (c *Client) SetTokenName(
721721
return common.EmptyHash, err
722722
}
723723

724-
return c.SendExternalTransaction(ctx, data, contractAddr, pk, types.NewFeePackFromGas(100_000))
724+
return c.SendExternalTransaction(ctx, data, contractAddr, pk, types.NewFeePackFromGas(500_000))
725725
}
726726

727727
func (c *Client) ChangeTokenAmount(
@@ -740,7 +740,7 @@ func (c *Client) ChangeTokenAmount(
740740
return common.EmptyHash, err
741741
}
742742

743-
return c.SendExternalTransaction(ctx, data, contractAddr, pk, types.NewFeePackFromGas(100_000))
743+
return c.SendExternalTransaction(ctx, data, contractAddr, pk, types.NewFeePackFromGas(500_000))
744744
}
745745

746746
func callDbAPI[T any](ctx context.Context, c *Client, method string, params ...any) (T, error) {

nil/cmd/nil/internal/contract/call-readonly.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func GetCallReadonlyCommand(cfg *common.Config) *cobra.Command {
3434
"The path to the ABI file",
3535
)
3636

37-
params.Fee = types.NewFeePackFromGas(100_000)
37+
params.Fee = types.NewFeePackFromGas(500_000)
3838
cmd.Flags().Var(
3939
&params.Fee.FeeCredit,
4040
feeCreditFlag,

nil/cmd/nil/internal/debug/debug.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,7 @@ func (d *DebugHandler) PrintReceipt(receipt *ReceiptInfo, indentEntry, indent st
266266
fmt.Printf("%s%s\n", makeKey("CallData"), d.truncateData(96, receipt.Transaction.Data))
267267
}
268268
if len(receipt.Receipt.Logs) != 0 {
269-
fmt.Println(makeKey("Logs"))
270-
269+
fmt.Print(makeKey("Logs"))
271270
for i, log := range receipt.Receipt.Logs {
272271
if hasContract {
273272
if i == len(receipt.Receipt.Logs)-1 {

nil/cmd/nil/internal/smartaccount/call-readonly.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,12 @@ func runCallReadonly(cmd *cobra.Command, args []string, cfg *common.Config, para
122122
return nil, nil, err
123123
}
124124

125-
result, err := common.CalldataToArgs(contractAbi, args[1], res.OutTransactions[0].Data)
125+
data, err := contracts.UnpackRelayerResult(res.OutTransactions[0].Data)
126+
if err != nil {
127+
return nil, nil, err
128+
}
129+
130+
result, err := common.CalldataToArgs(contractAbi, args[1], data)
126131
if err != nil {
127132
return nil, nil, err
128133
}

nil/cmd/nil_block_generator/internal/commands/client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func CreateNewSmartAccount(rpcEndpoint string, logger logging.Logger) (string, s
115115

116116
salt := types.NewUint256(0)
117117
amount := types.NewValueFromUint64(2_000_000_000_000_000)
118-
fee := types.NewFeePackFromFeeCredit(types.NewValueFromUint64(200_000_000_000_000))
118+
fee := types.NewFeePackFromGas(2_000_000)
119119

120120
srv, err := CreateCliService(rpcEndpoint, hexKey, logger)
121121
if err != nil {

nil/cmd/nild/devnet.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func (c *cluster) generateZeroState(nShards uint32, servers []server) (*executio
143143
return nil, err
144144
}
145145

146-
zeroState, err := execution.CreateDefaultZeroStateConfig(mainPublicKey)
146+
zeroState, err := execution.CreateDefaultZeroStateConfig(mainPublicKey, int(nShards))
147147
if err != nil {
148148
return nil, err
149149
}

nil/common/check/check.go

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ import (
1919
// As a rule of thumb, if you wish to use the function with a custom message,
2020
// consider returning a wrapped error instead.
2121

22+
23+
// PanicIf panics on true
24+
func PanicIf(flag bool) {
25+
PanicIfNot(!flag)
26+
}
27+
2228
// PanicIfNot panics on false (use as simple assert).
2329
func PanicIfNot(flag bool) {
2430
if !flag {

nil/contracts/generate.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ package contracts
22

33
import "embed"
44

5-
//go:generate bash -c "solc ../../smart-contracts/contracts/*.sol --bin --abi --hashes --overwrite -o ./compiled --no-cbor-metadata --metadata-hash none"
6-
//go:generate bash -c "solc solidity/system/*.sol --bin --abi --hashes --overwrite -o ./compiled/system --allow-paths ./solidity/lib --no-cbor-metadata --metadata-hash none"
7-
//go:generate bash -c "solc solidity/tests/*.sol --allow-paths ../../ --base-path ../../ --bin --abi --hashes --overwrite -o ./compiled/tests --no-cbor-metadata --metadata-hash none"
8-
//go:generate bash -c "ln -nsf ../.. @nilfoundation && solc ../../uniswap/contracts/*.sol --bin --abi --overwrite -o ./compiled/uniswap --allow-paths .,../.. --via-ir && rm @nilfoundation"
5+
//go:generate bash -c "solc solidity/lib/*.sol --via-ir --optimize --bin --abi --hashes --overwrite -o ./compiled --no-cbor-metadata --metadata-hash none"
6+
//go:generate bash -c "solc solidity/system/*.sol --via-ir --optimize --bin --abi --hashes --overwrite -o ./compiled/system --allow-paths ./solidity/lib --no-cbor-metadata --metadata-hash none"
7+
//go:generate bash -c "solc solidity/tests/*.sol --via-ir --optimize --allow-paths ../../ --base-path ../../ --bin --abi --hashes --overwrite -o ./compiled/tests --no-cbor-metadata --metadata-hash none"
8+
//-go:generate bash -c "ln -nsf ../.. @nilfoundation && solc ../../uniswap/contracts/*.sol --bin --abi --overwrite -o ./compiled/uniswap --allow-paths .,../.. --via-ir && rm @nilfoundation"
99
//go:embed compiled/*
1010
var Fs embed.FS

nil/contracts/genlog.py

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def func_id_hex(self) -> str:
3535
Type(sol_name="uint256", go_name="Uint256Ty", modifier=""),
3636
Type(sol_name="bool", go_name="BoolTy", modifier=""),
3737
Type(sol_name="address", go_name="AddressTy", modifier=""),
38+
Type(sol_name="bytes", go_name="BytesTy", modifier="memory"),
3839
]
3940
STRING_TYPE = TYPES[0]
4041
MAX_PARAM_COUNT = 4

nil/contracts/solidity/compile-faucet.json

+13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"compilerVersion": "0.8.28",
44
"settings": {
55
"evmVersion": "cancun",
6+
"viaIR": true,
67
"optimizer": {
78
"enabled": false,
89
"runs": 200
@@ -20,6 +21,18 @@
2021
},
2122
"Nil.sol": {
2223
"urls": ["lib/Nil.sol"]
24+
},
25+
"Relayer.sol": {
26+
"urls": ["lib/Relayer.sol"]
27+
},
28+
"NilTokenManager.sol": {
29+
"urls": ["lib/NilTokenManager.sol"]
30+
},
31+
"IterableMapping.sol": {
32+
"urls": ["lib/IterableMapping.sol"]
33+
},
34+
"system/console.sol": {
35+
"urls": ["system/console.sol"]
2336
}
2437
}
2538
}

nil/contracts/solidity/compile-smart-account.json

+14-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
"compilerVersion": "0.8.28",
44
"settings": {
55
"evmVersion": "cancun",
6+
"viaIR": true,
67
"optimizer": {
7-
"enabled": false,
8+
"enabled": true,
89
"runs": 200
910
}
1011
},
@@ -17,6 +18,18 @@
1718
},
1819
"Nil.sol": {
1920
"urls": ["lib/Nil.sol"]
21+
},
22+
"Relayer.sol": {
23+
"urls": ["lib/Relayer.sol"]
24+
},
25+
"NilTokenManager.sol": {
26+
"urls": ["lib/NilTokenManager.sol"]
27+
},
28+
"IterableMapping.sol": {
29+
"urls": ["lib/IterableMapping.sol"]
30+
},
31+
"system/console.sol": {
32+
"urls": ["system/console.sol"]
2033
}
2134
}
2235
}

nil/tests/contracts/async_call.sol renamed to nil/contracts/solidity/tests/BounceTest.sol

+14-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// SPDX-License-Identifier: MIT
22
pragma solidity ^0.8.9;
33

4-
import "../../contracts/solidity/lib/Nil.sol";
4+
import "../lib/Nil.sol";
5+
import "../system/console.sol";
56

67
contract Callee {
78
int32 value;
@@ -16,7 +17,7 @@ contract Callee {
1617
}
1718
}
1819

19-
contract Caller is NilBounceable {
20+
contract BounceTest is NilBounceable {
2021
using Nil for address;
2122

2223
string last_bounce_err;
@@ -53,10 +54,17 @@ contract Caller is NilBounceable {
5354
return true;
5455
}
5556

56-
function bounce(
57-
string calldata err
58-
) external payable override onlyInternal {
59-
last_bounce_err = err;
57+
function bounce(bytes memory returnData) external payable override onlyInternal {
58+
console.log("BOUNCE RECEIVE: %_", returnData.length);
59+
if (returnData.length > 68) {
60+
assembly {
61+
returnData := add(returnData, 0x04)
62+
}
63+
last_bounce_err = abi.decode(returnData, (string));
64+
} else {
65+
last_bounce_err = "<no revert reason>";
66+
}
67+
console.log("BOUNCE MSG: %_", last_bounce_err);
6068
}
6169

6270
function get_bounce_err() public view returns (string memory) {

nil/contracts/solidity/tests/RequestResponseTest.sol

+1
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ contract RequestResponseTest is NilTokenBase, NilAwaitable {
251251
bytes memory /*returnData*/,
252252
bytes memory context
253253
) public payable {
254+
console.log("responseSendToken: success=%_", success);
254255
require(success, "Request should be successful");
255256
uint ctxValue = abi.decode(context, (uint));
256257
require(ctxValue == uint(11111), "Context value should be the same");

nil/contracts/solidity/tests/Stresser.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ contract Stresser is NilAwaitable {
3636
return value;
3737
}
3838

39-
// Consumes gas by using hot SSTORE(~529 gas per iteration)
39+
// Consumes gas by using hot SSTORE(~307 gas per iteration)
4040
function gasConsumer(uint256 v) public returns(uint256) {
4141
for (uint256 i = 1; i < v; i++) {
4242
value *= 2;

nil/contracts/solidity/tests/TokensTest.sol

+8-29
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ contract TokensTest is NilTokenBase {
4545
address(0),
4646
address(0),
4747
gas,
48-
Nil.FORWARD_NONE,
48+
Nil.FORWARD_REMAINING,
4949
0,
5050
tokens,
51-
callData
51+
callData,
52+
0,
53+
0
5254
);
5355
}
5456

@@ -95,7 +97,7 @@ contract TokensTest is NilTokenBase {
9597
function testConsole() public pure {
9698
console.log("test console.log: int=%_, str=%_, addr=%_",
9799
1234567890,
98-
"Simple string",
100+
string("Simple string"),
99101
address(0xabcdef)
100102
);
101103
}
@@ -111,34 +113,11 @@ contract TokensTest is NilTokenBase {
111113
event tokenTxnBalance(uint256 balance);
112114

113115
function checkIncomingToken(TokenId id) public payable {
114-
emit tokenTxnBalance(Nil.txnTokens()[0].amount); // TODO: [PoC] Tokens remove it
116+
Nil.Token[] memory tokens = Nil.txnTokens();
117+
require(tokens.length == 1, "Expected one token in transaction");
118+
emit tokenTxnBalance(tokens[0].amount);
115119
emit tokenBalance(Nil.tokenBalance(address(this), id));
116120
}
117121

118122
receive() external payable {}
119123
}
120-
121-
contract TokensTestNoExternalAccess is NilTokenBase {
122-
function setTokenName(string memory) public view override onlyExternal {
123-
revert("Not allowed");
124-
}
125-
126-
function mintToken(uint256) public view override onlyExternal {
127-
revert("Not allowed");
128-
}
129-
130-
function sendToken(
131-
address,
132-
TokenId,
133-
uint256
134-
) public view override onlyExternal {
135-
revert("Not allowed");
136-
}
137-
138-
function verifyExternal(
139-
uint256,
140-
bytes calldata
141-
) external pure returns (bool) {
142-
return true;
143-
}
144-
}

nil/contracts/solidity/tests/TransactionCheck.sol

-28
This file was deleted.

nil/contracts/solidity/tests/compile-test.json

+26-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
"compilerVersion": "0.8.28",
44
"settings": {
55
"evmVersion": "cancun",
6+
"viaIR": true,
67
"optimizer": {
7-
"enabled": false,
8+
"enabled": true,
89
"runs": 200
910
}
1011
},
@@ -15,8 +16,32 @@
1516
"lib/Nil.sol": {
1617
"urls": ["../lib/Nil.sol"]
1718
},
19+
"Nil.sol": {
20+
"urls": ["../lib/Nil.sol"]
21+
},
1822
"lib/NilAwaitable.sol": {
1923
"urls": ["../lib/NilAwaitable.sol"]
24+
},
25+
"Relayer.sol": {
26+
"urls": ["../lib/Relayer.sol"]
27+
},
28+
"lib/Relayer.sol": {
29+
"urls": ["../lib/Relayer.sol"]
30+
},
31+
"lib/NilTokenManager.sol": {
32+
"urls": ["../lib/NilTokenManager.sol"]
33+
},
34+
"NilTokenManager.sol": {
35+
"urls": ["../lib/NilTokenManager.sol"]
36+
},
37+
"lib/IterableMapping.sol": {
38+
"urls": ["../lib/IterableMapping.sol"]
39+
},
40+
"IterableMapping.sol": {
41+
"urls": ["../lib/IterableMapping.sol"]
42+
},
43+
"system/console.sol": {
44+
"urls": ["../system/console.sol"]
2045
}
2146
}
2247
}

0 commit comments

Comments
 (0)