Skip to content

Commit

Permalink
Merge pull request #294 from hyperledger-labs/use-ir-pipeline
Browse files Browse the repository at this point in the history
Enable build and tests utilizing IR pipeline in CI

Signed-off-by: Jun Kimura <[email protected]>
  • Loading branch information
bluele authored Aug 9, 2024
2 parents ee66e23 + 8dbbb6c commit 32c3918
Show file tree
Hide file tree
Showing 14 changed files with 256 additions and 213 deletions.
154 changes: 77 additions & 77 deletions .gas-snapshot
Original file line number Diff line number Diff line change
@@ -1,77 +1,77 @@
IBCBenchmarks:testAcknowledgePacket() (gas: 100109)
IBCBenchmarks:testCreateMockClient() (gas: 216843)
IBCBenchmarks:testRecvPacket() (gas: 158121)
IBCBenchmarks:testSendPacket() (gas: 96524)
IBCBenchmarks:testUpdateMockClientDirectly() (gas: 64815)
IBCBenchmarks:testUpdateMockClientViaHandler() (gas: 150703)
IBCMockAppTest:testHandshake() (gas: 4420576)
IBCMockAppTest:testHandshakeBetweenDifferentPorts() (gas: 3339603)
IBCMockAppTest:testPacketRelay() (gas: 13935831)
IBCMockAppTest:testPacketTimeout() (gas: 4284259)
ICS24HostTest:testValidatePortIdentifier() (gas: 37060)
TestICS02:testCreateClient() (gas: 36875161)
TestICS02:testHeightToUint128((uint64,uint64)) (runs: 256, μ: 887, ~: 887)
TestICS02:testInvalidCreateClient() (gas: 36772272)
TestICS02:testInvalidUpdateClient() (gas: 36771288)
TestICS02:testRegisterClient() (gas: 36426954)
TestICS02:testRegisterClientDuplicatedClientType() (gas: 36412263)
TestICS02:testRegisterClientInvalidClientType() (gas: 36441769)
TestICS02:testUpdateClient() (gas: 36939488)
TestICS03Handshake:testConnOpenAck() (gas: 1858230)
TestICS03Handshake:testConnOpenConfirm() (gas: 2054143)
TestICS03Handshake:testConnOpenInit() (gas: 1429838)
TestICS03Handshake:testConnOpenTry() (gas: 2398844)
TestICS03Handshake:testInvalidConnOpenAck() (gas: 2421822)
TestICS03Handshake:testInvalidConnOpenConfirm() (gas: 2535568)
TestICS03Handshake:testInvalidConnOpenInit() (gas: 783147)
TestICS03Handshake:testInvalidConnOpenTry() (gas: 2342543)
TestICS03Version:testCopyVersions() (gas: 558658)
TestICS03Version:testFindSupportedVersion() (gas: 19400)
TestICS03Version:testIsSupportedVersion() (gas: 7864)
TestICS03Version:testPickVersion() (gas: 25327)
TestICS03Version:testVerifyProposedVersion() (gas: 11777)
TestICS03Version:testVerifySupportedFeature() (gas: 4153)
TestICS04Handshake:testBindPort() (gas: 458623)
TestICS04Handshake:testChanClose() (gas: 12973942)
TestICS04Handshake:testChanOpenAck() (gas: 3459492)
TestICS04Handshake:testChanOpenConfirm() (gas: 3770761)
TestICS04Handshake:testChanOpenInit() (gas: 2543590)
TestICS04Handshake:testChanOpenTry() (gas: 3099942)
TestICS04Handshake:testInvalidChanOpenAck() (gas: 2439771)
TestICS04Handshake:testInvalidChanOpenConfirm() (gas: 2517382)
TestICS04Handshake:testInvalidChanOpenInit() (gas: 1760558)
TestICS04Handshake:testInvalidChanOpenTry() (gas: 1775528)
TestICS04Packet:testAcknowledgementPacket() (gas: 3351204)
TestICS04Packet:testInvalidSendPacket() (gas: 3579171)
TestICS04Packet:testRecvPacket() (gas: 11007558)
TestICS04Packet:testRecvPacketTimeoutHeight() (gas: 3259769)
TestICS04Packet:testRecvPacketTimeoutTimestamp() (gas: 3284145)
TestICS04Packet:testSendPacket() (gas: 6411842)
TestICS04Packet:testTimeoutOnClose() (gas: 3553375)
TestICS04Upgrade:testCrossingHelloInconsistentVersions() (gas: 10152794)
TestICS04Upgrade:testUpgradeAuthorityCancel() (gas: 47011316)
TestICS04Upgrade:testUpgradeCannotCancelWithOldErrorReceipt() (gas: 3460218)
TestICS04Upgrade:testUpgradeCannotRecvNextUpgradePacket() (gas: 5325143)
TestICS04Upgrade:testUpgradeCounterpartyAdvanceNextSequenceBeforeOpen() (gas: 5295126)
TestICS04Upgrade:testUpgradeCrossingHelloIncompatibleProposals() (gas: 5070497)
TestICS04Upgrade:testUpgradeFull() (gas: 57118740)
TestICS04Upgrade:testUpgradeInit() (gas: 3075843)
TestICS04Upgrade:testUpgradeNoChanges() (gas: 2473554)
TestICS04Upgrade:testUpgradeNotUpgradableModule() (gas: 3649002)
TestICS04Upgrade:testUpgradeOutOfSync() (gas: 3909083)
TestICS04Upgrade:testUpgradeRelaySuccessAtCounterpartyFlushComplete() (gas: 5296851)
TestICS04Upgrade:testUpgradeRelaySuccessAtFlushing() (gas: 5670614)
TestICS04Upgrade:testUpgradeSendPacketFailAtFlushingOrFlushComplete() (gas: 4089431)
TestICS04Upgrade:testUpgradeTimeoutAbortAck() (gas: 17829083)
TestICS04Upgrade:testUpgradeTimeoutAbortConfirm() (gas: 21547969)
TestICS04Upgrade:testUpgradeTimeoutUpgrade() (gas: 71726806)
TestICS04Upgrade:testUpgradeToOrdered() (gas: 56982472)
TestICS04Upgrade:testUpgradeToUnordered() (gas: 45498427)
TestICS04UpgradeApp:testUpgradeAuthorizationChanneNotFound() (gas: 61690)
TestICS04UpgradeApp:testUpgradeAuthorizationRePropose() (gas: 2565379)
TestICS04UpgradeApp:testUpgradeAuthorizationRemove() (gas: 2475938)
TestICS20:testAddressToHex(address) (runs: 256, μ: 22668, ~: 22804)
TestICS20:testHexToAddress(string) (runs: 256, μ: 4776, ~: 4734)
TestICS20:testIsEscapedString() (gas: 48979)
TestICS20:testMarshaling() (gas: 148517)
TestICS20:testParseAmount(uint256) (runs: 256, μ: 26349, ~: 23311)
IBCBenchmarks:testAcknowledgePacket() (gas: 98678)
IBCBenchmarks:testCreateMockClient() (gas: 217244)
IBCBenchmarks:testRecvPacket() (gas: 155487)
IBCBenchmarks:testSendPacket() (gas: 95329)
IBCBenchmarks:testUpdateMockClientDirectly() (gas: 64879)
IBCBenchmarks:testUpdateMockClientViaHandler() (gas: 148205)
IBCMockAppTest:testHandshake() (gas: 4343205)
IBCMockAppTest:testHandshakeBetweenDifferentPorts() (gas: 3286459)
IBCMockAppTest:testPacketRelay() (gas: 11692905)
IBCMockAppTest:testPacketTimeout() (gas: 4242242)
ICS24HostTest:testValidatePortIdentifier() (gas: 44476)
TestICS02:testCreateClient() (gas: 30153096)
TestICS02:testHeightToUint128((uint64,uint64)) (runs: 256, μ: 907, ~: 907)
TestICS02:testInvalidCreateClient() (gas: 30038762)
TestICS02:testInvalidUpdateClient() (gas: 30042040)
TestICS02:testRegisterClient() (gas: 29702122)
TestICS02:testRegisterClientDuplicatedClientType() (gas: 29688342)
TestICS02:testRegisterClientInvalidClientType() (gas: 29717304)
TestICS02:testUpdateClient() (gas: 30208564)
TestICS03Handshake:testConnOpenAck() (gas: 1811332)
TestICS03Handshake:testConnOpenConfirm() (gas: 1989221)
TestICS03Handshake:testConnOpenInit() (gas: 1423613)
TestICS03Handshake:testConnOpenTry() (gas: 2348126)
TestICS03Handshake:testInvalidConnOpenAck() (gas: 2323078)
TestICS03Handshake:testInvalidConnOpenConfirm() (gas: 2421885)
TestICS03Handshake:testInvalidConnOpenInit() (gas: 777600)
TestICS03Handshake:testInvalidConnOpenTry() (gas: 2283933)
TestICS03Version:testCopyVersions() (gas: 570207)
TestICS03Version:testFindSupportedVersion() (gas: 34452)
TestICS03Version:testIsSupportedVersion() (gas: 13568)
TestICS03Version:testPickVersion() (gas: 37836)
TestICS03Version:testVerifyProposedVersion() (gas: 21308)
TestICS03Version:testVerifySupportedFeature() (gas: 10229)
TestICS04Handshake:testBindPort() (gas: 456271)
TestICS04Handshake:testChanClose() (gas: 12800640)
TestICS04Handshake:testChanOpenAck() (gas: 3428597)
TestICS04Handshake:testChanOpenConfirm() (gas: 3724273)
TestICS04Handshake:testChanOpenInit() (gas: 2535741)
TestICS04Handshake:testChanOpenTry() (gas: 3083807)
TestICS04Handshake:testInvalidChanOpenAck() (gas: 2411670)
TestICS04Handshake:testInvalidChanOpenConfirm() (gas: 2486327)
TestICS04Handshake:testInvalidChanOpenInit() (gas: 1730517)
TestICS04Handshake:testInvalidChanOpenTry() (gas: 1742638)
TestICS04Packet:testAcknowledgementPacket() (gas: 3316365)
TestICS04Packet:testInvalidSendPacket() (gas: 3476451)
TestICS04Packet:testRecvPacket() (gas: 9965223)
TestICS04Packet:testRecvPacketTimeoutHeight() (gas: 3236945)
TestICS04Packet:testRecvPacketTimeoutTimestamp() (gas: 3261000)
TestICS04Packet:testSendPacket() (gas: 4583983)
TestICS04Packet:testTimeoutOnClose() (gas: 3488144)
TestICS04Upgrade:testCrossingHelloInconsistentVersions() (gas: 9918550)
TestICS04Upgrade:testUpgradeAuthorityCancel() (gas: 46157666)
TestICS04Upgrade:testUpgradeCannotCancelWithOldErrorReceipt() (gas: 3392338)
TestICS04Upgrade:testUpgradeCannotRecvNextUpgradePacket() (gas: 5230053)
TestICS04Upgrade:testUpgradeCounterpartyAdvanceNextSequenceBeforeOpen() (gas: 5191254)
TestICS04Upgrade:testUpgradeCrossingHelloIncompatibleProposals() (gas: 4944387)
TestICS04Upgrade:testUpgradeFull() (gas: 55984957)
TestICS04Upgrade:testUpgradeInit() (gas: 3018393)
TestICS04Upgrade:testUpgradeNoChanges() (gas: 2433786)
TestICS04Upgrade:testUpgradeNotUpgradableModule() (gas: 3533495)
TestICS04Upgrade:testUpgradeOutOfSync() (gas: 3826003)
TestICS04Upgrade:testUpgradeRelaySuccessAtCounterpartyFlushComplete() (gas: 5201982)
TestICS04Upgrade:testUpgradeRelaySuccessAtFlushing() (gas: 5575834)
TestICS04Upgrade:testUpgradeSendPacketFailAtFlushingOrFlushComplete() (gas: 4012928)
TestICS04Upgrade:testUpgradeTimeoutAbortAck() (gas: 17445807)
TestICS04Upgrade:testUpgradeTimeoutAbortConfirm() (gas: 21062598)
TestICS04Upgrade:testUpgradeTimeoutUpgrade() (gas: 70448064)
TestICS04Upgrade:testUpgradeToOrdered() (gas: 53937015)
TestICS04Upgrade:testUpgradeToUnordered() (gas: 43053273)
TestICS04UpgradeApp:testUpgradeAuthorizationChanneNotFound() (gas: 62062)
TestICS04UpgradeApp:testUpgradeAuthorizationRePropose() (gas: 2456047)
TestICS04UpgradeApp:testUpgradeAuthorizationRemove() (gas: 2436473)
TestICS20:testAddressToHex(address) (runs: 256, μ: 26850, ~: 27044)
TestICS20:testHexToAddress(string) (runs: 256, μ: 4636, ~: 4595)
TestICS20:testIsEscapedString() (gas: 62745)
TestICS20:testMarshaling() (gas: 180081)
TestICS20:testParseAmount(uint256) (runs: 256, μ: 32408, ~: 28568)
9 changes: 9 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ jobs:
with:
version: nightly

