Skip to content

Commit bc57d1a

Browse files
committed
base
1 parent 71bb0f5 commit bc57d1a

Some content is hidden

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

67 files changed

+1009
-1176
lines changed

docs/tests/AsyncToken.sol

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ contract AsyncTokenSender {
1616
Nil.FORWARD_REMAINING,
1717
0,
1818
tokens,
19-
""
19+
"",
20+
0,
21+
0
2022
);
2123
}
2224
}

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
@@ -144,7 +144,7 @@ func (c *cluster) generateZeroState(nShards uint32, servers []server) (*executio
144144
return nil, err
145145
}
146146

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

nil/common/check/check.go

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ 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+
// PanicIf panics on true
23+
func PanicIf(flag bool) {
24+
PanicIfNot(!flag)
25+
}
26+
2227
// PanicIfNot panics on false (use as simple assert).
2328
func PanicIfNot(flag bool) {
2429
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 --optimize && 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

+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
},
@@ -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/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

@@ -110,7 +112,7 @@ contract TokensTest is NilTokenBase {
110112
function testConsole() public pure {
111113
console.log("test console.log: int=%_, str=%_, addr=%_",
112114
1234567890,
113-
"Simple string",
115+
string("Simple string"),
114116
address(0xabcdef)
115117
);
116118
}
@@ -126,34 +128,11 @@ contract TokensTest is NilTokenBase {
126128
event tokenTxnBalance(uint256 balance);
127129

128130
function checkIncomingToken(TokenId id) public payable {
129-
emit tokenTxnBalance(Nil.txnTokens()[0].amount);
131+
Nil.Token[] memory tokens = Nil.txnTokens();
132+
require(tokens.length == 1, "Expected one token in transaction");
133+
emit tokenTxnBalance(tokens[0].amount);
130134
emit tokenBalance(Nil.tokenBalance(address(this), id));
131135
}
132136

133137
receive() external payable {}
134138
}
135-
136-
contract TokensTestNoExternalAccess is NilTokenBase {
137-
function setTokenName(string memory) public view override onlyExternal {
138-
revert("Not allowed");
139-
}
140-
141-
function mintToken(uint256) public view override onlyExternal {
142-
revert("Not allowed");
143-
}
144-
145-
function sendToken(
146-
address,
147-
TokenId,
148-
uint256
149-
) public view override onlyExternal {
150-
revert("Not allowed");
151-
}
152-
153-
function verifyExternal(
154-
uint256,
155-
bytes calldata
156-
) external pure returns (bool) {
157-
return true;
158-
}
159-
}

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)