In this work, we propose a novel sidechain structure via an optimized two-way peg protocol for device authentication in the smart community in order to overcome the limitations of existing approaches. The proposed scheme uses private side blockchains to distribute and manage the local registration and authentication processes, in addition to a local mainchain block to circulate the information record with other smart systems. More importantly, we propose the optimized two-way peg protocol in the proposed sidechain system in order to prevent the worthless information injection attack during the authentication information sharing procedure between the main chain and side blockchains. The optimized two-way peg protocol supervises the availability of the required information by dynamically evaluating the trustworthiness of each smart device. The evaluation is based on numerous criteria, such as the authentication method, previous authentication information sharing history, and local authentication results. Consequently, the simulation results prove the superiority of the proposed scheme in terms of reducing authentication time, improving information management efficiency and decreasing storage consumption as compared to existing works, and the applicability and feasibility of the optimized two-way peg protocol have been approved. It is noteworthy that the proposed sidechain-based method shows its superiority in reducing the cost of authentication time compared with the blockchain-based method when using blockchain structure. The reflected savings are 33.33%, 34.29%, and 36.36% when in comparison to the conventional authentication process without applying any additional method, the authentication process using the proposed sidechain based method, and the authentication process using the blockchain based method, respectively.