- name: Show forge version
run: forge --version

- name: Resolve dependencies
run: npm install

Expand All @@ -47,6 +50,12 @@ jobs:
- name: Run tests with minimal solidity version
run: make SOLC_VERSION=${{ env.MINIMAL_SOLC_VERSION }} test

- name: Build via IR-pipeline
run: make FOUNDRY_PROFILE=ir build

- name: Run snapshot tests via IR-pipeline
run: make FOUNDRY_PROFILE=ir snapshot

slither:
name: Slither analysis
needs: contract-test
Expand Down
36 changes: 22 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,37 +1,45 @@
FORGE ?= forge
SOLC_VERSION ?= 0.8.24
ABIGEN ?= "docker run -v .:/workspace -w /workspace -it ethereum/client-go:alltools-v1.11.6 abigen"
DOCKER_COMPOSE ?= docker compose
E2E_TEST_COMPOSE_FILE ?= ./chains/compose.yml
TEST_BROADCAST_LOG_DIR ?= ./broadcast/Deploy.s.sol
TEST_MNEMONIC ?= "math razor capable expose worth grape metal sunset metal sudden usage scheme"
FOUNDRY_PROFILE=default
FORGE=FOUNDRY_PROFILE=$(FOUNDRY_PROFILE) forge
SOLC_VERSION=0.8.24
DOCKER=docker
ABIGEN="$(DOCKER) run -v .:/workspace -w /workspace -it ethereum/client-go:alltools-v1.11.6 abigen"
SOLHINT=npx solhint
SLITHER=slither
DOCKER_COMPOSE=$(DOCKER) compose
E2E_TEST_COMPOSE_FILE=./chains/compose.yml
TEST_BROADCAST_LOG_DIR=./broadcast/Deploy.s.sol
TEST_MNEMONIC="math razor capable expose worth grape metal sunset metal sudden usage scheme"

######## Development ########

.PHONY: build
build:
@forge build --sizes --skip test --use solc:$(SOLC_VERSION)
$(FORGE) build --sizes --skip test --use solc:$(SOLC_VERSION)

.PHONY: fmt
fmt:
@$(FORGE) fmt $(FORGE_FMT_OPTS)
$(FORGE) fmt $(FORGE_FMT_OPTS)

.PHONY: lint
lint:
@npx solhint 'contracts/**/*.sol'
@$(SOLHINT) 'contracts/**/*.sol'
@$(MAKE) FORGE_FMT_OPTS=--check fmt

.PHONY: test
test:
@forge snapshot -vvvv --gas-report --isolate --use solc:$(SOLC_VERSION) $(FORGE_SNAPSHOT_OPTION)
$(FORGE) test -vvvv --gas-report --isolate --use solc:$(SOLC_VERSION) $(FORGE_SNAPSHOT_OPTION)

.PHONY: snapshot
snapshot:
$(FORGE) snapshot -vvvv --gas-report --isolate --use solc:$(SOLC_VERSION) $(FORGE_SNAPSHOT_OPTION)

.PHONY: coverage
coverage:
@forge coverage --use solc:$(SOLC_VERSION)
$(FORGE) coverage --use solc:$(SOLC_VERSION)

.PHONY: slither
slither:
@slither .
@$(SLITHER) .

######## Protobuf ########

Expand All @@ -48,7 +56,7 @@ proto-go:
ifndef SOLPB_DIR
$(error SOLPB_DIR is not specified)
else
docker run \
$(DOCKER) run \
-v $(CURDIR):/workspace \
-v $(SOLPB_DIR):/solpb \
-e SOLPB_DIR=/solpb \
Expand Down
5 changes: 2 additions & 3 deletions contracts/core/04-channel/IBCChannelPacketSendRecv.sol
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ contract IBCChannelPacketSendRecv is
*/
function recvPacket(MsgPacketRecv calldata msg_) public override {
Channel.Data storage channel = channels[msg_.packet.destinationPort][msg_.packet.destinationChannel];
if (channel.state == Channel.State.STATE_OPEN) {} else if (
channel.state == Channel.State.STATE_FLUSHING || channel.state == Channel.State.STATE_FLUSHCOMPLETE
) {
if (channel.state == Channel.State.STATE_OPEN) {}
else if (channel.state == Channel.State.STATE_FLUSHING || channel.state == Channel.State.STATE_FLUSHCOMPLETE) {
RecvStartSequence storage rseq =
recvStartSequences[msg_.packet.destinationPort][msg_.packet.destinationChannel];
// prevSequence=0 means the channel is not in the process of being upgraded or counterparty has not been upgraded yet
Expand Down
19 changes: 9 additions & 10 deletions contracts/core/24-host/IBCHostLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ library IBCHostLib {
unchecked {
for (uint256 i = 0; i < portIdLength; i++) {
uint256 c = uint256(uint8(portId[i]));
// return false if the character is not in one of the following categories:
// a-z
// 0-9
// A-Z
// ".", "_", "+", "-"
// "#", "[", "]", "<", ">"
if (
// a-z
!(c >= 0x61 && c <= 0x7A)
// 0-9
&& !(c >= 0x30 && c <= 0x39)
// A-Z
&& !(c >= 0x41 && c <= 0x5A)
// ".", "_", "+", "-"
&& !(c == 0x2E || c == 0x5F || c == 0x2B || c == 0x2D)
// "#", "[", "]", "<", ">"
&& !(c == 0x23 || c == 0x5B || c == 0x5D || c == 0x3C || c == 0x3E)
!(c >= 0x61 && c <= 0x7A) && !(c >= 0x30 && c <= 0x39) && !(c >= 0x41 && c <= 0x5A)
&& !(c == 0x2E || c == 0x5F || c == 0x2B || c == 0x2D)
&& !(c == 0x23 || c == 0x5B || c == 0x5D || c == 0x3C || c == 0x3E)
) {
return false;
}
Expand Down
21 changes: 19 additions & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,29 @@ test = 'tests/foundry/src'
gas_reports = ["*"]
optimizer = true
optimizer_runs = 9_999_999
via-ir = false

[fmt]
line_length = 120
tab_width = 4
bracket_spacing = false
int_types = "long"
multiline_func_header = "attributes_first"
quote_style = "double"
number_underscore = "preserve"
hex_underscore = "remove"
single_line_statement_blocks = "preserve"
override_spacing = false
wrap_comments = false
ignore = [
'./contracts/proto/**/*.sol',
'./tests/**/*.sol'
"./contracts/proto/**/*.sol",
"./tests/**/*.sol",
]
contract_new_lines = false
sort_imports = false

[profile.no_optimization]
optimizer = false

[profile.ir]
via-ir = true
6 changes: 3 additions & 3 deletions tests/foundry/src/IBCBenchmarks.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ contract IBCBenchmarks is IBCTestHelper {
})
),
protoConsensusState: wrapAnyMockConsensusState(
IbcLightclientsMockV1ConsensusState.Data({timestamp: uint64(block.timestamp * 1e9)})
IbcLightclientsMockV1ConsensusState.Data({timestamp: uint64(getBlockTimestampNano())})
)
});
vm.resumeGasMetering();
Expand All @@ -163,7 +163,7 @@ contract IBCBenchmarks is IBCTestHelper {
protoClientMessage: wrapAnyMockHeader(
IbcLightclientsMockV1Header.Data({
height: Height.Data({revision_number: 0, revision_height: nextRevisionHeight}),
timestamp: uint64(block.timestamp * 1e9)
timestamp: uint64(getBlockTimestampNano())
})
)
});
Expand All @@ -175,7 +175,7 @@ contract IBCBenchmarks is IBCTestHelper {
vm.pauseGasMetering();
IbcLightclientsMockV1Header.Data memory header = IbcLightclientsMockV1Header.Data({
height: Height.Data({revision_number: 0, revision_height: nextRevisionHeight}),
timestamp: uint64(block.timestamp * 1e9)
timestamp: uint64(getBlockTimestampNano())
});
vm.resumeGasMetering();
mockClient.updateClient(
Expand Down
4 changes: 2 additions & 2 deletions tests/foundry/src/IBCMockApp.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ contract IBCMockAppTest is IBCTestHelper, ICS04PacketEventTestHelper {
for (uint256 i = 0; i < orders.length; i++) {
(ChannelInfo memory channel0, ChannelInfo memory channel1) =
createMockAppChannel(orders[i], connId0, connId1);
Height.Data memory timeoutHeight = H(uint64(block.number + 1));
Height.Data memory timeoutHeight = H(uint64(getBlockNumber(1)));
mockApp.sendPacket(IBCMockLib.MOCK_PACKET_DATA, channel0.portId, channel0.channelId, timeoutHeight, 0);
Packet memory packet =
getLastSentPacket(ibcHandler, channel0.portId, channel0.channelId, vm.getRecordedLogs());
Expand Down Expand Up @@ -187,7 +187,7 @@ contract IBCMockAppTest is IBCTestHelper, ICS04PacketEventTestHelper {
function sendAndRelay(ChannelInfo memory ca, ChannelInfo memory cb, Channel.Order ordering, RelayCase memory rc)
private
{
uint64 sequence = mockApp.sendPacket(rc.packetData, ca.portId, ca.channelId, H(uint64(block.number + 1)), 0);
uint64 sequence = mockApp.sendPacket(rc.packetData, ca.portId, ca.channelId, H(uint64(getBlockNumber(1))), 0);
Packet memory packet = getLastSentPacket(ibcHandler, ca.portId, ca.channelId, vm.getRecordedLogs());
assertEq(packet.data, rc.packetData);
ibcHandler.recvPacket(
Expand Down
Loading

0 comments on commit 32c3918

Please sign in to comment.